Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ SRC_DIR=$(GOPATH)/src

.PHONY: proto
proto:
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/*.proto
#protoc-go-inject-tag -I ./proto -I ${GOPATH}/src --go_out=plugins=grpc: proto/${W}/${V}/*;
find proto/ -name '*.proto' -exec protoc --proto_path=$(PROTO_PATH) $(PROTO_FLAGS) --go_out=plugins=grpc:. {} \;


.PHONY: lint
lint:
golangci-lint run -v ./...
fix-lint:
goimports -w .
7 changes: 6 additions & 1 deletion pkg/response/actions/get_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ func NewGetGorm(m schema.Tabler, key string) *Get {
func (e *Get) getGorm(c *gin.Context, key string) {
api := response.Make(c)
m := pkg.TablerDeepCopy(e.ModelGorm)
err := gormdb.DB.First(m, "id = ?", c.Param(key)).Error
preloads := c.QueryArray("preloads[]")
query := gormdb.DB.Model(m).Where("id = ?", c.Param(key))
for _, preload := range preloads {
query = query.Preload(preload)
}
err := query.First(m).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
api.Err(http.StatusNotFound)
Expand Down
16 changes: 8 additions & 8 deletions pkg/response/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ func (e *response) OK(c *gin.Context, data interface{}) {
res := Default.Clone()
res.SetList(data)
res.SetTraceID(pkg.GenerateMsgIDFromContext(c))
status := http.StatusOK
switch c.Request.Method {
case http.MethodDelete:
res.SetCode(http.StatusNoContent)
c.AbortWithStatusJSON(http.StatusNoContent, data)
return
status = http.StatusNoContent
case http.MethodPost:
res.SetCode(http.StatusCreated)
c.AbortWithStatusJSON(http.StatusCreated, data)
status = http.StatusCreated
}
res.SetCode(status)
if data == nil {
c.AbortWithStatus(status)
return
default:
res.SetCode(http.StatusOK)
c.AbortWithStatusJSON(http.StatusOK, data)
}
c.AbortWithStatusJSON(status, data)
}

// PageOK page ok
Expand Down