Skip to content

Commit d860bdd

Browse files
authored
Merge pull request #44 from FantLab/FLGO-43
FLGO-43 protobuf
2 parents 410bdf0 + 3256601 commit d860bdd

31 files changed

+2328
-386
lines changed

.vscode/launch.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"program": "${workspaceRoot}/main.go",
1010
"env": {
1111
"MYSQL_CS": "root@/fl?charset=utf8&parseTime=True&loc=Local",
12-
"PORT": 4242
12+
"PORT": 4242,
13+
"GIN_MODE": "debug"
1314
},
1415
"args": [],
1516
"buildFlags": "-tags debug"
@@ -22,7 +23,8 @@
2223
"program": "${workspaceRoot}/main.go",
2324
"env": {
2425
"MYSQL_CS": "root@/fl?charset=utf8&parseTime=True&loc=Local",
25-
"PORT": 4242
26+
"PORT": 4242,
27+
"GIN_MODE": "release"
2628
},
2729
"args": []
2830
}

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@
1010
- Назначить reviewer-а
1111
- ...
1212
- PROFIT
13+
14+
# Protobuf
15+
16+
```
17+
cd protobuf
18+
19+
protoc --go_out=generated schema/*.proto
20+
```

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.12
44

55
require (
66
github.com/gin-gonic/gin v1.4.0
7+
github.com/golang/protobuf v1.3.1
78
github.com/jinzhu/gorm v1.9.8
89
github.com/segmentio/ksuid v1.0.2
910
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c

main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ func main() {
2929
db.SetLogger(logger.GormLogger)
3030
db.LogMode(true)
3131

32-
utils.SetupGinMode()
33-
3432
configuration := config.ParseConfig()
3533
services := &shared.Services{
3634
Config: configuration,

make_module.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fi
99

1010
cd modules
1111
mkdir -p $PACKAGE && cd $PACKAGE
12-
for FILE in datacontroller dbcontroller dbmodels models; do
12+
for FILE in datacontroller dbcontroller dbmodels; do
1313
if [ ! -f "$FILE.go" ]; then
1414
echo "package $PACKAGE" > "$FILE.go"
1515
fi

middlewares/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func Session(services *shared.Services) gin.HandlerFunc {
1212

1313
if len(sid) > 0 {
1414
type userID struct {
15-
Value int `gorm:"Column:user_id"`
15+
Value uint32 `gorm:"Column:user_id"`
1616
}
1717

1818
var uid userID

modules/authapi/api.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package authapi
22

33
import (
4+
"fantlab/protobuf/generated/fantlab/pb"
45
"fantlab/shared"
56
"fantlab/utils"
67
"net/http"
@@ -54,9 +55,10 @@ func (c *Controller) Login(ctx *gin.Context) {
5455
return
5556
}
5657

57-
session := session{
58-
UserId: userData.UserID,
59-
Session: sid,
58+
session := &pb.UserSessionResponse{
59+
UserId: userData.UserID,
60+
SessionToken: sid,
6061
}
61-
utils.ShowJson(ctx, http.StatusOK, session)
62+
63+
utils.ShowProto(ctx, http.StatusOK, session)
6264
}

modules/authapi/datacontroller.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

modules/authapi/models.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

modules/blogsapi/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewController(services *shared.Services) *Controller {
2222
func (c *Controller) ShowCommunities(ctx *gin.Context) {
2323
dbCommunities := fetchCommunities(c.services.DB)
2424
communities := getCommunities(dbCommunities)
25-
utils.ShowJson(ctx, http.StatusOK, communities)
25+
utils.ShowProto(ctx, http.StatusOK, communities)
2626
}
2727

2828
func (c *Controller) ShowBlogs(ctx *gin.Context) {
@@ -46,7 +46,7 @@ func (c *Controller) ShowBlogs(ctx *gin.Context) {
4646

4747
dbBlogs := fetchBlogs(c.services.DB, uint32(limit), uint32(offset), sort)
4848
blogs := getBlogs(dbBlogs)
49-
utils.ShowJson(ctx, http.StatusOK, blogs)
49+
utils.ShowProto(ctx, http.StatusOK, blogs)
5050
}
5151

5252
func (c *Controller) ShowBlogArticles(ctx *gin.Context) {
@@ -82,5 +82,5 @@ func (c *Controller) ShowBlogArticles(ctx *gin.Context) {
8282
}
8383

8484
articles := getBlogArticles(dbBlogTopics, c.services.UrlFormatter)
85-
utils.ShowJson(ctx, http.StatusOK, articles)
85+
utils.ShowProto(ctx, http.StatusOK, articles)
8686
}

0 commit comments

Comments
 (0)