From ab78141e7d26c695d425e5955e265b04dd389eeb Mon Sep 17 00:00:00 2001 From: liuhaotian Date: Wed, 19 Jan 2022 19:39:04 +0800 Subject: [PATCH] feat : --- .idea/.gitignore | 8 + .idea/backend.iml | 9 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .../api/murder/internal/handler/scripts_h.go | 86 +++- app/brahma/api/murder/internal/pkg/ctx.go | 21 + app/brahma/api/murder/main.go | 6 +- app/brahma/service/murder/main.go | 72 +++- .../service/token/internal/model/script.go | 51 +++ .../token/internal/pkg/concurrent_worker.go | 72 ++++ .../service/token/internal/pkg/query.go | 1 + .../service/token/internal/server/rpc.go | 31 -- .../service/token/internal/server/script.go | 53 +++ .../service/token/internal/server/server.go | 24 ++ .../service/token/internal/server/tag.go | 1 + app/brahma/service/token/main.go | 5 +- go.mod | 2 +- go.sum | 45 +-- pkg/api/fiber.go | 3 +- pkg/etcd/etcd.go | 5 +- pkg/orm/trrace.go | 94 +++++ pkg/proto/brahma/murder/hello.pb.go | 266 ++++++------ pkg/proto/brahma/murder/hello.proto | 22 +- pkg/proto/brahma/murder/hello_grpc.pb.go | 40 +- pkg/proto/brahma/murder/name.pb.go | 145 +++++++ pkg/proto/brahma/murder/name.proto | 8 + pkg/proto/brahma/murder/service.proto | 14 + pkg/proto/brahma/murders/script/script.pb.go | 377 ++++++++++++++++++ pkg/proto/brahma/murders/script/script.proto | 27 ++ pkg/proto/brahma/murders/service.pb.go | 184 +++++++++ pkg/proto/brahma/murders/service.proto | 14 + pkg/proto/brahma/murders/service_grpc.pb.go | 106 +++++ pkg/proto/brahma/murders/tag/tag.pb.go | 265 ++++++++++++ pkg/proto/brahma/murders/tag/tag.proto | 17 + pkg/rpc/middle_ware.go | 37 ++ pkg/time/time.go | 25 ++ 36 files changed, 1939 insertions(+), 211 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/backend.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 app/brahma/api/murder/internal/pkg/ctx.go create mode 100644 app/brahma/service/token/internal/model/script.go create mode 100644 app/brahma/service/token/internal/pkg/concurrent_worker.go create mode 100644 app/brahma/service/token/internal/pkg/query.go delete mode 100644 app/brahma/service/token/internal/server/rpc.go create mode 100644 app/brahma/service/token/internal/server/script.go create mode 100644 app/brahma/service/token/internal/server/server.go create mode 100644 app/brahma/service/token/internal/server/tag.go create mode 100644 pkg/orm/trrace.go create mode 100644 pkg/proto/brahma/murder/name.pb.go create mode 100644 pkg/proto/brahma/murder/name.proto create mode 100644 pkg/proto/brahma/murder/service.proto create mode 100644 pkg/proto/brahma/murders/script/script.pb.go create mode 100644 pkg/proto/brahma/murders/script/script.proto create mode 100644 pkg/proto/brahma/murders/service.pb.go create mode 100644 pkg/proto/brahma/murders/service.proto create mode 100644 pkg/proto/brahma/murders/service_grpc.pb.go create mode 100644 pkg/proto/brahma/murders/tag/tag.pb.go create mode 100644 pkg/proto/brahma/murders/tag/tag.proto create mode 100644 pkg/rpc/middle_ware.go create mode 100644 pkg/time/time.go diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/backend.iml b/.idea/backend.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/backend.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e066844 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/brahma/api/murder/internal/handler/scripts_h.go b/app/brahma/api/murder/internal/handler/scripts_h.go index 811b7ce..1b59640 100644 --- a/app/brahma/api/murder/internal/handler/scripts_h.go +++ b/app/brahma/api/murder/internal/handler/scripts_h.go @@ -4,11 +4,24 @@ import ( "fmt" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/error_process" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/model" + "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/pkg" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/service" + "git.icechen.cn/monorepo/backend/pkg/api" + "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders" + "github.com/go-playground/validator/v10" "github.com/gofiber/fiber/v2" ctxLogger "github.com/luizsuper/ctxLoggers" + "github.com/pkg/errors" "go.uber.org/zap" + "google.golang.org/grpc" + "log" "strconv" + "time" +) + +var ( + pageIsNotInt = api.WarpFError(errors.New("page 参数错误")) + limitIsNotInt = api.WarpFError(errors.New("limit 参数错误")) ) func GetScriptsH(ctx *fiber.Ctx) error { @@ -76,23 +89,56 @@ func DeleteScriptsH(ctx *fiber.Ctx) error { return ctx.JSON(success(nil)) } -//func HelloWorld() error { -// // Set up a connection to the server. -// conn, err := grpc.Dial("localhost:3000", grpc.WithInsecure(), grpc.WithBlock()) -// if err != nil { -// log.Fatalf("did not connect: %v", err) -// } -// defer conn.Close() -// c := murder.NewHelloWorldClient(conn) -// -// // Contact the server and print out its response. -// ctx, cancel := context.WithTimeout(context.Background(), time.Second) -// defer cancel() -// r, err := c.Login(ctx, &murder.HelloRequest{Code: "lht"}) -// -// if err != nil { -// log.Fatalf("could not greet: %v", err) -// } -// log.Printf("Greeting: %s", r.Token) -// return nil -//} +func GetScriptApi(ctx *fiber.Ctx) error { + //todo:调通中间层 + //todo:换成服务 + conn, err := grpc.Dial("localhost:3000", grpc.WithInsecure(), grpc.WithBlock()) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + + outgoingContext, cancelFunc := pkg.TransFiberCtx2NewOutgoingContext(ctx, 3*time.Second) + defer conn.Close() + defer cancelFunc() + c := murders.NewMurdersClient(conn) + + page := ctx.Query("page", "1") + limit := ctx.Query("size", "10") + p, err := strconv.Atoi(page) + if err != nil { + ctxLogger.Error(ctx.UserContext(), pageIsNotInt.Error(), zap.String("page", page)) + return pageIsNotInt + } + l, err := strconv.Atoi(limit) + if err != nil { + ctxLogger.Error(ctx.UserContext(), limitIsNotInt.Error(), zap.String("limit", limit)) + return pageIsNotInt + } + + validate := validator.New() + err = validate.Var(p, "gte=0") + if err != nil { + ctxLogger.Error(ctx.UserContext(), limitIsNotInt.Error(), zap.String("limit", limit)) + return api.WarpFError(err) + } + err = validate.Var(l, "gte=-1") + if err != nil { + ctxLogger.Error(ctx.UserContext(), limitIsNotInt.Error(), zap.String("limit", limit)) + return api.WarpFError(err) + } + + p64 := int64(p) + l64 := int64(l) + condition := murders.QueryCondition{ + Page: &p64, + Size: &l64, + QueryMap: nil, + } + + scripts, err := c.GetScripts(outgoingContext, &condition) + if err != nil { + return api.WarpFError(err) + } + + return ctx.JSON(scripts) +} diff --git a/app/brahma/api/murder/internal/pkg/ctx.go b/app/brahma/api/murder/internal/pkg/ctx.go new file mode 100644 index 0000000..893b5b2 --- /dev/null +++ b/app/brahma/api/murder/internal/pkg/ctx.go @@ -0,0 +1,21 @@ +package pkg + +import ( + "context" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/utils" + "google.golang.org/grpc/metadata" + "time" +) + +func TransFiberCtx2NewOutgoingContext(fCtx *fiber.Ctx, time time.Duration) (context.Context, context.CancelFunc) { + ctx := fCtx.UserContext() + md := metadata.MD{} + if value, ok := ctx.Value(fiber.HeaderXRequestID).(string); ok { + md = metadata.Pairs(fiber.HeaderXRequestID, value) + } else { + md = metadata.Pairs(fiber.HeaderXRequestID, utils.UUIDv4()) + } + //3s 过期超时 + return context.WithTimeout(metadata.NewOutgoingContext(ctx, md), time) +} diff --git a/app/brahma/api/murder/main.go b/app/brahma/api/murder/main.go index 9ca558c..ec37619 100755 --- a/app/brahma/api/murder/main.go +++ b/app/brahma/api/murder/main.go @@ -19,7 +19,7 @@ const ( tag = "/tag" category = "/category" scripts = "/scripts" - hello = "/hello" + script = "/script" ) var ( @@ -110,6 +110,10 @@ func routerInit() { scriptsGroup.Delete("", func(ctx *fiber.Ctx) error { return handler.DeleteScriptsH(ctx) }) + scriptGroup := app.Group(script) + scriptGroup.Get("", func(ctx *fiber.Ctx) error { + return handler.GetScriptApi(ctx) + }) } diff --git a/app/brahma/service/murder/main.go b/app/brahma/service/murder/main.go index 21ec4e8..6251423 100755 --- a/app/brahma/service/murder/main.go +++ b/app/brahma/service/murder/main.go @@ -1,7 +1,75 @@ package main -import "fmt" +import ( + "bytes" + "fmt" + "go.dedis.ch/protobuf" +) + +type QueryCondition struct { + Page *int + Size *int + QueryMap map[string]string +} + +type ( + ints []int + strs []string + scripts []Script +) + +type Script struct { + ScriptName string `json:"script_name" gorm:"column:script_name"` + ScriptIntro string `json:"script_intro" gorm:"column:script_intro"` + ScriptTag ints `json:"script_tag" gorm:"column:script_tag"` + ScriptScore float64 `json:"script_score" gorm:"column:script_score"` + GroupDuration int `json:"group_duration" gorm:"column:group_duration"` + ScriptCoverUrl string `json:"script_cover_url" gorm:"column:script_cover_url"` + ScriptTextContext string `json:"script_text_context" gorm:"column:script_text_context"` + ScriptPlotScore float64 `json:"script_plot_score" gorm:"column:script_plot_score"` + ScriptImageContent strs `json:"script_image_content" gorm:"column:script_image_content"` + ScriptMalePlayer int `json:"script_male_player" gorm:"column:script_male_player"` + ScriptFemalePlayer int `json:"script_female_player" gorm:"column:script_female_player"` + ScriptDifficultDegree string `json:"script_difficult_degree" gorm:"column:script_difficult_degree"` + ScriptPlayerLimit int `json:"script_player_limit" gorm:"column:script_player_limit"` + Uuid string `json:"uuid" gorm:"column:uuid" valid:"no_empty"` + ScriptComplexScore float64 `json:"script_complex_score" gorm:"column:script_complex_score"` + Qid string `json:"qid" gorm:"column:qid"` + IsDel int `json:"-" gorm:"column:is_del"` +} + +type Scripts struct { + Scripts scripts `json:"scripts" ` +} + +type ( + Tag struct { + Value string `json:"value" gorm:"column:value"` + Uuid int `json:"uuid" gorm:"primary_key" valid:"no_empty"` + IsDel int `json:"-" gorm:"column:is_del" value:"1|0"` + Cs []Category `json:"categories,omitempty" gorm:"many2many:c_tag;foreignKey:Uuid;joinForeignKey:TagUid;References:Uuid;JoinReferences:CategoryUid" valid:"no_empty"` + } +) + +type ( + Category struct { + Value string `json:"value" gorm:"column:value"` + Uuid string `json:"uuid" gorm:"primary_key" valid:"no_empty"` + IsDel int `json:"-" gorm:"column:is_del"` + Tags []Tag `json:"tags,omitempty" gorm:"many2many:c_tag;foreignKey:Uuid;joinForeignKey:CategoryUid;References:Uuid;JoinReferences:TagUid" valid:"no_empty"` + } +) func main() { - fmt.Println("我是个示例") + w := &bytes.Buffer{} + types := []interface{}{ + Tag{}, + Category{}, + } + err := protobuf.GenerateProtobufDefinition(w, types, nil, nil) + if err != nil { + fmt.Println(err) + } + fmt.Println(w.String()) + } diff --git a/app/brahma/service/token/internal/model/script.go b/app/brahma/service/token/internal/model/script.go new file mode 100644 index 0000000..ce5c2fc --- /dev/null +++ b/app/brahma/service/token/internal/model/script.go @@ -0,0 +1,51 @@ +package model + +import ( + "database/sql/driver" + "encoding/json" +) + +type ( + ints []int + strs []string +) + +type Scripts struct { + ScriptName string `json:"script_name" gorm:"column:script_name"` + ScriptIntro string `json:"script_intro" gorm:"column:script_intro"` + ScriptTag ints `json:"script_tag" gorm:"column:script_tag"` + ScriptScore float64 `json:"script_score" gorm:"column:script_score"` + GroupDuration int `json:"group_duration" gorm:"column:group_duration"` + ScriptCoverUrl string `json:"script_cover_url" gorm:"column:script_cover_url"` + ScriptTextContext string `json:"script_text_context" gorm:"column:script_text_context"` + ScriptPlotScore float64 `json:"script_plot_score" gorm:"column:script_plot_score"` + ScriptImageContent strs `json:"script_image_content" gorm:"column:script_image_content"` + ScriptMalePlayer int `json:"script_male_player" gorm:"column:script_male_player"` + ScriptFemalePlayer int `json:"script_female_player" gorm:"column:script_female_player"` + ScriptDifficultDegree string `json:"script_difficult_degree" gorm:"column:script_difficult_degree"` + ScriptPlayerLimit int `json:"script_player_limit" gorm:"column:script_player_limit"` + Uuid string `json:"uuid" gorm:"column:uuid" valid:"no_empty"` + ScriptComplexScore float64 `json:"script_complex_score" gorm:"column:script_complex_score"` + Qid string `json:"qid" gorm:"column:qid"` + IsDel int `json:"-" gorm:"column:is_del"` +} + +func (m *Scripts) TableName() string { + return "scripts" +} + +func (p ints) Value() (driver.Value, error) { + return json.Marshal(p) +} + +func (p *ints) Scan(input interface{}) error { + return json.Unmarshal(input.([]byte), &p) +} + +func (p strs) Value() (driver.Value, error) { + return json.Marshal(p) +} + +func (p *strs) Scan(input interface{}) error { + return json.Unmarshal(input.([]byte), &p) +} diff --git a/app/brahma/service/token/internal/pkg/concurrent_worker.go b/app/brahma/service/token/internal/pkg/concurrent_worker.go new file mode 100644 index 0000000..27eb853 --- /dev/null +++ b/app/brahma/service/token/internal/pkg/concurrent_worker.go @@ -0,0 +1,72 @@ +package pkg + +import ( + "context" + "github.com/pkg/errors" + "time" +) + +type Finish struct { + IsDone bool + Err error +} + +type Worker interface { + Work(ctx context.Context, finishChan chan<- Finish) +} + +type WorkerInterFace struct { +} + +func (w WorkerInterFace) Work(ctx context.Context, finishChan chan<- Finish) { + panic("implement me") +} + +func Run(timeout time.Duration, ctx context.Context, workers ...Worker) error { + cancel, cancelFunc := context.WithTimeout(ctx, timeout) + finishSignal := make(chan Finish) + errs := make([]error, 0) + defer cancelFunc() + for _, worker := range workers { + go worker.Work(cancel, finishSignal) + } + for i := 0; i < len(workers); i++ { + if f := <-finishSignal; !f.IsDone { + errs = append(errs, f.Err) + if len(errs) == 1 { + cancelFunc() + } + } + } + close(finishSignal) + if len(errs) != 0 { + return errs[0] + } + return nil +} + +func SafeSend(ch chan<- Finish, value Finish) { + defer func() { + if recover() != nil { + + } + }() + ch <- value // panic if ch is closed +} + +func Watcher(ctx context.Context, ch chan<- Finish) { + go func() { + loop: + for { + select { + //无论主动还是被动推出。总会 + case <-ctx.Done(): + SafeSend(ch, Finish{ + IsDone: false, + Err: errors.New(""), + }) + break loop + } + } + }() +} diff --git a/app/brahma/service/token/internal/pkg/query.go b/app/brahma/service/token/internal/pkg/query.go new file mode 100644 index 0000000..c1caffe --- /dev/null +++ b/app/brahma/service/token/internal/pkg/query.go @@ -0,0 +1 @@ +package pkg diff --git a/app/brahma/service/token/internal/server/rpc.go b/app/brahma/service/token/internal/server/rpc.go deleted file mode 100644 index 35f6633..0000000 --- a/app/brahma/service/token/internal/server/rpc.go +++ /dev/null @@ -1,31 +0,0 @@ -package servesr - -import ( - "context" - "fmt" - "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murder" - "google.golang.org/grpc" - "log" - "net" -) - -type helloRequet struct { - murder.UnimplementedHelloWorldServer -} - -func (helloRequet) Login(ctx context.Context, name *murder.HelloRequest) (*murder.HelloResponse, error) { - return &murder.HelloResponse{Token: name.Code}, nil -} - -func RpcServer() { - lis, err := net.Listen("tcp", ":3000") - if err != nil { - log.Fatalf("failed to listen: %v", err) - } - s := grpc.NewServer() - murder.RegisterHelloWorldServer(s, &helloRequet{}) - fmt.Println("lark server run in :3000") - if err := s.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) - } -} diff --git a/app/brahma/service/token/internal/server/script.go b/app/brahma/service/token/internal/server/script.go new file mode 100644 index 0000000..8372b54 --- /dev/null +++ b/app/brahma/service/token/internal/server/script.go @@ -0,0 +1,53 @@ +package servesr + +import ( + "context" + "errors" + "git.icechen.cn/monorepo/backend/app/brahma/service/token/internal/model" + "git.icechen.cn/monorepo/backend/app/brahma/service/token/internal/pkg" + "git.icechen.cn/monorepo/backend/pkg/orm" + "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders" + "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/script" + "time" +) + +type Script struct { + murders.UnimplementedMurdersServer + pkg.WorkerInterFace + queryMap *murders.QueryCondition + scriptModel *[]model.Scripts +} + +func (s *Script) GetScripts(ctx context.Context, queryMap *murders.QueryCondition) (*script.Scripts, error) { + s.queryMap = queryMap + err := pkg.Run(1*time.Second, ctx, s) + if err != nil { + return nil, err + } + return nil, err +} + +func (s *Script) Work(ctx context.Context, finishChan chan<- pkg.Finish) { + go pkg.Watcher(ctx, finishChan) + db, err := orm.GetContextDB(ctx, orm.DB) + if err != nil { + pkg.SafeSend(finishChan, pkg.Finish{ + IsDone: false, + Err: err, + }) + } + + i := new([]model.Scripts) + if num := db.Find(i).RowsAffected; num < 0 { + pkg.SafeSend(finishChan, pkg.Finish{ + IsDone: false, + Err: errors.New("RowsAffected < 0"), + }) + } + + s.scriptModel = i + pkg.SafeSend(finishChan, pkg.Finish{ + IsDone: true, + Err: nil, + }) +} diff --git a/app/brahma/service/token/internal/server/server.go b/app/brahma/service/token/internal/server/server.go new file mode 100644 index 0000000..c469136 --- /dev/null +++ b/app/brahma/service/token/internal/server/server.go @@ -0,0 +1,24 @@ +package servesr + +import ( + "fmt" + "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders" + "git.icechen.cn/monorepo/backend/pkg/rpc" + ctxLogger "github.com/luizsuper/ctxLoggers" + "go.uber.org/zap" + "google.golang.org/grpc" + "net" +) + +func RpcServer() { + lis, err := net.Listen("tcp", ":3000") + if err != nil { + ctxLogger.Info(nil, "brahma server start up error", zap.String("error", err.Error())) + } + s := grpc.NewServer(grpc.UnaryInterceptor(rpc.Interceptor)) + murders.RegisterMurdersServer(s, &Script{}) + fmt.Println("lark server run in :3000") + if err := s.Serve(lis); err != nil { + ctxLogger.Info(nil, "brahma server start up error", zap.String("error", err.Error())) + } +} diff --git a/app/brahma/service/token/internal/server/tag.go b/app/brahma/service/token/internal/server/tag.go new file mode 100644 index 0000000..05a7892 --- /dev/null +++ b/app/brahma/service/token/internal/server/tag.go @@ -0,0 +1 @@ +package servesr diff --git a/app/brahma/service/token/main.go b/app/brahma/service/token/main.go index 0024d32..23015a1 100755 --- a/app/brahma/service/token/main.go +++ b/app/brahma/service/token/main.go @@ -1,9 +1,8 @@ package main -import ( - servesr "git.icechen.cn/monorepo/backend/app/brahma/service/token/internal/server" -) +import servesr "git.icechen.cn/monorepo/backend/app/brahma/service/token/internal/server" func main() { servesr.RpcServer() + } diff --git a/go.mod b/go.mod index 0575834..512b7f9 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/google/uuid v1.1.2 github.com/jinzhu/copier v0.3.4 github.com/larksuite/oapi-sdk-go v1.1.43 - github.com/luizsuper/ctxLoggers v1.0.3 + github.com/luizsuper/ctxLoggers v1.0.4 github.com/pkg/errors v0.9.1 github.com/spf13/cast v1.4.1 go.etcd.io/etcd/client/v3 v3.5.1 diff --git a/go.sum b/go.sum index 8b7db33..5307689 100644 --- a/go.sum +++ b/go.sum @@ -28,7 +28,6 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -57,16 +56,13 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= -github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-redis/redis/v8 v8.2.2/go.mod h1:ysgGY09J/QeDYbu3HikWEIPCwaeOkuNoTgKayTEaEOw= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= @@ -136,14 +132,11 @@ github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/larksuite/oapi-sdk-go v1.1.43 h1:DVUAbiYOfE+1yPyTKYofxcEpB027nhq9Lfk2DaLX960= github.com/larksuite/oapi-sdk-go v1.1.43/go.mod h1:7ybKAbVdKBjXuX0YrMTfnWUyCaIe/zeI1wqjNfN9XOk= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= @@ -155,8 +148,8 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkL github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= github.com/lestrrat-go/strftime v1.0.5 h1:A7H3tT8DhTz8u65w+JRpiBxM4dINQhUXAZnhBa2xeOE= github.com/lestrrat-go/strftime v1.0.5/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g= -github.com/luizsuper/ctxLoggers v1.0.3 h1:u7YGzxhXb2uHm2sJxoO70xfpHz97PC7wIsmsX43Auzc= -github.com/luizsuper/ctxLoggers v1.0.3/go.mod h1:wjnYowzWZwBJ7eWVwtcZN9Vbb4DdW8VHKSXzCvsdjIo= +github.com/luizsuper/ctxLoggers v1.0.4 h1:0RQiu7/yBgwA3okueOb4C4ltxbbhZHcrBXewwHjUCDA= +github.com/luizsuper/ctxLoggers v1.0.4/go.mod h1:wjnYowzWZwBJ7eWVwtcZN9Vbb4DdW8VHKSXzCvsdjIo= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= @@ -177,7 +170,6 @@ github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -200,9 +192,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= @@ -234,6 +223,15 @@ github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7Fw github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= +go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= +go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= +go.dedis.ch/kyber/v3 v3.0.9 h1:i0ZbOQocHUjfFasBiUql5zVeC7u/vahFd96DFA8UOWk= +go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= +go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= +go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= +go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= +go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E= @@ -256,11 +254,11 @@ go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= go.uber.org/zap v1.20.0 h1:N4oPlghZwYG55MlU6LXk/Zp00FVNE9X9wrYO8CEs4lc= go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -308,6 +306,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -332,7 +331,6 @@ golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY= golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -386,16 +384,13 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkg/api/fiber.go b/pkg/api/fiber.go index bb035da..0ae2626 100644 --- a/pkg/api/fiber.go +++ b/pkg/api/fiber.go @@ -65,7 +65,8 @@ func GetFibberRecoverConfig() recover.Config { // FibberUserCtxWithTraceHandler 把fibberCtx的traceId 置入UserCtx中 func FibberUserCtxWithTraceHandler(c *fiber.Ctx) error { - c.SetUserContext(context.WithValue(context.Background(), fiber.HeaderXRequestID, c.Response().Header.Peek(fiber.HeaderXRequestID))) + peek := c.Response().Header.Peek(fiber.HeaderXRequestID) + c.SetUserContext(context.WithValue(context.Background(), fiber.HeaderXRequestID, string(peek))) return c.Next() } diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index 305c3c2..73ee68a 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -11,8 +11,9 @@ import ( ) var ( - EndPoints = "ENDPOINTS" - EndAddress = "etcd." + env.Namespace + ":2379" + EndPoints = "ENDPOINTS" + //EndAddress = "etcd." + env.Namespace + ":2379" + EndAddress = "127.0.0.1:2379" ) var ( diff --git a/pkg/orm/trrace.go b/pkg/orm/trrace.go new file mode 100644 index 0000000..28f1758 --- /dev/null +++ b/pkg/orm/trrace.go @@ -0,0 +1,94 @@ +package orm + +import ( + "context" + times "git.icechen.cn/monorepo/backend/pkg/time" + "github.com/gofiber/fiber/v2" + ctxLogger "github.com/luizsuper/ctxLoggers" + "github.com/spf13/cast" + "go.uber.org/zap" + "gorm.io/gorm" + "gorm.io/gorm/utils" + "time" +) + +func GetContextDB(ctx context.Context, db *gorm.DB) (*gorm.DB, error) { + if err := db.Use(&TracePlugin{}); err != nil { + return nil, err + } + return db.WithContext(ctx), nil +} + +type SQL struct { + Timestamp string `json:"timestamp"` // 时间,格式:2006-01-02 15:04:05 + Stack string `json:"stack"` // 文件地址和行号 + SQL string `json:"sql"` // SQL 语句 + Rows int64 `json:"rows_affected"` // 影响行数 + CostSeconds float64 `json:"cost_seconds"` // 执行时长(单位秒) +} + +const ( + callBackBeforeName = "core:before" + callBackAfterName = "core:after" + startTime = "_start_time" +) + +type TracePlugin struct{} + +func (op *TracePlugin) Name() string { + return "tracePlugin" +} + +func (op *TracePlugin) Initialize(db *gorm.DB) (err error) { + // 开始前 + _ = db.Callback().Create().Before("gorm:before_create").Register(callBackBeforeName, before) + _ = db.Callback().Query().Before("gorm:query").Register(callBackBeforeName, before) + _ = db.Callback().Delete().Before("gorm:before_delete").Register(callBackBeforeName, before) + _ = db.Callback().Update().Before("gorm:setup_reflect_value").Register(callBackBeforeName, before) + _ = db.Callback().Row().Before("gorm:row").Register(callBackBeforeName, before) + _ = db.Callback().Raw().Before("gorm:raw").Register(callBackBeforeName, before) + + // 结束后 + _ = db.Callback().Create().After("gorm:after_create").Register(callBackAfterName, after) + _ = db.Callback().Query().After("gorm:after_query").Register(callBackAfterName, after) + _ = db.Callback().Delete().After("gorm:after_delete").Register(callBackAfterName, after) + _ = db.Callback().Update().After("gorm:after_update").Register(callBackAfterName, after) + _ = db.Callback().Row().After("gorm:row").Register(callBackAfterName, after) + _ = db.Callback().Raw().After("gorm:raw").Register(callBackAfterName, after) + return +} + +//记录db开始时间 +func before(db *gorm.DB) { + db.InstanceSet(startTime, time.Now()) + return +} + +func after(db *gorm.DB) { + _ctx := db.Statement.Context + ctx, ok := _ctx.(context.Context) + if !ok { + return + } + defer ctx.Done() + _ts, isExist := db.InstanceGet(startTime) + if !isExist { + return + } + ts, ok := _ts.(time.Time) + if !ok { + return + } + + sql := db.Dialector.Explain(db.Statement.SQL.String(), db.Statement.Vars...) + sqlInfo := new(SQL) + sqlInfo.Timestamp = times.CSTLayoutString() + sqlInfo.SQL = sql + sqlInfo.Stack = utils.FileWithLineNum() + sqlInfo.Rows = db.Statement.RowsAffected + sqlInfo.CostSeconds = time.Since(ts).Seconds() + + ctxLogger.FInfo(nil, "sql", zap.Any("info", sqlInfo), zap.String("trace_id", cast.ToString(ctx.Value(fiber.HeaderXRequestID)))) + + return +} diff --git a/pkg/proto/brahma/murder/hello.pb.go b/pkg/proto/brahma/murder/hello.pb.go index 408f8fc..5b74f1e 100644 --- a/pkg/proto/brahma/murder/hello.pb.go +++ b/pkg/proto/brahma/murder/hello.pb.go @@ -2,7 +2,7 @@ // versions: // protoc-gen-go v1.27.1 // protoc v3.19.3 -// source: murder/hello.proto +// source: hello.proto package murder @@ -20,53 +20,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type HelloRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` -} - -func (x *HelloRequest) Reset() { - *x = HelloRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_murder_hello_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HelloRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HelloRequest) ProtoMessage() {} - -func (x *HelloRequest) ProtoReflect() protoreflect.Message { - mi := &file_murder_hello_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. -func (*HelloRequest) Descriptor() ([]byte, []int) { - return file_murder_hello_proto_rawDescGZIP(), []int{0} -} - -func (x *HelloRequest) GetCode() string { - if x != nil { - return x.Code - } - return "" -} - type HelloResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -78,7 +31,7 @@ type HelloResponse struct { func (x *HelloResponse) Reset() { *x = HelloResponse{} if protoimpl.UnsafeEnabled { - mi := &file_murder_hello_proto_msgTypes[1] + mi := &file_hello_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -91,7 +44,7 @@ func (x *HelloResponse) String() string { func (*HelloResponse) ProtoMessage() {} func (x *HelloResponse) ProtoReflect() protoreflect.Message { - mi := &file_murder_hello_proto_msgTypes[1] + mi := &file_hello_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -104,7 +57,7 @@ func (x *HelloResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use HelloResponse.ProtoReflect.Descriptor instead. func (*HelloResponse) Descriptor() ([]byte, []int) { - return file_murder_hello_proto_rawDescGZIP(), []int{1} + return file_hello_proto_rawDescGZIP(), []int{0} } func (x *HelloResponse) GetToken() string { @@ -114,74 +67,148 @@ func (x *HelloResponse) GetToken() string { return "" } -var File_murder_hello_proto protoreflect.FileDescriptor +type QueryCondition struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -var file_murder_hello_proto_rawDesc = []byte{ - 0x0a, 0x12, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x5f, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0x22, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x25, 0x0a, 0x0d, 0x48, 0x65, 0x6c, - 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, - 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x32, 0x56, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x12, 0x48, - 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x1d, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, - 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x2e, - 0x69, 0x63, 0x65, 0x63, 0x68, 0x65, 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, - 0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72, - 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + Page *int64 `protobuf:"zigzag64,1,opt,name=page,proto3,oneof" json:"page,omitempty"` + Size *int64 `protobuf:"zigzag64,2,opt,name=size,proto3,oneof" json:"size,omitempty"` + QueryMap map[string]string `protobuf:"bytes,3,rep,name=query_map,json=queryMap,proto3" json:"query_map,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *QueryCondition) Reset() { + *x = QueryCondition{} + if protoimpl.UnsafeEnabled { + mi := &file_hello_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *QueryCondition) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*QueryCondition) ProtoMessage() {} + +func (x *QueryCondition) ProtoReflect() protoreflect.Message { + mi := &file_hello_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use QueryCondition.ProtoReflect.Descriptor instead. +func (*QueryCondition) Descriptor() ([]byte, []int) { + return file_hello_proto_rawDescGZIP(), []int{1} +} + +func (x *QueryCondition) GetPage() int64 { + if x != nil && x.Page != nil { + return *x.Page + } + return 0 +} + +func (x *QueryCondition) GetSize() int64 { + if x != nil && x.Size != nil { + return *x.Size + } + return 0 +} + +func (x *QueryCondition) GetQueryMap() map[string]string { + if x != nil { + return x.QueryMap + } + return nil +} + +var File_hello_proto protoreflect.FileDescriptor + +var file_hello_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x65, + 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x1a, 0x0a, + 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x25, 0x0a, 0x0d, 0x48, 0x65, + 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x22, 0xdd, 0x01, 0x0a, 0x0e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x12, 0x48, 0x00, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, + 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x12, 0x48, 0x01, 0x52, 0x04, 0x73, + 0x69, 0x7a, 0x65, 0x88, 0x01, 0x01, 0x12, 0x4a, 0x0a, 0x09, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, + 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x71, 0x75, 0x65, 0x72, 0x79, 0x4d, + 0x61, 0x70, 0x1a, 0x3b, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x4d, 0x61, 0x70, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, + 0x07, 0x0a, 0x05, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x73, 0x69, 0x7a, + 0x65, 0x32, 0xa7, 0x01, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x57, 0x6f, 0x72, 0x6c, 0x64, + 0x12, 0x48, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x1d, 0x2e, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, + 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, + 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0a, 0x47, 0x65, + 0x74, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x12, 0x1f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, + 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x1e, 0x2e, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, + 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, + 0x69, 0x74, 0x2e, 0x69, 0x63, 0x65, 0x63, 0x68, 0x65, 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, + 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, + 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, + 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_murder_hello_proto_rawDescOnce sync.Once - file_murder_hello_proto_rawDescData = file_murder_hello_proto_rawDesc + file_hello_proto_rawDescOnce sync.Once + file_hello_proto_rawDescData = file_hello_proto_rawDesc ) -func file_murder_hello_proto_rawDescGZIP() []byte { - file_murder_hello_proto_rawDescOnce.Do(func() { - file_murder_hello_proto_rawDescData = protoimpl.X.CompressGZIP(file_murder_hello_proto_rawDescData) +func file_hello_proto_rawDescGZIP() []byte { + file_hello_proto_rawDescOnce.Do(func() { + file_hello_proto_rawDescData = protoimpl.X.CompressGZIP(file_hello_proto_rawDescData) }) - return file_murder_hello_proto_rawDescData + return file_hello_proto_rawDescData } -var file_murder_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_murder_hello_proto_goTypes = []interface{}{ - (*HelloRequest)(nil), // 0: example_service.HelloRequest - (*HelloResponse)(nil), // 1: example_service.HelloResponse +var file_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_hello_proto_goTypes = []interface{}{ + (*HelloResponse)(nil), // 0: example_service.HelloResponse + (*QueryCondition)(nil), // 1: example_service.QueryCondition + nil, // 2: example_service.QueryCondition.QueryMapEntry + (*HelloRequest)(nil), // 3: example_service.HelloRequest } -var file_murder_hello_proto_depIdxs = []int32{ - 0, // 0: example_service.HelloWorld.Login:input_type -> example_service.HelloRequest - 1, // 1: example_service.HelloWorld.Login:output_type -> example_service.HelloResponse - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name +var file_hello_proto_depIdxs = []int32{ + 2, // 0: example_service.QueryCondition.query_map:type_name -> example_service.QueryCondition.QueryMapEntry + 3, // 1: example_service.HelloWorld.Login:input_type -> example_service.HelloRequest + 1, // 2: example_service.HelloWorld.GetScripts:input_type -> example_service.QueryCondition + 0, // 3: example_service.HelloWorld.Login:output_type -> example_service.HelloResponse + 0, // 4: example_service.HelloWorld.GetScripts:output_type -> example_service.HelloResponse + 3, // [3:5] is the sub-list for method output_type + 1, // [1:3] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } -func init() { file_murder_hello_proto_init() } -func file_murder_hello_proto_init() { - if File_murder_hello_proto != nil { +func init() { file_hello_proto_init() } +func file_hello_proto_init() { + if File_hello_proto != nil { return } + file_name_proto_init() if !protoimpl.UnsafeEnabled { - file_murder_hello_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HelloRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_murder_hello_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_hello_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*HelloResponse); i { case 0: return &v.state @@ -193,23 +220,36 @@ func file_murder_hello_proto_init() { return nil } } + file_hello_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*QueryCondition); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } + file_hello_proto_msgTypes[1].OneofWrappers = []interface{}{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_murder_hello_proto_rawDesc, + RawDescriptor: file_hello_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 3, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_murder_hello_proto_goTypes, - DependencyIndexes: file_murder_hello_proto_depIdxs, - MessageInfos: file_murder_hello_proto_msgTypes, + GoTypes: file_hello_proto_goTypes, + DependencyIndexes: file_hello_proto_depIdxs, + MessageInfos: file_hello_proto_msgTypes, }.Build() - File_murder_hello_proto = out.File - file_murder_hello_proto_rawDesc = nil - file_murder_hello_proto_goTypes = nil - file_murder_hello_proto_depIdxs = nil + File_hello_proto = out.File + file_hello_proto_rawDesc = nil + file_hello_proto_goTypes = nil + file_hello_proto_depIdxs = nil } diff --git a/pkg/proto/brahma/murder/hello.proto b/pkg/proto/brahma/murder/hello.proto index 5c6d3a0..08a8ac4 100644 --- a/pkg/proto/brahma/murder/hello.proto +++ b/pkg/proto/brahma/murder/hello.proto @@ -1,17 +1,19 @@ syntax = "proto3"; - +import "name.proto"; option go_package = "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murder"; +package murder; -package example_service; - -service HelloWorld { - rpc Login (HelloRequest) returns (HelloResponse) {} -} - -message HelloRequest { - string code = 1; +service murder { + rpc Login (murder.HelloRequest) returns (HelloResponse) {} + rpc GetScripts(QueryCondition) returns(HelloResponse){} } message HelloResponse { string token = 1; -} \ No newline at end of file +} + +message QueryCondition { + optional sint64 page = 1; + optional sint64 size = 2; + map query_map = 3; +} diff --git a/pkg/proto/brahma/murder/hello_grpc.pb.go b/pkg/proto/brahma/murder/hello_grpc.pb.go index 33c9e9b..83ede30 100644 --- a/pkg/proto/brahma/murder/hello_grpc.pb.go +++ b/pkg/proto/brahma/murder/hello_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.2.0 // - protoc v3.19.3 -// source: murder/hello.proto +// source: hello.proto package murder @@ -23,6 +23,7 @@ const _ = grpc.SupportPackageIsVersion7 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type HelloWorldClient interface { Login(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) + GetScripts(ctx context.Context, in *QueryCondition, opts ...grpc.CallOption) (*HelloResponse, error) } type helloWorldClient struct { @@ -42,11 +43,21 @@ func (c *helloWorldClient) Login(ctx context.Context, in *HelloRequest, opts ... return out, nil } +func (c *helloWorldClient) GetScripts(ctx context.Context, in *QueryCondition, opts ...grpc.CallOption) (*HelloResponse, error) { + out := new(HelloResponse) + err := c.cc.Invoke(ctx, "/example_service.HelloWorld/GetScripts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // HelloWorldServer is the server API for HelloWorld service. // All implementations must embed UnimplementedHelloWorldServer // for forward compatibility type HelloWorldServer interface { Login(context.Context, *HelloRequest) (*HelloResponse, error) + GetScripts(context.Context, *QueryCondition) (*HelloResponse, error) mustEmbedUnimplementedHelloWorldServer() } @@ -57,6 +68,9 @@ type UnimplementedHelloWorldServer struct { func (UnimplementedHelloWorldServer) Login(context.Context, *HelloRequest) (*HelloResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Login not implemented") } +func (UnimplementedHelloWorldServer) GetScripts(context.Context, *QueryCondition) (*HelloResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetScripts not implemented") +} func (UnimplementedHelloWorldServer) mustEmbedUnimplementedHelloWorldServer() {} // UnsafeHelloWorldServer may be embedded to opt out of forward compatibility for this service. @@ -88,6 +102,24 @@ func _HelloWorld_Login_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _HelloWorld_GetScripts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryCondition) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HelloWorldServer).GetScripts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/example_service.HelloWorld/GetScripts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HelloWorldServer).GetScripts(ctx, req.(*QueryCondition)) + } + return interceptor(ctx, in, info, handler) +} + // HelloWorld_ServiceDesc is the grpc.ServiceDesc for HelloWorld service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -99,7 +131,11 @@ var HelloWorld_ServiceDesc = grpc.ServiceDesc{ MethodName: "Login", Handler: _HelloWorld_Login_Handler, }, + { + MethodName: "GetScripts", + Handler: _HelloWorld_GetScripts_Handler, + }, }, Streams: []grpc.StreamDesc{}, - Metadata: "murder/hello.proto", + Metadata: "hello.proto", } diff --git a/pkg/proto/brahma/murder/name.pb.go b/pkg/proto/brahma/murder/name.pb.go new file mode 100644 index 0000000..606880f --- /dev/null +++ b/pkg/proto/brahma/murder/name.pb.go @@ -0,0 +1,145 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.3 +// source: name.proto + +package murder + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type HelloRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` +} + +func (x *HelloRequest) Reset() { + *x = HelloRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_name_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HelloRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HelloRequest) ProtoMessage() {} + +func (x *HelloRequest) ProtoReflect() protoreflect.Message { + mi := &file_name_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. +func (*HelloRequest) Descriptor() ([]byte, []int) { + return file_name_proto_rawDescGZIP(), []int{0} +} + +func (x *HelloRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +var File_name_proto protoreflect.FileDescriptor + +var file_name_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x65, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0x22, 0x0a, + 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x2e, 0x69, 0x63, 0x65, 0x63, 0x68, 0x65, 0x6e, + 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61, 0x63, + 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, + 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_name_proto_rawDescOnce sync.Once + file_name_proto_rawDescData = file_name_proto_rawDesc +) + +func file_name_proto_rawDescGZIP() []byte { + file_name_proto_rawDescOnce.Do(func() { + file_name_proto_rawDescData = protoimpl.X.CompressGZIP(file_name_proto_rawDescData) + }) + return file_name_proto_rawDescData +} + +var file_name_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_name_proto_goTypes = []interface{}{ + (*HelloRequest)(nil), // 0: example_service.HelloRequest +} +var file_name_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_name_proto_init() } +func file_name_proto_init() { + if File_name_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_name_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HelloRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_name_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_name_proto_goTypes, + DependencyIndexes: file_name_proto_depIdxs, + MessageInfos: file_name_proto_msgTypes, + }.Build() + File_name_proto = out.File + file_name_proto_rawDesc = nil + file_name_proto_goTypes = nil + file_name_proto_depIdxs = nil +} diff --git a/pkg/proto/brahma/murder/name.proto b/pkg/proto/brahma/murder/name.proto new file mode 100644 index 0000000..5d5cd3f --- /dev/null +++ b/pkg/proto/brahma/murder/name.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +option go_package = "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murder"; +package murder; + +message HelloRequest { + string code = 1; +} \ No newline at end of file diff --git a/pkg/proto/brahma/murder/service.proto b/pkg/proto/brahma/murder/service.proto new file mode 100644 index 0000000..773e390 --- /dev/null +++ b/pkg/proto/brahma/murder/service.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +import "name.proto"; +option go_package = "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murder"; +package murder; + +message HelloResponse { + string token = 1; +} + +message QueryCondition { + optional sint64 page = 1; + optional sint64 size = 2; + map query_map = 3; +} \ No newline at end of file diff --git a/pkg/proto/brahma/murders/script/script.pb.go b/pkg/proto/brahma/murders/script/script.pb.go new file mode 100644 index 0000000..bed089c --- /dev/null +++ b/pkg/proto/brahma/murders/script/script.pb.go @@ -0,0 +1,377 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.3 +// source: script.proto + +package script + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Script struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ScriptName string `protobuf:"bytes,1,opt,name=script_name,json=scriptName,proto3" json:"script_name,omitempty"` + ScriptIntro string `protobuf:"bytes,2,opt,name=script_intro,json=scriptIntro,proto3" json:"script_intro,omitempty"` + ScriptTag []string `protobuf:"bytes,3,rep,name=script_tag,json=scriptTag,proto3" json:"script_tag,omitempty"` + ScriptScore float64 `protobuf:"fixed64,4,opt,name=script_score,json=scriptScore,proto3" json:"script_score,omitempty"` + GroupDuration int64 `protobuf:"zigzag64,5,opt,name=group_duration,json=groupDuration,proto3" json:"group_duration,omitempty"` + ScriptCoverUrl string `protobuf:"bytes,6,opt,name=script_cover_url,json=scriptCoverUrl,proto3" json:"script_cover_url,omitempty"` + ScriptTextContext string `protobuf:"bytes,7,opt,name=script_text_context,json=scriptTextContext,proto3" json:"script_text_context,omitempty"` + ScriptPlotScore float64 `protobuf:"fixed64,8,opt,name=script_plot_score,json=scriptPlotScore,proto3" json:"script_plot_score,omitempty"` + ScriptImageContent []string `protobuf:"bytes,9,rep,name=script_image_content,json=scriptImageContent,proto3" json:"script_image_content,omitempty"` + ScriptMalePlayer int64 `protobuf:"zigzag64,10,opt,name=script_male_player,json=scriptMalePlayer,proto3" json:"script_male_player,omitempty"` + ScriptFemalePlayer int64 `protobuf:"zigzag64,11,opt,name=script_female_player,json=scriptFemalePlayer,proto3" json:"script_female_player,omitempty"` + ScriptDifficultDegree string `protobuf:"bytes,12,opt,name=script_difficult_degree,json=scriptDifficultDegree,proto3" json:"script_difficult_degree,omitempty"` + ScriptPlayerLimit int64 `protobuf:"zigzag64,13,opt,name=script_player_limit,json=scriptPlayerLimit,proto3" json:"script_player_limit,omitempty"` + Uuid string `protobuf:"bytes,14,opt,name=uuid,proto3" json:"uuid,omitempty"` + ScriptComplexScore float64 `protobuf:"fixed64,15,opt,name=script_complex_score,json=scriptComplexScore,proto3" json:"script_complex_score,omitempty"` + Qid string `protobuf:"bytes,16,opt,name=qid,proto3" json:"qid,omitempty"` + IsDel int64 `protobuf:"zigzag64,17,opt,name=is_del,json=isDel,proto3" json:"is_del,omitempty"` +} + +func (x *Script) Reset() { + *x = Script{} + if protoimpl.UnsafeEnabled { + mi := &file_script_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Script) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Script) ProtoMessage() {} + +func (x *Script) ProtoReflect() protoreflect.Message { + mi := &file_script_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Script.ProtoReflect.Descriptor instead. +func (*Script) Descriptor() ([]byte, []int) { + return file_script_proto_rawDescGZIP(), []int{0} +} + +func (x *Script) GetScriptName() string { + if x != nil { + return x.ScriptName + } + return "" +} + +func (x *Script) GetScriptIntro() string { + if x != nil { + return x.ScriptIntro + } + return "" +} + +func (x *Script) GetScriptTag() []string { + if x != nil { + return x.ScriptTag + } + return nil +} + +func (x *Script) GetScriptScore() float64 { + if x != nil { + return x.ScriptScore + } + return 0 +} + +func (x *Script) GetGroupDuration() int64 { + if x != nil { + return x.GroupDuration + } + return 0 +} + +func (x *Script) GetScriptCoverUrl() string { + if x != nil { + return x.ScriptCoverUrl + } + return "" +} + +func (x *Script) GetScriptTextContext() string { + if x != nil { + return x.ScriptTextContext + } + return "" +} + +func (x *Script) GetScriptPlotScore() float64 { + if x != nil { + return x.ScriptPlotScore + } + return 0 +} + +func (x *Script) GetScriptImageContent() []string { + if x != nil { + return x.ScriptImageContent + } + return nil +} + +func (x *Script) GetScriptMalePlayer() int64 { + if x != nil { + return x.ScriptMalePlayer + } + return 0 +} + +func (x *Script) GetScriptFemalePlayer() int64 { + if x != nil { + return x.ScriptFemalePlayer + } + return 0 +} + +func (x *Script) GetScriptDifficultDegree() string { + if x != nil { + return x.ScriptDifficultDegree + } + return "" +} + +func (x *Script) GetScriptPlayerLimit() int64 { + if x != nil { + return x.ScriptPlayerLimit + } + return 0 +} + +func (x *Script) GetUuid() string { + if x != nil { + return x.Uuid + } + return "" +} + +func (x *Script) GetScriptComplexScore() float64 { + if x != nil { + return x.ScriptComplexScore + } + return 0 +} + +func (x *Script) GetQid() string { + if x != nil { + return x.Qid + } + return "" +} + +func (x *Script) GetIsDel() int64 { + if x != nil { + return x.IsDel + } + return 0 +} + +type Scripts struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Scripts []*Script `protobuf:"bytes,1,rep,name=scripts,proto3" json:"scripts,omitempty"` +} + +func (x *Scripts) Reset() { + *x = Scripts{} + if protoimpl.UnsafeEnabled { + mi := &file_script_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Scripts) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Scripts) ProtoMessage() {} + +func (x *Scripts) ProtoReflect() protoreflect.Message { + mi := &file_script_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Scripts.ProtoReflect.Descriptor instead. +func (*Scripts) Descriptor() ([]byte, []int) { + return file_script_proto_rawDescGZIP(), []int{1} +} + +func (x *Scripts) GetScripts() []*Script { + if x != nil { + return x.Scripts + } + return nil +} + +var File_script_proto protoreflect.FileDescriptor + +var file_script_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, + 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x22, 0xa4, 0x05, 0x0a, 0x06, 0x53, 0x63, 0x72, 0x69, 0x70, + 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x4e, 0x61, + 0x6d, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x69, 0x6e, 0x74, + 0x72, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x49, 0x6e, 0x74, 0x72, 0x6f, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, + 0x74, 0x61, 0x67, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x73, 0x63, 0x72, 0x69, 0x70, + 0x74, 0x54, 0x61, 0x67, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x73, + 0x63, 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0b, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x67, 0x72, 0x6f, 0x75, 0x70, + 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x12, 0x52, + 0x0d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x28, + 0x0a, 0x10, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x75, + 0x72, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x43, 0x6f, 0x76, 0x65, 0x72, 0x55, 0x72, 0x6c, 0x12, 0x2e, 0x0a, 0x13, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x54, 0x65, 0x78, + 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x12, 0x2a, 0x0a, 0x11, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x5f, 0x70, 0x6c, 0x6f, 0x74, 0x5f, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x08, 0x20, + 0x01, 0x28, 0x01, 0x52, 0x0f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x50, 0x6c, 0x6f, 0x74, 0x53, + 0x63, 0x6f, 0x72, 0x65, 0x12, 0x30, 0x0a, 0x14, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x69, + 0x6d, 0x61, 0x67, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x09, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x12, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x43, + 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x2c, 0x0a, 0x12, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x5f, 0x6d, 0x61, 0x6c, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x12, 0x52, 0x10, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x4d, 0x61, 0x6c, 0x65, 0x50, 0x6c, + 0x61, 0x79, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x66, + 0x65, 0x6d, 0x61, 0x6c, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, + 0x28, 0x12, 0x52, 0x12, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x46, 0x65, 0x6d, 0x61, 0x6c, 0x65, + 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x12, 0x36, 0x0a, 0x17, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x5f, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x5f, 0x64, 0x65, 0x67, 0x72, 0x65, + 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x15, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x44, + 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x44, 0x65, 0x67, 0x72, 0x65, 0x65, 0x12, 0x2e, + 0x0a, 0x13, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x12, 0x52, 0x11, 0x73, 0x63, 0x72, + 0x69, 0x70, 0x74, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x12, + 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, + 0x69, 0x64, 0x12, 0x30, 0x0a, 0x14, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x5f, 0x63, 0x6f, 0x6d, + 0x70, 0x6c, 0x65, 0x78, 0x5f, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x01, + 0x52, 0x12, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x43, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x78, 0x53, + 0x63, 0x6f, 0x72, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x69, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x71, 0x69, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x69, 0x73, 0x5f, 0x64, 0x65, 0x6c, + 0x18, 0x11, 0x20, 0x01, 0x28, 0x12, 0x52, 0x05, 0x69, 0x73, 0x44, 0x65, 0x6c, 0x22, 0x33, 0x0a, + 0x07, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x2e, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x52, 0x07, 0x73, 0x63, 0x72, 0x69, 0x70, + 0x74, 0x73, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x2e, 0x69, 0x63, 0x65, 0x63, 0x68, 0x65, + 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61, + 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, + 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x73, + 0x63, 0x72, 0x69, 0x70, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_script_proto_rawDescOnce sync.Once + file_script_proto_rawDescData = file_script_proto_rawDesc +) + +func file_script_proto_rawDescGZIP() []byte { + file_script_proto_rawDescOnce.Do(func() { + file_script_proto_rawDescData = protoimpl.X.CompressGZIP(file_script_proto_rawDescData) + }) + return file_script_proto_rawDescData +} + +var file_script_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_script_proto_goTypes = []interface{}{ + (*Script)(nil), // 0: script.Script + (*Scripts)(nil), // 1: script.Scripts +} +var file_script_proto_depIdxs = []int32{ + 0, // 0: script.Scripts.scripts:type_name -> script.Script + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_script_proto_init() } +func file_script_proto_init() { + if File_script_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_script_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Script); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_script_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Scripts); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_script_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_script_proto_goTypes, + DependencyIndexes: file_script_proto_depIdxs, + MessageInfos: file_script_proto_msgTypes, + }.Build() + File_script_proto = out.File + file_script_proto_rawDesc = nil + file_script_proto_goTypes = nil + file_script_proto_depIdxs = nil +} diff --git a/pkg/proto/brahma/murders/script/script.proto b/pkg/proto/brahma/murders/script/script.proto new file mode 100644 index 0000000..6b87e84 --- /dev/null +++ b/pkg/proto/brahma/murders/script/script.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; +option go_package = "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/script"; +package script; + +message Script { + string script_name = 1; + string script_intro = 2; + repeated string script_tag = 3; + double script_score = 4; + sint64 group_duration = 5; + string script_cover_url = 6; + string script_text_context = 7; + double script_plot_score = 8; + repeated string script_image_content = 9; + sint64 script_male_player = 10; + sint64 script_female_player = 11; + string script_difficult_degree = 12; + sint64 script_player_limit = 13; + string uuid = 14; + double script_complex_score = 15; + string qid = 16; + sint64 is_del = 17; +} + +message Scripts { + repeated Script scripts = 1; +} diff --git a/pkg/proto/brahma/murders/service.pb.go b/pkg/proto/brahma/murders/service.pb.go new file mode 100644 index 0000000..766ad5c --- /dev/null +++ b/pkg/proto/brahma/murders/service.pb.go @@ -0,0 +1,184 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.3 +// source: service.proto + +package murders + +import ( + script "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/script" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type QueryCondition struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Page *int64 `protobuf:"zigzag64,1,opt,name=page,proto3,oneof" json:"page,omitempty"` + Size *int64 `protobuf:"zigzag64,2,opt,name=size,proto3,oneof" json:"size,omitempty"` + QueryMap map[string]string `protobuf:"bytes,3,rep,name=query_map,json=queryMap,proto3" json:"query_map,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *QueryCondition) Reset() { + *x = QueryCondition{} + if protoimpl.UnsafeEnabled { + mi := &file_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *QueryCondition) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*QueryCondition) ProtoMessage() {} + +func (x *QueryCondition) ProtoReflect() protoreflect.Message { + mi := &file_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use QueryCondition.ProtoReflect.Descriptor instead. +func (*QueryCondition) Descriptor() ([]byte, []int) { + return file_service_proto_rawDescGZIP(), []int{0} +} + +func (x *QueryCondition) GetPage() int64 { + if x != nil && x.Page != nil { + return *x.Page + } + return 0 +} + +func (x *QueryCondition) GetSize() int64 { + if x != nil && x.Size != nil { + return *x.Size + } + return 0 +} + +func (x *QueryCondition) GetQueryMap() map[string]string { + if x != nil { + return x.QueryMap + } + return nil +} + +var File_service_proto protoreflect.FileDescriptor + +var file_service_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x06, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x1a, 0x13, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2f, + 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd4, 0x01, 0x0a, + 0x0e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x17, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x12, 0x48, 0x00, 0x52, + 0x04, 0x70, 0x61, 0x67, 0x65, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x12, 0x48, 0x01, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x88, 0x01, + 0x01, 0x12, 0x41, 0x0a, 0x09, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x51, 0x75, + 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, + 0x72, 0x79, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x71, 0x75, 0x65, 0x72, + 0x79, 0x4d, 0x61, 0x70, 0x1a, 0x3b, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x4d, 0x61, 0x70, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x73, + 0x69, 0x7a, 0x65, 0x32, 0x42, 0x0a, 0x07, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x73, 0x12, 0x37, + 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x12, 0x16, 0x2e, 0x6d, + 0x75, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x0f, 0x2e, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2e, 0x53, 0x63, + 0x72, 0x69, 0x70, 0x74, 0x73, 0x22, 0x00, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x2e, 0x69, + 0x63, 0x65, 0x63, 0x68, 0x65, 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65, + 0x70, 0x6f, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72, 0x64, + 0x65, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_service_proto_rawDescOnce sync.Once + file_service_proto_rawDescData = file_service_proto_rawDesc +) + +func file_service_proto_rawDescGZIP() []byte { + file_service_proto_rawDescOnce.Do(func() { + file_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_service_proto_rawDescData) + }) + return file_service_proto_rawDescData +} + +var file_service_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_service_proto_goTypes = []interface{}{ + (*QueryCondition)(nil), // 0: murder.QueryCondition + nil, // 1: murder.QueryCondition.QueryMapEntry + (*script.Scripts)(nil), // 2: script.Scripts +} +var file_service_proto_depIdxs = []int32{ + 1, // 0: murder.QueryCondition.query_map:type_name -> murder.QueryCondition.QueryMapEntry + 0, // 1: murder.murders.GetScripts:input_type -> murder.QueryCondition + 2, // 2: murder.murders.GetScripts:output_type -> script.Scripts + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_service_proto_init() } +func file_service_proto_init() { + if File_service_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*QueryCondition); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_service_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_service_proto_goTypes, + DependencyIndexes: file_service_proto_depIdxs, + MessageInfos: file_service_proto_msgTypes, + }.Build() + File_service_proto = out.File + file_service_proto_rawDesc = nil + file_service_proto_goTypes = nil + file_service_proto_depIdxs = nil +} diff --git a/pkg/proto/brahma/murders/service.proto b/pkg/proto/brahma/murders/service.proto new file mode 100644 index 0000000..53a3077 --- /dev/null +++ b/pkg/proto/brahma/murders/service.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +import "script/script.proto"; +option go_package = "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders"; +package murder; + +service murders{ + rpc GetScripts(QueryCondition) returns(script.Scripts){} +} + +message QueryCondition { + optional sint64 page = 1; + optional sint64 size = 2; + map query_map = 3; +} \ No newline at end of file diff --git a/pkg/proto/brahma/murders/service_grpc.pb.go b/pkg/proto/brahma/murders/service_grpc.pb.go new file mode 100644 index 0000000..5ddfb44 --- /dev/null +++ b/pkg/proto/brahma/murders/service_grpc.pb.go @@ -0,0 +1,106 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.3 +// source: service.proto + +package murders + +import ( + context "context" + script "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/script" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// MurdersClient is the client API for Murders service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type MurdersClient interface { + GetScripts(ctx context.Context, in *QueryCondition, opts ...grpc.CallOption) (*script.Scripts, error) +} + +type murdersClient struct { + cc grpc.ClientConnInterface +} + +func NewMurdersClient(cc grpc.ClientConnInterface) MurdersClient { + return &murdersClient{cc} +} + +func (c *murdersClient) GetScripts(ctx context.Context, in *QueryCondition, opts ...grpc.CallOption) (*script.Scripts, error) { + out := new(script.Scripts) + err := c.cc.Invoke(ctx, "/murder.murders/GetScripts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MurdersServer is the server API for Murders service. +// All implementations must embed UnimplementedMurdersServer +// for forward compatibility +type MurdersServer interface { + GetScripts(context.Context, *QueryCondition) (*script.Scripts, error) + mustEmbedUnimplementedMurdersServer() +} + +// UnimplementedMurdersServer must be embedded to have forward compatible implementations. +type UnimplementedMurdersServer struct { +} + +func (UnimplementedMurdersServer) GetScripts(context.Context, *QueryCondition) (*script.Scripts, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetScripts not implemented") +} +func (UnimplementedMurdersServer) mustEmbedUnimplementedMurdersServer() {} + +// UnsafeMurdersServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to MurdersServer will +// result in compilation errors. +type UnsafeMurdersServer interface { + mustEmbedUnimplementedMurdersServer() +} + +func RegisterMurdersServer(s grpc.ServiceRegistrar, srv MurdersServer) { + s.RegisterService(&Murders_ServiceDesc, srv) +} + +func _Murders_GetScripts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryCondition) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MurdersServer).GetScripts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/murder.murders/GetScripts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MurdersServer).GetScripts(ctx, req.(*QueryCondition)) + } + return interceptor(ctx, in, info, handler) +} + +// Murders_ServiceDesc is the grpc.ServiceDesc for Murders service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Murders_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "murder.murders", + HandlerType: (*MurdersServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetScripts", + Handler: _Murders_GetScripts_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "service.proto", +} diff --git a/pkg/proto/brahma/murders/tag/tag.pb.go b/pkg/proto/brahma/murders/tag/tag.pb.go new file mode 100644 index 0000000..df2a9ad --- /dev/null +++ b/pkg/proto/brahma/murders/tag/tag.pb.go @@ -0,0 +1,265 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.3 +// source: tag.proto + +package tag + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Category struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + Uuid string `protobuf:"bytes,2,opt,name=uuid,proto3" json:"uuid,omitempty"` + IsDel int64 `protobuf:"zigzag64,3,opt,name=is_del,json=isDel,proto3" json:"is_del,omitempty"` + Tags []*Tag `protobuf:"bytes,4,rep,name=tags,proto3" json:"tags,omitempty"` +} + +func (x *Category) Reset() { + *x = Category{} + if protoimpl.UnsafeEnabled { + mi := &file_tag_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Category) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Category) ProtoMessage() {} + +func (x *Category) ProtoReflect() protoreflect.Message { + mi := &file_tag_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Category.ProtoReflect.Descriptor instead. +func (*Category) Descriptor() ([]byte, []int) { + return file_tag_proto_rawDescGZIP(), []int{0} +} + +func (x *Category) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +func (x *Category) GetUuid() string { + if x != nil { + return x.Uuid + } + return "" +} + +func (x *Category) GetIsDel() int64 { + if x != nil { + return x.IsDel + } + return 0 +} + +func (x *Category) GetTags() []*Tag { + if x != nil { + return x.Tags + } + return nil +} + +type Tag struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + Uuid int64 `protobuf:"zigzag64,2,opt,name=uuid,proto3" json:"uuid,omitempty"` + IsDel int64 `protobuf:"zigzag64,3,opt,name=is_del,json=isDel,proto3" json:"is_del,omitempty"` + Cs *Category `protobuf:"bytes,4,opt,name=cs,proto3" json:"cs,omitempty"` +} + +func (x *Tag) Reset() { + *x = Tag{} + if protoimpl.UnsafeEnabled { + mi := &file_tag_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Tag) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Tag) ProtoMessage() {} + +func (x *Tag) ProtoReflect() protoreflect.Message { + mi := &file_tag_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Tag.ProtoReflect.Descriptor instead. +func (*Tag) Descriptor() ([]byte, []int) { + return file_tag_proto_rawDescGZIP(), []int{1} +} + +func (x *Tag) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +func (x *Tag) GetUuid() int64 { + if x != nil { + return x.Uuid + } + return 0 +} + +func (x *Tag) GetIsDel() int64 { + if x != nil { + return x.IsDel + } + return 0 +} + +func (x *Tag) GetCs() *Category { + if x != nil { + return x.Cs + } + return nil +} + +var File_tag_proto protoreflect.FileDescriptor + +var file_tag_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x74, 0x61, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x74, 0x61, 0x67, + 0x22, 0x69, 0x0a, 0x08, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x14, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x69, 0x73, 0x5f, 0x64, 0x65, 0x6c, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x12, 0x52, 0x05, 0x69, 0x73, 0x44, 0x65, 0x6c, 0x12, 0x1c, 0x0a, + 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x74, 0x61, + 0x67, 0x2e, 0x54, 0x61, 0x67, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x22, 0x65, 0x0a, 0x03, 0x54, + 0x61, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x12, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x15, 0x0a, 0x06, + 0x69, 0x73, 0x5f, 0x64, 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x12, 0x52, 0x05, 0x69, 0x73, + 0x44, 0x65, 0x6c, 0x12, 0x1d, 0x0a, 0x02, 0x63, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0d, 0x2e, 0x74, 0x61, 0x67, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x02, + 0x63, 0x73, 0x42, 0x3e, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x2e, 0x69, 0x63, 0x65, 0x63, 0x68, 0x65, + 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61, + 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, + 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x74, + 0x61, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_tag_proto_rawDescOnce sync.Once + file_tag_proto_rawDescData = file_tag_proto_rawDesc +) + +func file_tag_proto_rawDescGZIP() []byte { + file_tag_proto_rawDescOnce.Do(func() { + file_tag_proto_rawDescData = protoimpl.X.CompressGZIP(file_tag_proto_rawDescData) + }) + return file_tag_proto_rawDescData +} + +var file_tag_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_tag_proto_goTypes = []interface{}{ + (*Category)(nil), // 0: tag.Category + (*Tag)(nil), // 1: tag.Tag +} +var file_tag_proto_depIdxs = []int32{ + 1, // 0: tag.Category.tags:type_name -> tag.Tag + 0, // 1: tag.Tag.cs:type_name -> tag.Category + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_tag_proto_init() } +func file_tag_proto_init() { + if File_tag_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_tag_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Category); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_tag_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Tag); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_tag_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_tag_proto_goTypes, + DependencyIndexes: file_tag_proto_depIdxs, + MessageInfos: file_tag_proto_msgTypes, + }.Build() + File_tag_proto = out.File + file_tag_proto_rawDesc = nil + file_tag_proto_goTypes = nil + file_tag_proto_depIdxs = nil +} diff --git a/pkg/proto/brahma/murders/tag/tag.proto b/pkg/proto/brahma/murders/tag/tag.proto new file mode 100644 index 0000000..6d556ef --- /dev/null +++ b/pkg/proto/brahma/murders/tag/tag.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +option go_package = "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/tag"; +package tag; + +message Category { + string value = 1; + string uuid = 2; + sint64 is_del = 3; + repeated Tag tags = 4; +} + +message Tag { + string value = 1; + sint64 uuid = 2; + sint64 is_del = 3; + Category cs = 4; +} diff --git a/pkg/rpc/middle_ware.go b/pkg/rpc/middle_ware.go new file mode 100644 index 0000000..a6a5402 --- /dev/null +++ b/pkg/rpc/middle_ware.go @@ -0,0 +1,37 @@ +package rpc + +import ( + "context" + "fmt" + "git.icechen.cn/monorepo/backend/pkg/env" + "github.com/gofiber/fiber/v2" + ctxLogger "github.com/luizsuper/ctxLoggers" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "strings" + "time" +) + +// Interceptor 将requestId 存入ctx,记录出入参数,记录时间 +func Interceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, + handler grpc.UnaryHandler) (interface{}, error) { + serverName := env.Namespace + "-" + env.AppName + "-" + "service" + startTime := time.Now() + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + fmt.Printf("get metadata error") + } + if t, ok := md[strings.ToLower(fiber.HeaderXRequestID)]; ok { + ctx = context.WithValue(ctx, fiber.HeaderXRequestID, t[0]) + } + ctxLogger.Debug(ctx, serverName, zap.String("gRPC method", fmt.Sprintf(" %s", info.FullMethod)), zap.Any("req", req)) + resp, err := handler(ctx, req) + costSeconds := time.Since(startTime).Seconds() + if err != nil { + ctxLogger.Debug(ctx, serverName, zap.String("gRPC method", fmt.Sprintf(" %s", info.FullMethod)), zap.Float64("cost_time", costSeconds), zap.String("errorReason", err.Error())) + } else { + ctxLogger.Debug(ctx, serverName, zap.String("gRPC method", fmt.Sprintf(" %s, %v", info.FullMethod, resp)), zap.Float64("cost_time", costSeconds), zap.Any("resp", resp)) + } + return resp, err +} diff --git a/pkg/time/time.go b/pkg/time/time.go new file mode 100644 index 0000000..70765fd --- /dev/null +++ b/pkg/time/time.go @@ -0,0 +1,25 @@ +package times + +import "time" + +var ( + cst *time.Location +) + +func init() { + var err error + if cst, err = time.LoadLocation("Asia/Shanghai"); err != nil { + panic(err) + } + + // 默认设置为中国时区 + time.Local = cst +} + +// CSTLayout China Standard Time Layout +const CSTLayout = "2006-01-02 15:04:05" + +func CSTLayoutString() string { + ts := time.Now() + return ts.In(cst).Format(CSTLayout) +}