├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── api ├── achievement │ └── service │ │ └── v1 │ │ ├── achievement.pb.go │ │ ├── achievement.pb.validate.go │ │ ├── achievement.proto │ │ ├── achievement_error.pb.go │ │ ├── achievement_error.pb.validate.go │ │ ├── achievement_error.proto │ │ ├── achievement_error_errors.pb.go │ │ ├── achievement_grpc.pb.go │ │ └── achievement_http.pb.go ├── bff │ └── interface │ │ └── v1 │ │ ├── bff.pb.go │ │ ├── bff.pb.validate.go │ │ ├── bff.proto │ │ ├── bff_error.pb.go │ │ ├── bff_error.pb.validate.go │ │ ├── bff_error.proto │ │ ├── bff_error_errors.pb.go │ │ ├── bff_grpc.pb.go │ │ └── bff_http.pb.go ├── comment │ └── service │ │ └── v1 │ │ ├── comment.pb.go │ │ ├── comment.pb.validate.go │ │ ├── comment.proto │ │ ├── comment_error.pb.go │ │ ├── comment_error.pb.validate.go │ │ ├── comment_error.proto │ │ ├── comment_error_errors.pb.go │ │ ├── comment_grpc.pb.go │ │ └── comment_http.pb.go ├── creation │ └── service │ │ └── v1 │ │ ├── creation.pb.go │ │ ├── creation.pb.validate.go │ │ ├── creation.proto │ │ ├── creation_error.pb.go │ │ ├── creation_error.pb.validate.go │ │ ├── creation_error.proto │ │ ├── creation_error_errors.pb.go │ │ ├── creation_grpc.pb.go │ │ └── creation_http.pb.go ├── message │ └── service │ │ └── v1 │ │ ├── message.pb.go │ │ ├── message.pb.validate.go │ │ ├── message.proto │ │ ├── message_error.pb.go │ │ ├── message_error.pb.validate.go │ │ ├── message_error.proto │ │ ├── message_error_errors.pb.go │ │ ├── message_grpc.pb.go │ │ └── message_http.pb.go └── user │ └── service │ └── v1 │ ├── user.pb.go │ ├── user.pb.validate.go │ ├── user.proto │ ├── user_error.pb.go │ ├── user_error.pb.validate.go │ ├── user_error.proto │ ├── user_error_errors.pb.go │ ├── user_grpc.pb.go │ └── user_http.pb.go ├── app ├── achievement │ └── service │ │ ├── Makefile │ │ ├── README.md │ │ ├── cmd │ │ └── achievement │ │ │ ├── main.go │ │ │ ├── wire.go │ │ │ └── wire_gen.go │ │ └── internal │ │ ├── biz │ │ ├── achievement.go │ │ ├── biz.go │ │ ├── do.go │ │ └── do_easyjson.go │ │ ├── conf │ │ ├── conf.pb.go │ │ └── conf.proto │ │ ├── data │ │ ├── achievement.go │ │ ├── data.go │ │ └── model.go │ │ ├── server │ │ ├── grpc.go │ │ ├── http.go │ │ └── server.go │ │ ├── service │ │ ├── achievement.go │ │ └── service.go │ │ └── tool │ │ ├── lua │ │ └── lua.go │ │ └── update │ │ └── db.go ├── bff │ └── interface │ │ ├── Makefile │ │ ├── README.md │ │ ├── cmd │ │ └── bff │ │ │ ├── main.go │ │ │ ├── wire.go │ │ │ └── wire_gen.go │ │ └── internal │ │ ├── biz │ │ ├── achievement.go │ │ ├── biz.go │ │ ├── comment.go │ │ ├── creation.go │ │ ├── do.go │ │ ├── message.go │ │ └── user.go │ │ ├── conf │ │ ├── conf.pb.go │ │ └── conf.proto │ │ ├── data │ │ ├── achievement.go │ │ ├── comment.go │ │ ├── creation.go │ │ ├── data.go │ │ ├── message.go │ │ └── user.go │ │ ├── server │ │ ├── grpc.go │ │ ├── http.go │ │ └── server.go │ │ └── service │ │ ├── achievement.go │ │ ├── comment.go │ │ ├── creation.go │ │ ├── message.go │ │ ├── service.go │ │ └── user.go ├── comment │ └── service │ │ ├── Makefile │ │ ├── README.md │ │ ├── cmd │ │ └── comment │ │ │ ├── main.go │ │ │ ├── wire.go │ │ │ └── wire_gen.go │ │ └── internal │ │ ├── biz │ │ ├── biz.go │ │ ├── comment.go │ │ ├── do.go │ │ └── do_easyjson.go │ │ ├── conf │ │ ├── conf.pb.go │ │ └── conf.proto │ │ ├── data │ │ ├── comment.go │ │ ├── data.go │ │ └── model.go │ │ ├── server │ │ ├── grpc.go │ │ ├── http.go │ │ └── server.go │ │ ├── service │ │ ├── comment.go │ │ └── service.go │ │ └── tool │ │ ├── lua │ │ └── lua.go │ │ └── update │ │ └── db.go ├── creation │ └── service │ │ ├── Makefile │ │ ├── README.md │ │ ├── cmd │ │ └── creation │ │ │ ├── main.go │ │ │ ├── wire.go │ │ │ └── wire_gen.go │ │ └── internal │ │ ├── biz │ │ ├── article.go │ │ ├── biz.go │ │ ├── column.go │ │ ├── creation.go │ │ ├── do.go │ │ ├── do_easyjson.go │ │ ├── news.go │ │ └── talk.go │ │ ├── conf │ │ ├── conf.pb.go │ │ └── conf.proto │ │ ├── data │ │ ├── article.go │ │ ├── column.go │ │ ├── creation.go │ │ ├── data.go │ │ ├── model.go │ │ ├── news.go │ │ └── talk.go │ │ ├── server │ │ ├── grpc.go │ │ ├── http.go │ │ └── server.go │ │ ├── service │ │ ├── article.go │ │ ├── column.go │ │ ├── creation.go │ │ ├── news.go │ │ ├── service.go │ │ └── talk.go │ │ └── tool │ │ ├── es │ │ └── dsl │ │ ├── lua │ │ └── lua.go │ │ └── update │ │ └── db.go ├── job │ └── service │ │ ├── Makefile │ │ ├── cmd │ │ └── job │ │ │ ├── config.go │ │ │ ├── content.go │ │ │ ├── cos.go │ │ │ ├── db.go │ │ │ ├── es.go │ │ │ ├── images.go │ │ │ ├── log.go │ │ │ ├── main.go │ │ │ ├── news.go │ │ │ └── redis.go │ │ └── internal │ │ └── tool │ │ └── es │ │ └── dsl ├── message │ └── service │ │ ├── Makefile │ │ ├── README.md │ │ ├── cmd │ │ └── message │ │ │ ├── main.go │ │ │ ├── wire.go │ │ │ └── wire_gen.go │ │ └── internal │ │ ├── biz │ │ ├── achievement.go │ │ ├── biz.go │ │ ├── comment.go │ │ ├── creation.go │ │ ├── do.go │ │ ├── do_easyjson.go │ │ ├── message.go │ │ └── user.go │ │ ├── conf │ │ ├── conf.pb.go │ │ └── conf.proto │ │ ├── data │ │ ├── achievement.go │ │ ├── comment.go │ │ ├── creation.go │ │ ├── data.go │ │ ├── jwt.go │ │ ├── message.go │ │ ├── model.go │ │ └── user.go │ │ ├── pkg │ │ └── util │ │ │ └── template.go │ │ ├── server │ │ ├── grpc.go │ │ ├── http.go │ │ ├── mq.go │ │ ├── recovery.go │ │ └── server.go │ │ ├── service │ │ ├── achievement.go │ │ ├── comment.go │ │ ├── creation.go │ │ ├── message.go │ │ ├── service.go │ │ └── user.go │ │ └── tool │ │ ├── lua │ │ └── lua.go │ │ └── update │ │ └── db.go └── user │ └── service │ ├── Makefile │ ├── README.md │ ├── cmd │ └── user │ │ ├── main.go │ │ ├── wire.go │ │ └── wire_gen.go │ ├── configs │ └── config.yaml │ └── internal │ ├── biz │ ├── README.md │ ├── auth.go │ ├── biz.go │ ├── do.go │ ├── do_easyjson.go │ └── user.go │ ├── conf │ ├── conf.pb.go │ └── conf.proto │ ├── data │ ├── README.md │ ├── auth.go │ ├── data.go │ ├── model.go │ ├── model_easyjson.go │ └── user.go │ ├── pkg │ └── util │ │ ├── check.go │ │ ├── lancet.go │ │ ├── password.go │ │ ├── random.go │ │ ├── template.go │ │ └── time.go │ ├── server │ ├── grpc.go │ ├── http.go │ └── server.go │ ├── service │ ├── README.md │ ├── auth.go │ ├── service.go │ └── user.go │ └── tool │ ├── es │ └── dsl │ ├── lua │ └── lua.go │ └── update │ └── db.go ├── architecture.jpeg ├── go.mod ├── go.sum ├── pkg ├── jwtclaim │ └── jwt.go ├── kube │ └── kube.go ├── request │ └── request.go ├── responce │ └── responce.go └── trace │ └── trace.go └── third_party ├── README.md ├── errors └── errors.proto ├── google ├── api │ ├── annotations.proto │ ├── client.proto │ ├── field_behavior.proto │ ├── http.proto │ └── httpbody.proto └── protobuf │ ├── any.proto │ ├── descriptor.proto │ ├── duration.proto │ ├── empty.proto │ └── timestamp.proto └── validate ├── README.md └── validate.proto /.gitignore: -------------------------------------------------------------------------------- 1 | # Reference https://github.com/github/gitignore/blob/master/Go.gitignore 2 | # Binaries for programs and plugins 3 | *.exe 4 | *.exe~ 5 | *.dll 6 | *.so 7 | *.dylib 8 | 9 | # Test binary, built with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # Dependency directories (remove the comment below to include it) 16 | vendor/ 17 | 18 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 19 | *.o 20 | *.a 21 | *.so 22 | 23 | # OS General 24 | Thumbs.db 25 | .DS_Store 26 | 27 | # project 28 | *.cert 29 | *.key 30 | *.log 31 | bin/ 32 | 33 | # Develop tools 34 | .vscode/ 35 | .idea/ 36 | *.swp 37 | /deploy/ 38 | 39 | # api-gateway 40 | kratos-gateway/ 41 | 42 | # cache & log 43 | cache/ 44 | log/ 45 | 46 | # db schema update 47 | update/ 48 | lua/ 49 | 50 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stable-slim 2 | RUN apt-get update && apt-get install -y --no-install-recommends \ 3 | ca-certificates \ 4 | netbase \ 5 | && rm -rf /var/lib/apt/lists/ \ 6 | && apt-get autoremove -y && apt-get autoclean -y 7 | ARG filename 8 | COPY ./bin/${filename} /home/app/ 9 | RUN useradd matrix && chown -R matrix:matrix /home/app/ && chmod 700 /home/app/ 10 | WORKDIR /home/app/ 11 | USER matrix 12 | EXPOSE 8000 13 | EXPOSE 9000 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 matrix 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GOPATH:=$(shell go env GOPATH) 2 | VERSION=$(shell git describe --tags --abbrev=0) 3 | INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) 4 | API_PROTO_FILES=$(shell find api -name *.proto) 5 | 6 | 7 | .PHONY: init 8 | # init env 9 | init: 10 | go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 11 | go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest 12 | go install github.com/go-kratos/kratos/cmd/kratos/v2@latest 13 | go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest 14 | go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest 15 | go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest 16 | go install github.com/envoyproxy/protoc-gen-validate@latest 17 | go get k8s.io/client-go@v0.23.0 18 | 19 | .PHONY: api 20 | # generate api proto 21 | api: 22 | protoc --proto_path=./api \ 23 | --proto_path=./third_party \ 24 | --go_out=paths=source_relative:./api \ 25 | --go-http_out=paths=source_relative:./api \ 26 | --go-grpc_out=paths=source_relative:./api \ 27 | --go-errors_out=paths=source_relative:./api \ 28 | --validate_out=paths=source_relative,lang=go:./api \ 29 | $(API_PROTO_FILES) 30 | 31 | .PHONY: swagger 32 | # generate api proto 33 | swagger: 34 | protoc --proto_path=. \ 35 | --proto_path=./third_party \ 36 | --openapiv2_out . \ 37 | --openapiv2_opt logtostderr=true \ 38 | --openapiv2_opt json_names_for_fields=false \ 39 | api/user/service/v1/user.proto 40 | .PHONY: build 41 | # build 42 | build: 43 | mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... 44 | 45 | .PHONY: image 46 | # image 47 | image: 48 | make all; 49 | for file in `ls bin`;\ 50 | do \ 51 | docker build --build-arg filename=$$file -t $$file:$(VERSION) .;\ 52 | done 53 | 54 | .PHONY: tidy 55 | # generate 56 | tidy: 57 | go mod tidy 58 | 59 | 60 | .PHONY: generate 61 | # generate 62 | generate: 63 | go mod tidy 64 | go get github.com/google/wire/cmd/wire@latest 65 | go generate ./... 66 | 67 | .PHONY: wire 68 | # wire 69 | wire: 70 | go generate ./... 71 | 72 | .PHONY: easyjson 73 | # easyjson 74 | easyjson: 75 | go get github.com/mailru/easyjson/easyjson 76 | 77 | .PHONY: all 78 | # generate all 79 | all: 80 | make init; 81 | make api; 82 | make generate; 83 | make build; 84 | 85 | # show help 86 | help: 87 | @echo '' 88 | @echo 'Usage:' 89 | @echo ' make [target]' 90 | @echo '' 91 | @echo 'Targets:' 92 | @awk '/^[a-zA-Z\-\_0-9]+:/ { \ 93 | helpMessage = match(lastLine, /^# (.*)/); \ 94 | if (helpMessage) { \ 95 | helpCommand = substr($$1, 0, index($$1, ":")-1); \ 96 | helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ 97 | printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ 98 | } \ 99 | } \ 100 | { lastLine = $$0 }' $(MAKEFILE_LIST) 101 | 102 | .DEFAULT_GOAL := help 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # System Architecture 2 | ![image](architecture.jpeg) 3 | ## 一键构建 4 | ``` 5 | make all 6 | ``` 7 | ## 启动参数 8 | ``` 9 | conf: 各模块全局配置文件,默认为conf.yaml,若使用第三方配置中心,此参数可忽略 10 | traceUrl: 链路追踪,开发环境可忽略,生产环境必配 11 | traceToken: 链路追踪相关token,与traceUrl一同配置 12 | nacosUrl: 采用nacos作为配置中心,并发现和注册服务 13 | nacosNameSpace: 使用的nacos命名空间,默认为public 14 | nacosGroup: 使用的nacos分组,默认为DEFAULT_GROUP 15 | nacosConfig: 若使用nacos作为配置中心,需指明具体使用哪个配置文件 16 | nacosUserName: nacos账号 17 | nacosPassword: nacos密码 18 | logSelect: 日志收集器,默认输出到标准输出,也可以选择输出到Tencent的日志服务CLS 19 | ``` 20 | ## 模块配置文件参数-成就系统 21 | ``` 22 | server{ 23 | http{ 24 | network: 配置服务端的 network 协议,如 tcp 25 | address: 配置服务端监听的地址, 如:0.0.0.0:8000 26 | timeout: 超时时间,默认1s 27 | } 28 | grpc{ 29 | network: 配置服务端的 network 协议,如 tcp 30 | address: 配置服务端监听的地址, 如:0.0.0.0:9000 31 | timeout: 超时时间,默认1s 32 | } 33 | data{ 34 | database{ 35 | driver: 数据库引擎,例如: mysql 36 | source: 相应的登录凭证,如 账号:密码@tcp(ip:端口)/库名?charset=utf8mb4&parseTime=True&loc=Local 37 | } 38 | redis{ 39 | addr: ip:端口 40 | read_timeout: 读超时 41 | write_timeout: 写超时 42 | password: 密码 43 | } 44 | rocketmq{ 45 | serverAddress: ip:端口 46 | nameSpace: 命名空间 47 | groupName: 消费组 48 | } 49 | } 50 | ...... 51 | } 52 | 其他模块配置类似,不再过多阐述,想知道更多细节请查看各模块的conf.proto 53 | ``` -------------------------------------------------------------------------------- /api/achievement/service/v1/achievement_error.pb.validate.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-validate. DO NOT EDIT. 2 | // source: achievement/service/v1/achievement_error.proto 3 | 4 | package v1 5 | 6 | import ( 7 | "bytes" 8 | "errors" 9 | "fmt" 10 | "net" 11 | "net/mail" 12 | "net/url" 13 | "regexp" 14 | "sort" 15 | "strings" 16 | "time" 17 | "unicode/utf8" 18 | 19 | "google.golang.org/protobuf/types/known/anypb" 20 | ) 21 | 22 | // ensure the imports are used 23 | var ( 24 | _ = bytes.MinRead 25 | _ = errors.New("") 26 | _ = fmt.Print 27 | _ = utf8.UTFMax 28 | _ = (*regexp.Regexp)(nil) 29 | _ = (*strings.Reader)(nil) 30 | _ = net.IPv4len 31 | _ = time.Duration(0) 32 | _ = (*url.URL)(nil) 33 | _ = (*mail.Address)(nil) 34 | _ = anypb.Any{} 35 | _ = sort.Sort 36 | ) 37 | -------------------------------------------------------------------------------- /api/achievement/service/v1/achievement_error.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package achievement.v1; 4 | import "errors/errors.proto"; 5 | 6 | option go_package = "api/achievement/service/v1/pb;v1"; 7 | 8 | enum AchievementErrorReason { 9 | option (errors.default_code) = 500; 10 | UNKNOWN_ERROR = 0; 11 | SET_ACHIEVEMENT_AGREE_FAILED = 1; 12 | SET_ACHIEVEMENT_VIEW_FAILED = 2; 13 | SET_ACHIEVEMENT_COLLECT_FAILED = 3; 14 | SET_ACHIEVEMENT_FOLLOW_FAILED = 4; 15 | SET_MEDAL_FAILED = 5; 16 | ACCESS_MEDAL_FAILED = 6; 17 | CANCEL_ACHIEVEMENT_AGREE_FAILED = 7; 18 | CANCEL_ACHIEVEMENT_COLLECT_FAILED = 8; 19 | CANCEL_ACHIEVEMENT_FOLLOW_FAILED = 9; 20 | CANCEL_MEDAL_SET_FAILED = 10; 21 | GET_ACHIEVEMENT_LIST_FAILED = 11; 22 | GET_ACHIEVEMENT_FAILED = 12; 23 | GET_MEDAL_FAILED = 13; 24 | GET_ACTIVE_FAILED = 14; 25 | ADD_ACHIEVEMENT_SCORE_FAILED = 15; 26 | REDUCE_ACHIEVEMENT_SCORE_FAILED = 16; 27 | } 28 | -------------------------------------------------------------------------------- /api/achievement/service/v1/achievement_http.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-http. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-http v2.5.3 4 | // - protoc v3.20.0 5 | // source: achievement/service/v1/achievement.proto 6 | 7 | package v1 8 | 9 | import ( 10 | context "context" 11 | http "github.com/go-kratos/kratos/v2/transport/http" 12 | binding "github.com/go-kratos/kratos/v2/transport/http/binding" 13 | emptypb "google.golang.org/protobuf/types/known/emptypb" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the kratos package it is being compiled against. 18 | var _ = new(context.Context) 19 | var _ = binding.EncodeURL 20 | 21 | const _ = http.SupportPackageIsVersion1 22 | 23 | const OperationAchievementGetHealth = "/achievement.v1.Achievement/GetHealth" 24 | 25 | type AchievementHTTPServer interface { 26 | GetHealth(context.Context, *emptypb.Empty) (*emptypb.Empty, error) 27 | } 28 | 29 | func RegisterAchievementHTTPServer(s *http.Server, srv AchievementHTTPServer) { 30 | r := s.Route("/") 31 | r.GET("/v1/get/health", _Achievement_GetHealth0_HTTP_Handler(srv)) 32 | } 33 | 34 | func _Achievement_GetHealth0_HTTP_Handler(srv AchievementHTTPServer) func(ctx http.Context) error { 35 | return func(ctx http.Context) error { 36 | var in emptypb.Empty 37 | if err := ctx.BindQuery(&in); err != nil { 38 | return err 39 | } 40 | http.SetOperation(ctx, OperationAchievementGetHealth) 41 | h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { 42 | return srv.GetHealth(ctx, req.(*emptypb.Empty)) 43 | }) 44 | out, err := h(ctx, &in) 45 | if err != nil { 46 | return err 47 | } 48 | reply := out.(*emptypb.Empty) 49 | return ctx.Result(200, reply) 50 | } 51 | } 52 | 53 | type AchievementHTTPClient interface { 54 | GetHealth(ctx context.Context, req *emptypb.Empty, opts ...http.CallOption) (rsp *emptypb.Empty, err error) 55 | } 56 | 57 | type AchievementHTTPClientImpl struct { 58 | cc *http.Client 59 | } 60 | 61 | func NewAchievementHTTPClient(client *http.Client) AchievementHTTPClient { 62 | return &AchievementHTTPClientImpl{client} 63 | } 64 | 65 | func (c *AchievementHTTPClientImpl) GetHealth(ctx context.Context, in *emptypb.Empty, opts ...http.CallOption) (*emptypb.Empty, error) { 66 | var out emptypb.Empty 67 | pattern := "/v1/get/health" 68 | path := binding.EncodeURL(pattern, in, true) 69 | opts = append(opts, http.Operation(OperationAchievementGetHealth)) 70 | opts = append(opts, http.PathTemplate(pattern)) 71 | err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) 72 | if err != nil { 73 | return nil, err 74 | } 75 | return &out, err 76 | } 77 | -------------------------------------------------------------------------------- /api/bff/interface/v1/bff_error.pb.validate.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-validate. DO NOT EDIT. 2 | // source: bff/interface/v1/bff_error.proto 3 | 4 | package v1 5 | 6 | import ( 7 | "bytes" 8 | "errors" 9 | "fmt" 10 | "net" 11 | "net/mail" 12 | "net/url" 13 | "regexp" 14 | "sort" 15 | "strings" 16 | "time" 17 | "unicode/utf8" 18 | 19 | "google.golang.org/protobuf/types/known/anypb" 20 | ) 21 | 22 | // ensure the imports are used 23 | var ( 24 | _ = bytes.MinRead 25 | _ = errors.New("") 26 | _ = fmt.Print 27 | _ = utf8.UTFMax 28 | _ = (*regexp.Regexp)(nil) 29 | _ = (*strings.Reader)(nil) 30 | _ = net.IPv4len 31 | _ = time.Duration(0) 32 | _ = (*url.URL)(nil) 33 | _ = (*mail.Address)(nil) 34 | _ = anypb.Any{} 35 | _ = sort.Sort 36 | ) 37 | -------------------------------------------------------------------------------- /api/bff/interface/v1/bff_error.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package bff.v1; 4 | import "errors/errors.proto"; 5 | 6 | option go_package = "api/bff/interface/v1;v1"; 7 | 8 | enum BffErrorReason { 9 | option (errors.default_code) = 500; 10 | 11 | UNKNOWN_ERROR = 0; 12 | } 13 | -------------------------------------------------------------------------------- /api/bff/interface/v1/bff_error_errors.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-errors. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | import ( 6 | fmt "fmt" 7 | errors "github.com/go-kratos/kratos/v2/errors" 8 | ) 9 | 10 | // This is a compile-time assertion to ensure that this generated file 11 | // is compatible with the kratos package it is being compiled against. 12 | const _ = errors.SupportPackageIsVersion1 13 | 14 | func IsUnknownError(err error) bool { 15 | if err == nil { 16 | return false 17 | } 18 | e := errors.FromError(err) 19 | return e.Reason == BffErrorReason_UNKNOWN_ERROR.String() && e.Code == 500 20 | } 21 | 22 | func ErrorUnknownError(format string, args ...interface{}) *errors.Error { 23 | return errors.New(500, BffErrorReason_UNKNOWN_ERROR.String(), fmt.Sprintf(format, args...)) 24 | } 25 | -------------------------------------------------------------------------------- /api/comment/service/v1/comment_error.pb.validate.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-validate. DO NOT EDIT. 2 | // source: comment/service/v1/comment_error.proto 3 | 4 | package v1 5 | 6 | import ( 7 | "bytes" 8 | "errors" 9 | "fmt" 10 | "net" 11 | "net/mail" 12 | "net/url" 13 | "regexp" 14 | "sort" 15 | "strings" 16 | "time" 17 | "unicode/utf8" 18 | 19 | "google.golang.org/protobuf/types/known/anypb" 20 | ) 21 | 22 | // ensure the imports are used 23 | var ( 24 | _ = bytes.MinRead 25 | _ = errors.New("") 26 | _ = fmt.Print 27 | _ = utf8.UTFMax 28 | _ = (*regexp.Regexp)(nil) 29 | _ = (*strings.Reader)(nil) 30 | _ = net.IPv4len 31 | _ = time.Duration(0) 32 | _ = (*url.URL)(nil) 33 | _ = (*mail.Address)(nil) 34 | _ = anypb.Any{} 35 | _ = sort.Sort 36 | ) 37 | -------------------------------------------------------------------------------- /api/comment/service/v1/comment_error.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package comment.v1; 4 | import "errors/errors.proto"; 5 | 6 | option go_package = "api/comment/service/v1/pb;v1"; 7 | 8 | enum CommentErrorReason { 9 | option (errors.default_code) = 500; 10 | UNKNOWN_ERROR = 0; 11 | GET_COMMENT_DRAFT_FAILED = 1; 12 | GET_COMMENT_LIST_FAILED = 2; 13 | GET_COMMENT_USER_FAILED = 3; 14 | GET_COMMENT_STATISTIC_FAILED = 4; 15 | GET_USER_COMMENT_AGREE_FAILED = 5; 16 | GET_USER_COMMENT_CREATION_REPLY_LIST_FAILED = 6; 17 | GET_USER_COMMENT_CREATION_REPLIED_LIST_FAILED = 7; 18 | GET_USER_SUB_COMMENT_CREATION_REPLY_LIST_FAILED = 9; 19 | GET_USER_SUB_COMMENT_CREATION_REPLIED_LIST_FAILED = 10; 20 | GET_CONTENT_REVIEW_FAILED = 11; 21 | CREATE_DRAFT_FAILED = 12; 22 | CREATE_COMMENT_FAILED = 13; 23 | SET_RECORD_FAILED = 14; 24 | SET_AGREE_FAILED = 15; 25 | SET_CONTENT_IRREGULAR_FAILED = 16; 26 | CANCEL_AGREE_FAILED = 17; 27 | REMOVE_COMMENT_FAILED = 18; 28 | RECORD_NOT_FOUND = 19; 29 | } 30 | -------------------------------------------------------------------------------- /api/comment/service/v1/comment_http.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-http. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-http v2.5.3 4 | // - protoc v3.20.0 5 | // source: comment/service/v1/comment.proto 6 | 7 | package v1 8 | 9 | import ( 10 | context "context" 11 | http "github.com/go-kratos/kratos/v2/transport/http" 12 | binding "github.com/go-kratos/kratos/v2/transport/http/binding" 13 | emptypb "google.golang.org/protobuf/types/known/emptypb" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the kratos package it is being compiled against. 18 | var _ = new(context.Context) 19 | var _ = binding.EncodeURL 20 | 21 | const _ = http.SupportPackageIsVersion1 22 | 23 | const OperationCommentGetHealth = "/comment.v1.Comment/GetHealth" 24 | 25 | type CommentHTTPServer interface { 26 | GetHealth(context.Context, *emptypb.Empty) (*emptypb.Empty, error) 27 | } 28 | 29 | func RegisterCommentHTTPServer(s *http.Server, srv CommentHTTPServer) { 30 | r := s.Route("/") 31 | r.GET("/v1/get/health", _Comment_GetHealth1_HTTP_Handler(srv)) 32 | } 33 | 34 | func _Comment_GetHealth1_HTTP_Handler(srv CommentHTTPServer) func(ctx http.Context) error { 35 | return func(ctx http.Context) error { 36 | var in emptypb.Empty 37 | if err := ctx.BindQuery(&in); err != nil { 38 | return err 39 | } 40 | http.SetOperation(ctx, OperationCommentGetHealth) 41 | h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { 42 | return srv.GetHealth(ctx, req.(*emptypb.Empty)) 43 | }) 44 | out, err := h(ctx, &in) 45 | if err != nil { 46 | return err 47 | } 48 | reply := out.(*emptypb.Empty) 49 | return ctx.Result(200, reply) 50 | } 51 | } 52 | 53 | type CommentHTTPClient interface { 54 | GetHealth(ctx context.Context, req *emptypb.Empty, opts ...http.CallOption) (rsp *emptypb.Empty, err error) 55 | } 56 | 57 | type CommentHTTPClientImpl struct { 58 | cc *http.Client 59 | } 60 | 61 | func NewCommentHTTPClient(client *http.Client) CommentHTTPClient { 62 | return &CommentHTTPClientImpl{client} 63 | } 64 | 65 | func (c *CommentHTTPClientImpl) GetHealth(ctx context.Context, in *emptypb.Empty, opts ...http.CallOption) (*emptypb.Empty, error) { 66 | var out emptypb.Empty 67 | pattern := "/v1/get/health" 68 | path := binding.EncodeURL(pattern, in, true) 69 | opts = append(opts, http.Operation(OperationCommentGetHealth)) 70 | opts = append(opts, http.PathTemplate(pattern)) 71 | err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) 72 | if err != nil { 73 | return nil, err 74 | } 75 | return &out, err 76 | } 77 | -------------------------------------------------------------------------------- /api/creation/service/v1/creation_error.pb.validate.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-validate. DO NOT EDIT. 2 | // source: creation/service/v1/creation_error.proto 3 | 4 | package v1 5 | 6 | import ( 7 | "bytes" 8 | "errors" 9 | "fmt" 10 | "net" 11 | "net/mail" 12 | "net/url" 13 | "regexp" 14 | "sort" 15 | "strings" 16 | "time" 17 | "unicode/utf8" 18 | 19 | "google.golang.org/protobuf/types/known/anypb" 20 | ) 21 | 22 | // ensure the imports are used 23 | var ( 24 | _ = bytes.MinRead 25 | _ = errors.New("") 26 | _ = fmt.Print 27 | _ = utf8.UTFMax 28 | _ = (*regexp.Regexp)(nil) 29 | _ = (*strings.Reader)(nil) 30 | _ = net.IPv4len 31 | _ = time.Duration(0) 32 | _ = (*url.URL)(nil) 33 | _ = (*mail.Address)(nil) 34 | _ = anypb.Any{} 35 | _ = sort.Sort 36 | ) 37 | -------------------------------------------------------------------------------- /api/creation/service/v1/creation_error.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package creation.v1; 4 | import "errors/errors.proto"; 5 | 6 | option go_package = "api/creation/service/v1/pb;v1"; 7 | 8 | enum CreationErrorReason { 9 | option (errors.default_code) = 500; 10 | 11 | UNKNOWN_ERROR = 0; 12 | RECORD_NOT_FOUND = 1; 13 | 14 | GET_LEADER_BOARD_FAILED = 2; 15 | GET_COLLECT_ARTICLE_FAILED = 3; 16 | GET_COLLECTION_FAILED = 4; 17 | GET_COLLECTIONS_LIST_FAILED = 5; 18 | GET_TIMELINE_LIST_FAILED = 6; 19 | CREATE_COLLECTIONS_FAILED = 7; 20 | CREATE_TIMELINE_FAILED = 8; 21 | EDIT_COLLECTIONS_FAILED = 9; 22 | DELETE_COLLECTIONS_FAILED = 10; 23 | 24 | GET_ARTICLE_FAILED = 11; 25 | GET_ARTICLE_DRAFT_FAILED = 12; 26 | GET_ARTICLE_LIST_FAILED = 13; 27 | GET_ARTICLE_SEARCH_FAILED = 14; 28 | GET_ARTICLE_AGREE_FAILED = 15; 29 | GET_ARTICLE_COLLECT_FAILED = 16; 30 | CREATE_ARTICLE_FAILED = 17; 31 | EDIT_ARTICLE_FAILED = 18; 32 | DELETE_ARTICLE_FAILED = 19; 33 | 34 | GET_TALK_FAILED = 20; 35 | GET_TALK_AGREE_FAILED = 21; 36 | GET_TALK_COLLECT_FAILED = 22; 37 | GET_TALK_DRAFT_FAILED = 23; 38 | GET_TALK_LIST_FAILED = 24; 39 | GET_TALK_SEARCH_FAILED = 25; 40 | CREATE_TALK_FAILED = 26; 41 | EDIT_TALK_FAILED = 27; 42 | DELETE_TALK_FAILED = 28; 43 | 44 | GET_DRAFT_LIST_FAILED = 29; 45 | CREATE_DRAFT_FAILED = 30; 46 | DRAFT_MARK_FAILED = 31; 47 | 48 | GET_COLUMN_FAILED = 32; 49 | GET_COLUMN_AGREE_FAILED = 33; 50 | GET_COLUMN_COLLECT_FAILED = 34; 51 | GET_COLUMN_DRAFT_FAILED = 35; 52 | GET_COLUMN_SEARCH_FAILED = 36; 53 | CREATE_COLUMN_FAILED = 37; 54 | EDIT_COLUMN_FAILED = 38; 55 | DELETE_COLUMN_FAILED = 39; 56 | GET_COLUMN_LIST_FAILED = 40; 57 | GET_SUBSCRIBE_COLUMN_LIST_FAILED = 41; 58 | GET_COLUMN_SUBSCRIBES_FAILED = 42; 59 | GET_SUBSCRIBE_COLUMN_FAILED = 43; 60 | ADD_COLUMN_INCLUDES_FAILED = 44; 61 | DELETE_COLUMN_INCLUDES_FAILED = 45; 62 | SUBSCRIBE_COLUMN_FAILED = 46; 63 | SUBSCRIBE_COLUMN_JUDGE_FAILED = 47; 64 | CANCEL_SUBSCRIBE_COLUMN_FAILED = 48; 65 | 66 | GET_NEWS_FAILED = 49; 67 | GET_NEWS_SEARCH_FAILED = 50; 68 | 69 | SET_AGREE_FAILED = 51; 70 | SET_VIEW_FAILED = 52; 71 | SET_COLLECT_FAILED = 53; 72 | SET_IMAGE_IRREGULAR_FAILED = 54; 73 | SET_CONTENT_IRREGULAR_FAILED = 55; 74 | 75 | CANCEL_AGREE_FAILED = 56; 76 | CANCEL_VIEW_FAILED = 57; 77 | CANCEL_COLLECT_FAILED = 58; 78 | GET_STATISTIC_FAILED = 59; 79 | GET_STATISTIC_JUDGE_FAILED = 60; 80 | GET_COUNT_FAILED = 61; 81 | GET_CREATION_USER_FAILED = 62; 82 | GET_IMAGE_REVIEW_FAILED = 63; 83 | GET_CONTENT_REVIEW_FAILED = 64; 84 | 85 | SET_RECORD_FAILED = 65; 86 | NOT_EMPTY = 66; 87 | ADD_COMMENT_FAILED = 67; 88 | REDUCE_COMMENT_FAILED = 68; 89 | } 90 | -------------------------------------------------------------------------------- /api/creation/service/v1/creation_http.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-http. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-http v2.5.3 4 | // - protoc v3.20.0 5 | // source: creation/service/v1/creation.proto 6 | 7 | package v1 8 | 9 | import ( 10 | context "context" 11 | http "github.com/go-kratos/kratos/v2/transport/http" 12 | binding "github.com/go-kratos/kratos/v2/transport/http/binding" 13 | emptypb "google.golang.org/protobuf/types/known/emptypb" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the kratos package it is being compiled against. 18 | var _ = new(context.Context) 19 | var _ = binding.EncodeURL 20 | 21 | const _ = http.SupportPackageIsVersion1 22 | 23 | const OperationCreationGetHealth = "/creation.v1.Creation/GetHealth" 24 | 25 | type CreationHTTPServer interface { 26 | GetHealth(context.Context, *emptypb.Empty) (*emptypb.Empty, error) 27 | } 28 | 29 | func RegisterCreationHTTPServer(s *http.Server, srv CreationHTTPServer) { 30 | r := s.Route("/") 31 | r.GET("/v1/get/health", _Creation_GetHealth4_HTTP_Handler(srv)) 32 | } 33 | 34 | func _Creation_GetHealth4_HTTP_Handler(srv CreationHTTPServer) func(ctx http.Context) error { 35 | return func(ctx http.Context) error { 36 | var in emptypb.Empty 37 | if err := ctx.BindQuery(&in); err != nil { 38 | return err 39 | } 40 | http.SetOperation(ctx, OperationCreationGetHealth) 41 | h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { 42 | return srv.GetHealth(ctx, req.(*emptypb.Empty)) 43 | }) 44 | out, err := h(ctx, &in) 45 | if err != nil { 46 | return err 47 | } 48 | reply := out.(*emptypb.Empty) 49 | return ctx.Result(200, reply) 50 | } 51 | } 52 | 53 | type CreationHTTPClient interface { 54 | GetHealth(ctx context.Context, req *emptypb.Empty, opts ...http.CallOption) (rsp *emptypb.Empty, err error) 55 | } 56 | 57 | type CreationHTTPClientImpl struct { 58 | cc *http.Client 59 | } 60 | 61 | func NewCreationHTTPClient(client *http.Client) CreationHTTPClient { 62 | return &CreationHTTPClientImpl{client} 63 | } 64 | 65 | func (c *CreationHTTPClientImpl) GetHealth(ctx context.Context, in *emptypb.Empty, opts ...http.CallOption) (*emptypb.Empty, error) { 66 | var out emptypb.Empty 67 | pattern := "/v1/get/health" 68 | path := binding.EncodeURL(pattern, in, true) 69 | opts = append(opts, http.Operation(OperationCreationGetHealth)) 70 | opts = append(opts, http.PathTemplate(pattern)) 71 | err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) 72 | if err != nil { 73 | return nil, err 74 | } 75 | return &out, err 76 | } 77 | -------------------------------------------------------------------------------- /api/message/service/v1/message_error.pb.validate.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-validate. DO NOT EDIT. 2 | // source: message/service/v1/message_error.proto 3 | 4 | package v1 5 | 6 | import ( 7 | "bytes" 8 | "errors" 9 | "fmt" 10 | "net" 11 | "net/mail" 12 | "net/url" 13 | "regexp" 14 | "sort" 15 | "strings" 16 | "time" 17 | "unicode/utf8" 18 | 19 | "google.golang.org/protobuf/types/known/anypb" 20 | ) 21 | 22 | // ensure the imports are used 23 | var ( 24 | _ = bytes.MinRead 25 | _ = errors.New("") 26 | _ = fmt.Print 27 | _ = utf8.UTFMax 28 | _ = (*regexp.Regexp)(nil) 29 | _ = (*strings.Reader)(nil) 30 | _ = net.IPv4len 31 | _ = time.Duration(0) 32 | _ = (*url.URL)(nil) 33 | _ = (*mail.Address)(nil) 34 | _ = anypb.Any{} 35 | _ = sort.Sort 36 | ) 37 | -------------------------------------------------------------------------------- /api/message/service/v1/message_error.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package message.v1; 4 | import "errors/errors.proto"; 5 | 6 | option go_package = "api/message/service/v1/pb;v1"; 7 | 8 | enum MessageErrorReason { 9 | option (errors.default_code) = 500; 10 | 11 | UNKNOWN_ERROR = 0; 12 | ACCESS_USER_MEDAL_FAILED = 1; 13 | GET_MAILBOX_LAST_TIME_FAILED = 2; 14 | GET_MESSAGE_NOTIFICATION_FAILED = 3; 15 | SET_MAILBOX_LAST_TIME_FAILED = 4; 16 | REMOVE_MAILBOX_COMMENT_FAILED = 5; 17 | REMOVE_MAILBOX_SYSTEM_NOTIFICATION_FAILED = 6; 18 | } 19 | -------------------------------------------------------------------------------- /api/message/service/v1/message_error_errors.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-errors. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | import ( 6 | fmt "fmt" 7 | errors "github.com/go-kratos/kratos/v2/errors" 8 | ) 9 | 10 | // This is a compile-time assertion to ensure that this generated file 11 | // is compatible with the kratos package it is being compiled against. 12 | const _ = errors.SupportPackageIsVersion1 13 | 14 | func IsUnknownError(err error) bool { 15 | if err == nil { 16 | return false 17 | } 18 | e := errors.FromError(err) 19 | return e.Reason == MessageErrorReason_UNKNOWN_ERROR.String() && e.Code == 500 20 | } 21 | 22 | func ErrorUnknownError(format string, args ...interface{}) *errors.Error { 23 | return errors.New(500, MessageErrorReason_UNKNOWN_ERROR.String(), fmt.Sprintf(format, args...)) 24 | } 25 | 26 | func IsAccessUserMedalFailed(err error) bool { 27 | if err == nil { 28 | return false 29 | } 30 | e := errors.FromError(err) 31 | return e.Reason == MessageErrorReason_ACCESS_USER_MEDAL_FAILED.String() && e.Code == 500 32 | } 33 | 34 | func ErrorAccessUserMedalFailed(format string, args ...interface{}) *errors.Error { 35 | return errors.New(500, MessageErrorReason_ACCESS_USER_MEDAL_FAILED.String(), fmt.Sprintf(format, args...)) 36 | } 37 | 38 | func IsGetMailboxLastTimeFailed(err error) bool { 39 | if err == nil { 40 | return false 41 | } 42 | e := errors.FromError(err) 43 | return e.Reason == MessageErrorReason_GET_MAILBOX_LAST_TIME_FAILED.String() && e.Code == 500 44 | } 45 | 46 | func ErrorGetMailboxLastTimeFailed(format string, args ...interface{}) *errors.Error { 47 | return errors.New(500, MessageErrorReason_GET_MAILBOX_LAST_TIME_FAILED.String(), fmt.Sprintf(format, args...)) 48 | } 49 | 50 | func IsGetMessageNotificationFailed(err error) bool { 51 | if err == nil { 52 | return false 53 | } 54 | e := errors.FromError(err) 55 | return e.Reason == MessageErrorReason_GET_MESSAGE_NOTIFICATION_FAILED.String() && e.Code == 500 56 | } 57 | 58 | func ErrorGetMessageNotificationFailed(format string, args ...interface{}) *errors.Error { 59 | return errors.New(500, MessageErrorReason_GET_MESSAGE_NOTIFICATION_FAILED.String(), fmt.Sprintf(format, args...)) 60 | } 61 | 62 | func IsSetMailboxLastTimeFailed(err error) bool { 63 | if err == nil { 64 | return false 65 | } 66 | e := errors.FromError(err) 67 | return e.Reason == MessageErrorReason_SET_MAILBOX_LAST_TIME_FAILED.String() && e.Code == 500 68 | } 69 | 70 | func ErrorSetMailboxLastTimeFailed(format string, args ...interface{}) *errors.Error { 71 | return errors.New(500, MessageErrorReason_SET_MAILBOX_LAST_TIME_FAILED.String(), fmt.Sprintf(format, args...)) 72 | } 73 | 74 | func IsRemoveMailboxCommentFailed(err error) bool { 75 | if err == nil { 76 | return false 77 | } 78 | e := errors.FromError(err) 79 | return e.Reason == MessageErrorReason_REMOVE_MAILBOX_COMMENT_FAILED.String() && e.Code == 500 80 | } 81 | 82 | func ErrorRemoveMailboxCommentFailed(format string, args ...interface{}) *errors.Error { 83 | return errors.New(500, MessageErrorReason_REMOVE_MAILBOX_COMMENT_FAILED.String(), fmt.Sprintf(format, args...)) 84 | } 85 | 86 | func IsRemoveMailboxSystemNotificationFailed(err error) bool { 87 | if err == nil { 88 | return false 89 | } 90 | e := errors.FromError(err) 91 | return e.Reason == MessageErrorReason_REMOVE_MAILBOX_SYSTEM_NOTIFICATION_FAILED.String() && e.Code == 500 92 | } 93 | 94 | func ErrorRemoveMailboxSystemNotificationFailed(format string, args ...interface{}) *errors.Error { 95 | return errors.New(500, MessageErrorReason_REMOVE_MAILBOX_SYSTEM_NOTIFICATION_FAILED.String(), fmt.Sprintf(format, args...)) 96 | } 97 | -------------------------------------------------------------------------------- /api/user/service/v1/user_error.pb.validate.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-validate. DO NOT EDIT. 2 | // source: user/service/v1/user_error.proto 3 | 4 | package v1 5 | 6 | import ( 7 | "bytes" 8 | "errors" 9 | "fmt" 10 | "net" 11 | "net/mail" 12 | "net/url" 13 | "regexp" 14 | "sort" 15 | "strings" 16 | "time" 17 | "unicode/utf8" 18 | 19 | "google.golang.org/protobuf/types/known/anypb" 20 | ) 21 | 22 | // ensure the imports are used 23 | var ( 24 | _ = bytes.MinRead 25 | _ = errors.New("") 26 | _ = fmt.Print 27 | _ = utf8.UTFMax 28 | _ = (*regexp.Regexp)(nil) 29 | _ = (*strings.Reader)(nil) 30 | _ = net.IPv4len 31 | _ = time.Duration(0) 32 | _ = (*url.URL)(nil) 33 | _ = (*mail.Address)(nil) 34 | _ = anypb.Any{} 35 | _ = sort.Sort 36 | ) 37 | -------------------------------------------------------------------------------- /api/user/service/v1/user_error.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package user.v1; 4 | import "errors/errors.proto"; 5 | 6 | option go_package = "api/user/service/v1/pb;v1"; 7 | 8 | enum UserErrorReason { 9 | option (errors.default_code) = 500; 10 | 11 | UNKNOWN_ERROR = 0; 12 | VERIFY_PASSWORD_FAILED = 1 [(errors.code) = 401]; 13 | VERIFY_CODE_FAILED = 2 [(errors.code) = 401]; 14 | USERNAME_CONFLICT = 3 [(errors.code) = 409]; 15 | PHONE_CONFLICT = 4 [(errors.code) = 409]; 16 | EMAIL_CONFLICT = 5 [(errors.code) = 409]; 17 | WECHAT_CONFLICT = 6 [(errors.code) = 409]; 18 | QQ_CONFLICT = 7 [(errors.code) = 409]; 19 | GITEE_CONFLICT = 8 [(errors.code) = 409]; 20 | GITHUB_CONFLICT = 9 [(errors.code) = 409]; 21 | USER_NAME_CONFLICT = 10 [(errors.code) = 409]; 22 | GET_ACCOUNT_FAILED = 11 [(errors.code) = 404]; 23 | GET_PROFILE_FAILED = 12 [(errors.code) = 404]; 24 | GET_PROFILE_UPDATE_FAILED = 13 [(errors.code) = 404]; 25 | GET_ACHIEVEMENT_FAILED = 14 [(errors.code) = 404]; 26 | GET_USER_FOLLOW_FAILED = 15; 27 | GET_FOLLOW_LIST_FAILED = 16; 28 | GET_FOLLOW_LIST_COUNT_FAILED = 17; 29 | GET_PROFILE_LIST_FAILED = 18; 30 | GET_USER_SEARCH_FAILED = 19; 31 | GET_PICTURE_REVIEW_FAILED = 20; 32 | SEND_CODE_FAILED = 21; 33 | SET_PHONE_FAILED = 22; 34 | SET_EMAIL_FAILED = 23; 35 | SET_PROFILE_FAILED = 24; 36 | SET_PROFILE_UPDATE_FAILED = 25; 37 | SET_USERNAME_FAILED = 26; 38 | SET_PASSWORD_FAILED = 27; 39 | SET_FOLLOW_FAILED = 28; 40 | SET_IMAGE_FAILED = 29; 41 | SET_IMAGE_IRREGULAR_FAILED = 30; 42 | SET_WECHAT_FAILED = 31; 43 | SET_QQ_FAILED = 32; 44 | SET_GITEE_FAILED = 33; 45 | SET_GITHUB_FAILED = 34; 46 | CANCEL_FOLLOW_FAILED = 35; 47 | LOGIN_FAILED = 36; 48 | REGISTER_FAILED = 37; 49 | RESET_PASSWORD_FAILED = 38; 50 | PROFILE_REVIEW_MODIFY_FAILED = 39; 51 | PROFILE_UPDATE_MODIFY_FAILED = 40; 52 | UNBIND_ACCOUNT_FAILED = 41; 53 | UNIQUE_ACCOUNT = 42; 54 | } 55 | -------------------------------------------------------------------------------- /api/user/service/v1/user_http.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-http. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-http v2.5.3 4 | // - protoc v3.20.0 5 | // source: user/service/v1/user.proto 6 | 7 | package v1 8 | 9 | import ( 10 | context "context" 11 | http "github.com/go-kratos/kratos/v2/transport/http" 12 | binding "github.com/go-kratos/kratos/v2/transport/http/binding" 13 | emptypb "google.golang.org/protobuf/types/known/emptypb" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the kratos package it is being compiled against. 18 | var _ = new(context.Context) 19 | var _ = binding.EncodeURL 20 | 21 | const _ = http.SupportPackageIsVersion1 22 | 23 | const OperationUserGetHealth = "/user.v1.User/GetHealth" 24 | 25 | type UserHTTPServer interface { 26 | GetHealth(context.Context, *emptypb.Empty) (*emptypb.Empty, error) 27 | } 28 | 29 | func RegisterUserHTTPServer(s *http.Server, srv UserHTTPServer) { 30 | r := s.Route("/") 31 | r.GET("/v1/get/health", _User_GetHealth3_HTTP_Handler(srv)) 32 | } 33 | 34 | func _User_GetHealth3_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error { 35 | return func(ctx http.Context) error { 36 | var in emptypb.Empty 37 | if err := ctx.BindQuery(&in); err != nil { 38 | return err 39 | } 40 | http.SetOperation(ctx, OperationUserGetHealth) 41 | h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { 42 | return srv.GetHealth(ctx, req.(*emptypb.Empty)) 43 | }) 44 | out, err := h(ctx, &in) 45 | if err != nil { 46 | return err 47 | } 48 | reply := out.(*emptypb.Empty) 49 | return ctx.Result(200, reply) 50 | } 51 | } 52 | 53 | type UserHTTPClient interface { 54 | GetHealth(ctx context.Context, req *emptypb.Empty, opts ...http.CallOption) (rsp *emptypb.Empty, err error) 55 | } 56 | 57 | type UserHTTPClientImpl struct { 58 | cc *http.Client 59 | } 60 | 61 | func NewUserHTTPClient(client *http.Client) UserHTTPClient { 62 | return &UserHTTPClientImpl{client} 63 | } 64 | 65 | func (c *UserHTTPClientImpl) GetHealth(ctx context.Context, in *emptypb.Empty, opts ...http.CallOption) (*emptypb.Empty, error) { 66 | var out emptypb.Empty 67 | pattern := "/v1/get/health" 68 | path := binding.EncodeURL(pattern, in, true) 69 | opts = append(opts, http.Operation(OperationUserGetHealth)) 70 | opts = append(opts, http.PathTemplate(pattern)) 71 | err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) 72 | if err != nil { 73 | return nil, err 74 | } 75 | return &out, err 76 | } 77 | -------------------------------------------------------------------------------- /app/achievement/service/Makefile: -------------------------------------------------------------------------------- 1 | INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) 2 | INTERNAL_EASYJSON_FILES=$(shell find internal -name do.go) 3 | .PHONY: config 4 | # generate internal proto 5 | config: 6 | protoc --proto_path=./internal \ 7 | --proto_path=../../../third_party \ 8 | --go_out=paths=source_relative:./internal \ 9 | $(INTERNAL_PROTO_FILES) 10 | 11 | .PHONY: easyjson 12 | # generate internal proto 13 | easyjson: 14 | easyjson -lower_camel_case $(INTERNAL_EASYJSON_FILES) 15 | -------------------------------------------------------------------------------- /app/achievement/service/README.md: -------------------------------------------------------------------------------- 1 | # Achievement Service 2 | -------------------------------------------------------------------------------- /app/achievement/service/cmd/achievement/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package main 7 | 8 | import ( 9 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 10 | "github.com/go-kratos/kratos/v2" 11 | "github.com/go-kratos/kratos/v2/log" 12 | "github.com/google/wire" 13 | "github.com/the-zion/matrix-core/app/achievement/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/achievement/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/achievement/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/achievement/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/achievement/service/internal/service" 18 | ) 19 | 20 | // wireApp init kratos application. 21 | func wireApp(*conf.Server, *conf.Data, log.Logger, *nacos.Registry) (*kratos.App, func(), error) { 22 | panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) 23 | } 24 | -------------------------------------------------------------------------------- /app/achievement/service/cmd/achievement/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 11 | "github.com/go-kratos/kratos/v2" 12 | "github.com/go-kratos/kratos/v2/log" 13 | "github.com/the-zion/matrix-core/app/achievement/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/achievement/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/achievement/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/achievement/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/achievement/service/internal/service" 18 | ) 19 | 20 | // Injectors from wire.go: 21 | 22 | // wireApp init kratos application. 23 | func wireApp(confServer *conf.Server, confData *conf.Data, logLogger log.Logger, registry *nacos.Registry) (*kratos.App, func(), error) { 24 | db := data.NewDB(confData) 25 | cmdable := data.NewRedis(confData) 26 | mqPro := data.NewRocketmqProducer(confData) 27 | dataData, cleanup2, err := data.NewData(db, cmdable, mqPro, logLogger) 28 | if err != nil { 29 | return nil, nil, err 30 | } 31 | achievementRepo := data.NewAchievementRepo(dataData, logLogger) 32 | recovery := data.NewRecovery(dataData) 33 | transaction := data.NewTransaction(dataData) 34 | achievementUseCase := biz.NewAchievementUseCase(achievementRepo, recovery, transaction, logLogger) 35 | achievementService := service.NewAchievementService(achievementUseCase, logLogger) 36 | httpServer := server.NewHTTPServer(confServer, achievementService, logLogger) 37 | grpcServer := server.NewGRPCServer(confServer, achievementService, logLogger) 38 | kratosApp := newApp(registry, httpServer, grpcServer) 39 | return kratosApp, func() { 40 | cleanup2() 41 | }, nil 42 | } 43 | -------------------------------------------------------------------------------- /app/achievement/service/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/google/wire" 6 | ) 7 | 8 | var ProviderSet = wire.NewSet(NewAchievementUseCase) 9 | 10 | type Transaction interface { 11 | ExecTx(context.Context, func(ctx context.Context) error) error 12 | } 13 | 14 | type Recovery interface { 15 | GroupRecover(context.Context, func(ctx context.Context) error) func() error 16 | } 17 | -------------------------------------------------------------------------------- /app/achievement/service/internal/biz/do.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | type Achievement struct { 4 | Uuid string 5 | Agree int32 6 | Collect int32 7 | View int32 8 | Follow int32 9 | Followed int32 10 | Score int32 11 | } 12 | 13 | type Medal struct { 14 | Creation1 int32 15 | Creation2 int32 16 | Creation3 int32 17 | Creation4 int32 18 | Creation5 int32 19 | Creation6 int32 20 | Creation7 int32 21 | Agree1 int32 22 | Agree2 int32 23 | Agree3 int32 24 | Agree4 int32 25 | Agree5 int32 26 | Agree6 int32 27 | View1 int32 28 | View2 int32 29 | View3 int32 30 | Comment1 int32 31 | Comment2 int32 32 | Comment3 int32 33 | Collect1 int32 34 | Collect2 int32 35 | Collect3 int32 36 | } 37 | 38 | type Active struct { 39 | Agree int32 40 | } 41 | 42 | //easyjson:json 43 | type CommentMap struct { 44 | Uuid string 45 | Medal string 46 | Mode string 47 | } 48 | -------------------------------------------------------------------------------- /app/achievement/service/internal/biz/do_easyjson.go: -------------------------------------------------------------------------------- 1 | // Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. 2 | 3 | package biz 4 | 5 | import ( 6 | json "encoding/json" 7 | easyjson "github.com/mailru/easyjson" 8 | jlexer "github.com/mailru/easyjson/jlexer" 9 | jwriter "github.com/mailru/easyjson/jwriter" 10 | ) 11 | 12 | // suppress unused package warning 13 | var ( 14 | _ *json.RawMessage 15 | _ *jlexer.Lexer 16 | _ *jwriter.Writer 17 | _ easyjson.Marshaler 18 | ) 19 | 20 | func easyjson899f4d6bDecodeGithubComTheZionMatrixCoreAppAchievementServiceInternalBiz(in *jlexer.Lexer, out *CommentMap) { 21 | isTopLevel := in.IsStart() 22 | if in.IsNull() { 23 | if isTopLevel { 24 | in.Consumed() 25 | } 26 | in.Skip() 27 | return 28 | } 29 | in.Delim('{') 30 | for !in.IsDelim('}') { 31 | key := in.UnsafeFieldName(false) 32 | in.WantColon() 33 | if in.IsNull() { 34 | in.Skip() 35 | in.WantComma() 36 | continue 37 | } 38 | switch key { 39 | case "uuid": 40 | out.Uuid = string(in.String()) 41 | case "medal": 42 | out.Medal = string(in.String()) 43 | case "mode": 44 | out.Mode = string(in.String()) 45 | default: 46 | in.SkipRecursive() 47 | } 48 | in.WantComma() 49 | } 50 | in.Delim('}') 51 | if isTopLevel { 52 | in.Consumed() 53 | } 54 | } 55 | func easyjson899f4d6bEncodeGithubComTheZionMatrixCoreAppAchievementServiceInternalBiz(out *jwriter.Writer, in CommentMap) { 56 | out.RawByte('{') 57 | first := true 58 | _ = first 59 | { 60 | const prefix string = ",\"uuid\":" 61 | out.RawString(prefix[1:]) 62 | out.String(string(in.Uuid)) 63 | } 64 | { 65 | const prefix string = ",\"medal\":" 66 | out.RawString(prefix) 67 | out.String(string(in.Medal)) 68 | } 69 | { 70 | const prefix string = ",\"mode\":" 71 | out.RawString(prefix) 72 | out.String(string(in.Mode)) 73 | } 74 | out.RawByte('}') 75 | } 76 | 77 | // MarshalJSON supports json.Marshaler interface 78 | func (v CommentMap) MarshalJSON() ([]byte, error) { 79 | w := jwriter.Writer{} 80 | easyjson899f4d6bEncodeGithubComTheZionMatrixCoreAppAchievementServiceInternalBiz(&w, v) 81 | return w.Buffer.BuildBytes(), w.Error 82 | } 83 | 84 | // MarshalEasyJSON supports easyjson.Marshaler interface 85 | func (v CommentMap) MarshalEasyJSON(w *jwriter.Writer) { 86 | easyjson899f4d6bEncodeGithubComTheZionMatrixCoreAppAchievementServiceInternalBiz(w, v) 87 | } 88 | 89 | // UnmarshalJSON supports json.Unmarshaler interface 90 | func (v *CommentMap) UnmarshalJSON(data []byte) error { 91 | r := jlexer.Lexer{Data: data} 92 | easyjson899f4d6bDecodeGithubComTheZionMatrixCoreAppAchievementServiceInternalBiz(&r, v) 93 | return r.Error() 94 | } 95 | 96 | // UnmarshalEasyJSON supports easyjson.Unmarshaler interface 97 | func (v *CommentMap) UnmarshalEasyJSON(l *jlexer.Lexer) { 98 | easyjson899f4d6bDecodeGithubComTheZionMatrixCoreAppAchievementServiceInternalBiz(l, v) 99 | } 100 | -------------------------------------------------------------------------------- /app/achievement/service/internal/conf/conf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package kratos.api; 3 | 4 | option go_package = "achievement/service/internal/conf;conf"; 5 | 6 | import "google/protobuf/duration.proto"; 7 | 8 | message Bootstrap { 9 | Config config = 1; 10 | } 11 | 12 | message Config{ 13 | Server server = 1; 14 | Data data = 2; 15 | Log log = 3; 16 | } 17 | 18 | message Server { 19 | message HTTP { 20 | string network = 1; 21 | string addr = 2; 22 | google.protobuf.Duration timeout = 3; 23 | } 24 | message GRPC { 25 | string network = 1; 26 | string addr = 2; 27 | google.protobuf.Duration timeout = 3; 28 | } 29 | HTTP http = 1; 30 | GRPC grpc = 2; 31 | } 32 | 33 | message Data { 34 | message Database { 35 | string driver = 1; 36 | string source = 2; 37 | } 38 | message Redis { 39 | string network = 1; 40 | string addr = 2; 41 | string password = 3; 42 | google.protobuf.Duration read_timeout = 4; 43 | google.protobuf.Duration write_timeout = 5; 44 | } 45 | message RocketMq{ 46 | string serverAddress = 1; 47 | string secretKey = 2; 48 | string accessKey = 3; 49 | string nameSpace = 4; 50 | string groupName = 5; 51 | } 52 | Database database = 1; 53 | Redis redis = 2; 54 | RocketMq rocketmq = 3; 55 | } 56 | 57 | message Log { 58 | string host = 1; 59 | string accessKeyID = 2; 60 | string accessKeySecret = 3; 61 | string topicID = 4; 62 | } 63 | -------------------------------------------------------------------------------- /app/achievement/service/internal/data/model.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | type Achievement struct { 4 | Uuid string `gorm:"primaryKey;size:20"` 5 | Score int32 `gorm:"type:int unsigned;default:0"` 6 | Agree int32 `gorm:"type:int unsigned;default:0"` 7 | Collect int32 `gorm:"type:int unsigned;default:0"` 8 | View int32 `gorm:"type:int unsigned;default:0"` 9 | Follow int32 `gorm:"type:int unsigned;default:0"` 10 | Followed int32 `gorm:"type:int unsigned;default:0"` 11 | } 12 | 13 | type Active struct { 14 | Uuid string `gorm:"primaryKey;size:20"` 15 | Agree int32 `gorm:"type:int unsigned;default:0"` 16 | } 17 | 18 | type Medal struct { 19 | Uuid string `gorm:"primaryKey;size:20"` 20 | Creation1 int32 `gorm:"type:int unsigned;default:0"` 21 | Creation2 int32 `gorm:"type:int unsigned;default:0"` 22 | Creation3 int32 `gorm:"type:int unsigned;default:0"` 23 | Creation4 int32 `gorm:"type:int unsigned;default:0"` 24 | Creation5 int32 `gorm:"type:int unsigned;default:0"` 25 | Creation6 int32 `gorm:"type:int unsigned;default:0"` 26 | Creation7 int32 `gorm:"type:int unsigned;default:0"` 27 | Agree1 int32 `gorm:"type:int unsigned;default:0"` 28 | Agree2 int32 `gorm:"type:int unsigned;default:0"` 29 | Agree3 int32 `gorm:"type:int unsigned;default:0"` 30 | Agree4 int32 `gorm:"type:int unsigned;default:0"` 31 | Agree5 int32 `gorm:"type:int unsigned;default:0"` 32 | Agree6 int32 `gorm:"type:int unsigned;default:0"` 33 | View1 int32 `gorm:"type:int unsigned;default:0"` 34 | View2 int32 `gorm:"type:int unsigned;default:0"` 35 | View3 int32 `gorm:"type:int unsigned;default:0"` 36 | Comment1 int32 `gorm:"type:int unsigned;default:0"` 37 | Comment2 int32 `gorm:"type:int unsigned;default:0"` 38 | Comment3 int32 `gorm:"type:int unsigned;default:0"` 39 | Collect1 int32 `gorm:"type:int unsigned;default:0"` 40 | Collect2 int32 `gorm:"type:int unsigned;default:0"` 41 | Collect3 int32 `gorm:"type:int unsigned;default:0"` 42 | } 43 | -------------------------------------------------------------------------------- /app/achievement/service/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/ratelimit" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/middleware/tracing" 10 | "github.com/go-kratos/kratos/v2/middleware/validate" 11 | "github.com/go-kratos/kratos/v2/transport/grpc" 12 | v1 "github.com/the-zion/matrix-core/api/achievement/service/v1" 13 | "github.com/the-zion/matrix-core/app/achievement/service/internal/conf" 14 | "github.com/the-zion/matrix-core/app/achievement/service/internal/service" 15 | "github.com/the-zion/matrix-core/pkg/responce" 16 | ) 17 | 18 | func NewGRPCServer(c *conf.Server, achievementService *service.AchievementService, logger log.Logger) *grpc.Server { 19 | var opts = []grpc.ServerOption{ 20 | grpc.Middleware( 21 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 22 | l := log.NewHelper(log.With(logger, "message", "panic")) 23 | l.Error(err) 24 | return nil 25 | })), 26 | ratelimit.Server(), 27 | tracing.Server(), 28 | responce.Server(), 29 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 30 | validate.Validator(), 31 | ), 32 | } 33 | if c.Grpc.Network != "" { 34 | opts = append(opts, grpc.Network(c.Grpc.Network)) 35 | } 36 | if c.Grpc.Addr != "" { 37 | opts = append(opts, grpc.Address(c.Grpc.Addr)) 38 | } 39 | if c.Grpc.Timeout != nil { 40 | opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) 41 | } 42 | srv := grpc.NewServer(opts...) 43 | v1.RegisterAchievementServer(srv, achievementService) 44 | return srv 45 | } 46 | -------------------------------------------------------------------------------- /app/achievement/service/internal/server/http.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/recovery" 8 | "github.com/go-kratos/kratos/v2/transport/http" 9 | "github.com/the-zion/matrix-core/api/achievement/service/v1" 10 | "github.com/the-zion/matrix-core/app/achievement/service/internal/conf" 11 | "github.com/the-zion/matrix-core/app/achievement/service/internal/service" 12 | ) 13 | 14 | // NewHTTPServer new a HTTP user. 15 | func NewHTTPServer(c *conf.Server, achievementService *service.AchievementService, logger log.Logger) *http.Server { 16 | var opts = []http.ServerOption{ 17 | http.Middleware( 18 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 19 | l := log.NewHelper(log.With(logger, "message", "panic")) 20 | l.Error(err) 21 | return nil 22 | })), 23 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 24 | ), 25 | } 26 | if c.Http.Network != "" { 27 | opts = append(opts, http.Network(c.Http.Network)) 28 | } 29 | if c.Http.Addr != "" { 30 | opts = append(opts, http.Address(c.Http.Addr)) 31 | } 32 | if c.Http.Timeout != nil { 33 | opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) 34 | } 35 | srv := http.NewServer(opts...) 36 | v1.RegisterAchievementHTTPServer(srv, achievementService) 37 | return srv 38 | } 39 | -------------------------------------------------------------------------------- /app/achievement/service/internal/server/server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSet is user providers. 8 | var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) 9 | -------------------------------------------------------------------------------- /app/achievement/service/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/google/wire" 7 | v1 "github.com/the-zion/matrix-core/api/achievement/service/v1" 8 | "github.com/the-zion/matrix-core/app/achievement/service/internal/biz" 9 | "google.golang.org/protobuf/types/known/emptypb" 10 | ) 11 | 12 | var ProviderSet = wire.NewSet(NewAchievementService) 13 | 14 | type AchievementService struct { 15 | v1.UnimplementedAchievementServer 16 | ac *biz.AchievementUseCase 17 | log *log.Helper 18 | } 19 | 20 | func NewAchievementService(ac *biz.AchievementUseCase, logger log.Logger) *AchievementService { 21 | return &AchievementService{ 22 | log: log.NewHelper(log.With(logger, "module", "achievement/service")), 23 | ac: ac, 24 | } 25 | } 26 | 27 | func (s *AchievementService) GetHealth(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 28 | return &emptypb.Empty{}, nil 29 | } 30 | -------------------------------------------------------------------------------- /app/achievement/service/internal/tool/update/db.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/the-zion/matrix-core/app/achievement/service/internal/data" 7 | "gorm.io/driver/mysql" 8 | "gorm.io/gorm" 9 | "os" 10 | ) 11 | 12 | var ( 13 | source string 14 | ) 15 | 16 | func NewDB(logger log.Logger) *gorm.DB { 17 | l := log.NewHelper(log.With(logger, "update", "db")) 18 | 19 | db, err := gorm.Open(mysql.Open(source), &gorm.Config{ 20 | DisableForeignKeyConstraintWhenMigrating: true, 21 | }) 22 | if err != nil { 23 | l.Fatalf("failed opening connection to db: %v", err) 24 | } 25 | if err := db.AutoMigrate( 26 | &data.Achievement{}, 27 | &data.Active{}, 28 | &data.Medal{}, 29 | ); err != nil { 30 | l.Fatalf("failed creat or update table resources: %v", err) 31 | } 32 | return db 33 | } 34 | 35 | func main() { 36 | flag.Parse() 37 | logger := log.NewStdLogger(os.Stdout) 38 | NewDB(logger) 39 | } 40 | 41 | func init() { 42 | flag.StringVar(&source, "source", 43 | "root:123456@tcp(127.0.0.1:3306)/core?charset=utf8mb4&parseTime=True&loc=Local", 44 | "database source, eg: -source source path") 45 | } 46 | -------------------------------------------------------------------------------- /app/bff/interface/Makefile: -------------------------------------------------------------------------------- 1 | INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) 2 | .PHONY: config 3 | # generate internal proto 4 | config: 5 | protoc --proto_path=./internal \ 6 | --proto_path=../../../third_party \ 7 | --go_out=paths=source_relative:./internal \ 8 | $(INTERNAL_PROTO_FILES) -------------------------------------------------------------------------------- /app/bff/interface/README.md: -------------------------------------------------------------------------------- 1 | # The MATRIX BFF 2 | -------------------------------------------------------------------------------- /app/bff/interface/cmd/bff/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package main 7 | 8 | import ( 9 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 10 | "github.com/go-kratos/kratos/v2" 11 | "github.com/go-kratos/kratos/v2/log" 12 | "github.com/google/wire" 13 | "github.com/the-zion/matrix-core/app/bff/interface/internal/biz" 14 | "github.com/the-zion/matrix-core/app/bff/interface/internal/conf" 15 | "github.com/the-zion/matrix-core/app/bff/interface/internal/data" 16 | "github.com/the-zion/matrix-core/app/bff/interface/internal/server" 17 | "github.com/the-zion/matrix-core/app/bff/interface/internal/service" 18 | ) 19 | 20 | // wireApp init kratos application. 21 | func wireApp(*conf.Server, *conf.Data, log.Logger, *nacos.Registry) (*kratos.App, func(), error) { 22 | panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) 23 | } 24 | -------------------------------------------------------------------------------- /app/bff/interface/cmd/bff/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 11 | "github.com/go-kratos/kratos/v2" 12 | "github.com/go-kratos/kratos/v2/log" 13 | "github.com/the-zion/matrix-core/app/bff/interface/internal/biz" 14 | "github.com/the-zion/matrix-core/app/bff/interface/internal/conf" 15 | "github.com/the-zion/matrix-core/app/bff/interface/internal/data" 16 | "github.com/the-zion/matrix-core/app/bff/interface/internal/server" 17 | "github.com/the-zion/matrix-core/app/bff/interface/internal/service" 18 | ) 19 | 20 | // Injectors from wire.go: 21 | 22 | // wireApp init kratos application. 23 | func wireApp(confServer *conf.Server, confData *conf.Data, logLogger log.Logger, registry *nacos.Registry) (*kratos.App, func(), error) { 24 | userClient := data.NewUserServiceClient(registry) 25 | creationClient := data.NewCreationServiceClient(registry) 26 | messageClient := data.NewMessageServiceClient(registry) 27 | achievementClient := data.NewAchievementServiceClient(registry) 28 | commentClient := data.NewCommentServiceClient(registry) 29 | dataData, cleanup2, err := data.NewData(userClient, creationClient, messageClient, achievementClient, commentClient, logLogger) 30 | if err != nil { 31 | return nil, nil, err 32 | } 33 | userRepo := data.NewUserRepo(dataData, logLogger) 34 | achievementRepo := data.NewAchievementRepo(dataData, logLogger) 35 | creationRepo := data.NewCreationRepo(dataData, logLogger) 36 | recovery := data.NewRecovery(dataData) 37 | userUseCase := biz.NewUserUseCase(userRepo, achievementRepo, creationRepo, recovery, logLogger) 38 | articleRepo := data.NewArticleRepo(dataData, logLogger) 39 | columnRepo := data.NewColumnRepo(dataData, logLogger) 40 | talkRepo := data.NewTalkRepo(dataData, logLogger) 41 | creationUseCase := biz.NewCreationUseCase(creationRepo, articleRepo, columnRepo, talkRepo, recovery, logLogger) 42 | talkUseCase := biz.NewTalkUseCase(talkRepo, recovery, logLogger) 43 | articleUseCase := biz.NewArticleUseCase(articleRepo, recovery, logLogger) 44 | columnUseCase := biz.NewColumnUseCase(columnRepo, recovery, logLogger) 45 | commentRepo := data.NewCommentRepo(dataData, logLogger) 46 | achievementUseCase := biz.NewAchievementUseCase(achievementRepo, creationRepo, commentRepo, recovery, logLogger) 47 | newsRepo := data.NewNewsRepo(dataData, logLogger) 48 | newsUseCase := biz.NewNewsUseCase(newsRepo, recovery, logLogger) 49 | commentUseCase := biz.NewCommentUseCase(commentRepo, recovery, logLogger) 50 | messageRepo := data.NewMessageRepo(dataData, logLogger) 51 | messageUseCase := biz.NewMessageUseCase(messageRepo, userRepo, recovery, logLogger) 52 | bffService := service.NewBffService(userUseCase, creationUseCase, talkUseCase, articleUseCase, columnUseCase, achievementUseCase, newsUseCase, commentUseCase, messageUseCase, logLogger) 53 | httpServer := server.NewHTTPServer(confServer, bffService, logLogger) 54 | grpcServer := server.NewGRPCServer(confServer, bffService, logLogger) 55 | kratosApp := newApp(registry, httpServer, grpcServer) 56 | return kratosApp, func() { 57 | cleanup2() 58 | }, nil 59 | } 60 | -------------------------------------------------------------------------------- /app/bff/interface/internal/biz/achievement.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "golang.org/x/sync/errgroup" 7 | ) 8 | 9 | type AchievementRepo interface { 10 | GetAchievementList(ctx context.Context, uuids []string) ([]*Achievement, error) 11 | GetUserAchievement(ctx context.Context, uuid string) (*Achievement, error) 12 | GetUserActive(ctx context.Context, uuid string) (*Active, error) 13 | GetUserMedal(ctx context.Context, uuid string) (*Medal, error) 14 | SetUserMedal(ctx context.Context, medal, uuid string) error 15 | CancelUserMedalSet(ctx context.Context, medal, uuid string) error 16 | AccessUserMedal(ctx context.Context, medal, uuid string) error 17 | } 18 | 19 | type AchievementUseCase struct { 20 | repo AchievementRepo 21 | creationRepo CreationRepo 22 | commentRepo CommentRepo 23 | re Recovery 24 | log *log.Helper 25 | } 26 | 27 | func NewAchievementUseCase(repo AchievementRepo, creationRepo CreationRepo, commentRepo CommentRepo, re Recovery, logger log.Logger) *AchievementUseCase { 28 | return &AchievementUseCase{ 29 | repo: repo, 30 | creationRepo: creationRepo, 31 | commentRepo: commentRepo, 32 | re: re, 33 | log: log.NewHelper(log.With(logger, "module", "bff/biz/AchievementUseCase")), 34 | } 35 | } 36 | 37 | func (r *AchievementUseCase) GetAchievementList(ctx context.Context, uuids []string) ([]*Achievement, error) { 38 | return r.repo.GetAchievementList(ctx, uuids) 39 | } 40 | 41 | func (r *AchievementUseCase) GetUserAchievement(ctx context.Context, uuid string) (*Achievement, error) { 42 | return r.repo.GetUserAchievement(ctx, uuid) 43 | } 44 | 45 | func (r *AchievementUseCase) GetUserMedal(ctx context.Context, uuid string) (*Medal, error) { 46 | return r.repo.GetUserMedal(ctx, uuid) 47 | } 48 | 49 | func (r *AchievementUseCase) GetUserMedalProgress(ctx context.Context) (*MedalProgress, error) { 50 | uuid := ctx.Value("uuid").(string) 51 | mp := &MedalProgress{} 52 | g, _ := errgroup.WithContext(ctx) 53 | g.Go(r.re.GroupRecover(ctx, func(ctx context.Context) error { 54 | achievement, err := r.repo.GetUserAchievement(ctx, uuid) 55 | if err != nil { 56 | return err 57 | } 58 | mp.Agree = achievement.Agree 59 | mp.View = achievement.View 60 | return nil 61 | })) 62 | g.Go(r.re.GroupRecover(ctx, func(ctx context.Context) error { 63 | active, err := r.repo.GetUserActive(ctx, uuid) 64 | if err != nil { 65 | return err 66 | } 67 | mp.ActiveAgree = active.Agree 68 | return nil 69 | })) 70 | g.Go(r.re.GroupRecover(ctx, func(ctx context.Context) error { 71 | creation, err := r.creationRepo.GetCreationUser(ctx, uuid) 72 | if err != nil { 73 | return err 74 | } 75 | mp.Article = creation.Article 76 | mp.Talk = creation.Talk 77 | mp.Collect = creation.Collect 78 | return nil 79 | })) 80 | g.Go(r.re.GroupRecover(ctx, func(ctx context.Context) error { 81 | commentUser, err := r.commentRepo.GetCommentUser(ctx, uuid) 82 | if err != nil { 83 | return err 84 | } 85 | mp.Comment = commentUser.Comment 86 | return nil 87 | })) 88 | err := g.Wait() 89 | if err != nil { 90 | return nil, err 91 | } 92 | return mp, nil 93 | } 94 | 95 | func (r *AchievementUseCase) SetUserMedal(ctx context.Context, medal string) error { 96 | uuid := ctx.Value("uuid").(string) 97 | return r.repo.SetUserMedal(ctx, medal, uuid) 98 | } 99 | 100 | func (r *AchievementUseCase) CancelUserMedalSet(ctx context.Context, medal string) error { 101 | uuid := ctx.Value("uuid").(string) 102 | return r.repo.CancelUserMedalSet(ctx, medal, uuid) 103 | } 104 | 105 | func (r *AchievementUseCase) AccessUserMedal(ctx context.Context, medal string) error { 106 | uuid := ctx.Value("uuid").(string) 107 | return r.repo.AccessUserMedal(ctx, medal, uuid) 108 | } 109 | -------------------------------------------------------------------------------- /app/bff/interface/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/google/wire" 6 | ) 7 | 8 | var ProviderSet = wire.NewSet(NewUserUseCase, NewArticleUseCase, NewCreationUseCase, NewTalkUseCase, NewColumnUseCase, NewAchievementUseCase, NewNewsUseCase, NewCommentUseCase, NewMessageUseCase) 9 | 10 | type Recovery interface { 11 | GroupRecover(context.Context, func(ctx context.Context) error) func() error 12 | } 13 | -------------------------------------------------------------------------------- /app/bff/interface/internal/biz/message.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | ) 7 | 8 | type MessageRepo interface { 9 | GetMailBoxLastTime(ctx context.Context, uuid string) (*MailBox, error) 10 | GetMessageNotification(ctx context.Context, uuid string, follows []string) (*Notification, error) 11 | GetMessageSystemNotification(ctx context.Context, page int32, uuid string) ([]*SystemNotification, error) 12 | SetMailBoxLastTime(ctx context.Context, uuid string, time int32) error 13 | RemoveMailBoxCommentCount(ctx context.Context, uuid string) error 14 | RemoveMailBoxSubCommentCount(ctx context.Context, uuid string) error 15 | RemoveMailBoxSystemNotificationCount(ctx context.Context, uuid string) error 16 | } 17 | 18 | type MessageUseCase struct { 19 | repo MessageRepo 20 | userRepo UserRepo 21 | re Recovery 22 | log *log.Helper 23 | } 24 | 25 | func NewMessageUseCase(repo MessageRepo, userRepo UserRepo, re Recovery, logger log.Logger) *MessageUseCase { 26 | return &MessageUseCase{ 27 | repo: repo, 28 | userRepo: userRepo, 29 | re: re, 30 | log: log.NewHelper(log.With(logger, "module", "bff/biz/MessageUseCase")), 31 | } 32 | } 33 | 34 | func (r *MessageUseCase) GetMessageNotification(ctx context.Context) (*Notification, error) { 35 | uuid := ctx.Value("uuid").(string) 36 | uuidMap, err := r.userRepo.GetUserFollows(ctx, uuid) 37 | if err != nil { 38 | return nil, err 39 | } 40 | follows := make([]string, 0, len(uuidMap)) 41 | for key := range uuidMap { 42 | follows = append(follows, key) 43 | } 44 | return r.repo.GetMessageNotification(ctx, uuid, follows) 45 | } 46 | 47 | func (r *MessageUseCase) GetMailBoxLastTime(ctx context.Context) (*MailBox, error) { 48 | uuid := ctx.Value("uuid").(string) 49 | return r.repo.GetMailBoxLastTime(ctx, uuid) 50 | } 51 | 52 | func (r *MessageUseCase) GetMessageSystemNotification(ctx context.Context, page int32) ([]*SystemNotification, error) { 53 | uuid := ctx.Value("uuid").(string) 54 | return r.repo.GetMessageSystemNotification(ctx, page, uuid) 55 | } 56 | 57 | func (r *MessageUseCase) SetMailBoxLastTime(ctx context.Context, time int32) error { 58 | uuid := ctx.Value("uuid").(string) 59 | return r.repo.SetMailBoxLastTime(ctx, uuid, time) 60 | } 61 | 62 | func (r *MessageUseCase) RemoveMailBoxCommentCount(ctx context.Context) error { 63 | uuid := ctx.Value("uuid").(string) 64 | return r.repo.RemoveMailBoxCommentCount(ctx, uuid) 65 | } 66 | 67 | func (r *MessageUseCase) RemoveMailBoxSubCommentCount(ctx context.Context) error { 68 | uuid := ctx.Value("uuid").(string) 69 | return r.repo.RemoveMailBoxSubCommentCount(ctx, uuid) 70 | } 71 | 72 | func (r *MessageUseCase) RemoveMailBoxSystemNotificationCount(ctx context.Context) error { 73 | uuid := ctx.Value("uuid").(string) 74 | return r.repo.RemoveMailBoxSystemNotificationCount(ctx, uuid) 75 | } 76 | -------------------------------------------------------------------------------- /app/bff/interface/internal/conf/conf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package kratos.api; 3 | 4 | option go_package = "bff/interface/internal/conf;conf"; 5 | 6 | import "google/protobuf/duration.proto"; 7 | 8 | message Bootstrap { 9 | Config config = 1; 10 | } 11 | 12 | message Config{ 13 | Server server = 1; 14 | Data data = 2; 15 | Log log = 3; 16 | } 17 | 18 | message Server { 19 | message HTTP { 20 | string network = 1; 21 | string addr = 2; 22 | google.protobuf.Duration timeout = 3; 23 | } 24 | message GRPC { 25 | string network = 1; 26 | string addr = 2; 27 | google.protobuf.Duration timeout = 3; 28 | } 29 | HTTP http = 1; 30 | GRPC grpc = 2; 31 | } 32 | 33 | message Data { 34 | } 35 | 36 | message Log { 37 | string host = 1; 38 | string accessKeyID = 2; 39 | string accessKeySecret = 3; 40 | string topicID = 4; 41 | } 42 | -------------------------------------------------------------------------------- /app/bff/interface/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/recovery" 8 | "github.com/go-kratos/kratos/v2/middleware/tracing" 9 | "github.com/go-kratos/kratos/v2/middleware/validate" 10 | "github.com/go-kratos/kratos/v2/transport/grpc" 11 | v1 "github.com/the-zion/matrix-core/api/bff/interface/v1" 12 | "github.com/the-zion/matrix-core/app/bff/interface/internal/conf" 13 | "github.com/the-zion/matrix-core/app/bff/interface/internal/service" 14 | "github.com/the-zion/matrix-core/pkg/responce" 15 | ) 16 | 17 | func NewGRPCServer(c *conf.Server, bffService *service.BffService, logger log.Logger) *grpc.Server { 18 | var opts = []grpc.ServerOption{ 19 | grpc.Middleware( 20 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 21 | l := log.NewHelper(log.With(logger, "message", "panic")) 22 | l.Error(err) 23 | return nil 24 | })), 25 | tracing.Server(), 26 | responce.Server(), 27 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 28 | validate.Validator(), 29 | ), 30 | } 31 | if c.Grpc.Network != "" { 32 | opts = append(opts, grpc.Network(c.Grpc.Network)) 33 | } 34 | if c.Grpc.Addr != "" { 35 | opts = append(opts, grpc.Address(c.Grpc.Addr)) 36 | } 37 | if c.Grpc.Timeout != nil { 38 | opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) 39 | } 40 | srv := grpc.NewServer(opts...) 41 | v1.RegisterBffServer(srv, bffService) 42 | return srv 43 | } 44 | -------------------------------------------------------------------------------- /app/bff/interface/internal/server/http.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/ratelimit" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/middleware/tracing" 10 | "github.com/go-kratos/kratos/v2/middleware/validate" 11 | "github.com/go-kratos/kratos/v2/transport/http" 12 | "github.com/the-zion/matrix-core/api/bff/interface/v1" 13 | "github.com/the-zion/matrix-core/app/bff/interface/internal/conf" 14 | "github.com/the-zion/matrix-core/app/bff/interface/internal/service" 15 | "github.com/the-zion/matrix-core/pkg/request" 16 | ) 17 | 18 | // NewHTTPServer new a HTTP user. 19 | func NewHTTPServer(c *conf.Server, bffService *service.BffService, logger log.Logger) *http.Server { 20 | var opts = []http.ServerOption{ 21 | http.Middleware( 22 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 23 | l := log.NewHelper(log.With(logger, "message", "panic")) 24 | l.Error(err) 25 | return nil 26 | })), 27 | ratelimit.Server(), 28 | tracing.Server(), 29 | request.Server(), 30 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 31 | validate.Validator(), 32 | ), 33 | } 34 | if c.Http.Network != "" { 35 | opts = append(opts, http.Network(c.Http.Network)) 36 | } 37 | if c.Http.Addr != "" { 38 | opts = append(opts, http.Address(c.Http.Addr)) 39 | } 40 | if c.Http.Timeout != nil { 41 | opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) 42 | } 43 | srv := http.NewServer(opts...) 44 | v1.RegisterBffHTTPServer(srv, bffService) 45 | return srv 46 | } 47 | -------------------------------------------------------------------------------- /app/bff/interface/internal/server/server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSet is user providers. 8 | var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) 9 | -------------------------------------------------------------------------------- /app/bff/interface/internal/service/achievement.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/the-zion/matrix-core/api/bff/interface/v1" 6 | "google.golang.org/protobuf/types/known/emptypb" 7 | ) 8 | 9 | func (s *BffService) GetAchievementList(ctx context.Context, req *v1.GetAchievementListReq) (*v1.GetAchievementListReply, error) { 10 | achievementList, err := s.achc.GetAchievementList(ctx, req.Uuids) 11 | if err != nil { 12 | return nil, err 13 | } 14 | reply := &v1.GetAchievementListReply{Achievement: make([]*v1.GetAchievementListReply_Achievement, 0, len(achievementList))} 15 | for _, item := range achievementList { 16 | reply.Achievement = append(reply.Achievement, &v1.GetAchievementListReply_Achievement{ 17 | Uuid: item.Uuid, 18 | View: item.View, 19 | Agree: item.Agree, 20 | Follow: item.Follow, 21 | Followed: item.Followed, 22 | }) 23 | } 24 | return reply, nil 25 | } 26 | 27 | func (s *BffService) GetUserAchievement(ctx context.Context, req *v1.GetUserAchievementReq) (*v1.GetUserAchievementReply, error) { 28 | achievement, err := s.achc.GetUserAchievement(ctx, req.Uuid) 29 | if err != nil { 30 | return nil, err 31 | } 32 | return &v1.GetUserAchievementReply{ 33 | Agree: achievement.Agree, 34 | View: achievement.View, 35 | Collect: achievement.Collect, 36 | Follow: achievement.Follow, 37 | Followed: achievement.Followed, 38 | }, nil 39 | } 40 | 41 | func (s *BffService) GetUserMedal(ctx context.Context, req *v1.GetUserMedalReq) (*v1.GetUserMedalReply, error) { 42 | medal, err := s.achc.GetUserMedal(ctx, req.Uuid) 43 | if err != nil { 44 | return nil, err 45 | } 46 | return &v1.GetUserMedalReply{ 47 | Creation1: medal.Creation1, 48 | Creation2: medal.Creation2, 49 | Creation3: medal.Creation3, 50 | Creation4: medal.Creation4, 51 | Creation5: medal.Creation5, 52 | Creation6: medal.Creation6, 53 | Creation7: medal.Creation7, 54 | Agree1: medal.Agree1, 55 | Agree2: medal.Agree2, 56 | Agree3: medal.Agree3, 57 | Agree4: medal.Agree4, 58 | Agree5: medal.Agree5, 59 | Agree6: medal.Agree6, 60 | View1: medal.View1, 61 | View2: medal.View2, 62 | View3: medal.View3, 63 | Comment1: medal.Comment1, 64 | Comment2: medal.Comment2, 65 | Comment3: medal.Comment3, 66 | Collect1: medal.Collect1, 67 | Collect2: medal.Collect2, 68 | Collect3: medal.Collect3, 69 | }, nil 70 | } 71 | 72 | func (s *BffService) GetUserMedalProgress(ctx context.Context, _ *emptypb.Empty) (*v1.GetUserMedalProgressReply, error) { 73 | progress, err := s.achc.GetUserMedalProgress(ctx) 74 | if err != nil { 75 | return nil, err 76 | } 77 | return &v1.GetUserMedalProgressReply{ 78 | Creation: progress.Article + progress.Talk, 79 | Agree: progress.Agree, 80 | ActiveAgree: progress.ActiveAgree, 81 | View: progress.View, 82 | Comment: progress.Comment, 83 | Collect: progress.Collect, 84 | }, nil 85 | } 86 | 87 | func (s *BffService) SetUserMedal(ctx context.Context, req *v1.SetUserMedalReq) (*emptypb.Empty, error) { 88 | err := s.achc.SetUserMedal(ctx, req.Medal) 89 | if err != nil { 90 | return nil, err 91 | } 92 | return &emptypb.Empty{}, nil 93 | } 94 | 95 | func (s *BffService) CancelUserMedalSet(ctx context.Context, req *v1.CancelUserMedalSetReq) (*emptypb.Empty, error) { 96 | err := s.achc.CancelUserMedalSet(ctx, req.Medal) 97 | if err != nil { 98 | return nil, err 99 | } 100 | return &emptypb.Empty{}, nil 101 | } 102 | 103 | func (s *BffService) AccessUserMedal(ctx context.Context, req *v1.AccessUserMedalReq) (*emptypb.Empty, error) { 104 | err := s.achc.AccessUserMedal(ctx, req.Medal) 105 | if err != nil { 106 | return nil, err 107 | } 108 | return &emptypb.Empty{}, nil 109 | } 110 | -------------------------------------------------------------------------------- /app/bff/interface/internal/service/message.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/the-zion/matrix-core/api/bff/interface/v1" 6 | "google.golang.org/protobuf/types/known/emptypb" 7 | ) 8 | 9 | func (s *BffService) GetMessageNotification(ctx context.Context, _ *emptypb.Empty) (*v1.GetMessageNotificationReply, error) { 10 | notification, err := s.mc.GetMessageNotification(ctx) 11 | if err != nil { 12 | return nil, err 13 | } 14 | return &v1.GetMessageNotificationReply{ 15 | Timeline: notification.Timeline, 16 | Comment: notification.Comment, 17 | SubComment: notification.SubComment, 18 | System: notification.SystemNotification, 19 | }, nil 20 | } 21 | 22 | func (s *BffService) GetMailBoxLastTime(ctx context.Context, _ *emptypb.Empty) (*v1.GetMailBoxLastTimeReply, error) { 23 | mailbox, err := s.mc.GetMailBoxLastTime(ctx) 24 | if err != nil { 25 | return nil, err 26 | } 27 | return &v1.GetMailBoxLastTimeReply{ 28 | Time: mailbox.Time, 29 | }, nil 30 | } 31 | 32 | func (s *BffService) GetMessageSystemNotification(ctx context.Context, req *v1.GetMessageSystemNotificationReq) (*v1.GetMessageSystemNotificationReply, error) { 33 | notificationList, err := s.mc.GetMessageSystemNotification(ctx, req.Page) 34 | if err != nil { 35 | return nil, err 36 | } 37 | reply := &v1.GetMessageSystemNotificationReply{List: make([]*v1.GetMessageSystemNotificationReply_List, 0, len(notificationList))} 38 | for _, item := range notificationList { 39 | reply.List = append(reply.List, &v1.GetMessageSystemNotificationReply_List{ 40 | Id: item.Id, 41 | ContentId: item.ContentId, 42 | CreatedAt: item.CreatedAt, 43 | NotificationType: item.NotificationType, 44 | Title: item.Title, 45 | Uid: item.Uid, 46 | Uuid: item.Uuid, 47 | Label: item.Label, 48 | Result: item.Result, 49 | Section: item.Section, 50 | Text: item.Text, 51 | Comment: item.Comment, 52 | }) 53 | } 54 | return reply, nil 55 | } 56 | 57 | func (s *BffService) SetMailBoxLastTime(ctx context.Context, req *v1.SetMailBoxLastTimeReq) (*emptypb.Empty, error) { 58 | err := s.mc.SetMailBoxLastTime(ctx, req.Time) 59 | if err != nil { 60 | return nil, err 61 | } 62 | return &emptypb.Empty{}, nil 63 | } 64 | 65 | func (s *BffService) RemoveMailBoxCommentCount(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 66 | err := s.mc.RemoveMailBoxCommentCount(ctx) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return &emptypb.Empty{}, nil 71 | } 72 | 73 | func (s *BffService) RemoveMailBoxSubCommentCount(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 74 | err := s.mc.RemoveMailBoxSubCommentCount(ctx) 75 | if err != nil { 76 | return nil, err 77 | } 78 | return &emptypb.Empty{}, nil 79 | } 80 | 81 | func (s *BffService) RemoveMailBoxSystemNotificationCount(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 82 | err := s.mc.RemoveMailBoxSystemNotificationCount(ctx) 83 | if err != nil { 84 | return nil, err 85 | } 86 | return &emptypb.Empty{}, nil 87 | } 88 | -------------------------------------------------------------------------------- /app/bff/interface/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/google/wire" 7 | v1 "github.com/the-zion/matrix-core/api/bff/interface/v1" 8 | "github.com/the-zion/matrix-core/app/bff/interface/internal/biz" 9 | "google.golang.org/protobuf/types/known/emptypb" 10 | ) 11 | 12 | var ProviderSet = wire.NewSet(NewBffService) 13 | 14 | type BffService struct { 15 | v1.UnimplementedBffServer 16 | ac *biz.ArticleUseCase 17 | tc *biz.TalkUseCase 18 | cc *biz.CreationUseCase 19 | coc *biz.ColumnUseCase 20 | uc *biz.UserUseCase 21 | achc *biz.AchievementUseCase 22 | nc *biz.NewsUseCase 23 | commc *biz.CommentUseCase 24 | mc *biz.MessageUseCase 25 | log *log.Helper 26 | } 27 | 28 | func NewBffService(uc *biz.UserUseCase, cc *biz.CreationUseCase, tc *biz.TalkUseCase, ac *biz.ArticleUseCase, coc *biz.ColumnUseCase, achc *biz.AchievementUseCase, nc *biz.NewsUseCase, commc *biz.CommentUseCase, mc *biz.MessageUseCase, logger log.Logger) *BffService { 29 | return &BffService{ 30 | log: log.NewHelper(log.With(logger, "module", "bff/interface")), 31 | uc: uc, 32 | ac: ac, 33 | tc: tc, 34 | cc: cc, 35 | coc: coc, 36 | achc: achc, 37 | nc: nc, 38 | mc: mc, 39 | commc: commc, 40 | } 41 | } 42 | 43 | func (s *BffService) GetHealth(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 44 | return &emptypb.Empty{}, nil 45 | } 46 | -------------------------------------------------------------------------------- /app/comment/service/Makefile: -------------------------------------------------------------------------------- 1 | INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) 2 | INTERNAL_EASYJSON_FILES=$(shell find internal -name do.go) 3 | .PHONY: config 4 | # generate internal proto 5 | config: 6 | protoc --proto_path=./internal \ 7 | --proto_path=../../../third_party \ 8 | --go_out=paths=source_relative:./internal \ 9 | $(INTERNAL_PROTO_FILES) 10 | 11 | 12 | .PHONY: easyjson 13 | # generate internal proto 14 | easyjson: 15 | easyjson -lower_camel_case $(INTERNAL_EASYJSON_FILES) -------------------------------------------------------------------------------- /app/comment/service/README.md: -------------------------------------------------------------------------------- 1 | # Comment Service 2 | -------------------------------------------------------------------------------- /app/comment/service/cmd/comment/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package main 7 | 8 | import ( 9 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 10 | "github.com/go-kratos/kratos/v2" 11 | "github.com/go-kratos/kratos/v2/log" 12 | "github.com/google/wire" 13 | "github.com/the-zion/matrix-core/app/comment/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/comment/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/comment/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/comment/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/comment/service/internal/service" 18 | ) 19 | 20 | // wireApp init kratos application. 21 | func wireApp(*conf.Server, *conf.Data, log.Logger, *nacos.Registry) (*kratos.App, func(), error) { 22 | panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) 23 | } 24 | -------------------------------------------------------------------------------- /app/comment/service/cmd/comment/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 11 | "github.com/go-kratos/kratos/v2" 12 | "github.com/go-kratos/kratos/v2/log" 13 | "github.com/the-zion/matrix-core/app/comment/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/comment/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/comment/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/comment/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/comment/service/internal/service" 18 | ) 19 | 20 | // Injectors from wire.go: 21 | 22 | // wireApp init kratos application. 23 | func wireApp(confServer *conf.Server, confData *conf.Data, logLogger log.Logger, registry *nacos.Registry) (*kratos.App, func(), error) { 24 | db := data.NewDB(confData) 25 | client := data.NewCosServiceClient(confData) 26 | cmdable := data.NewRedis(confData) 27 | mqPro := data.NewRocketMqProducer(confData) 28 | creationClient := data.NewCreationServiceClient(registry) 29 | dataData, cleanup2, err := data.NewData(db, client, cmdable, mqPro, creationClient, logLogger) 30 | if err != nil { 31 | return nil, nil, err 32 | } 33 | commentRepo := data.NewCommentRepo(dataData, logLogger) 34 | recovery := data.NewRecovery(dataData) 35 | transaction := data.NewTransaction(dataData) 36 | commentUseCase := biz.NewCommentUseCase(commentRepo, recovery, transaction, logLogger) 37 | commentService := service.NewCommentService(commentUseCase, logLogger) 38 | httpServer := server.NewHTTPServer(confServer, commentService, logLogger) 39 | grpcServer := server.NewGRPCServer(confServer, commentService, logLogger) 40 | kratosApp := newApp(registry, httpServer, grpcServer) 41 | return kratosApp, func() { 42 | cleanup2() 43 | }, nil 44 | } 45 | -------------------------------------------------------------------------------- /app/comment/service/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/google/wire" 6 | ) 7 | 8 | var ProviderSet = wire.NewSet(NewCommentUseCase) 9 | 10 | type Transaction interface { 11 | ExecTx(context.Context, func(ctx context.Context) error) error 12 | } 13 | 14 | type Recovery interface { 15 | GroupRecover(context.Context, func(ctx context.Context) error) func() error 16 | } 17 | -------------------------------------------------------------------------------- /app/comment/service/internal/biz/do.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | type CommentDraft struct { 4 | Id int32 5 | Uuid string 6 | Status int32 7 | } 8 | 9 | //easyjson:json 10 | type CommentReview struct { 11 | Uuid string 12 | Id int32 13 | Mode string 14 | } 15 | 16 | type Comment struct { 17 | UpdatedAt int32 18 | CommentId int32 19 | CreationId int32 20 | CreationType int32 21 | CreationAuthor string 22 | Uuid string 23 | Agree int32 24 | Comment int32 25 | } 26 | 27 | type CommentUser struct { 28 | Uuid string 29 | Comment int32 30 | ArticleReply int32 31 | ArticleReplySub int32 32 | TalkReply int32 33 | TalkReplySub int32 34 | ArticleReplied int32 35 | ArticleRepliedSub int32 36 | TalkReplied int32 37 | TalkRepliedSub int32 38 | } 39 | 40 | type SubComment struct { 41 | CommentId int32 42 | UpdatedAt int32 43 | CreationId int32 44 | RootId int32 45 | ParentId int32 46 | CreationType int32 47 | CreationAuthor string 48 | RootUser string 49 | Uuid string 50 | Reply string 51 | UserName string 52 | ReplyName string 53 | RootName string 54 | Agree int32 55 | } 56 | 57 | type CommentStatistic struct { 58 | CommentId int32 59 | Agree int32 60 | Comment int32 61 | } 62 | 63 | //easyjson:json 64 | type TextReview struct { 65 | Id int32 66 | CommentId int32 67 | CreateAt string 68 | Comment string 69 | Kind string 70 | JobId string 71 | Label string 72 | Result int32 73 | Uuid string 74 | Mode string 75 | Section string 76 | } 77 | 78 | //easyjson:json 79 | type SendCommentMap struct { 80 | Uuid string 81 | Id int32 82 | CreationId int32 83 | CreationType int32 84 | Mode string 85 | } 86 | 87 | //easyjson:json 88 | type SendSubCommentMap struct { 89 | Uuid string 90 | Id int32 91 | RootId int32 92 | ParentId int32 93 | Mode string 94 | } 95 | 96 | //easyjson:json 97 | type SendCommentAgreeMap struct { 98 | Uuid string 99 | Id int32 100 | CreationId int32 101 | CreationType int32 102 | UserUuid string 103 | Mode string 104 | } 105 | 106 | //easyjson:json 107 | type SendSubCommentAgreeMap struct { 108 | Uuid string 109 | Id int32 110 | UserUuid string 111 | Mode string 112 | } 113 | 114 | //easyjson:json 115 | type SendCommentStatisticMap struct { 116 | Uuid string 117 | UserUuid string 118 | Mode string 119 | } 120 | 121 | //easyjson:json 122 | type SendScoreMap struct { 123 | Uuid string 124 | Score int32 125 | Mode string 126 | } 127 | -------------------------------------------------------------------------------- /app/comment/service/internal/conf/conf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package kratos.api; 3 | 4 | option go_package = "comment/service/internal/conf;conf"; 5 | 6 | import "google/protobuf/duration.proto"; 7 | 8 | message Bootstrap { 9 | Config config = 1; 10 | } 11 | 12 | message Config{ 13 | Server server = 1; 14 | Data data = 2; 15 | Log log = 3; 16 | } 17 | 18 | message Server { 19 | message HTTP { 20 | string network = 1; 21 | string addr = 2; 22 | google.protobuf.Duration timeout = 3; 23 | } 24 | message GRPC { 25 | string network = 1; 26 | string addr = 2; 27 | google.protobuf.Duration timeout = 3; 28 | } 29 | HTTP http = 1; 30 | GRPC grpc = 2; 31 | } 32 | 33 | message Data { 34 | message Database { 35 | string driver = 1; 36 | string source = 2; 37 | } 38 | message Redis { 39 | string network = 1; 40 | string addr = 2; 41 | string password = 3; 42 | google.protobuf.Duration read_timeout = 4; 43 | google.protobuf.Duration write_timeout = 5; 44 | } 45 | message RocketMq{ 46 | string serverAddress = 1; 47 | string secretKey = 2; 48 | string accessKey = 3; 49 | string nameSpace = 4; 50 | string groupName = 5; 51 | } 52 | message Cos{ 53 | string url = 1; 54 | string secret_id = 2; 55 | string secret_key = 3; 56 | } 57 | Database database = 1; 58 | Redis redis = 2; 59 | RocketMq rocketmq = 3; 60 | Cos cos = 4; 61 | } 62 | 63 | message Log { 64 | string host = 1; 65 | string accessKeyID = 2; 66 | string accessKeySecret = 3; 67 | string topicID = 4; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /app/comment/service/internal/data/model.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "gorm.io/gorm" 5 | "time" 6 | ) 7 | 8 | type CommentDraft struct { 9 | gorm.Model 10 | Uuid string `gorm:"index;size:20"` 11 | Status int32 `gorm:"default:1"` 12 | } 13 | 14 | type Comment struct { 15 | CommentId int32 `gorm:"primarykey"` 16 | CreatedAt time.Time 17 | UpdatedAt time.Time 18 | DeletedAt gorm.DeletedAt `gorm:"index"` 19 | CreationId int32 `gorm:"index:creation"` 20 | CreationType int32 `gorm:"index:creation"` 21 | CreationAuthor string `gorm:"index;size:20"` 22 | Uuid string `gorm:"index;size:20"` 23 | Agree int32 `gorm:"index;type:int unsigned;default:0"` 24 | Comment int32 `gorm:"type:int unsigned;default:0"` 25 | } 26 | 27 | type CommentAgree struct { 28 | gorm.Model 29 | CommentId int32 `gorm:"uniqueIndex:idx_unique"` 30 | Uuid string `gorm:"uniqueIndex:idx_unique;index;size:20"` 31 | Status int32 `gorm:"default:1"` 32 | } 33 | 34 | type SubComment struct { 35 | CommentId int32 `gorm:"primarykey"` 36 | CreatedAt time.Time 37 | UpdatedAt time.Time 38 | DeletedAt gorm.DeletedAt `gorm:"index"` 39 | CreationId int32 `gorm:"index:creation"` 40 | CreationType int32 `gorm:"index:creation"` 41 | CreationAuthor string `gorm:"size:20"` 42 | RootId int32 `gorm:"index"` 43 | RootUser string `gorm:"index;size:20"` 44 | ParentId int32 `gorm:"index"` 45 | Uuid string `gorm:"index;size:20"` 46 | Reply string `gorm:"index;size:20"` 47 | Agree int32 `gorm:"type:int unsigned;default:0"` 48 | } 49 | 50 | type CommentUser struct { 51 | CreatedAt time.Time 52 | UpdatedAt time.Time 53 | Uuid string `gorm:"primarykey;size:20"` 54 | Comment int32 `gorm:"type:int unsigned;default:0"` 55 | ArticleReply int32 `gorm:"type:int unsigned;default:0"` 56 | ArticleReplySub int32 `gorm:"type:int unsigned;default:0"` 57 | TalkReply int32 `gorm:"type:int unsigned;default:0"` 58 | TalkReplySub int32 `gorm:"type:int unsigned;default:0"` 59 | ArticleReplied int32 `gorm:"type:int unsigned;default:0"` 60 | ArticleRepliedSub int32 `gorm:"type:int unsigned;default:0"` 61 | TalkReplied int32 `gorm:"type:int unsigned;default:0"` 62 | TalkRepliedSub int32 `gorm:"type:int unsigned;default:0"` 63 | } 64 | 65 | type CommentContentReview struct { 66 | gorm.Model 67 | CommentId int32 68 | Comment string 69 | Kind string 70 | Uuid string `gorm:"index;size:20"` 71 | JobId string `gorm:"size:100"` 72 | Label string `gorm:"size:100"` 73 | Result int32 74 | Section string 75 | } 76 | 77 | type Record struct { 78 | gorm.Model 79 | Uuid string `gorm:"size:20"` 80 | CommonId int32 81 | Ip string 82 | } 83 | -------------------------------------------------------------------------------- /app/comment/service/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/ratelimit" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/middleware/tracing" 10 | "github.com/go-kratos/kratos/v2/middleware/validate" 11 | "github.com/go-kratos/kratos/v2/transport/grpc" 12 | v1 "github.com/the-zion/matrix-core/api/comment/service/v1" 13 | "github.com/the-zion/matrix-core/app/comment/service/internal/conf" 14 | "github.com/the-zion/matrix-core/app/comment/service/internal/service" 15 | "github.com/the-zion/matrix-core/pkg/responce" 16 | ) 17 | 18 | func NewGRPCServer(c *conf.Server, commentService *service.CommentService, logger log.Logger) *grpc.Server { 19 | var opts = []grpc.ServerOption{ 20 | grpc.Middleware( 21 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 22 | l := log.NewHelper(log.With(logger, "message", "panic")) 23 | l.Error(err) 24 | return nil 25 | })), 26 | ratelimit.Server(), 27 | tracing.Server(), 28 | responce.Server(), 29 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 30 | validate.Validator(), 31 | ), 32 | } 33 | if c.Grpc.Network != "" { 34 | opts = append(opts, grpc.Network(c.Grpc.Network)) 35 | } 36 | if c.Grpc.Addr != "" { 37 | opts = append(opts, grpc.Address(c.Grpc.Addr)) 38 | } 39 | if c.Grpc.Timeout != nil { 40 | opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) 41 | } 42 | srv := grpc.NewServer(opts...) 43 | v1.RegisterCommentServer(srv, commentService) 44 | return srv 45 | } 46 | -------------------------------------------------------------------------------- /app/comment/service/internal/server/http.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/recovery" 8 | "github.com/go-kratos/kratos/v2/transport/http" 9 | "github.com/the-zion/matrix-core/api/comment/service/v1" 10 | "github.com/the-zion/matrix-core/app/comment/service/internal/conf" 11 | "github.com/the-zion/matrix-core/app/comment/service/internal/service" 12 | ) 13 | 14 | // NewHTTPServer new a HTTP user. 15 | func NewHTTPServer(c *conf.Server, commentService *service.CommentService, logger log.Logger) *http.Server { 16 | var opts = []http.ServerOption{ 17 | http.Middleware( 18 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 19 | l := log.NewHelper(log.With(logger, "message", "panic")) 20 | l.Error(err) 21 | return nil 22 | })), 23 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 24 | ), 25 | } 26 | if c.Http.Network != "" { 27 | opts = append(opts, http.Network(c.Http.Network)) 28 | } 29 | if c.Http.Addr != "" { 30 | opts = append(opts, http.Address(c.Http.Addr)) 31 | } 32 | if c.Http.Timeout != nil { 33 | opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) 34 | } 35 | srv := http.NewServer(opts...) 36 | v1.RegisterCommentHTTPServer(srv, commentService) 37 | return srv 38 | } 39 | -------------------------------------------------------------------------------- /app/comment/service/internal/server/server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSet is user providers. 8 | var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) 9 | -------------------------------------------------------------------------------- /app/comment/service/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/google/wire" 7 | v1 "github.com/the-zion/matrix-core/api/comment/service/v1" 8 | "github.com/the-zion/matrix-core/app/comment/service/internal/biz" 9 | "google.golang.org/protobuf/types/known/emptypb" 10 | ) 11 | 12 | var ProviderSet = wire.NewSet(NewCommentService) 13 | 14 | type CommentService struct { 15 | v1.UnimplementedCommentServer 16 | cc *biz.CommentUseCase 17 | log *log.Helper 18 | } 19 | 20 | func NewCommentService(cc *biz.CommentUseCase, logger log.Logger) *CommentService { 21 | return &CommentService{ 22 | log: log.NewHelper(log.With(logger, "module", "comment/service")), 23 | cc: cc, 24 | } 25 | } 26 | 27 | func (s *CommentService) GetHealth(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 28 | return &emptypb.Empty{}, nil 29 | } 30 | -------------------------------------------------------------------------------- /app/comment/service/internal/tool/update/db.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/the-zion/matrix-core/app/comment/service/internal/data" 7 | "gorm.io/driver/mysql" 8 | "gorm.io/gorm" 9 | "os" 10 | ) 11 | 12 | var ( 13 | source string 14 | ) 15 | 16 | func NewDB(logger log.Logger) *gorm.DB { 17 | l := log.NewHelper(log.With(logger, "update", "db")) 18 | 19 | db, err := gorm.Open(mysql.Open(source), &gorm.Config{ 20 | DisableForeignKeyConstraintWhenMigrating: true, 21 | }) 22 | if err != nil { 23 | l.Fatalf("failed opening connection to db: %v", err) 24 | } 25 | if err := db.AutoMigrate( 26 | &data.Comment{}, 27 | &data.SubComment{}, 28 | &data.CommentDraft{}, 29 | &data.Record{}, 30 | &data.CommentAgree{}, 31 | &data.CommentUser{}, 32 | &data.CommentContentReview{}, 33 | ); err != nil { 34 | l.Fatalf("failed creat or update table resources: %v", err) 35 | } 36 | return db 37 | } 38 | 39 | func main() { 40 | flag.Parse() 41 | logger := log.NewStdLogger(os.Stdout) 42 | NewDB(logger) 43 | } 44 | 45 | func init() { 46 | flag.StringVar(&source, "source", 47 | "root:123456@tcp(127.0.0.1:3306)/core?charset=utf8mb4&parseTime=True&loc=Local", 48 | "database source, eg: -source source path") 49 | } 50 | -------------------------------------------------------------------------------- /app/creation/service/Makefile: -------------------------------------------------------------------------------- 1 | INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) 2 | INTERNAL_EASYJSON_FILES=$(shell find internal -name do.go) 3 | .PHONY: config 4 | # generate internal proto 5 | config: 6 | protoc --proto_path=./internal \ 7 | --proto_path=../../../third_party \ 8 | --go_out=paths=source_relative:./internal \ 9 | $(INTERNAL_PROTO_FILES) 10 | 11 | .PHONY: easyjson 12 | # generate internal proto 13 | easyjson: 14 | easyjson -lower_camel_case $(INTERNAL_EASYJSON_FILES) -------------------------------------------------------------------------------- /app/creation/service/README.md: -------------------------------------------------------------------------------- 1 | # Creation Service 2 | -------------------------------------------------------------------------------- /app/creation/service/cmd/creation/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package main 7 | 8 | import ( 9 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 10 | "github.com/go-kratos/kratos/v2" 11 | "github.com/go-kratos/kratos/v2/log" 12 | "github.com/google/wire" 13 | "github.com/the-zion/matrix-core/app/creation/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/creation/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/creation/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/creation/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/creation/service/internal/service" 18 | ) 19 | 20 | // wireApp init kratos application. 21 | func wireApp(*conf.Server, *conf.Data, log.Logger, *nacos.Registry) (*kratos.App, func(), error) { 22 | panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) 23 | } 24 | -------------------------------------------------------------------------------- /app/creation/service/cmd/creation/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 11 | "github.com/go-kratos/kratos/v2" 12 | "github.com/go-kratos/kratos/v2/log" 13 | "github.com/the-zion/matrix-core/app/creation/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/creation/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/creation/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/creation/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/creation/service/internal/service" 18 | ) 19 | 20 | // Injectors from wire.go: 21 | 22 | // wireApp init kratos application. 23 | func wireApp(confServer *conf.Server, confData *conf.Data, logLogger log.Logger, registry *nacos.Registry) (*kratos.App, func(), error) { 24 | db := data.NewDB(confData) 25 | cmdable := data.NewRedis(confData) 26 | client := data.NewCosServiceClient(confData) 27 | elasticSearch := data.NewElasticsearch(confData) 28 | mqPro := data.NewRocketmqProducer(confData) 29 | newsClient := data.NewNewsClient(confData) 30 | dataData, cleanup2, err := data.NewData(db, cmdable, client, elasticSearch, mqPro, newsClient, logLogger) 31 | if err != nil { 32 | return nil, nil, err 33 | } 34 | articleRepo := data.NewArticleRepo(dataData, logLogger) 35 | recovery := data.NewRecovery(dataData) 36 | creationRepo := data.NewCreationRepo(dataData, logLogger) 37 | transaction := data.NewTransaction(dataData) 38 | articleUseCase := biz.NewArticleUseCase(articleRepo, recovery, creationRepo, transaction, logLogger) 39 | talkRepo := data.NewTalkRepo(dataData, logLogger) 40 | talkUseCase := biz.NewTalkUseCase(talkRepo, recovery, creationRepo, transaction, logLogger) 41 | columnRepo := data.NewColumnRepo(dataData, logLogger) 42 | creationUseCase := biz.NewCreationUseCase(creationRepo, articleRepo, talkRepo, columnRepo, transaction, recovery, logLogger) 43 | columnUseCase := biz.NewColumnUseCase(columnRepo, recovery, creationRepo, transaction, logLogger) 44 | newsRepo := data.NewNewsRepo(dataData, logLogger) 45 | newsUseCase := biz.NewNewsUseCase(newsRepo, transaction, logLogger) 46 | creationService := service.NewCreationService(articleUseCase, talkUseCase, creationUseCase, columnUseCase, newsUseCase, logLogger) 47 | httpServer := server.NewHTTPServer(confServer, creationService, logLogger) 48 | grpcServer := server.NewGRPCServer(confServer, creationService, logLogger) 49 | kratosApp := newApp(registry, httpServer, grpcServer) 50 | return kratosApp, func() { 51 | cleanup2() 52 | }, nil 53 | } 54 | -------------------------------------------------------------------------------- /app/creation/service/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/google/wire" 6 | ) 7 | 8 | var ProviderSet = wire.NewSet(NewArticleUseCase, NewTalkUseCase, NewCreationUseCase, NewColumnUseCase, NewNewsUseCase) 9 | 10 | type Transaction interface { 11 | ExecTx(context.Context, func(ctx context.Context) error) error 12 | } 13 | 14 | type Recovery interface { 15 | GroupRecover(context.Context, func(ctx context.Context) error) func() error 16 | } 17 | -------------------------------------------------------------------------------- /app/creation/service/internal/biz/news.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | v1 "github.com/the-zion/matrix-core/api/creation/service/v1" 7 | ) 8 | 9 | type NewsRepo interface { 10 | GetNews(ctx context.Context, page int32) ([]*News, error) 11 | GetNewsSearch(ctx context.Context, page int32, search, time string) ([]*NewsSearch, int32, error) 12 | } 13 | 14 | type NewsUseCase struct { 15 | repo NewsRepo 16 | tm Transaction 17 | log *log.Helper 18 | } 19 | 20 | func NewNewsUseCase(repo NewsRepo, tm Transaction, logger log.Logger) *NewsUseCase { 21 | return &NewsUseCase{ 22 | repo: repo, 23 | tm: tm, 24 | log: log.NewHelper(log.With(logger, "module", "creation/biz/newsUseCase")), 25 | } 26 | } 27 | 28 | func (r *NewsUseCase) GetNews(ctx context.Context, page int32) ([]*News, error) { 29 | news, err := r.repo.GetNews(ctx, page) 30 | if err != nil { 31 | return nil, v1.ErrorGetNewsFailed("get news failed: %s", err.Error()) 32 | } 33 | return news, nil 34 | } 35 | 36 | func (r *NewsUseCase) GetNewsSearch(ctx context.Context, page int32, search, time string) ([]*NewsSearch, int32, error) { 37 | newsList, total, err := r.repo.GetNewsSearch(ctx, page, search, time) 38 | if err != nil { 39 | return nil, 0, v1.ErrorGetNewsSearchFailed("get news search failed: %s", err.Error()) 40 | } 41 | return newsList, total, nil 42 | } 43 | -------------------------------------------------------------------------------- /app/creation/service/internal/conf/conf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package kratos.api; 3 | 4 | option go_package = "message/service/internal/conf;conf"; 5 | 6 | import "google/protobuf/duration.proto"; 7 | 8 | message Bootstrap { 9 | Config config = 1; 10 | } 11 | 12 | message Config{ 13 | Server server = 1; 14 | Data data = 2; 15 | Log log = 3; 16 | } 17 | 18 | message Server { 19 | message HTTP { 20 | string network = 1; 21 | string addr = 2; 22 | google.protobuf.Duration timeout = 3; 23 | } 24 | message GRPC { 25 | string network = 1; 26 | string addr = 2; 27 | google.protobuf.Duration timeout = 3; 28 | } 29 | HTTP http = 1; 30 | GRPC grpc = 2; 31 | } 32 | 33 | message Data { 34 | message Database { 35 | string driver = 1; 36 | string source = 2; 37 | } 38 | message Redis { 39 | string network = 1; 40 | string addr = 2; 41 | string password = 3; 42 | google.protobuf.Duration read_timeout = 4; 43 | google.protobuf.Duration write_timeout = 5; 44 | } 45 | message Cos{ 46 | string url = 1; 47 | string secret_id = 2; 48 | string secret_key = 3; 49 | } 50 | message RocketMq{ 51 | string serverAddress = 1; 52 | string secretKey = 2; 53 | string accessKey = 3; 54 | string nameSpace = 4; 55 | string groupName = 5; 56 | } 57 | message ElasticSearch{ 58 | string endpoint = 1; 59 | string user = 2; 60 | string password = 3; 61 | } 62 | message News{ 63 | string url = 1; 64 | } 65 | Database database = 1; 66 | Redis redis = 2; 67 | Cos cos = 3; 68 | RocketMq rocketmq = 4; 69 | ElasticSearch elasticSearch = 6; 70 | News news = 7; 71 | } 72 | 73 | message Log { 74 | string host = 1; 75 | string accessKeyID = 2; 76 | string accessKeySecret = 3; 77 | string topicID = 4; 78 | } 79 | -------------------------------------------------------------------------------- /app/creation/service/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/ratelimit" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/middleware/tracing" 10 | "github.com/go-kratos/kratos/v2/middleware/validate" 11 | "github.com/go-kratos/kratos/v2/transport/grpc" 12 | v1 "github.com/the-zion/matrix-core/api/creation/service/v1" 13 | "github.com/the-zion/matrix-core/app/creation/service/internal/conf" 14 | "github.com/the-zion/matrix-core/app/creation/service/internal/service" 15 | "github.com/the-zion/matrix-core/pkg/responce" 16 | ) 17 | 18 | func NewGRPCServer(c *conf.Server, creationService *service.CreationService, logger log.Logger) *grpc.Server { 19 | var opts = []grpc.ServerOption{ 20 | grpc.Middleware( 21 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 22 | l := log.NewHelper(log.With(logger, "message", "panic")) 23 | l.Error(err) 24 | return nil 25 | })), 26 | ratelimit.Server(), 27 | tracing.Server(), 28 | responce.Server(), 29 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 30 | validate.Validator(), 31 | ), 32 | } 33 | if c.Grpc.Network != "" { 34 | opts = append(opts, grpc.Network(c.Grpc.Network)) 35 | } 36 | if c.Grpc.Addr != "" { 37 | opts = append(opts, grpc.Address(c.Grpc.Addr)) 38 | } 39 | if c.Grpc.Timeout != nil { 40 | opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) 41 | } 42 | srv := grpc.NewServer(opts...) 43 | v1.RegisterCreationServer(srv, creationService) 44 | return srv 45 | 46 | } 47 | -------------------------------------------------------------------------------- /app/creation/service/internal/server/http.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/recovery" 8 | "github.com/go-kratos/kratos/v2/transport/http" 9 | "github.com/the-zion/matrix-core/api/creation/service/v1" 10 | "github.com/the-zion/matrix-core/app/creation/service/internal/conf" 11 | "github.com/the-zion/matrix-core/app/creation/service/internal/service" 12 | ) 13 | 14 | // NewHTTPServer new a HTTP user. 15 | func NewHTTPServer(c *conf.Server, creationService *service.CreationService, logger log.Logger) *http.Server { 16 | var opts = []http.ServerOption{ 17 | http.Middleware( 18 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 19 | l := log.NewHelper(log.With(logger, "message", "panic")) 20 | l.Error(err) 21 | return nil 22 | })), 23 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 24 | ), 25 | } 26 | if c.Http.Network != "" { 27 | opts = append(opts, http.Network(c.Http.Network)) 28 | } 29 | if c.Http.Addr != "" { 30 | opts = append(opts, http.Address(c.Http.Addr)) 31 | } 32 | if c.Http.Timeout != nil { 33 | opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) 34 | } 35 | srv := http.NewServer(opts...) 36 | v1.RegisterCreationHTTPServer(srv, creationService) 37 | return srv 38 | } 39 | -------------------------------------------------------------------------------- /app/creation/service/internal/server/server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSet is user providers. 8 | var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) 9 | -------------------------------------------------------------------------------- /app/creation/service/internal/service/news.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | v1 "github.com/the-zion/matrix-core/api/creation/service/v1" 6 | ) 7 | 8 | func (s *CreationService) GetNews(ctx context.Context, req *v1.GetNewsReq) (*v1.GetNewsReply, error) { 9 | newsList, err := s.nc.GetNews(ctx, req.Page) 10 | if err != nil { 11 | return nil, err 12 | } 13 | reply := &v1.GetNewsReply{News: make([]*v1.GetNewsReply_News, 0, len(newsList))} 14 | for _, item := range newsList { 15 | reply.News = append(reply.News, &v1.GetNewsReply_News{ 16 | Id: item.Id, 17 | }) 18 | } 19 | return reply, nil 20 | } 21 | 22 | func (s *CreationService) GetNewsSearch(ctx context.Context, req *v1.GetNewsSearchReq) (*v1.GetNewsSearchReply, error) { 23 | newsList, total, err := s.nc.GetNewsSearch(ctx, req.Page, req.Search, req.Time) 24 | if err != nil { 25 | return nil, err 26 | } 27 | reply := &v1.GetNewsSearchReply{List: make([]*v1.GetNewsSearchReply_List, 0, len(newsList))} 28 | for _, item := range newsList { 29 | reply.List = append(reply.List, &v1.GetNewsSearchReply_List{ 30 | Id: item.Id, 31 | Tags: item.Tags, 32 | Title: item.Title, 33 | Author: item.Author, 34 | Update: item.Update, 35 | Url: item.Url, 36 | Content: item.Content, 37 | Cover: item.Cover, 38 | }) 39 | } 40 | reply.Total = total 41 | return reply, nil 42 | } 43 | -------------------------------------------------------------------------------- /app/creation/service/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/google/wire" 7 | v1 "github.com/the-zion/matrix-core/api/creation/service/v1" 8 | "github.com/the-zion/matrix-core/app/creation/service/internal/biz" 9 | "google.golang.org/protobuf/types/known/emptypb" 10 | ) 11 | 12 | var ProviderSet = wire.NewSet(NewCreationService) 13 | 14 | type CreationService struct { 15 | v1.UnimplementedCreationServer 16 | ac *biz.ArticleUseCase 17 | tc *biz.TalkUseCase 18 | cc *biz.CreationUseCase 19 | coc *biz.ColumnUseCase 20 | nc *biz.NewsUseCase 21 | log *log.Helper 22 | } 23 | 24 | func NewCreationService(ac *biz.ArticleUseCase, tc *biz.TalkUseCase, cc *biz.CreationUseCase, coc *biz.ColumnUseCase, nc *biz.NewsUseCase, logger log.Logger) *CreationService { 25 | return &CreationService{ 26 | log: log.NewHelper(log.With(logger, "module", "creation/service")), 27 | ac: ac, 28 | tc: tc, 29 | cc: cc, 30 | coc: coc, 31 | nc: nc, 32 | } 33 | } 34 | 35 | func (s *CreationService) GetHealth(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 36 | return &emptypb.Empty{}, nil 37 | } 38 | -------------------------------------------------------------------------------- /app/creation/service/internal/tool/es/dsl: -------------------------------------------------------------------------------- 1 | PUT article 2 | { 3 | "mappings": { 4 | "properties": { 5 | "title": { 6 | "type": "text", 7 | "analyzer": "thulac" 8 | }, 9 | "tags": { 10 | "type": "text", 11 | "analyzer": "thulac" 12 | }, 13 | "text": { 14 | "type": "text", 15 | "analyzer": "thulac" 16 | }, 17 | "cover": { 18 | "type": "text", 19 | "index": false 20 | }, 21 | "uuid": { 22 | "type": "text", 23 | "index": false 24 | }, 25 | "update": { 26 | "type": "date", 27 | "format": "yyyy/M/d" 28 | } 29 | } 30 | } 31 | } 32 | 33 | PUT talk 34 | { 35 | "mappings": { 36 | "properties": { 37 | "title": { 38 | "type": "text", 39 | "analyzer": "thulac" 40 | }, 41 | "tags": { 42 | "type": "text", 43 | "analyzer": "thulac" 44 | }, 45 | "text": { 46 | "type": "text", 47 | "analyzer": "thulac" 48 | }, 49 | "cover": { 50 | "type": "text", 51 | "index": false 52 | }, 53 | "uuid": { 54 | "type": "text", 55 | "index": false 56 | }, 57 | "update": { 58 | "type": "date", 59 | "format": "yyyy/M/d" 60 | } 61 | } 62 | } 63 | } 64 | 65 | PUT column 66 | { 67 | "mappings": { 68 | "properties": { 69 | "name": { 70 | "type": "text", 71 | "analyzer": "thulac" 72 | }, 73 | "tags": { 74 | "type": "text", 75 | "analyzer": "thulac" 76 | }, 77 | "introduce": { 78 | "type": "text", 79 | "analyzer": "thulac" 80 | }, 81 | "cover": { 82 | "type": "text", 83 | "index": false 84 | }, 85 | "uuid": { 86 | "type": "text", 87 | "index": false 88 | }, 89 | "update": { 90 | "type": "date", 91 | "format": "yyyy/M/d" 92 | } 93 | } 94 | } 95 | } 96 | 97 | PUT news 98 | { 99 | "mappings": { 100 | "properties": { 101 | "title": { 102 | "type": "text", 103 | "analyzer": "thulac" 104 | }, 105 | "tags": { 106 | "type": "text", 107 | "analyzer": "thulac" 108 | }, 109 | "content": { 110 | "type": "text", 111 | "analyzer": "thulac" 112 | }, 113 | "cover": { 114 | "type": "text", 115 | "index": false 116 | }, 117 | "author": { 118 | "type": "text", 119 | "index": false 120 | }, 121 | "url": { 122 | "type": "text", 123 | "index": false 124 | }, 125 | "update": { 126 | "type": "date", 127 | "format": "yyyy-MM-dd HH:mm:ss" 128 | } 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /app/creation/service/internal/tool/update/db.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/the-zion/matrix-core/app/creation/service/internal/data" 7 | "gorm.io/driver/mysql" 8 | "gorm.io/gorm" 9 | "os" 10 | ) 11 | 12 | var ( 13 | source string 14 | ) 15 | 16 | func NewDB(logger log.Logger) *gorm.DB { 17 | l := log.NewHelper(log.With(logger, "update", "db")) 18 | 19 | db, err := gorm.Open(mysql.Open(source), &gorm.Config{ 20 | DisableForeignKeyConstraintWhenMigrating: true, 21 | }) 22 | if err != nil { 23 | l.Fatalf("failed opening connection to db: %v", err) 24 | } 25 | if err := db.AutoMigrate( 26 | &data.Article{}, 27 | &data.ArticleReview{}, 28 | &data.ArticleContentReview{}, 29 | &data.Subscribe{}, 30 | &data.ArticleStatistic{}, 31 | &data.ArticleDraft{}, 32 | &data.ArticleAgree{}, 33 | &data.ArticleCollect{}, 34 | &data.Collections{}, 35 | &data.Collect{}, 36 | &data.CollectionsDraft{}, 37 | &data.CollectionsContentReview{}, 38 | &data.Talk{}, 39 | &data.TalkReview{}, 40 | &data.TalkContentReview{}, 41 | &data.TalkDraft{}, 42 | &data.TalkStatistic{}, 43 | &data.TalkAgree{}, 44 | &data.TalkCollect{}, 45 | &data.Column{}, 46 | &data.ColumnReview{}, 47 | &data.ColumnContentReview{}, 48 | &data.ColumnDraft{}, 49 | &data.ColumnStatistic{}, 50 | &data.ColumnInclusion{}, 51 | &data.ColumnAgree{}, 52 | &data.ColumnCollect{}, 53 | &data.Subscribe{}, 54 | &data.Record{}, 55 | &data.CreationUser{}, 56 | &data.CreationUserVisitor{}, 57 | &data.TimeLine{}, 58 | &data.News{}, 59 | ); err != nil { 60 | l.Fatalf("failed creat or update table resources: %v", err) 61 | } 62 | return db 63 | } 64 | 65 | func main() { 66 | flag.Parse() 67 | logger := log.NewStdLogger(os.Stdout) 68 | NewDB(logger) 69 | } 70 | 71 | func init() { 72 | flag.StringVar(&source, "source", 73 | "root:123456@tcp(127.0.0.1:3306)/core?charset=utf8mb4&parseTime=True&loc=Local", 74 | "database source, eg: -source source path") 75 | } 76 | -------------------------------------------------------------------------------- /app/job/service/Makefile: -------------------------------------------------------------------------------- 1 | INTERNAL_EASYJSON_FILES=$(shell find cmd -name main.go) 2 | 3 | .PHONY: easyjson 4 | # generate internal proto 5 | easyjson: 6 | easyjson -lower_camel_case $(INTERNAL_EASYJSON_FILES) -------------------------------------------------------------------------------- /app/job/service/cmd/job/config.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/pkg/errors" 8 | "io/ioutil" 9 | "net/http" 10 | "os" 11 | "time" 12 | ) 13 | 14 | func getConfig() (map[string]interface{}, error) { 15 | config := map[string]interface{}{} 16 | url := fmt.Sprintf("http://%s/nacos/v1/cs/configs?dataId=%s&group=%s&tenant=%s&accessToken=%s", 17 | os.Getenv("NACOS_ADDR"), 18 | os.Getenv("NACOS_DATAID"), 19 | os.Getenv("NACOS_GROUP"), 20 | os.Getenv("NACOS_NAMESPACE"), 21 | os.Getenv("NACOS_ACCESS_TOKEN")) 22 | method := "GET" 23 | client := &http.Client{} 24 | 25 | ctx, _ := context.WithTimeout(context.Background(), time.Second*5) 26 | req, err := http.NewRequestWithContext(ctx, method, url, nil) 27 | if err != nil { 28 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to new request: %s", "getConfig")) 29 | } 30 | 31 | res, err := client.Do(req) 32 | defer res.Body.Close() 33 | if err != nil { 34 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to load config: %s", "getConfig")) 35 | } 36 | 37 | body, err := ioutil.ReadAll(res.Body) 38 | err = json.Unmarshal(body, &config) 39 | if err != nil { 40 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to unmarshal news: %s", "getConfig")) 41 | } 42 | return config, nil 43 | } 44 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/content.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/pkg/errors" 8 | "io/ioutil" 9 | "net/http" 10 | "regexp" 11 | "strings" 12 | "time" 13 | "unicode/utf8" 14 | ) 15 | 16 | func getContent(config map[string]interface{}, m map[string]string) error { 17 | url := config["gugudata"].(map[string]interface{})["content_url"].(string) 18 | key := config["gugudata"].(map[string]interface{})["content_key"].(string) 19 | method := "POST" 20 | data := map[string]interface{}{} 21 | 22 | payload := strings.NewReader(fmt.Sprintf("appkey=%s&url=%s&contentwithhtml=false&htmlsourcecontent=false", key, m["url"])) 23 | 24 | client := &http.Client{} 25 | ctx, _ := context.WithTimeout(context.Background(), time.Second*60) 26 | req, err := http.NewRequestWithContext(ctx, method, url, payload) 27 | if err != nil { 28 | return errors.Wrapf(err, fmt.Sprintf("fail to new request: %s", "getContent")) 29 | } 30 | 31 | req.Header.Add("Content-Type", "application/x-www-form-urlencoded") 32 | 33 | res, err := client.Do(req) 34 | if err != nil { 35 | return errors.Wrapf(err, fmt.Sprintf("fail to get news content: %s", "getContent")) 36 | } 37 | defer res.Body.Close() 38 | 39 | body, err := ioutil.ReadAll(res.Body) 40 | if err != nil { 41 | return errors.Wrapf(err, fmt.Sprintf("fail to read data from body: %s", "getContent")) 42 | } 43 | 44 | err = json.Unmarshal(body, &data) 45 | if err != nil { 46 | return errors.Wrapf(err, fmt.Sprintf("fail to unmarshal news: %s", "getContent")) 47 | } 48 | 49 | if data["Data"] == nil { 50 | err = errors.New(fmt.Sprintf("%v", data)) 51 | return errors.Wrapf(err, fmt.Sprintf("fail to get news content: %s", "getContent")) 52 | } 53 | 54 | m["content"] = regexp.MustCompile("\\s+").ReplaceAllString(data["Data"].(map[string]interface{})["Content"].(string), "") 55 | m["content"] = regexp.MustCompile("\\[[\\\\u0-9a-zA-Z]+\\]").ReplaceAllString(m["content"], "") 56 | if m["content"] != "" { 57 | length := utf8.RuneCountInString(m["content"]) 58 | if length > 250 { 59 | var n, i int 60 | for i = range m["content"] { 61 | if n == 250 { 62 | break 63 | } 64 | n++ 65 | } 66 | m["introduce"] = m["content"][:i] 67 | } else { 68 | m["introduce"] = m["content"] 69 | } 70 | } 71 | return nil 72 | } 73 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/cos.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "encoding/json" 7 | "fmt" 8 | "github.com/pkg/errors" 9 | "github.com/tencentyun/cos-go-sdk-v5" 10 | "net/http" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | type CosClient struct { 16 | client *cos.Client 17 | } 18 | 19 | func (s *CosClient) setNews(m map[string]string) error { 20 | content, err := json.Marshal(m) 21 | if err != nil { 22 | return errors.Wrapf(err, fmt.Sprintf("fail to unmarshal news content: %s", "cos-setNews")) 23 | } 24 | 25 | name := "news/" + m["id"] + "/content" 26 | ctx, _ := context.WithTimeout(context.Background(), time.Second*60) 27 | _, err = s.client.Object.Put(ctx, name, bytes.NewReader(content), nil) 28 | if err != nil { 29 | return errors.Wrapf(err, fmt.Sprintf("fail to add content to cos: %s", "cos-setNews")) 30 | } 31 | 32 | introduce, err := json.Marshal(map[string]string{ 33 | "id": m["id"], 34 | "cover": m["cover"], 35 | "update": m["update"], 36 | "title": m["title"], 37 | "author": m["author"], 38 | "tags": m["tags"], 39 | "url": m["url"], 40 | "introduce": m["introduce"], 41 | }) 42 | if err != nil { 43 | return errors.Wrapf(err, fmt.Sprintf("fail to unmarshal news content: %s", "cos-setNews")) 44 | } 45 | 46 | name = "news/" + m["id"] + "/introduce" 47 | ctx, _ = context.WithTimeout(context.Background(), time.Second*60) 48 | _, err = s.client.Object.Put(ctx, name, bytes.NewReader(introduce), nil) 49 | if err != nil { 50 | return errors.Wrapf(err, fmt.Sprintf("fail to add introduce to cos: %s", "cos-setNews")) 51 | } 52 | return err 53 | } 54 | 55 | func newCosServiceClient(config map[string]interface{}) (*CosClient, error) { 56 | addr := config["cos"].(map[string]interface{})["url"].(string) 57 | secretId := config["cos"].(map[string]interface{})["secret_id"].(string) 58 | secretKey := config["cos"].(map[string]interface{})["secret_key"].(string) 59 | 60 | u, err := url.Parse(addr) 61 | if err != nil { 62 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to init cos server: %s", "newCosServiceClient")) 63 | } 64 | b := &cos.BaseURL{BucketURL: u} 65 | return &CosClient{ 66 | client: cos.NewClient(b, &http.Client{ 67 | Transport: &cos.AuthorizationTransport{ 68 | SecretID: secretId, 69 | SecretKey: secretKey, 70 | }, 71 | })}, nil 72 | } 73 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/db.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "github.com/pkg/errors" 7 | "gorm.io/driver/mysql" 8 | "gorm.io/gorm" 9 | "strings" 10 | "time" 11 | ) 12 | 13 | type DB struct { 14 | client *gorm.DB 15 | } 16 | 17 | func (db *DB) setNews(m map[string]string) error { 18 | user := &News{ 19 | Id: m["id"], 20 | } 21 | ctx, _ := context.WithTimeout(context.Background(), time.Second*60) 22 | err := db.client.WithContext(ctx).Select("Id").Create(user).Error 23 | if err != nil { 24 | e := err.Error() 25 | if strings.Contains(e, "Duplicate") { 26 | return nil 27 | } else { 28 | return errors.Wrapf(err, fmt.Sprintf("fail to insert a new: %s", "db-setNews")) 29 | } 30 | } 31 | return nil 32 | } 33 | 34 | func newDB(config map[string]interface{}) (*DB, error) { 35 | source := config["db"].(map[string]interface{})["source"].(string) 36 | db, err := gorm.Open(mysql.Open(source), &gorm.Config{ 37 | DisableForeignKeyConstraintWhenMigrating: true, 38 | }) 39 | if err != nil { 40 | return nil, errors.Wrapf(err, fmt.Sprintf("failed opening connection to db: %s", "newDB")) 41 | } 42 | return &DB{ 43 | client: db, 44 | }, nil 45 | } 46 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/es.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "encoding/json" 7 | "fmt" 8 | "github.com/elastic/go-elasticsearch/v7" 9 | "github.com/elastic/go-elasticsearch/v7/esapi" 10 | "github.com/pkg/errors" 11 | "time" 12 | ) 13 | 14 | type ElasticSearch struct { 15 | client *elasticsearch.Client 16 | } 17 | 18 | func (es *ElasticSearch) setNews(m map[string]string) error { 19 | delete(m, "introduce") 20 | s, err := json.Marshal(m) 21 | if err != nil { 22 | return errors.Wrapf(err, fmt.Sprintf("fail to marshal news: %s", "es-setNews")) 23 | } 24 | 25 | req := esapi.IndexRequest{ 26 | Index: "news", 27 | DocumentID: m["id"], 28 | Body: bytes.NewReader(s), 29 | Refresh: "true", 30 | } 31 | ctx, _ := context.WithTimeout(context.Background(), time.Second*60) 32 | res, err := req.Do(ctx, es.client) 33 | if err != nil { 34 | return errors.Wrapf(err, fmt.Sprintf("error getting news search create response: %s", "es-setNews")) 35 | } 36 | defer res.Body.Close() 37 | 38 | if res.IsError() { 39 | var e map[string]interface{} 40 | if err = json.NewDecoder(res.Body).Decode(&e); err != nil { 41 | return errors.Wrapf(err, fmt.Sprintf("error parsing the response body: %s", "es-setNews")) 42 | } else { 43 | return errors.Wrapf(err, fmt.Sprintf("error indexing document to es: %s", "es-setNews")) 44 | } 45 | } 46 | return nil 47 | } 48 | 49 | func newElasticsearch(config map[string]interface{}) (*ElasticSearch, error) { 50 | addr := config["elasticSearch"].(map[string]interface{})["addr"].(string) 51 | user := config["elasticSearch"].(map[string]interface{})["user"].(string) 52 | password := config["elasticSearch"].(map[string]interface{})["password"].(string) 53 | 54 | cfg := elasticsearch.Config{ 55 | Username: user, 56 | Password: password, 57 | Addresses: []string{ 58 | addr, 59 | }, 60 | } 61 | es, err := elasticsearch.NewClient(cfg) 62 | if err != nil { 63 | return nil, errors.Wrapf(err, fmt.Sprintf("error creating the es client: %s", "newElasticsearch")) 64 | } 65 | 66 | res, err := es.Info() 67 | if err != nil { 68 | return nil, errors.Wrapf(err, fmt.Sprintf("Error getting response: %s", "newElasticsearch")) 69 | } 70 | defer res.Body.Close() 71 | 72 | if res.IsError() { 73 | return nil, errors.Wrapf(err, fmt.Sprintf("Error: %s", "newElasticsearch")) 74 | } 75 | 76 | return &ElasticSearch{ 77 | client: es, 78 | }, nil 79 | } 80 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | cls "github.com/tencentcloud/tencentcloud-cls-sdk-go" 6 | "os" 7 | "time" 8 | ) 9 | 10 | type Log struct { 11 | client *cls.AsyncProducerClient 12 | topicId string 13 | } 14 | 15 | func (l *Log) SendLog(content string) { 16 | callBack := &Callback{} 17 | log := cls.NewCLSLog(time.Now().Unix(), map[string]string{"error": content}) 18 | err := l.client.SendLog(l.topicId, log, callBack) 19 | if err != nil { 20 | fmt.Println(err) 21 | } 22 | } 23 | 24 | type Callback struct { 25 | } 26 | 27 | func (callback *Callback) Success(result *cls.Result) { 28 | attemptList := result.GetReservedAttempts() 29 | for _, attempt := range attemptList { 30 | fmt.Printf("%+v \n", attempt) 31 | } 32 | } 33 | 34 | func (callback *Callback) Fail(result *cls.Result) { 35 | fmt.Println(result.IsSuccessful()) 36 | fmt.Println(result.GetErrorCode()) 37 | fmt.Println(result.GetErrorMessage()) 38 | fmt.Println(result.GetReservedAttempts()) 39 | fmt.Println(result.GetRequestId()) 40 | fmt.Println(result.GetTimeStampMs()) 41 | } 42 | 43 | func logInit() (*Log, error) { 44 | producerConfig := cls.GetDefaultAsyncProducerClientConfig() 45 | producerConfig.Endpoint = os.Getenv("TENCENT_LOG_HOST") 46 | producerConfig.AccessKeyID = os.Getenv("TENCENT_LOG_ACCESSKEY") 47 | producerConfig.AccessKeySecret = os.Getenv("TENCENT_LOG_ACCESSSECRET") 48 | topicId := os.Getenv("TENCENT_LOG_TOPIC_ID") 49 | producerInstance, err := cls.NewAsyncProducerClient(producerConfig) 50 | if err != nil { 51 | fmt.Print(fmt.Sprintf("fail to init log: %v", err)) 52 | return nil, err 53 | } 54 | 55 | producerInstance.Start() 56 | return &Log{ 57 | client: producerInstance, 58 | topicId: topicId, 59 | }, nil 60 | } 61 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "time" 4 | 5 | func main() { 6 | log, err := logInit() 7 | if err != nil { 8 | return 9 | } 10 | defer log.client.Close(60000) 11 | 12 | config, err := getConfig() 13 | if err != nil { 14 | log.SendLog(err.Error()) 15 | return 16 | } 17 | 18 | news, err := getNews(config) 19 | if err != nil { 20 | log.SendLog(err.Error()) 21 | return 22 | } 23 | 24 | dbClient, err := newDB(config) 25 | if err != nil { 26 | log.SendLog(err.Error()) 27 | return 28 | } 29 | 30 | redisClient, err := newRedis(config) 31 | if err != nil { 32 | log.SendLog(err.Error()) 33 | return 34 | } 35 | 36 | cosCli, err := newCosServiceClient(config) 37 | if err != nil { 38 | log.SendLog(err.Error()) 39 | return 40 | } 41 | 42 | es, err := newElasticsearch(config) 43 | if err != nil { 44 | log.SendLog(err.Error()) 45 | return 46 | } 47 | 48 | setNews(news, cosCli, es, dbClient, redisClient, config, log) 49 | } 50 | 51 | func setNews(news []*News, cosCli *CosClient, es *ElasticSearch, db *DB, redis *Redis, config map[string]interface{}, log *Log) { 52 | for _, n := range news { 53 | item := convertToMap(n) 54 | 55 | err := getContent(config, item) 56 | if err != nil { 57 | log.SendLog(err.Error()) 58 | continue 59 | } 60 | 61 | err = getImages(config, item, cosCli) 62 | if err != nil { 63 | log.SendLog(err.Error()) 64 | continue 65 | } 66 | 67 | err = cosCli.setNews(item) 68 | if err != nil { 69 | log.SendLog(err.Error()) 70 | continue 71 | } 72 | 73 | err = db.setNews(item) 74 | if err != nil { 75 | log.SendLog(err.Error()) 76 | continue 77 | } 78 | 79 | err = es.setNews(item) 80 | if err != nil { 81 | log.SendLog(err.Error()) 82 | continue 83 | } 84 | 85 | err = redis.setNews(item) 86 | if err != nil { 87 | log.SendLog(err.Error()) 88 | continue 89 | } 90 | time.Sleep(time.Second * 1) 91 | } 92 | } 93 | 94 | func convertToMap(news *News) map[string]string { 95 | return map[string]string{ 96 | "id": news.Id, 97 | "cover": news.Cover, 98 | "update": news.Update, 99 | "title": news.Title, 100 | "author": news.Author, 101 | "tags": news.Tags, 102 | "url": news.Url, 103 | "introduce": "", 104 | "content": "", 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/news.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/pkg/errors" 8 | "io/ioutil" 9 | "net/http" 10 | "regexp" 11 | "strings" 12 | "time" 13 | ) 14 | 15 | type News struct { 16 | Id string 17 | Update string 18 | Title string 19 | Author string 20 | Content string 21 | Tags string 22 | Cover string 23 | Url string 24 | } 25 | 26 | func getNews(config map[string]interface{}) ([]*News, error) { 27 | addr := config["gugudata"].(map[string]interface{})["url"].(string) 28 | 29 | data := map[string]interface{}{} 30 | url := addr + "1" 31 | method := "GET" 32 | client := &http.Client{} 33 | 34 | ctx, _ := context.WithTimeout(context.Background(), time.Second*5) 35 | req, err := http.NewRequestWithContext(ctx, method, url, nil) 36 | if err != nil { 37 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to new request: %s", "getNews")) 38 | } 39 | 40 | res, err := client.Do(req) 41 | if err != nil { 42 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to get news: %s", "getNews")) 43 | } 44 | defer res.Body.Close() 45 | 46 | body, err := ioutil.ReadAll(res.Body) 47 | if err != nil { 48 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to read data from body: %s", "getNews")) 49 | } 50 | 51 | err = json.Unmarshal(body, &data) 52 | if err != nil { 53 | return nil, errors.Wrapf(err, fmt.Sprintf("fail to unmarshal news: %s", "getNews")) 54 | } 55 | 56 | news := make([]*News, 0, len(data["Data"].([]interface{}))) 57 | for _, item := range data["Data"].([]interface{}) { 58 | title := regexp.MustCompile("\\s+").ReplaceAllString(item.(map[string]interface{})["ArticleTitle"].(string), "") 59 | title = regexp.MustCompile("\\[[\\\\u0-9a-zA-Z]+\\]").ReplaceAllString(title, "") 60 | news = append(news, &News{ 61 | Id: item.(map[string]interface{})["ArticleId"].(string), 62 | Update: item.(map[string]interface{})["CreateDateTime"].(string), 63 | Title: title, 64 | Author: item.(map[string]interface{})["ArticleAuthor"].(string), 65 | Tags: getTags(item.(map[string]interface{})["Tags"].([]interface{})), 66 | Url: item.(map[string]interface{})["ArticleSourceUrl"].(string), 67 | }) 68 | } 69 | return news, nil 70 | } 71 | 72 | func getTags(tags []interface{}) string { 73 | box := make([]string, 0, len(tags)) 74 | for _, item := range tags { 75 | box = append(box, item.(map[string]interface{})["TagName"].(string)) 76 | } 77 | return strings.Join(box, `;`) 78 | } 79 | -------------------------------------------------------------------------------- /app/job/service/cmd/job/redis.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "github.com/go-redis/redis/v8" 7 | "github.com/pkg/errors" 8 | "strconv" 9 | "time" 10 | ) 11 | 12 | type Redis struct { 13 | client redis.Cmdable 14 | } 15 | 16 | func (r *Redis) setNews(m map[string]string) error { 17 | ctx, _ := context.WithTimeout(context.Background(), time.Second*60) 18 | id, err := strconv.Atoi(m["id"]) 19 | if err != nil { 20 | return errors.Wrapf(err, fmt.Sprintf("cannot convert id %s from string to int: %s", m["id"], "redis-setNews")) 21 | } 22 | 23 | err = r.client.ZAddNX(ctx, "news", &redis.Z{ 24 | Score: float64(id), 25 | Member: m["id"], 26 | }).Err() 27 | if err != nil { 28 | return errors.Wrapf(err, fmt.Sprintf("cannot set news %s to redis: %s", m["id"], "redis-setNews")) 29 | } 30 | return nil 31 | } 32 | 33 | func newRedis(config map[string]interface{}) (*Redis, error) { 34 | addr := config["redis"].(map[string]interface{})["addr"].(string) 35 | password := config["redis"].(map[string]interface{})["password"].(string) 36 | 37 | client := redis.NewClient(&redis.Options{ 38 | Addr: addr, 39 | DB: 1, 40 | DialTimeout: time.Second * 2, 41 | PoolSize: 10, 42 | Password: password, 43 | }) 44 | timeout, cancelFunc := context.WithTimeout(context.Background(), time.Second*2) 45 | defer cancelFunc() 46 | err := client.Ping(timeout).Err() 47 | if err != nil { 48 | return nil, errors.Wrapf(err, fmt.Sprintf("redis connect: %s", "newRedis")) 49 | } 50 | return &Redis{ 51 | client: client, 52 | }, nil 53 | } 54 | -------------------------------------------------------------------------------- /app/job/service/internal/tool/es/dsl: -------------------------------------------------------------------------------- 1 | PUT news 2 | { 3 | "mappings": { 4 | "properties": { 5 | "title": { 6 | "type": "text", 7 | "analyzer": "thulac" 8 | }, 9 | "tags": { 10 | "type": "text", 11 | "analyzer": "thulac" 12 | }, 13 | "author": { 14 | "type": "text", 15 | "index": false 16 | }, 17 | "link": { 18 | "type": "text", 19 | "index": false 20 | }, 21 | "update": { 22 | "type": "date", 23 | "format": "yyyy-M-d" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /app/message/service/Makefile: -------------------------------------------------------------------------------- 1 | INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) 2 | INTERNAL_EASYJSON_FILES=$(shell find internal -name do.go) 3 | .PHONY: config 4 | # generate internal proto 5 | config: 6 | protoc --proto_path=./internal \ 7 | --proto_path=../../../third_party \ 8 | --go_out=paths=source_relative:./internal \ 9 | $(INTERNAL_PROTO_FILES) 10 | 11 | .PHONY: easyjson 12 | # generate internal proto 13 | easyjson: 14 | easyjson -lower_camel_case $(INTERNAL_EASYJSON_FILES) -------------------------------------------------------------------------------- /app/message/service/README.md: -------------------------------------------------------------------------------- 1 | # Message Service 2 | -------------------------------------------------------------------------------- /app/message/service/cmd/message/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package main 7 | 8 | import ( 9 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 10 | "github.com/go-kratos/kratos/v2" 11 | "github.com/go-kratos/kratos/v2/log" 12 | "github.com/google/wire" 13 | "github.com/the-zion/matrix-core/app/message/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/message/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/message/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/message/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/message/service/internal/service" 18 | ) 19 | 20 | // wireApp init kratos application. 21 | func wireApp(*conf.Server, *conf.Data, log.Logger, *nacos.Registry) (*kratos.App, func(), error) { 22 | panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) 23 | } 24 | -------------------------------------------------------------------------------- /app/message/service/cmd/message/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 11 | "github.com/go-kratos/kratos/v2" 12 | "github.com/go-kratos/kratos/v2/log" 13 | "github.com/the-zion/matrix-core/app/message/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/message/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/message/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/message/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/message/service/internal/service" 18 | ) 19 | 20 | // Injectors from wire.go: 21 | 22 | // wireApp init kratos application. 23 | func wireApp(confServer *conf.Server, confData *conf.Data, logLogger log.Logger, registry *nacos.Registry) (*kratos.App, func(), error) { 24 | db := data.NewDB(confData) 25 | cmdable := data.NewRedis(confData) 26 | userClient := data.NewUserServiceClient(registry) 27 | creationClient := data.NewCreationServiceClient(registry) 28 | commentClient := data.NewCommentServiceClient(registry) 29 | achievementClient := data.NewAchievementServiceClient(registry) 30 | jwt := data.NewJwtClient(confData) 31 | cosUser := data.NewCosUserClient(confData) 32 | cosCreation := data.NewCosCreationClient(confData) 33 | cosComment := data.NewCosCommentClient(confData) 34 | dataData, cleanup2, err := data.NewData(db, cmdable, userClient, creationClient, commentClient, achievementClient, jwt, cosUser, cosCreation, cosComment, logLogger) 35 | if err != nil { 36 | return nil, nil, err 37 | } 38 | userRepo := data.NewUserRepo(dataData, logLogger) 39 | messageRepo := data.NewMessageRepo(dataData, logLogger) 40 | transaction := data.NewTransaction(dataData) 41 | bizJwt := data.NewJwt(dataData) 42 | userUseCase := biz.NewUserUseCase(userRepo, messageRepo, transaction, bizJwt, logLogger) 43 | creationRepo := data.NewCreationRepo(dataData, logLogger) 44 | creationUseCase := biz.NewCreationUseCase(creationRepo, messageRepo, transaction, bizJwt, logLogger) 45 | achievementRepo := data.NewAchievementRepo(dataData, logLogger) 46 | commentRepo := data.NewCommentRepo(dataData, logLogger) 47 | recovery := data.NewRecovery(dataData) 48 | achievementUseCase := biz.NewAchievementUseCase(achievementRepo, creationRepo, commentRepo, recovery, logLogger) 49 | commentUseCase := biz.NewCommentUseCase(commentRepo, messageRepo, transaction, bizJwt, logLogger) 50 | messageUseCase := biz.NewMessageUseCase(messageRepo, recovery, logLogger) 51 | messageService := service.NewMessageService(userUseCase, creationUseCase, achievementUseCase, commentUseCase, messageUseCase, logLogger) 52 | httpServer := server.NewHTTPServer(confServer, messageService, logLogger) 53 | grpcServer := server.NewGRPCServer(confServer, messageService, logLogger) 54 | rocketMqConsumerServer := server.NewRocketMqConsumerServer(confServer, messageService, logLogger) 55 | kratosApp := newApp(registry, httpServer, grpcServer, rocketMqConsumerServer) 56 | return kratosApp, func() { 57 | cleanup2() 58 | }, nil 59 | } 60 | -------------------------------------------------------------------------------- /app/message/service/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/google/wire" 6 | ) 7 | 8 | var ProviderSet = wire.NewSet(NewUserUseCase, NewCreationUseCase, NewAchievementUseCase, NewCommentUseCase, NewMessageUseCase) 9 | 10 | type Jwt interface { 11 | JwtCheck(token string) (string, error) 12 | } 13 | 14 | type Transaction interface { 15 | ExecTx(context.Context, func(ctx context.Context) error) error 16 | } 17 | 18 | type Recovery interface { 19 | GroupRecover(context.Context, func(ctx context.Context) error) func() error 20 | } 21 | -------------------------------------------------------------------------------- /app/message/service/internal/biz/do.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | type ImageReview struct { 4 | Code string 5 | Message string 6 | JobId string 7 | State string 8 | Object string 9 | Url string 10 | Label string 11 | Result int32 12 | Score int32 13 | Category string 14 | SubLabel string 15 | BucketId string 16 | Region string 17 | CosHeaders map[string]string 18 | EventName string 19 | } 20 | 21 | type PornInfo struct { 22 | HitFlag int32 23 | Count int32 24 | } 25 | type AdsInfo struct { 26 | HitFlag int32 27 | Count int32 28 | } 29 | 30 | type IllegalInfo struct { 31 | HitFlag int32 32 | Count int32 33 | } 34 | 35 | type AbuseInfo struct { 36 | HitFlag int32 37 | Count int32 38 | } 39 | 40 | type Section struct { 41 | Label string 42 | Result int32 43 | PornInfo *SectionPornInfo 44 | AdsInfo *SectionAdsInfo 45 | IllegalInfo *SectionIllegalInfo 46 | AbuseInfo *SectionAbuseInfo 47 | } 48 | 49 | type SectionPornInfo struct { 50 | HitFlag int32 51 | Score int32 52 | Keywords string 53 | } 54 | 55 | type SectionAdsInfo struct { 56 | HitFlag int32 57 | Score int32 58 | Keywords string 59 | } 60 | 61 | type SectionIllegalInfo struct { 62 | HitFlag int32 63 | Score int32 64 | Keywords string 65 | } 66 | 67 | type SectionAbuseInfo struct { 68 | HitFlag int32 69 | Score int32 70 | Keywords string 71 | } 72 | 73 | type TextReview struct { 74 | Code string 75 | Message string 76 | JobId string 77 | DataId string 78 | State string 79 | CreationTime string 80 | Object string 81 | Label string 82 | Result int32 83 | PornInfo *PornInfo 84 | AdsInfo *AdsInfo 85 | IllegalInfo *IllegalInfo 86 | AbuseInfo *AbuseInfo 87 | BucketId string 88 | Region string 89 | CosHeaders map[string]string 90 | Section string 91 | } 92 | 93 | type MailBox struct { 94 | Time int32 95 | } 96 | 97 | type Notification struct { 98 | Timeline map[string]int32 99 | Comment int32 100 | SubComment int32 101 | SystemNotification int32 102 | } 103 | 104 | //easyjson:json 105 | type SystemNotification struct { 106 | Id int32 107 | ContentId int32 108 | CreatedAt string 109 | NotificationType string 110 | Title string 111 | Uid string 112 | Uuid string 113 | Label string 114 | Result int32 115 | Section string 116 | Text string 117 | Comment string 118 | } 119 | -------------------------------------------------------------------------------- /app/message/service/internal/biz/message.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | v1 "github.com/the-zion/matrix-core/api/message/service/v1" 7 | ) 8 | 9 | type MessageRepo interface { 10 | GetMailBoxLastTime(ctx context.Context, uuid string) (*MailBox, error) 11 | GetMessageNotification(ctx context.Context, uuid string, follows []string) (*Notification, error) 12 | GetMessageSystemNotification(ctx context.Context, page int32, uuid string) ([]*SystemNotification, error) 13 | SetMailBoxLastTime(ctx context.Context, uuid string, time int32) error 14 | RemoveMailBoxCommentCount(ctx context.Context, uuid string) error 15 | RemoveMailBoxSubCommentCount(ctx context.Context, uuid string) error 16 | RemoveMailBoxSystemNotificationCount(ctx context.Context, uuid string) error 17 | AddMailBoxSystemNotification(ctx context.Context, contentId int32, notificationType string, title string, uuid string, label string, result int32, section string, text string, uid string, comment string) (*SystemNotification, error) 18 | AddMailBoxSystemNotificationToCache(ctx context.Context, notification *SystemNotification) error 19 | } 20 | 21 | type MessageUseCase struct { 22 | repo MessageRepo 23 | re Recovery 24 | log *log.Helper 25 | } 26 | 27 | func NewMessageUseCase(repo MessageRepo, re Recovery, logger log.Logger) *MessageUseCase { 28 | return &MessageUseCase{ 29 | repo: repo, 30 | re: re, 31 | log: log.NewHelper(log.With(logger, "module", "message/biz/messageUseCase")), 32 | } 33 | } 34 | 35 | func (r *MessageUseCase) GetMailBoxLastTime(ctx context.Context, uuid string) (*MailBox, error) { 36 | mailbox, err := r.repo.GetMailBoxLastTime(ctx, uuid) 37 | if err != nil { 38 | return nil, v1.ErrorGetMailboxLastTimeFailed("get mailbox last time failed: %s", err.Error()) 39 | } 40 | return mailbox, nil 41 | } 42 | 43 | func (r *MessageUseCase) GetMessageNotification(ctx context.Context, uuid string, follows []string) (*Notification, error) { 44 | mailbox, err := r.repo.GetMessageNotification(ctx, uuid, follows) 45 | if err != nil { 46 | return nil, v1.ErrorGetMessageNotificationFailed("get message notification failed: %s", err.Error()) 47 | } 48 | return mailbox, nil 49 | } 50 | 51 | func (r *MessageUseCase) GetMessageSystemNotification(ctx context.Context, page int32, uuid string) ([]*SystemNotification, error) { 52 | notificationList, err := r.repo.GetMessageSystemNotification(ctx, page, uuid) 53 | if err != nil { 54 | return nil, v1.ErrorGetMessageNotificationFailed("get message system notification failed: %s", err.Error()) 55 | } 56 | return notificationList, nil 57 | } 58 | 59 | func (r *MessageUseCase) SetMailBoxLastTime(ctx context.Context, uuid string, time int32) error { 60 | err := r.repo.SetMailBoxLastTime(ctx, uuid, time) 61 | if err != nil { 62 | return v1.ErrorSetMailboxLastTimeFailed("set mailbox last time failed: %s", err.Error()) 63 | } 64 | return nil 65 | } 66 | 67 | func (r *MessageUseCase) RemoveMailBoxCommentCount(ctx context.Context, uuid string) error { 68 | err := r.repo.RemoveMailBoxCommentCount(ctx, uuid) 69 | if err != nil { 70 | return v1.ErrorRemoveMailboxCommentFailed("remove mail box comment count: %s", err.Error()) 71 | } 72 | return nil 73 | } 74 | 75 | func (r *MessageUseCase) RemoveMailBoxSubCommentCount(ctx context.Context, uuid string) error { 76 | err := r.repo.RemoveMailBoxSubCommentCount(ctx, uuid) 77 | if err != nil { 78 | return v1.ErrorRemoveMailboxCommentFailed("remove mail box sub comment count: %s", err.Error()) 79 | } 80 | return nil 81 | } 82 | 83 | func (r *MessageUseCase) RemoveMailBoxSystemNotificationCount(ctx context.Context, uuid string) error { 84 | err := r.repo.RemoveMailBoxSystemNotificationCount(ctx, uuid) 85 | if err != nil { 86 | return v1.ErrorRemoveMailboxSystemNotificationFailed("remove mail box system notification failed: %s", err.Error()) 87 | } 88 | return nil 89 | } 90 | -------------------------------------------------------------------------------- /app/message/service/internal/conf/conf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package kratos.api; 3 | 4 | option go_package = "message/service/internal/conf;conf"; 5 | 6 | import "google/protobuf/duration.proto"; 7 | 8 | message Bootstrap { 9 | Config config = 1; 10 | } 11 | 12 | message Config{ 13 | Server server = 1; 14 | Data data = 2; 15 | Log log = 3; 16 | } 17 | 18 | message Server { 19 | message HTTP { 20 | string network = 1; 21 | string addr = 2; 22 | google.protobuf.Duration timeout = 3; 23 | } 24 | message GRPC { 25 | string network = 1; 26 | string addr = 2; 27 | google.protobuf.Duration timeout = 3; 28 | } 29 | message RocketMq{ 30 | string serverAddress = 1; 31 | string secretKey = 2; 32 | string accessKey = 3; 33 | string nameSpace = 4; 34 | string groupName = 5; 35 | } 36 | 37 | HTTP http = 1; 38 | GRPC grpc = 2; 39 | RocketMq rocketmq = 3; 40 | } 41 | 42 | message Data { 43 | message Database { 44 | string driver = 1; 45 | string source = 2; 46 | } 47 | message Redis { 48 | string network = 1; 49 | string addr = 2; 50 | string password = 3; 51 | google.protobuf.Duration read_timeout = 4; 52 | google.protobuf.Duration write_timeout = 5; 53 | } 54 | message Jwt{ 55 | string key = 1; 56 | } 57 | message Cos{ 58 | message BucketUser{ 59 | string bucketUrl = 1; 60 | string secret_id = 3; 61 | string secret_key = 4; 62 | } 63 | message BucketCreation{ 64 | string bucketUrl = 1; 65 | string ciUrl = 2; 66 | string secret_id = 3; 67 | string secret_key = 4; 68 | map callback = 5; 69 | } 70 | message BucketComment{ 71 | string bucketUrl = 1; 72 | string ciUrl = 2; 73 | string secret_id = 3; 74 | string secret_key = 4; 75 | map callback = 5; 76 | } 77 | BucketUser bucketUser = 1; 78 | BucketCreation bucketCreation = 2; 79 | BucketComment bucketComment = 3; 80 | } 81 | Database database = 1; 82 | Jwt jwt = 2; 83 | Cos cos = 3; 84 | Redis redis = 4; 85 | } 86 | 87 | message Log { 88 | string host = 1; 89 | string accessKeyID = 2; 90 | string accessKeySecret = 3; 91 | string topicID = 4; 92 | } 93 | 94 | -------------------------------------------------------------------------------- /app/message/service/internal/data/jwt.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "github.com/go-kratos/kratos/v2/errors" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/golang-jwt/jwt/v4" 7 | "github.com/the-zion/matrix-core/app/message/service/internal/biz" 8 | "github.com/the-zion/matrix-core/app/message/service/internal/conf" 9 | ) 10 | 11 | var ( 12 | LOG = log.NewHelper(log.With(log.GetLogger(), "source", "accesslog")) 13 | ErrMissingJwtToken = errors.Unauthorized("TOKEN_MISSING", "JWT token is missing") 14 | ErrTokenInvalid = errors.Unauthorized("TOKEN_INVALID", "Token is invalid") 15 | ErrTokenExpired = errors.Unauthorized("TOKEN_EXPIRED", "JWT token has expired") 16 | ErrTokenParseFail = errors.Unauthorized("TOKEN_PARSE_FAIL", "Fail to parse JWT token ") 17 | ErrUnSupportSigningMethod = errors.Unauthorized("UN_SUPPORT_SIGNING_METHOD", "Wrong signing method") 18 | ) 19 | 20 | func claimsFunc() jwt.Claims { 21 | return &jwt.MapClaims{} 22 | } 23 | 24 | func (d *Data) JwtCheck(jwtToken string) (string, error) { 25 | var ( 26 | tokenInfo *jwt.Token 27 | err error 28 | ) 29 | tokenInfo, err = jwt.ParseWithClaims(jwtToken, claimsFunc(), func(token *jwt.Token) (interface{}, error) { 30 | return []byte(d.jwt.key), nil 31 | }) 32 | if err != nil { 33 | ve, ok := err.(*jwt.ValidationError) 34 | if !ok { 35 | return "", errors.Unauthorized("UNAUTHORIZED", err.Error()) 36 | } 37 | if ve.Errors&jwt.ValidationErrorMalformed != 0 { 38 | return "", ErrTokenInvalid 39 | } 40 | if ve.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 { 41 | return "", ErrTokenExpired 42 | } 43 | return "", ErrTokenParseFail 44 | } 45 | if !tokenInfo.Valid { 46 | return "", ErrTokenInvalid 47 | } 48 | if tokenInfo.Method != jwt.SigningMethodHS256 { 49 | return "", ErrUnSupportSigningMethod 50 | } 51 | token := *((tokenInfo.Claims.(jwt.Claims)).(*jwt.MapClaims)) 52 | return token["uuid"].(string), nil 53 | } 54 | 55 | func NewJwt(d *Data) biz.Jwt { 56 | return d 57 | } 58 | 59 | func NewJwtClient(conf *conf.Data) Jwt { 60 | return Jwt{ 61 | key: conf.Jwt.Key, 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/message/service/internal/data/model.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import "gorm.io/gorm" 4 | 5 | type SystemNotification struct { 6 | gorm.Model 7 | ContentId int32 8 | NotificationType string 9 | Title string `gorm:"size:100"` 10 | Uid string 11 | Uuid string `gorm:"index;size:20"` 12 | Label string `gorm:"size:100"` 13 | Result int32 14 | Section string 15 | Text string 16 | Comment string `gorm:"size:100"` 17 | } 18 | -------------------------------------------------------------------------------- /app/message/service/internal/pkg/util/template.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | func GetPhoneTemplate(template string) string { 4 | var id string 5 | switch template { 6 | case "1": 7 | id = "1427600" 8 | case "2": 9 | id = "1427602" 10 | case "3": 11 | id = "1427603" 12 | case "4": 13 | id = "1427601" 14 | 15 | } 16 | return id 17 | } 18 | 19 | func GetEmailTemplate(template, code string) string { 20 | var content string 21 | switch template { 22 | case "1": 23 | content = code + " 为您的登录验证码,请于2分钟内填写,如非本人操作,请忽略本信息。" 24 | case "2": 25 | content = "您的动态验证码为:" + code + ", 2分钟内有效!您正在进行密码重置操作,如非本人操作,请忽略本信息!" 26 | case "3": 27 | content = "您正在修改注册手机号码,验证码为:" + code + ",2分钟有效,为保障帐户安全,请勿向任何人提供此验证码" 28 | case "4": 29 | content = "您正在修改注册邮箱号码,验证码为:" + code + ",2分钟有效,为保障帐户安全,请勿向任何人提供此验证码" 30 | case "5": 31 | content = code + " 为您的邮箱注册验证码,请于2分钟内填写,如非本人操作,请忽略本信息。" 32 | } 33 | return content 34 | } 35 | -------------------------------------------------------------------------------- /app/message/service/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/ratelimit" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/middleware/tracing" 10 | "github.com/go-kratos/kratos/v2/middleware/validate" 11 | "github.com/go-kratos/kratos/v2/transport/grpc" 12 | v1 "github.com/the-zion/matrix-core/api/message/service/v1" 13 | "github.com/the-zion/matrix-core/app/message/service/internal/conf" 14 | "github.com/the-zion/matrix-core/app/message/service/internal/service" 15 | "github.com/the-zion/matrix-core/pkg/responce" 16 | ) 17 | 18 | func NewGRPCServer(c *conf.Server, messageService *service.MessageService, logger log.Logger) *grpc.Server { 19 | var opts = []grpc.ServerOption{ 20 | grpc.Middleware( 21 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 22 | l := log.NewHelper(log.With(logger, "message", "panic")) 23 | l.Error(err) 24 | return nil 25 | })), 26 | ratelimit.Server(), 27 | tracing.Server(), 28 | responce.Server(), 29 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 30 | validate.Validator(), 31 | ), 32 | } 33 | if c.Grpc.Network != "" { 34 | opts = append(opts, grpc.Network(c.Grpc.Network)) 35 | } 36 | if c.Grpc.Addr != "" { 37 | opts = append(opts, grpc.Address(c.Grpc.Addr)) 38 | } 39 | if c.Grpc.Timeout != nil { 40 | opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) 41 | } 42 | srv := grpc.NewServer(opts...) 43 | v1.RegisterMessageServer(srv, messageService) 44 | return srv 45 | } 46 | -------------------------------------------------------------------------------- /app/message/service/internal/server/http.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/ratelimit" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/middleware/tracing" 10 | "github.com/go-kratos/kratos/v2/transport/http" 11 | "github.com/the-zion/matrix-core/api/message/service/v1" 12 | "github.com/the-zion/matrix-core/app/message/service/internal/conf" 13 | "github.com/the-zion/matrix-core/app/message/service/internal/service" 14 | ) 15 | 16 | // NewHTTPServer new a HTTP user. 17 | func NewHTTPServer(c *conf.Server, messageService *service.MessageService, logger log.Logger) *http.Server { 18 | var opts = []http.ServerOption{ 19 | http.Middleware( 20 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 21 | l := log.NewHelper(log.With(logger, "message", "panic")) 22 | l.Error(err) 23 | return nil 24 | })), 25 | ratelimit.Server(), 26 | tracing.Server(), 27 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 28 | ), 29 | } 30 | if c.Http.Network != "" { 31 | opts = append(opts, http.Network(c.Http.Network)) 32 | } 33 | if c.Http.Addr != "" { 34 | opts = append(opts, http.Address(c.Http.Addr)) 35 | } 36 | if c.Http.Timeout != nil { 37 | opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) 38 | } 39 | srv := http.NewServer(opts...) 40 | v1.RegisterMessageHTTPServer(srv, messageService) 41 | return srv 42 | } 43 | -------------------------------------------------------------------------------- /app/message/service/internal/server/recovery.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/apache/rocketmq-client-go/v2/consumer" 6 | "github.com/apache/rocketmq-client-go/v2/primitive" 7 | "github.com/go-kratos/kratos/v2/log" 8 | "runtime" 9 | ) 10 | 11 | func MqRecovery(fn func(ctx context.Context, 12 | msgs ...*primitive.MessageExt) (consumer.ConsumeResult, error)) func(ctx context.Context, 13 | msgs ...*primitive.MessageExt) (consumer.ConsumeResult, error) { 14 | return func(ctx context.Context, 15 | msgs ...*primitive.MessageExt) (consumer.ConsumeResult, error) { 16 | defer func() { 17 | if rerr := recover(); rerr != nil { 18 | buf := make([]byte, 64<<10) 19 | n := runtime.Stack(buf, false) 20 | buf = buf[:n] 21 | log.Context(ctx).Errorf("%v: %+v\n%s\n", rerr, msgs, buf) 22 | } 23 | }() 24 | return fn(ctx, msgs...) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/message/service/internal/server/server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSet is user providers. 8 | var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer, NewRocketMqConsumerServer) 9 | -------------------------------------------------------------------------------- /app/message/service/internal/service/achievement.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | func (s *MessageService) SetAchievementAgree(ctx context.Context, uuid, userUuid string) error { 8 | return s.ac.SetAchievementAgree(ctx, uuid, userUuid) 9 | } 10 | 11 | func (s *MessageService) CancelAchievementAgree(ctx context.Context, uuid, userUuid string) error { 12 | return s.ac.CancelAchievementAgree(ctx, uuid, userUuid) 13 | } 14 | 15 | func (s *MessageService) SetAchievementView(ctx context.Context, uuid string) error { 16 | return s.ac.SetAchievementView(ctx, uuid) 17 | } 18 | 19 | func (s *MessageService) SetAchievementCollect(ctx context.Context, uuid string) error { 20 | return s.ac.SetAchievementCollect(ctx, uuid) 21 | } 22 | 23 | func (s *MessageService) CancelAchievementCollect(ctx context.Context, uuid string) error { 24 | return s.ac.CancelAchievementCollect(ctx, uuid) 25 | } 26 | 27 | func (s *MessageService) SetAchievementFollow(ctx context.Context, follow, followed string) error { 28 | return s.ac.SetAchievementFollow(ctx, follow, followed) 29 | } 30 | 31 | func (s *MessageService) CancelAchievementFollow(ctx context.Context, follow, followed string) error { 32 | return s.ac.CancelAchievementFollow(ctx, follow, followed) 33 | } 34 | 35 | func (s *MessageService) AddAchievementScore(ctx context.Context, uuid string, score int32) error { 36 | return s.ac.AddAchievementScore(ctx, uuid, score) 37 | } 38 | 39 | func (s *MessageService) SetUserMedalDbAndCache(ctx context.Context, medal, uuid string) error { 40 | return s.ac.SetUserMedalDbAndCache(ctx, medal, uuid) 41 | } 42 | 43 | func (s *MessageService) CancelUserMedalDbAndCache(ctx context.Context, medal, uuid string) error { 44 | return s.ac.CancelUserMedalDbAndCache(ctx, medal, uuid) 45 | } 46 | 47 | func (s *MessageService) AccessUserMedalDbAndCache(ctx context.Context, medal, uuid string) error { 48 | return s.ac.AccessUserMedalDbAndCache(ctx, medal, uuid) 49 | } 50 | -------------------------------------------------------------------------------- /app/message/service/internal/service/comment.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | v1 "github.com/the-zion/matrix-core/api/message/service/v1" 6 | "google.golang.org/protobuf/types/known/emptypb" 7 | ) 8 | 9 | func (s *MessageService) ToReviewCreateComment(id int32, uuid string) error { 10 | return s.commc.ToReviewCreateComment(id, uuid) 11 | } 12 | 13 | func (s *MessageService) ToReviewCreateSubComment(id int32, uuid string) error { 14 | return s.commc.ToReviewCreateSubComment(id, uuid) 15 | } 16 | 17 | func (s *MessageService) CommentCreateReview(ctx context.Context, req *v1.TextReviewReq) (*emptypb.Empty, error) { 18 | tr, err := s.TextReview(req) 19 | if err != nil { 20 | return nil, err 21 | } 22 | 23 | err = s.commc.CommentCreateReview(ctx, tr) 24 | if err != nil { 25 | return nil, err 26 | } 27 | return &emptypb.Empty{}, nil 28 | } 29 | 30 | func (s *MessageService) SubCommentCreateReview(ctx context.Context, req *v1.TextReviewReq) (*emptypb.Empty, error) { 31 | tr, err := s.TextReview(req) 32 | if err != nil { 33 | return nil, err 34 | } 35 | 36 | err = s.commc.SubCommentCreateReview(ctx, tr) 37 | if err != nil { 38 | return nil, err 39 | } 40 | return &emptypb.Empty{}, nil 41 | } 42 | 43 | func (s *MessageService) CreateCommentDbAndCache(ctx context.Context, id, createId, createType int32, uuid string) error { 44 | return s.commc.CreateCommentDbAndCache(ctx, id, createId, createType, uuid) 45 | } 46 | 47 | func (s *MessageService) CreateSubCommentDbAndCache(ctx context.Context, id, rootId, parentId int32, uuid string) error { 48 | return s.commc.CreateSubCommentDbAndCache(ctx, id, rootId, parentId, uuid) 49 | } 50 | 51 | func (s *MessageService) RemoveCommentDbAndCache(ctx context.Context, id int32, uuid string) error { 52 | return s.commc.RemoveCommentDbAndCache(ctx, id, uuid) 53 | } 54 | 55 | func (s *MessageService) RemoveSubCommentDbAndCache(ctx context.Context, id int32, uuid string) error { 56 | return s.commc.RemoveSubCommentDbAndCache(ctx, id, uuid) 57 | } 58 | 59 | func (s *MessageService) SetCommentAgreeDbAndCache(ctx context.Context, id, creationId, creationType int32, uuid, userUuid string) error { 60 | return s.commc.SetCommentAgreeDbAndCache(ctx, id, creationId, creationType, uuid, userUuid) 61 | } 62 | 63 | func (s *MessageService) SetSubCommentAgreeDbAndCache(ctx context.Context, id int32, uuid, userUuid string) error { 64 | return s.commc.SetSubCommentAgreeDbAndCache(ctx, id, uuid, userUuid) 65 | } 66 | 67 | func (s *MessageService) CancelCommentAgreeDbAndCache(ctx context.Context, id, creationId, creationType int32, uuid, userUuid string) error { 68 | return s.commc.CancelCommentAgreeDbAndCache(ctx, id, creationId, creationType, uuid, userUuid) 69 | } 70 | 71 | func (s *MessageService) CancelSubCommentAgreeDbAndCache(ctx context.Context, id int32, uuid, userUuid string) error { 72 | return s.commc.CancelSubCommentAgreeDbAndCache(ctx, id, uuid, userUuid) 73 | } 74 | 75 | func (s *MessageService) AddCommentContentReviewDbAndCache(ctx context.Context, commentId, result int32, uuid, jobId, label, comment, kind string, section string) error { 76 | return s.commc.AddCommentContentReviewDbAndCache(ctx, commentId, result, uuid, jobId, label, comment, kind, section) 77 | } 78 | -------------------------------------------------------------------------------- /app/message/service/internal/service/message.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | v1 "github.com/the-zion/matrix-core/api/message/service/v1" 6 | "google.golang.org/protobuf/types/known/emptypb" 7 | ) 8 | 9 | func (s *MessageService) GetMailBoxLastTime(ctx context.Context, req *v1.GetMailBoxLastTimeReq) (*v1.GetMailBoxLastTimeReply, error) { 10 | mailbox, err := s.mc.GetMailBoxLastTime(ctx, req.Uuid) 11 | if err != nil { 12 | return nil, err 13 | } 14 | return &v1.GetMailBoxLastTimeReply{ 15 | Time: mailbox.Time, 16 | }, nil 17 | } 18 | 19 | func (s *MessageService) GetMessageNotification(ctx context.Context, req *v1.GetMessageNotificationReq) (*v1.GetMessageNotificationReply, error) { 20 | notification, err := s.mc.GetMessageNotification(ctx, req.Uuid, req.Follows) 21 | if err != nil { 22 | return nil, err 23 | } 24 | return &v1.GetMessageNotificationReply{ 25 | Timeline: notification.Timeline, 26 | Comment: notification.Comment, 27 | SubComment: notification.SubComment, 28 | System: notification.SystemNotification, 29 | }, nil 30 | } 31 | 32 | func (s *MessageService) GetMessageSystemNotification(ctx context.Context, req *v1.GetMessageSystemNotificationReq) (*v1.GetMessageSystemNotificationReply, error) { 33 | notificationList, err := s.mc.GetMessageSystemNotification(ctx, req.Page, req.Uuid) 34 | if err != nil { 35 | return nil, err 36 | } 37 | reply := &v1.GetMessageSystemNotificationReply{List: make([]*v1.GetMessageSystemNotificationReply_List, 0, len(notificationList))} 38 | for _, item := range notificationList { 39 | reply.List = append(reply.List, &v1.GetMessageSystemNotificationReply_List{ 40 | Id: item.Id, 41 | ContentId: item.ContentId, 42 | CreatedAt: item.CreatedAt, 43 | NotificationType: item.NotificationType, 44 | Title: item.Title, 45 | Uid: item.Uid, 46 | Uuid: item.Uuid, 47 | Label: item.Label, 48 | Result: item.Result, 49 | Section: item.Section, 50 | Text: item.Text, 51 | Comment: item.Comment, 52 | }) 53 | } 54 | return reply, nil 55 | } 56 | 57 | func (s *MessageService) SetMailBoxLastTime(ctx context.Context, req *v1.SetMailBoxLastTimeReq) (*emptypb.Empty, error) { 58 | err := s.mc.SetMailBoxLastTime(ctx, req.Uuid, req.Time) 59 | if err != nil { 60 | return nil, err 61 | } 62 | return &emptypb.Empty{}, nil 63 | } 64 | 65 | func (s *MessageService) RemoveMailBoxCommentCount(ctx context.Context, req *v1.RemoveMailBoxCommentCountReq) (*emptypb.Empty, error) { 66 | err := s.mc.RemoveMailBoxCommentCount(ctx, req.Uuid) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return &emptypb.Empty{}, nil 71 | } 72 | 73 | func (s *MessageService) RemoveMailBoxSubCommentCount(ctx context.Context, req *v1.RemoveMailBoxSubCommentCountReq) (*emptypb.Empty, error) { 74 | err := s.mc.RemoveMailBoxSubCommentCount(ctx, req.Uuid) 75 | if err != nil { 76 | return nil, err 77 | } 78 | return &emptypb.Empty{}, nil 79 | } 80 | 81 | func (s *MessageService) RemoveMailBoxSystemNotificationCount(ctx context.Context, req *v1.RemoveMailBoxSystemNotificationCountReq) (*emptypb.Empty, error) { 82 | err := s.mc.RemoveMailBoxSystemNotificationCount(ctx, req.Uuid) 83 | if err != nil { 84 | return nil, err 85 | } 86 | return &emptypb.Empty{}, nil 87 | } 88 | -------------------------------------------------------------------------------- /app/message/service/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "github.com/go-kratos/kratos/v2/log" 7 | "github.com/google/wire" 8 | v1 "github.com/the-zion/matrix-core/api/message/service/v1" 9 | "github.com/the-zion/matrix-core/app/message/service/internal/biz" 10 | "google.golang.org/protobuf/types/known/emptypb" 11 | ) 12 | 13 | var ProviderSet = wire.NewSet(NewMessageService) 14 | 15 | type MessageService struct { 16 | v1.UnimplementedMessageServer 17 | uc *biz.UserUseCase 18 | cc *biz.CreationUseCase 19 | ac *biz.AchievementUseCase 20 | commc *biz.CommentUseCase 21 | mc *biz.MessageUseCase 22 | log *log.Helper 23 | } 24 | 25 | func NewMessageService(uc *biz.UserUseCase, cc *biz.CreationUseCase, ac *biz.AchievementUseCase, commc *biz.CommentUseCase, mc *biz.MessageUseCase, logger log.Logger) *MessageService { 26 | return &MessageService{ 27 | log: log.NewHelper(log.With(logger, "module", "message/service")), 28 | uc: uc, 29 | cc: cc, 30 | ac: ac, 31 | commc: commc, 32 | mc: mc, 33 | } 34 | } 35 | 36 | func (s *MessageService) TextReview(req *v1.TextReviewReq) (*biz.TextReview, error) { 37 | tr := &biz.TextReview{ 38 | Code: req.JobsDetail.Code, 39 | Message: req.JobsDetail.Message, 40 | JobId: req.JobsDetail.JobId, 41 | DataId: req.JobsDetail.DataId, 42 | State: req.JobsDetail.State, 43 | CreationTime: req.JobsDetail.CreationTime, 44 | Object: req.JobsDetail.Object, 45 | Label: req.JobsDetail.Label, 46 | Result: req.JobsDetail.Result, 47 | BucketId: req.JobsDetail.BucketId, 48 | Region: req.JobsDetail.Region, 49 | CosHeaders: req.JobsDetail.CosHeaders, 50 | } 51 | 52 | var section []map[string]interface{} 53 | 54 | for _, item := range req.JobsDetail.Section { 55 | se := make(map[string]interface{}, 0) 56 | if item.PornInfo != nil { 57 | se["PornInfoHitFlag"] = item.PornInfo.HitFlag 58 | se["PornInfoKeywords"] = item.PornInfo.Keywords 59 | } else { 60 | se["PornInfoHitFlag"] = 0 61 | se["PornInfoKeywords"] = "" 62 | } 63 | 64 | if item.AdsInfo != nil { 65 | se["AdsInfoHitFlag"] = item.AdsInfo.HitFlag 66 | se["AdsInfoKeywords"] = item.AdsInfo.Keywords 67 | } else { 68 | se["AdsInfoHitFlag"] = 0 69 | se["AdsInfoKeywords"] = "" 70 | } 71 | 72 | if item.IllegalInfo != nil { 73 | se["IllegalInfoHitFlag"] = item.IllegalInfo.HitFlag 74 | se["IllegalInfoKeywords"] = item.IllegalInfo.Keywords 75 | } else { 76 | se["IllegalInfoHitFlag"] = 0 77 | se["IllegalInfoKeywords"] = "" 78 | } 79 | 80 | if item.AbuseInfo != nil { 81 | se["AbuseInfoHitFlag"] = item.AbuseInfo.HitFlag 82 | se["AbuseInfoKeywords"] = item.AbuseInfo.Keywords 83 | } else { 84 | se["AbuseInfoHitFlag"] = 0 85 | se["AbuseInfoKeywords"] = "" 86 | } 87 | 88 | section = append(section, se) 89 | } 90 | 91 | sectionMap, err := json.Marshal(section) 92 | if err != nil { 93 | return nil, err 94 | } 95 | 96 | tr.Section = string(sectionMap) 97 | return tr, nil 98 | } 99 | 100 | func (s *MessageService) GetHealth(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 101 | return &emptypb.Empty{}, nil 102 | } 103 | -------------------------------------------------------------------------------- /app/message/service/internal/service/user.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/the-zion/matrix-core/api/message/service/v1" 6 | "github.com/the-zion/matrix-core/app/message/service/internal/biz" 7 | "google.golang.org/protobuf/types/known/emptypb" 8 | ) 9 | 10 | func (s *MessageService) UploadProfileToCos(msg map[string]interface{}) error { 11 | return s.uc.UploadProfileToCos(msg) 12 | } 13 | 14 | func (s *MessageService) ProfileReview(ctx context.Context, req *v1.TextReviewReq) (*emptypb.Empty, error) { 15 | tr, err := s.TextReview(req) 16 | if err != nil { 17 | return nil, err 18 | } 19 | 20 | err = s.uc.ProfileReview(ctx, tr) 21 | if err != nil { 22 | return nil, err 23 | } 24 | return &emptypb.Empty{}, nil 25 | } 26 | 27 | func (s *MessageService) AvatarReview(ctx context.Context, req *v1.ImageReviewReq) (*emptypb.Empty, error) { 28 | err := s.uc.AvatarReview(ctx, &biz.ImageReview{ 29 | Code: req.JobsDetail.Code, 30 | Message: req.JobsDetail.Message, 31 | JobId: req.JobsDetail.JobId, 32 | State: req.JobsDetail.State, 33 | Object: req.JobsDetail.Object, 34 | Url: req.JobsDetail.Url, 35 | Label: req.JobsDetail.Label, 36 | Result: req.JobsDetail.Result, 37 | Score: req.JobsDetail.Score, 38 | Category: req.JobsDetail.Category, 39 | SubLabel: req.JobsDetail.SubLabel, 40 | BucketId: req.JobsDetail.BucketId, 41 | Region: req.JobsDetail.Region, 42 | CosHeaders: req.JobsDetail.CosHeaders, 43 | EventName: req.EventName, 44 | }) 45 | if err != nil { 46 | return nil, err 47 | } 48 | return &emptypb.Empty{}, nil 49 | } 50 | 51 | func (s *MessageService) CoverReview(ctx context.Context, req *v1.ImageReviewReq) (*emptypb.Empty, error) { 52 | err := s.uc.CoverReview(ctx, &biz.ImageReview{ 53 | Code: req.JobsDetail.Code, 54 | Message: req.JobsDetail.Message, 55 | JobId: req.JobsDetail.JobId, 56 | State: req.JobsDetail.State, 57 | Object: req.JobsDetail.Object, 58 | Url: req.JobsDetail.Url, 59 | Label: req.JobsDetail.Label, 60 | Result: req.JobsDetail.Result, 61 | Score: req.JobsDetail.Score, 62 | Category: req.JobsDetail.Category, 63 | SubLabel: req.JobsDetail.SubLabel, 64 | BucketId: req.JobsDetail.BucketId, 65 | Region: req.JobsDetail.Region, 66 | CosHeaders: req.JobsDetail.CosHeaders, 67 | EventName: req.EventName, 68 | }) 69 | if err != nil { 70 | return nil, err 71 | } 72 | return &emptypb.Empty{}, nil 73 | } 74 | 75 | func (s *MessageService) SetFollowDbAndCache(ctx context.Context, uuid, userId string) error { 76 | return s.uc.SetFollowDbAndCache(ctx, uuid, userId) 77 | } 78 | 79 | func (s *MessageService) CancelFollowDbAndCache(ctx context.Context, uuid, userId string) error { 80 | return s.uc.CancelFollowDbAndCache(ctx, uuid, userId) 81 | } 82 | 83 | func (s *MessageService) AddAvatarReviewDbAndCache(ctx context.Context, score, result int32, uuid, jobId, label, category, subLabel string) error { 84 | return s.uc.AddAvatarReviewDbAndCache(ctx, score, result, uuid, jobId, label, category, subLabel) 85 | } 86 | 87 | func (s *MessageService) AddCoverReviewDbAndCache(ctx context.Context, score, result int32, uuid, jobId, label, category, subLabel string) error { 88 | return s.uc.AddCoverReviewDbAndCache(ctx, score, result, uuid, jobId, label, category, subLabel) 89 | } 90 | -------------------------------------------------------------------------------- /app/message/service/internal/tool/lua/lua.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "github.com/go-kratos/kratos/v2/log" 8 | "github.com/go-redis/redis/v8" 9 | "os" 10 | "time" 11 | ) 12 | 13 | var ( 14 | addr string 15 | password string 16 | scriptBox = map[string]string{ 17 | "AddMailBoxSystemNotificationToCache": ` 18 | local key = KEYS[1] 19 | local value = ARGV[1] 20 | local uuid = ARGV[2] 21 | local exist = redis.call("EXISTS", key) 22 | if exist == 1 then 23 | redis.call("LPUSH", key, value) 24 | end 25 | redis.call("HINCRBY", "message_system", uuid, 1) 26 | return 0 27 | `, 28 | } 29 | ) 30 | 31 | func NewRedis(logger log.Logger) redis.Cmdable { 32 | l := log.NewHelper(log.With(logger, "lua", "redis")) 33 | 34 | client := redis.NewClient(&redis.Options{ 35 | Addr: addr, 36 | DB: 4, 37 | DialTimeout: time.Second * 2, 38 | PoolSize: 10, 39 | Password: password, 40 | }) 41 | timeout, cancelFunc := context.WithTimeout(context.Background(), time.Second*2) 42 | defer cancelFunc() 43 | err := client.Ping(timeout).Err() 44 | if err != nil { 45 | l.Fatalf("redis connect error: %v", err) 46 | } 47 | return client 48 | } 49 | 50 | func main() { 51 | flag.Parse() 52 | logger := log.NewStdLogger(os.Stdout) 53 | r := NewRedis(logger) 54 | ScriptLoad(r) 55 | } 56 | 57 | func ScriptLoad(r redis.Cmdable) { 58 | for key, value := range scriptBox { 59 | result, err := r.ScriptLoad(context.Background(), value).Result() 60 | if err != nil { 61 | fmt.Println(err) 62 | continue 63 | } 64 | fmt.Println(key, result) 65 | } 66 | } 67 | 68 | func init() { 69 | flag.StringVar(&addr, "addr", 70 | "ip:port", 71 | "redis addr, eg: -addr ip:port") 72 | flag.StringVar(&password, "password", 73 | "abc", 74 | "redis password, eg: -password abc") 75 | } 76 | -------------------------------------------------------------------------------- /app/message/service/internal/tool/update/db.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/the-zion/matrix-core/app/message/service/internal/data" 7 | "gorm.io/driver/mysql" 8 | "gorm.io/gorm" 9 | "os" 10 | ) 11 | 12 | var ( 13 | source string 14 | ) 15 | 16 | func NewDB(logger log.Logger) *gorm.DB { 17 | l := log.NewHelper(log.With(logger, "update", "db")) 18 | 19 | db, err := gorm.Open(mysql.Open(source), &gorm.Config{ 20 | DisableForeignKeyConstraintWhenMigrating: true, 21 | }) 22 | if err != nil { 23 | l.Fatalf("failed opening connection to db: %v", err) 24 | } 25 | if err := db.AutoMigrate( 26 | &data.SystemNotification{}, 27 | ); err != nil { 28 | l.Fatalf("failed creat or update table resources: %v", err) 29 | } 30 | return db 31 | } 32 | 33 | func main() { 34 | flag.Parse() 35 | logger := log.NewStdLogger(os.Stdout) 36 | NewDB(logger) 37 | } 38 | 39 | func init() { 40 | flag.StringVar(&source, "source", 41 | "root:123456@tcp(127.0.0.1:3306)/core?charset=utf8mb4&parseTime=True&loc=Local", 42 | "database source, eg: -source source path") 43 | } 44 | -------------------------------------------------------------------------------- /app/user/service/Makefile: -------------------------------------------------------------------------------- 1 | INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) 2 | INTERNAL_EASYJSON_DO_FILES=$(shell find internal -name do.go) 3 | INTERNAL_EASYJSON_MODEL_FILES=$(shell find internal -name model.go) 4 | .PHONY: config 5 | # generate internal proto 6 | config: 7 | protoc --proto_path=./internal \ 8 | --proto_path=../../../third_party \ 9 | --go_out=paths=source_relative:./internal \ 10 | $(INTERNAL_PROTO_FILES) 11 | 12 | .PHONY: easyjson 13 | # generate internal proto 14 | easyjson: 15 | easyjson -lower_camel_case $(INTERNAL_EASYJSON_DO_FILES) 16 | easyjson -lower_camel_case $(INTERNAL_EASYJSON_MODEL_FILES) -------------------------------------------------------------------------------- /app/user/service/README.md: -------------------------------------------------------------------------------- 1 | # User Service 2 | -------------------------------------------------------------------------------- /app/user/service/cmd/user/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package main 7 | 8 | import ( 9 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 10 | "github.com/go-kratos/kratos/v2" 11 | "github.com/go-kratos/kratos/v2/log" 12 | "github.com/google/wire" 13 | "github.com/the-zion/matrix-core/app/user/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/user/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/user/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/user/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/user/service/internal/service" 18 | ) 19 | 20 | // wireApp init kratos application. 21 | func wireApp(*conf.Server, *conf.Data, *conf.Auth, log.Logger, *nacos.Registry) (*kratos.App, func(), error) { 22 | panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) 23 | } 24 | -------------------------------------------------------------------------------- /app/user/service/cmd/user/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "github.com/go-kratos/kratos/contrib/registry/nacos/v2" 11 | "github.com/go-kratos/kratos/v2" 12 | "github.com/go-kratos/kratos/v2/log" 13 | "github.com/the-zion/matrix-core/app/user/service/internal/biz" 14 | "github.com/the-zion/matrix-core/app/user/service/internal/conf" 15 | "github.com/the-zion/matrix-core/app/user/service/internal/data" 16 | "github.com/the-zion/matrix-core/app/user/service/internal/server" 17 | "github.com/the-zion/matrix-core/app/user/service/internal/service" 18 | ) 19 | 20 | // Injectors from wire.go: 21 | 22 | // wireApp init kratos application. 23 | func wireApp(confServer *conf.Server, confData *conf.Data, auth *conf.Auth, logLogger log.Logger, registry *nacos.Registry) (*kratos.App, func(), error) { 24 | db := data.NewDB(confData) 25 | cmdable := data.NewRedis(confData) 26 | mqPro := data.NewRocketmqProducer(confData) 27 | elasticSearch := data.NewElasticsearch(confData) 28 | cos := data.NewCosClient(confData) 29 | client := data.NewCosServiceClient(confData) 30 | github := data.NewGithub(confData) 31 | wechat := data.NewWechat(confData) 32 | qq := data.NewQQ(confData) 33 | gitee := data.NewGitee(confData) 34 | aliCode := data.NewPhoneCodeClient(confData) 35 | mail := data.NewMail(confData) 36 | dataData, cleanup2, err := data.NewData(db, cmdable, mqPro, elasticSearch, cos, client, github, wechat, qq, gitee, aliCode, mail, logLogger) 37 | if err != nil { 38 | return nil, nil, err 39 | } 40 | userRepo := data.NewUserRepo(dataData, logLogger) 41 | recovery := data.NewRecovery(dataData) 42 | transaction := data.NewTransaction(dataData) 43 | userUseCase := biz.NewUserUseCase(userRepo, recovery, transaction, logLogger) 44 | authRepo := data.NewAuthRepo(dataData, logLogger) 45 | authUseCase := biz.NewAuthUseCase(auth, authRepo, recovery, userRepo, transaction, logLogger) 46 | userService := service.NewUserService(userUseCase, authUseCase, logLogger) 47 | httpServer := server.NewHTTPServer(confServer, userService, logLogger) 48 | grpcServer := server.NewGRPCServer(confServer, userService, logLogger) 49 | kratosApp := newApp(registry, httpServer, grpcServer) 50 | return kratosApp, func() { 51 | cleanup2() 52 | }, nil 53 | } 54 | -------------------------------------------------------------------------------- /app/user/service/configs/config.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | http: 3 | addr: 0.0.0.0:8000 4 | timeout: 1s 5 | grpc: 6 | addr: 0.0.0.0:9000 7 | timeout: 1s 8 | data: 9 | database: 10 | driver: mysql 11 | source: root:123456@tcp(127.0.0.1:3306)/core?charset=utf8mb4&parseTime=True&loc=Local 12 | redis: 13 | addr: 127.0.0.1:6379 14 | read_timeout: 0.2s 15 | write_timeout: 0.2s 16 | auth: 17 | api_key: some-secret-key-for-forntend 18 | -------------------------------------------------------------------------------- /app/user/service/internal/biz/README.md: -------------------------------------------------------------------------------- 1 | # Biz 2 | -------------------------------------------------------------------------------- /app/user/service/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "github.com/google/wire" 6 | ) 7 | 8 | // ProviderSet is biz providers. 9 | var ProviderSet = wire.NewSet(NewUserUseCase, NewAuthUseCase) 10 | 11 | type Transaction interface { 12 | ExecTx(context.Context, func(ctx context.Context) error) error 13 | } 14 | 15 | type Recovery interface { 16 | GroupRecover(context.Context, func(ctx context.Context) error) func() error 17 | } 18 | -------------------------------------------------------------------------------- /app/user/service/internal/biz/do.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | type User struct { 8 | Uuid string 9 | Phone string 10 | Email string 11 | Qq string 12 | Wechat string 13 | Gitee int32 14 | Github int32 15 | Password string 16 | } 17 | 18 | type Profile struct { 19 | Created string 20 | Updated string 21 | Uuid string 22 | Username string 23 | Avatar string 24 | School string 25 | Company string 26 | Job string 27 | Homepage string 28 | Github string 29 | Gitee string 30 | Introduce string 31 | } 32 | 33 | type UserSearch struct { 34 | Uuid string 35 | Username string 36 | Introduce string 37 | } 38 | 39 | //easyjson:json 40 | type ProfileUpdate struct { 41 | Profile 42 | Mode string 43 | Status int32 44 | } 45 | 46 | type Github struct { 47 | Token string 48 | Avatar string 49 | Register bool 50 | Uuid string 51 | } 52 | 53 | type Credentials struct { 54 | TmpSecretID string 55 | TmpSecretKey string 56 | SessionToken string 57 | StartTime int64 58 | ExpiredTime int64 59 | } 60 | 61 | type Follow struct { 62 | Id int32 63 | Update time.Time 64 | Follow string 65 | Followed string 66 | Status int32 67 | } 68 | 69 | type Follows struct { 70 | Uuid string 71 | Follow int32 72 | } 73 | 74 | //easyjson:json 75 | type ImageReview struct { 76 | Id int32 77 | CreateAt string 78 | Uuid string 79 | JobId string 80 | Url string 81 | Label string 82 | Result int32 83 | Category string 84 | SubLabel string 85 | Mode string 86 | Score int32 87 | } 88 | 89 | //easyjson:json 90 | type UserSearchMap struct { 91 | Username string 92 | Introduce string 93 | } 94 | 95 | //easyjson:json 96 | type ProfileUpdateMap struct { 97 | Username string 98 | Introduce string 99 | } 100 | 101 | //easyjson:json 102 | type SendUserStatisticMap struct { 103 | Follow string 104 | Followed string 105 | Mode string 106 | } 107 | 108 | //easyjson:json 109 | type SetFollowMap struct { 110 | Uuid string 111 | UserId string 112 | Mode string 113 | } 114 | -------------------------------------------------------------------------------- /app/user/service/internal/conf/conf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package kratos.api; 3 | 4 | option go_package = "user/service/internal/conf;conf"; 5 | 6 | import "google/protobuf/duration.proto"; 7 | 8 | message Bootstrap { 9 | Config config = 1; 10 | } 11 | 12 | message Config{ 13 | Server server = 1; 14 | Data data = 2; 15 | Auth auth = 3; 16 | Log log = 4; 17 | } 18 | 19 | message Server { 20 | message HTTP { 21 | string network = 1; 22 | string addr = 2; 23 | google.protobuf.Duration timeout = 3; 24 | } 25 | message GRPC { 26 | string network = 1; 27 | string addr = 2; 28 | google.protobuf.Duration timeout = 3; 29 | } 30 | HTTP http = 1; 31 | GRPC grpc = 2; 32 | } 33 | 34 | message Data { 35 | message Database { 36 | string driver = 1; 37 | string source = 2; 38 | } 39 | message Redis { 40 | string network = 1; 41 | string addr = 2; 42 | string password = 3; 43 | google.protobuf.Duration read_timeout = 4; 44 | google.protobuf.Duration write_timeout = 5; 45 | } 46 | message Rocketmq{ 47 | string serverAddress = 1; 48 | string secretKey = 2; 49 | string accessKey = 3; 50 | string nameSpace = 4; 51 | string groupName = 5; 52 | } 53 | message Cos{ 54 | message Statement{ 55 | repeated string action = 1; 56 | string effect = 2; 57 | repeated string resource = 3; 58 | } 59 | message Policy{ 60 | repeated Statement statement = 1; 61 | } 62 | string url = 1; 63 | string secret_id = 2; 64 | string secret_key = 3; 65 | string region = 4; 66 | Policy policy = 5; 67 | } 68 | message ElasticSearch{ 69 | string endpoint = 1; 70 | string user = 2; 71 | string password = 3; 72 | } 73 | message Github{ 74 | string accessTokenUrl = 1; 75 | string userInfoUrl = 2; 76 | string clientId = 3; 77 | string clientSecret = 4; 78 | } 79 | message Gitee{ 80 | string accessTokenUrl = 1; 81 | string userInfoUrl = 2; 82 | string clientId = 3; 83 | string clientSecret = 4; 84 | string grantType = 5; 85 | string redirectUri = 6; 86 | } 87 | message Wechat{ 88 | string accessTokenUrl = 1; 89 | string userInfoUrl = 2; 90 | string appid = 3; 91 | string secret = 4; 92 | string grantType = 5; 93 | } 94 | message QQ{ 95 | string accessTokenUrl = 1; 96 | string openIdUrl = 2; 97 | string userInfoUrl = 3; 98 | string clientId = 4; 99 | string clientSecret = 5; 100 | string grantType = 6; 101 | string redirectUri = 7; 102 | } 103 | message AliCode{ 104 | string domainUrl = 1; 105 | string accessKeyId = 2; 106 | string accessKeySecret = 3; 107 | string signName = 4; 108 | } 109 | message Mail{ 110 | string code = 1; 111 | } 112 | Database database = 1; 113 | Redis redis = 2; 114 | Rocketmq rocketmq = 3; 115 | ElasticSearch elasticSearch = 4; 116 | Cos cos = 5; 117 | Github github = 6; 118 | Gitee gitee = 7; 119 | Wechat wechat = 8; 120 | QQ qq = 9; 121 | AliCode aliCode = 10; 122 | Mail mail = 11; 123 | } 124 | 125 | message Auth { 126 | string api_key = 1; 127 | } 128 | 129 | message Log { 130 | string host = 1; 131 | string accessKeyID = 2; 132 | string accessKeySecret = 3; 133 | string topicID = 4; 134 | } 135 | -------------------------------------------------------------------------------- /app/user/service/internal/data/README.md: -------------------------------------------------------------------------------- 1 | # Data 2 | -------------------------------------------------------------------------------- /app/user/service/internal/data/model.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "gorm.io/gorm" 5 | "time" 6 | ) 7 | 8 | type User struct { 9 | gorm.Model 10 | Uuid string `gorm:"uniqueIndex;size:20"` 11 | Email string `gorm:"uniqueIndex;size:50"` 12 | Phone string `gorm:"uniqueIndex;size:20"` 13 | Wechat string `gorm:"uniqueIndex;size:100"` 14 | Qq string `gorm:"uniqueIndex;size:100"` 15 | Gitee int32 `gorm:"uniqueIndex;size:100"` 16 | Github int32 `gorm:"uniqueIndex"` 17 | Password string `gorm:"size:500"` 18 | } 19 | 20 | //easyjson:json 21 | type Profile struct { 22 | CreatedAt time.Time 23 | Updated int64 24 | Uuid string `gorm:"primaryKey;size:20"` 25 | Username string `gorm:"index;not null;size:100"` 26 | Avatar string `gorm:"size:200"` 27 | School string `gorm:"size:50"` 28 | Company string `gorm:"size:50"` 29 | Job string `gorm:"size:50"` 30 | Homepage string `gorm:"size:100"` 31 | Github string `gorm:"size:100"` 32 | Gitee string `gorm:"size:100"` 33 | Introduce string `gorm:"size:100"` 34 | } 35 | 36 | type ProfileUpdate struct { 37 | Profile 38 | Status int32 `gorm:"default:1"` 39 | } 40 | 41 | type AvatarReview struct { 42 | gorm.Model 43 | Uuid string `gorm:"index;size:20"` 44 | JobId string `gorm:"size:100"` 45 | Url string `gorm:"size:1000"` 46 | Label string `gorm:"size:100"` 47 | Result int32 48 | Category string `gorm:"size:100"` 49 | SubLabel string `gorm:"size:100"` 50 | Score int32 51 | } 52 | 53 | type CoverReview struct { 54 | gorm.Model 55 | Uuid string `gorm:"index;size:20"` 56 | JobId string `gorm:"size:100"` 57 | Url string `gorm:"size:1000"` 58 | Label string `gorm:"size:100"` 59 | Result int32 60 | Category string `gorm:"size:100"` 61 | SubLabel string `gorm:"size:100"` 62 | Score int32 63 | } 64 | 65 | type Follow struct { 66 | gorm.Model 67 | Follow string `gorm:"uniqueIndex:idx_follow;size:20"` 68 | Followed string `gorm:"uniqueIndex:idx_follow;index;size:20"` 69 | Status int32 70 | } 71 | -------------------------------------------------------------------------------- /app/user/service/internal/pkg/util/check.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "github.com/duke-git/lancet/validator" 4 | 5 | func Test() { 6 | validator.IsStrongPassword("qdq", 12) 7 | } 8 | -------------------------------------------------------------------------------- /app/user/service/internal/pkg/util/lancet.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "github.com/duke-git/lancet/random" 4 | 5 | func UUIdV4() (string, error) { 6 | uuid, err := random.UUIdV4() 7 | if err != nil { 8 | return "", err 9 | } 10 | return uuid, nil 11 | } 12 | -------------------------------------------------------------------------------- /app/user/service/internal/pkg/util/password.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "golang.org/x/crypto/bcrypt" 5 | ) 6 | 7 | func HashPassword(password string) (string, error) { 8 | bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10) 9 | return string(bytes), err 10 | } 11 | 12 | func CheckPasswordHash(password, hash string) bool { 13 | err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) 14 | return err == nil 15 | } 16 | -------------------------------------------------------------------------------- /app/user/service/internal/pkg/util/random.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "time" 7 | ) 8 | 9 | func RandomNumber() string { 10 | code := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000)) 11 | return code 12 | } 13 | -------------------------------------------------------------------------------- /app/user/service/internal/pkg/util/template.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "fmt" 4 | 5 | func GetPhoneTemplate(template string) string { 6 | var id string 7 | switch template { 8 | case "1": 9 | id = "SMS_264780342" 10 | case "2": 11 | id = "SMS_264740382" 12 | case "3": 13 | id = "SMS_264785340" 14 | case "4": 15 | id = "SMS_264775391" 16 | 17 | } 18 | return id 19 | } 20 | 21 | func GetEmailTemplate(template, code string) string { 22 | var content string 23 | switch template { 24 | case "1": 25 | content = code + " 为您的登录验证码,请于2分钟内填写,如非本人操作,请忽略本信息。" 26 | case "2": 27 | content = fmt.Sprintf("您的动态验证码为:%s, 2分钟内有效!您正在进行密码重置操作,如非本人操作,请忽略本信息!", code) 28 | case "3": 29 | content = fmt.Sprintf("您正在进行账号绑定,验证码为:%s,2分钟有效,为保障帐户安全,请勿向任何人提供此验证码。", code) 30 | case "4": 31 | content = fmt.Sprintf("您正在进行账号解绑操作,验证码为:%s,2分钟有效,为保障帐户安全,请勿向任何人提供此验证码", code) 32 | case "5": 33 | content = code + " 为您的邮箱注册验证码,请于2分钟内填写,如非本人操作,请忽略本信息。" 34 | } 35 | return content 36 | } 37 | -------------------------------------------------------------------------------- /app/user/service/internal/pkg/util/time.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "github.com/pkg/errors" 6 | "time" 7 | ) 8 | 9 | func TimeFormat(t time.Time) string { 10 | return t.Format("2006-01-02 15:04:05") 11 | } 12 | 13 | func StringToTime(datetime string) (time.Time, error) { 14 | formatTime, err := time.Parse("2006-01-02 15:04:05", datetime) 15 | if err != nil { 16 | return time.Time{}, errors.Wrapf(err, fmt.Sprintf("fail to parse time: time(%v)", datetime)) 17 | } 18 | return formatTime, nil 19 | } 20 | -------------------------------------------------------------------------------- /app/user/service/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/ratelimit" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/middleware/tracing" 10 | "github.com/go-kratos/kratos/v2/middleware/validate" 11 | "github.com/go-kratos/kratos/v2/transport/grpc" 12 | v1 "github.com/the-zion/matrix-core/api/user/service/v1" 13 | "github.com/the-zion/matrix-core/app/user/service/internal/conf" 14 | "github.com/the-zion/matrix-core/app/user/service/internal/service" 15 | "github.com/the-zion/matrix-core/pkg/responce" 16 | ) 17 | 18 | // NewGRPCServer new a gRPC user. 19 | func NewGRPCServer(c *conf.Server, userService *service.UserService, logger log.Logger) *grpc.Server { 20 | var opts = []grpc.ServerOption{ 21 | grpc.Middleware( 22 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 23 | l := log.NewHelper(log.With(logger, "message", "panic")) 24 | l.Error(err) 25 | return nil 26 | })), 27 | ratelimit.Server(), 28 | tracing.Server(), 29 | responce.Server(), 30 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 31 | validate.Validator(), 32 | ), 33 | } 34 | if c.Grpc.Network != "" { 35 | opts = append(opts, grpc.Network(c.Grpc.Network)) 36 | } 37 | if c.Grpc.Addr != "" { 38 | opts = append(opts, grpc.Address(c.Grpc.Addr)) 39 | } 40 | if c.Grpc.Timeout != nil { 41 | opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) 42 | } 43 | srv := grpc.NewServer(opts...) 44 | v1.RegisterUserServer(srv, userService) 45 | return srv 46 | } 47 | -------------------------------------------------------------------------------- /app/user/service/internal/server/http.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/go-kratos/kratos/v2/middleware/logging" 7 | "github.com/go-kratos/kratos/v2/middleware/recovery" 8 | "github.com/go-kratos/kratos/v2/middleware/validate" 9 | "github.com/go-kratos/kratos/v2/transport/http" 10 | v1 "github.com/the-zion/matrix-core/api/user/service/v1" 11 | "github.com/the-zion/matrix-core/app/user/service/internal/conf" 12 | "github.com/the-zion/matrix-core/app/user/service/internal/service" 13 | "github.com/the-zion/matrix-core/pkg/responce" 14 | ) 15 | 16 | // NewHTTPServer new a HTTP user. 17 | func NewHTTPServer(c *conf.Server, userService *service.UserService, logger log.Logger) *http.Server { 18 | var opts = []http.ServerOption{ 19 | http.Middleware( 20 | recovery.Recovery(recovery.WithHandler(func(ctx context.Context, req, err interface{}) error { 21 | l := log.NewHelper(log.With(logger, "message", "panic")) 22 | l.Error(err) 23 | return nil 24 | })), 25 | responce.Server(), 26 | logging.Server(log.NewFilter(logger, log.FilterLevel(log.LevelError))), 27 | validate.Validator(), 28 | ), 29 | } 30 | if c.Http.Network != "" { 31 | opts = append(opts, http.Network(c.Http.Network)) 32 | } 33 | if c.Http.Addr != "" { 34 | opts = append(opts, http.Address(c.Http.Addr)) 35 | } 36 | if c.Http.Timeout != nil { 37 | opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) 38 | } 39 | srv := http.NewServer(opts...) 40 | v1.RegisterUserHTTPServer(srv, userService) 41 | return srv 42 | } 43 | -------------------------------------------------------------------------------- /app/user/service/internal/server/server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSet is user providers. 8 | var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) 9 | -------------------------------------------------------------------------------- /app/user/service/internal/service/README.md: -------------------------------------------------------------------------------- 1 | # Service 2 | -------------------------------------------------------------------------------- /app/user/service/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/google/wire" 7 | v1 "github.com/the-zion/matrix-core/api/user/service/v1" 8 | "github.com/the-zion/matrix-core/app/user/service/internal/biz" 9 | "google.golang.org/protobuf/types/known/emptypb" 10 | ) 11 | 12 | var ProviderSet = wire.NewSet(NewUserService) 13 | 14 | type UserService struct { 15 | v1.UnimplementedUserServer 16 | uc *biz.UserUseCase 17 | ac *biz.AuthUseCase 18 | log *log.Helper 19 | } 20 | 21 | func NewUserService(uc *biz.UserUseCase, ac *biz.AuthUseCase, logger log.Logger) *UserService { 22 | return &UserService{ 23 | log: log.NewHelper(log.With(logger, "module", "user/service")), 24 | uc: uc, 25 | ac: ac, 26 | } 27 | } 28 | 29 | func (s *UserService) GetHealth(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { 30 | return &emptypb.Empty{}, nil 31 | } 32 | -------------------------------------------------------------------------------- /app/user/service/internal/tool/es/dsl: -------------------------------------------------------------------------------- 1 | PUT user 2 | { 3 | "mappings": { 4 | "properties": { 5 | "username": { 6 | "type": "text", 7 | "analyzer": "thulac" 8 | }, 9 | "introduce": { 10 | "type": "text", 11 | "index": false 12 | } 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /app/user/service/internal/tool/lua/lua.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "github.com/go-kratos/kratos/v2/log" 8 | "github.com/go-redis/redis/v8" 9 | "os" 10 | "time" 11 | ) 12 | 13 | var ( 14 | addr string 15 | password string 16 | scriptBox = map[string]string{ 17 | "SetAvatarIrregularToCache": ` 18 | local key = KEYS[1] 19 | local value = ARGV[1] 20 | local exist = redis.call("EXISTS", key) 21 | if exist == 1 then 22 | redis.call("LPUSH", key, value) 23 | end 24 | return 0 25 | `, 26 | "SetCoverIrregularToCache": ` 27 | local key = KEYS[1] 28 | local value = ARGV[1] 29 | local exist = redis.call("EXISTS", key) 30 | if exist == 1 then 31 | redis.call("LPUSH", key, value) 32 | end 33 | return 0 34 | `, 35 | "SetUserFollowToCache": ` 36 | local key = KEYS[1] 37 | local value = ARGV[1] 38 | local value2 = ARGV[2] 39 | local exist = redis.call("EXISTS", key) 40 | if exist == 1 then 41 | redis.call("SADD", key, value) 42 | end 43 | 44 | local followList = KEYS[2] 45 | local score = ARGV[3] 46 | local exist = redis.call("EXISTS", followList) 47 | if exist == 1 then 48 | redis.call("ZADD", followList, score, value) 49 | end 50 | 51 | local followedList = KEYS[3] 52 | local exist = redis.call("EXISTS", followedList) 53 | if exist == 1 then 54 | redis.call("ZADD", followedList, score, value2) 55 | end 56 | return 0 57 | `, 58 | } 59 | ) 60 | 61 | func NewRedis(logger log.Logger) redis.Cmdable { 62 | l := log.NewHelper(log.With(logger, "lua", "redis")) 63 | 64 | client := redis.NewClient(&redis.Options{ 65 | Addr: addr, 66 | DialTimeout: time.Second * 2, 67 | PoolSize: 10, 68 | Password: password, 69 | }) 70 | timeout, cancelFunc := context.WithTimeout(context.Background(), time.Second*2) 71 | defer cancelFunc() 72 | err := client.Ping(timeout).Err() 73 | if err != nil { 74 | l.Fatalf("redis connect error: %v", err) 75 | } 76 | return client 77 | } 78 | 79 | func main() { 80 | flag.Parse() 81 | logger := log.NewStdLogger(os.Stdout) 82 | r := NewRedis(logger) 83 | ScriptLoad(r) 84 | } 85 | 86 | func ScriptLoad(r redis.Cmdable) { 87 | for key, value := range scriptBox { 88 | result, err := r.ScriptLoad(context.Background(), value).Result() 89 | if err != nil { 90 | fmt.Println(err) 91 | continue 92 | } 93 | fmt.Println(key, result) 94 | } 95 | } 96 | 97 | func init() { 98 | flag.StringVar(&addr, "addr", 99 | "ip:port", 100 | "redis addr, eg: -addr ip:port") 101 | flag.StringVar(&password, "password", 102 | "abc", 103 | "redis password, eg: -password abc") 104 | } 105 | -------------------------------------------------------------------------------- /app/user/service/internal/tool/update/db.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/go-kratos/kratos/v2/log" 6 | "github.com/the-zion/matrix-core/app/user/service/internal/data" 7 | "gorm.io/driver/mysql" 8 | "gorm.io/gorm" 9 | "os" 10 | ) 11 | 12 | var ( 13 | source string 14 | ) 15 | 16 | func NewDB(logger log.Logger) *gorm.DB { 17 | l := log.NewHelper(log.With(logger, "update", "db")) 18 | 19 | db, err := gorm.Open(mysql.Open(source), &gorm.Config{ 20 | DisableForeignKeyConstraintWhenMigrating: true, 21 | }) 22 | if err != nil { 23 | l.Fatalf("failed opening connection to db: %v", err) 24 | } 25 | if err := db.AutoMigrate( 26 | &data.User{}, 27 | &data.Profile{}, 28 | &data.ProfileUpdate{}, 29 | &data.Follow{}, 30 | &data.AvatarReview{}, 31 | &data.CoverReview{}, 32 | ); err != nil { 33 | l.Fatalf("failed creat or update table resources: %v", err) 34 | } 35 | return db 36 | } 37 | 38 | func main() { 39 | flag.Parse() 40 | logger := log.NewStdLogger(os.Stdout) 41 | NewDB(logger) 42 | } 43 | 44 | func init() { 45 | flag.StringVar(&source, "source", 46 | "root:123456@tcp(127.0.0.1:3306)/core?charset=utf8mb4&parseTime=True&loc=Local", 47 | "database source, eg: -source source path") 48 | } 49 | -------------------------------------------------------------------------------- /architecture.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zion/matrix-core/8b7706757eb5b760d064fc87bcaa196344a1e9ac/architecture.jpeg -------------------------------------------------------------------------------- /pkg/jwtclaim/jwt.go: -------------------------------------------------------------------------------- 1 | package jwtclaim 2 | 3 | import "github.com/golang-jwt/jwt/v4" 4 | 5 | type JwtCustomClaims struct { 6 | Uuid string `json:"uuid"` 7 | jwt.StandardClaims 8 | } 9 | -------------------------------------------------------------------------------- /pkg/kube/kube.go: -------------------------------------------------------------------------------- 1 | package kube 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 7 | "k8s.io/client-go/kubernetes" 8 | "k8s.io/client-go/rest" 9 | "k8s.io/client-go/tools/clientcmd" 10 | "time" 11 | ) 12 | 13 | var ( 14 | configPath string 15 | ) 16 | 17 | type kubeClient struct { 18 | client *kubernetes.Clientset 19 | } 20 | 21 | func NewKubeClient() (*kubeClient, error) { 22 | var config *rest.Config 23 | var err error 24 | if configPath != "" { 25 | config, err = clientcmd.BuildConfigFromFlags("", configPath) 26 | if err != nil { 27 | return nil, err 28 | } 29 | } else { 30 | config, err = rest.InClusterConfig() 31 | if err != nil { 32 | return nil, err 33 | } 34 | } 35 | clientset, err := kubernetes.NewForConfig(config) 36 | if err != nil { 37 | return nil, err 38 | } 39 | return &kubeClient{ 40 | client: clientset, 41 | }, nil 42 | } 43 | 44 | func (k *kubeClient) Update(namespace, deploymentName string) error { 45 | ctx, _ := context.WithTimeout(context.Background(), time.Second*5) 46 | deployment, err := k.client.AppsV1().Deployments(namespace).Get(ctx, deploymentName, metav1.GetOptions{}) 47 | if err != nil { 48 | return err 49 | } 50 | containers := &deployment.Spec.Template.Spec.Containers 51 | for i := range *containers { 52 | c := *containers 53 | for j := range c[i].Env { 54 | if c[i].Env[j].Name == "timestep" { 55 | c[i].Env[j].Value = time.Now().Format("2006-01-02 15:04:05") 56 | } 57 | } 58 | } 59 | _, err = k.client.AppsV1().Deployments(namespace).Update(ctx, deployment, metav1.UpdateOptions{}) 60 | if err != nil { 61 | return err 62 | } 63 | return nil 64 | } 65 | 66 | func init() { 67 | flag.StringVar(&configPath, "kubeconfig", "", "kube config, eg: -kubeconfig xxx") 68 | } 69 | -------------------------------------------------------------------------------- /pkg/request/request.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/middleware" 6 | "github.com/go-kratos/kratos/v2/transport" 7 | ) 8 | 9 | func Server() middleware.Middleware { 10 | return func(handler middleware.Handler) middleware.Handler { 11 | return func(ctx context.Context, req interface{}) (reply interface{}, err error) { 12 | if header, ok := transport.FromServerContext(ctx); ok { 13 | ctx = context.WithValue(ctx, "uuid", header.RequestHeader().Get("uuid")) 14 | ctx = context.WithValue(ctx, "realIp", header.RequestHeader().Get("realIp")) 15 | } 16 | reply, err = handler(ctx, req) 17 | return 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pkg/responce/responce.go: -------------------------------------------------------------------------------- 1 | package responce 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2/errors" 6 | "github.com/go-kratos/kratos/v2/middleware" 7 | ) 8 | 9 | func Server() middleware.Middleware { 10 | return func(handler middleware.Handler) middleware.Handler { 11 | return func(ctx context.Context, req interface{}) (reply interface{}, err error) { 12 | reply, err = handler(ctx, req) 13 | if err != nil { 14 | e := err.(*errors.Error) 15 | e.Message = "" 16 | return reply, e 17 | } 18 | return 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pkg/trace/trace.go: -------------------------------------------------------------------------------- 1 | package trace 2 | 3 | import ( 4 | "context" 5 | "github.com/go-kratos/kratos/v2" 6 | "github.com/go-kratos/kratos/v2/metadata" 7 | "go.opentelemetry.io/otel" 8 | "go.opentelemetry.io/otel/attribute" 9 | "go.opentelemetry.io/otel/exporters/jaeger" 10 | "go.opentelemetry.io/otel/propagation" 11 | "go.opentelemetry.io/otel/sdk/resource" 12 | tracesdk "go.opentelemetry.io/otel/sdk/trace" 13 | semconv "go.opentelemetry.io/otel/semconv/v1.4.0" 14 | "strings" 15 | ) 16 | 17 | const serviceHeader = "x-md-service-name" 18 | 19 | // Metadata is tracing metadata propagator 20 | type Metadata struct{} 21 | 22 | var _ propagation.TextMapPropagator = Metadata{} 23 | 24 | // Inject sets metadata key-values from ctx into the carrier. 25 | func (b Metadata) Inject(ctx context.Context, carrier propagation.TextMapCarrier) { 26 | app, ok := kratos.FromContext(ctx) 27 | if ok { 28 | var builder strings.Builder 29 | for _, str := range []string{app.Name(), ".", app.ID()} { 30 | builder.WriteString(str) 31 | } 32 | carrier.Set(serviceHeader, builder.String()) 33 | } 34 | } 35 | 36 | // Extract returns a copy of parent with the metadata from the carrier added. 37 | func (b Metadata) Extract(parent context.Context, carrier propagation.TextMapCarrier) context.Context { 38 | name := carrier.Get(serviceHeader) 39 | if name == "" { 40 | return parent 41 | } 42 | if md, ok := metadata.FromServerContext(parent); ok { 43 | md.Set(serviceHeader, name) 44 | return parent 45 | } 46 | md := metadata.New() 47 | md.Set(serviceHeader, name) 48 | parent = metadata.NewServerContext(parent, md) 49 | return parent 50 | } 51 | 52 | // Fields returns the keys who's values are set with Inject. 53 | func (b Metadata) Fields() []string { 54 | return []string{serviceHeader} 55 | } 56 | 57 | func SetTracerProvider(url, token, service, hostname string) (*tracesdk.TracerProvider, error) { 58 | var builder strings.Builder 59 | for _, str := range []string{service, ".", hostname} { 60 | builder.WriteString(str) 61 | } 62 | exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) 63 | if err != nil { 64 | return nil, err 65 | } 66 | tp := tracesdk.NewTracerProvider( 67 | tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(0.5))), 68 | tracesdk.WithBatcher(exp), 69 | tracesdk.WithResource(resource.NewSchemaless( 70 | semconv.ServiceNameKey.String(builder.String()), 71 | attribute.String("exporter", "jaeger"), 72 | attribute.Float64("float", 312.23), 73 | attribute.KeyValue{ 74 | Key: "token", Value: attribute.StringValue(token), 75 | }, 76 | )), 77 | ) 78 | otel.SetTracerProvider(tp) 79 | return tp, nil 80 | } 81 | -------------------------------------------------------------------------------- /third_party/README.md: -------------------------------------------------------------------------------- 1 | # third_party 2 | -------------------------------------------------------------------------------- /third_party/errors/errors.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package errors; 4 | 5 | option go_package = "github.com/go-kratos/kratos/v2/errors;errors"; 6 | option java_multiple_files = true; 7 | option java_package = "com.github.kratos.errors"; 8 | option objc_class_prefix = "KratosErrors"; 9 | 10 | import "google/protobuf/descriptor.proto"; 11 | 12 | extend google.protobuf.EnumOptions { 13 | int32 default_code = 1108; 14 | } 15 | 16 | extend google.protobuf.EnumValueOptions { 17 | int32 code = 1109; 18 | } -------------------------------------------------------------------------------- /third_party/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/google/api/client.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/protobuf/descriptor.proto"; 20 | 21 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 22 | option java_multiple_files = true; 23 | option java_outer_classname = "ClientProto"; 24 | option java_package = "com.google.api"; 25 | option objc_class_prefix = "GAPI"; 26 | 27 | 28 | extend google.protobuf.ServiceOptions { 29 | // The hostname for this service. 30 | // This should be specified with no prefix or protocol. 31 | // 32 | // Example: 33 | // 34 | // service Foo { 35 | // option (google.api.default_host) = "foo.googleapi.com"; 36 | // ... 37 | // } 38 | string default_host = 1049; 39 | 40 | // OAuth scopes needed for the client. 41 | // 42 | // Example: 43 | // 44 | // service Foo { 45 | // option (google.api.oauth_scopes) = \ 46 | // "https://www.googleapis.com/auth/cloud-platform"; 47 | // ... 48 | // } 49 | // 50 | // If there is more than one scope, use a comma-separated string: 51 | // 52 | // Example: 53 | // 54 | // service Foo { 55 | // option (google.api.oauth_scopes) = \ 56 | // "https://www.googleapis.com/auth/cloud-platform," 57 | // "https://www.googleapis.com/auth/monitoring"; 58 | // ... 59 | // } 60 | string oauth_scopes = 1050; 61 | } 62 | 63 | 64 | extend google.protobuf.MethodOptions { 65 | // A definition of a client library method signature. 66 | // 67 | // In client libraries, each proto RPC corresponds to one or more methods 68 | // which the end user is able to call, and calls the underlying RPC. 69 | // Normally, this method receives a single argument (a struct or instance 70 | // corresponding to the RPC request object). Defining this field will 71 | // add one or more overloads providing flattened or simpler method signatures 72 | // in some languages. 73 | // 74 | // The fields on the method signature are provided as a comma-separated 75 | // string. 76 | // 77 | // For example, the proto RPC and annotation: 78 | // 79 | // rpc CreateSubscription(CreateSubscriptionRequest) 80 | // returns (Subscription) { 81 | // option (google.api.method_signature) = "name,topic"; 82 | // } 83 | // 84 | // Would add the following Java overload (in addition to the method accepting 85 | // the request object): 86 | // 87 | // public final Subscription createSubscription(String name, String topic) 88 | // 89 | // The following backwards-compatibility guidelines apply: 90 | // 91 | // * Adding this annotation to an unannotated method is backwards 92 | // compatible. 93 | // * Adding this annotation to a method which already has existing 94 | // method signature annotations is backwards compatible if and only if 95 | // the new method signature annotation is last in the sequence. 96 | // * Modifying or removing an existing method signature annotation is 97 | // a breaking change. 98 | // * Re-ordering existing method signature annotations is a breaking 99 | // change. 100 | repeated string method_signature = 1051; 101 | } -------------------------------------------------------------------------------- /third_party/google/api/field_behavior.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/protobuf/descriptor.proto"; 20 | 21 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 22 | option java_multiple_files = true; 23 | option java_outer_classname = "FieldBehaviorProto"; 24 | option java_package = "com.google.api"; 25 | option objc_class_prefix = "GAPI"; 26 | 27 | 28 | // An indicator of the behavior of a given field (for example, that a field 29 | // is required in requests, or given as output but ignored as input). 30 | // This **does not** change the behavior in protocol buffers itself; it only 31 | // denotes the behavior and may affect how API tooling handles the field. 32 | // 33 | // Note: This enum **may** receive new values in the future. 34 | enum FieldBehavior { 35 | // Conventional default for enums. Do not use this. 36 | FIELD_BEHAVIOR_UNSPECIFIED = 0; 37 | 38 | // Specifically denotes a field as optional. 39 | // While all fields in protocol buffers are optional, this may be specified 40 | // for emphasis if appropriate. 41 | OPTIONAL = 1; 42 | 43 | // Denotes a field as required. 44 | // This indicates that the field **must** be provided as part of the request, 45 | // and failure to do so will cause an error (usually `INVALID_ARGUMENT`). 46 | REQUIRED = 2; 47 | 48 | // Denotes a field as output only. 49 | // This indicates that the field is provided in responses, but including the 50 | // field in a request does nothing (the server *must* ignore it and 51 | // *must not* throw an error as a result of the field's presence). 52 | OUTPUT_ONLY = 3; 53 | 54 | // Denotes a field as input only. 55 | // This indicates that the field is provided in requests, and the 56 | // corresponding field is not included in output. 57 | INPUT_ONLY = 4; 58 | 59 | // Denotes a field as immutable. 60 | // This indicates that the field may be set once in a request to create a 61 | // resource, but may not be changed thereafter. 62 | IMMUTABLE = 5; 63 | } 64 | 65 | 66 | extend google.protobuf.FieldOptions { 67 | // A designation of a specific field behavior (required, output only, etc.) 68 | // in protobuf messages. 69 | // 70 | // Examples: 71 | // 72 | // string name = 1 [(google.api.field_behavior) = REQUIRED]; 73 | // State state = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; 74 | // google.protobuf.Duration ttl = 1 75 | // [(google.api.field_behavior) = INPUT_ONLY]; 76 | // google.protobuf.Timestamp expire_time = 1 77 | // [(google.api.field_behavior) = OUTPUT_ONLY, 78 | // (google.api.field_behavior) = IMMUTABLE]; 79 | repeated FieldBehavior field_behavior = 1052; 80 | } -------------------------------------------------------------------------------- /third_party/google/api/httpbody.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/protobuf/any.proto"; 20 | 21 | option cc_enable_arenas = true; 22 | option go_package = "google.golang.org/genproto/googleapis/api/httpbody;httpbody"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "HttpBodyProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | // Message that represents an arbitrary HTTP body. It should only be used for 29 | // payload formats that can't be represented as JSON, such as raw binary or 30 | // an HTML page. 31 | // 32 | // 33 | // This message can be used both in streaming and non-streaming API methods in 34 | // the request as well as the response. 35 | // 36 | // It can be used as a top-level request field, which is convenient if one 37 | // wants to extract parameters from either the URL or HTTP template into the 38 | // request fields and also want access to the raw HTTP body. 39 | // 40 | // Example: 41 | // 42 | // message GetResourceRequest { 43 | // // A unique request id. 44 | // string request_id = 1; 45 | // 46 | // // The raw HTTP body is bound to this field. 47 | // google.api.HttpBody http_body = 2; 48 | // } 49 | // 50 | // service ResourceService { 51 | // rpc GetResource(GetResourceRequest) returns (google.api.HttpBody); 52 | // rpc UpdateResource(google.api.HttpBody) returns 53 | // (google.protobuf.Empty); 54 | // } 55 | // 56 | // Example with streaming methods: 57 | // 58 | // service CaldavService { 59 | // rpc GetCalendar(stream google.api.HttpBody) 60 | // returns (stream google.api.HttpBody); 61 | // rpc UpdateCalendar(stream google.api.HttpBody) 62 | // returns (stream google.api.HttpBody); 63 | // } 64 | // 65 | // Use of this type only changes how the request and response bodies are 66 | // handled, all other features will continue to work unchanged. 67 | message HttpBody { 68 | // The HTTP Content-Type header value specifying the content type of the body. 69 | string content_type = 1; 70 | 71 | // The HTTP request/response body as raw binary. 72 | bytes data = 2; 73 | 74 | // Application specific response metadata. Must be set in the first response 75 | // for streaming APIs. 76 | repeated google.protobuf.Any extensions = 3; 77 | } 78 | -------------------------------------------------------------------------------- /third_party/google/protobuf/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "google.golang.org/protobuf/types/known/emptypb"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "EmptyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | option cc_enable_arenas = true; 42 | 43 | // A generic empty message that you can re-use to avoid defining duplicated 44 | // empty messages in your APIs. A typical example is to use it as the request 45 | // or the response type of an API method. For instance: 46 | // 47 | // service Foo { 48 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 49 | // } 50 | // 51 | message Empty {} -------------------------------------------------------------------------------- /third_party/validate/README.md: -------------------------------------------------------------------------------- 1 | # protoc-gen-validate (PGV) 2 | 3 | * https://github.com/envoyproxy/protoc-gen-validate 4 | --------------------------------------------------------------------------------