From 6f5173828bad1143399cbf0bda58a73f5c10342f Mon Sep 17 00:00:00 2001 From: yanweidong Date: Tue, 23 Sep 2025 22:25:19 +0800 Subject: [PATCH] initial --- .gitea/workflows/cicd.yaml | 112 ++++ .gitignore | 33 ++ buf.gen.yaml | 49 ++ buf.yaml | 10 + cmd/cli/main.go | 10 + cmd/main/main.go | 45 ++ etc/sample_dev.yaml | 44 ++ etc/sample_prod.yaml | 44 ++ etc/sample_test.yaml | 44 ++ etc/supervisor.bsm-apps-sample.conf | 8 + go.mod | 70 +++ go.sum | 170 ++++++ internal/config/config.go | 41 ++ internal/impl/impl.go | 25 + internal/logic/account/get.go | 69 +++ internal/logic/account/set_data.go | 65 +++ internal/logic/account/set_password.go | 52 ++ internal/logic/account/statistics.go | 23 + internal/logic/account/tag_create.go | 50 ++ internal/logic/account/tag_remove.go | 35 ++ internal/logic/common/token.go | 12 + internal/logic/forget/reset.go | 56 ++ internal/logic/forget/verify.go | 34 ++ internal/logic/login/code.go | 52 ++ internal/logic/login/code_and_register.go | 61 ++ internal/logic/login/pwd.go | 55 ++ internal/logic/register/code.go | 30 + internal/logic/register/do.go | 81 +++ internal/logic/register/pwd.go | 23 + internal/models/passport_account.go | 64 ++ internal/models/query.go | 7 + internal/server/account_server.go | 47 ++ internal/server/forget_server.go | 27 + internal/server/login_server.go | 32 + internal/server/new.go | 78 +++ internal/server/register_server.go | 27 + pb/account.pb.go | 676 ++++++++++++++++++++++ pb/account.pb.gw.go | 487 ++++++++++++++++ pb/account_grpc.pb.go | 328 +++++++++++ pb/blocks.pb.go | 391 +++++++++++++ pb/forget.pb.go | 277 +++++++++ pb/forget.pb.gw.go | 223 +++++++ pb/forget_grpc.pb.go | 168 ++++++ pb/login.pb.go | 288 +++++++++ pb/login.pb.gw.go | 289 +++++++++ pb/login_grpc.pb.go | 208 +++++++ pb/register.pb.go | 282 +++++++++ pb/register.pb.gw.go | 223 +++++++ pb/register_grpc.pb.go | 168 ++++++ proto/blocks.proto | 33 ++ proto/sample.proto | 82 +++ scripts/filebeat.yaml | 32 + scripts/lint.sh | 5 + swagger/passport.swagger.json | 263 +++++++++ test/login-pwd.http | 9 + test/readme.md | 1 + 56 files changed, 6118 insertions(+) create mode 100644 .gitea/workflows/cicd.yaml create mode 100644 .gitignore create mode 100644 buf.gen.yaml create mode 100644 buf.yaml create mode 100644 cmd/cli/main.go create mode 100644 cmd/main/main.go create mode 100644 etc/sample_dev.yaml create mode 100644 etc/sample_prod.yaml create mode 100644 etc/sample_test.yaml create mode 100644 etc/supervisor.bsm-apps-sample.conf create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/config/config.go create mode 100644 internal/impl/impl.go create mode 100644 internal/logic/account/get.go create mode 100644 internal/logic/account/set_data.go create mode 100644 internal/logic/account/set_password.go create mode 100644 internal/logic/account/statistics.go create mode 100644 internal/logic/account/tag_create.go create mode 100644 internal/logic/account/tag_remove.go create mode 100644 internal/logic/common/token.go create mode 100644 internal/logic/forget/reset.go create mode 100644 internal/logic/forget/verify.go create mode 100644 internal/logic/login/code.go create mode 100644 internal/logic/login/code_and_register.go create mode 100644 internal/logic/login/pwd.go create mode 100644 internal/logic/register/code.go create mode 100644 internal/logic/register/do.go create mode 100644 internal/logic/register/pwd.go create mode 100644 internal/models/passport_account.go create mode 100644 internal/models/query.go create mode 100644 internal/server/account_server.go create mode 100644 internal/server/forget_server.go create mode 100644 internal/server/login_server.go create mode 100644 internal/server/new.go create mode 100644 internal/server/register_server.go create mode 100644 pb/account.pb.go create mode 100644 pb/account.pb.gw.go create mode 100644 pb/account_grpc.pb.go create mode 100644 pb/blocks.pb.go create mode 100644 pb/forget.pb.go create mode 100644 pb/forget.pb.gw.go create mode 100644 pb/forget_grpc.pb.go create mode 100644 pb/login.pb.go create mode 100644 pb/login.pb.gw.go create mode 100644 pb/login_grpc.pb.go create mode 100644 pb/register.pb.go create mode 100644 pb/register.pb.gw.go create mode 100644 pb/register_grpc.pb.go create mode 100644 proto/blocks.proto create mode 100644 proto/sample.proto create mode 100644 scripts/filebeat.yaml create mode 100644 scripts/lint.sh create mode 100644 swagger/passport.swagger.json create mode 100644 test/login-pwd.http create mode 100644 test/readme.md diff --git a/.gitea/workflows/cicd.yaml b/.gitea/workflows/cicd.yaml new file mode 100644 index 0000000..743f0f5 --- /dev/null +++ b/.gitea/workflows/cicd.yaml @@ -0,0 +1,112 @@ +name: Actions +run-name: ${{ gitea.actor }} 🚀 +on: + push: + tags: + - 'v*' + + +jobs: + Explore-Gitea-Actions: + runs-on: ubuntu-latest + steps: + - name: Clean temp directory + run: rm -rf * + # 设置 Go 环境 + - name: 设置 Go + uses: https://git.apinb.com/github/setup-go@v5 + with: + go-version: '1.24.6' + tag_name: ${{ gitea.ref }} + release_name: ${{ gitea.ref }} + + - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." + - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository_owner }}." + - name: Extract repository name + id: extract_repo + run: | + repo_name=$(echo ${{ gitea.repository }} | cut -d'/' -f2) + echo "Repository name: $repo_name" + echo "::set-output name=repo_name::$repo_name" + + # 提取tag标签名称 + - name: Extract tag name + id: extract_tag + run: echo "::set-output name=tag_name::$(echo ${{ gitea.ref }} | sed 's/^refs\/tags\///')" + - run: echo "🏷 The tag name is ${{ steps.extract_tag.outputs.tag_name }}." + + # 检查出代码 + - name: Check out repository code + uses: https://git.apinb.com/github/checkout@v4 + + # 缓存 Go 依赖项 + - name: Cache Go modules + uses: https://git.apinb.com/github/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + + - name: set last version + run: | + echo "export srv_version='${{ steps.extract_tag.outputs.tag_name }}';export srv_name='${{ steps.extract_repo.outputs.repo_name }}'" > ${{ gitea.repository_owner }}-${{ steps.extract_repo.outputs.repo_name }}_last_version.sh + - run: go env -w GOPROXY=https://goproxy.cn + - run: go env -w GOPRIVATE=git.apinb.com/* + - run: go env -w GONOPROXY=git.apinb.com/* + - run: go env -w GOINSECURE=git.apinb.com/* + - run: go env -w GONOSUMDB=git.apinb.com/* + - run: go build -o ${{ gitea.repository_owner }}-${{ steps.extract_repo.outputs.repo_name }} ./cmd/main/main.go + - run: echo "🍏 This job's status is ${{ job.status }}." + - name: upload version.sh to minio oss - 1 + uses: https://git.apinb.com/github/minio-upload@main + with: + endpoint: http://172.24.0.20:9000 + access-key-id: 9jtPPB7wwJpe5R2164bS + access-key-secret: ho9LYavUIGdkf0b50aaOduIA4zdx8FQFWpUYx30p + bucket: reles + source: ./${{ gitea.repository_owner }}-${{ steps.extract_repo.outputs.repo_name }}_last_version.sh + insecure: true + recursive: true + + - name: upload bin to minio oss - 2 + uses: https://git.apinb.com/github/minio-upload@main + with: + endpoint: http://172.24.0.20:9000 + access-key-id: 9jtPPB7wwJpe5R2164bS + access-key-secret: ho9LYavUIGdkf0b50aaOduIA4zdx8FQFWpUYx30p + bucket: reles + source: ./${{ gitea.repository_owner }}-${{ steps.extract_repo.outputs.repo_name }} + target: /${{ gitea.repository_owner }}-${{ steps.extract_repo.outputs.repo_name }}@${{ steps.extract_tag.outputs.tag_name }}/ + insecure: true + recursive: false + + - name: upload etc/ to minio oss - 3 + uses: https://git.apinb.com/github/minio-upload@main + with: + endpoint: http://172.24.0.20:9000 + access-key-id: 9jtPPB7wwJpe5R2164bS + access-key-secret: ho9LYavUIGdkf0b50aaOduIA4zdx8FQFWpUYx30p + bucket: reles + source: ./etc + target: /${{ gitea.repository_owner }}-${{ steps.extract_repo.outputs.repo_name }}@${{ steps.extract_tag.outputs.tag_name }}/ + insecure: true + recursive: true + + - name: upload swagger to minio oss - 4 + uses: https://git.apinb.com/github/minio-upload@main + with: + endpoint: http://172.24.0.20:9000 + access-key-id: 9jtPPB7wwJpe5R2164bS + access-key-secret: ho9LYavUIGdkf0b50aaOduIA4zdx8FQFWpUYx30p + bucket: reles + source: ./swagger + target: /${{ gitea.repository_owner }}-${{ steps.extract_repo.outputs.repo_name }}@${{ steps.extract_tag.outputs.tag_name }}/ + insecure: true + recursive: true + + - name: upload success + run: echo "build&upload success." \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a30cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# ---> Go +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ +builds/ +logs/ +pkg/ +cache/ +tmp/ +.builds/ +.logs/ +.pkg/ +.cache/ +.tmp/ + +# Go workspace file +go.work + diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 0000000..4000ee8 --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,49 @@ +version: v2 +plugins: + - local: protoc-gen-go + out: pb + opt: + - paths=source_relative + + - local: protoc-gen-go + out: ../../bsm-sdk/client/golang/sample + opt: + - paths=source_relative + + - local: protoc-gen-go-grpc + out: pb + opt: + - paths=source_relative + + - local: protoc-gen-go-grpc + out: ../../bsm-sdk/client/golang/sample + opt: + - paths=source_relative + + - local: protoc-gen-grpc-gateway + out: pb + opt: + - paths=source_relative + - generate_unbound_methods=True + + - local: protoc-gen-slc + out: ./ + + - local: protoc-gen-ts + out: ../../bsm-sdk/client/typescript + + - local: protoc-gen-dart + out: ../../bsm-sdk/client/dart/sample + opt: + - grpc + + - local: protoc-gen-openapiv2 + out: ./swagger + opt: allow_merge=true,merge_file_name=sample + + - local: protoc-gen-openapiv2 + out: ../../bsm-sdk/client/docs/sample + opt: allow_merge=true,merge_file_name=sample + + - local: protoc-gen-markdown + out: ../../bsm-sdk/client/docs/sample \ No newline at end of file diff --git a/buf.yaml b/buf.yaml new file mode 100644 index 0000000..dcbcda2 --- /dev/null +++ b/buf.yaml @@ -0,0 +1,10 @@ +# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml +version: v2 +lint: + use: + - STANDARD +modules: + - path: proto +breaking: + use: + - FILE diff --git a/cmd/cli/main.go b/cmd/cli/main.go new file mode 100644 index 0000000..231edbf --- /dev/null +++ b/cmd/cli/main.go @@ -0,0 +1,10 @@ +package main + +import ( + "log" +) + +func main() { + log.Println("Service cli mode:") + log.Println("Done.") +} diff --git a/cmd/main/main.go b/cmd/main/main.go new file mode 100644 index 0000000..888e11b --- /dev/null +++ b/cmd/main/main.go @@ -0,0 +1,45 @@ +/** + * @Author: david.yan(david.yan@qq.com) + * @Date: 2021-11-26 15:25:03 + */ +package main + +import ( + "git.apinb.com/bsm-sdk/core/service" + "git.apinb.com/bsm-sdk/sample/internal/config" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/models" + "git.apinb.com/bsm-sdk/sample/internal/server" +) + +var ( + ServiceKey = "Sample" +) + +func main() { + config.New(ServiceKey) + impl.NewImpl() + + // 初始化服务 + s := server.New(config.Spec.Addr) + srv := service.New( + s.Grpc, + &service.Options{ + Addr: config.Spec.Addr, + MsConf: config.Spec.MicroService, + EtcdClient: impl.EtcdService, + GatewayCtx: s.Ctx, + GatewayConf: config.Spec.Gateway, + GatewayMux: s.Mux, + }, + ) + + // 注册:初始化数据 + srv.Use(models.InitData) + + // 停止服务 + defer srv.Stop() + + // 启动服务 + srv.Start() +} diff --git a/etc/sample_dev.yaml b/etc/sample_dev.yaml new file mode 100644 index 0000000..25d9dfb --- /dev/null +++ b/etc/sample_dev.yaml @@ -0,0 +1,44 @@ +Service: sample +Port: 12426 + +Databases: + Driver: postgres + Source: + - host=47.109.77.183 user=postgres password=Weidong2023~! dbname=${BSM_Workspace}_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai + +# cache DB的选择请在后面直接带参数,不带会自动HASH计算选择DB库。 +Cache: redis://null:Weidong2023~!@47.109.77.183:6379/ + +# 微服务设置 +MicroService: + Enable: false + Anonymous: + - sample.ping.hello + +# 微信设置 +WeChatConf: + AppID: 123 + AppSecret: 123 + +# Gateway 设置 +Gateway: + Enable: true + Port: 12425 + +# 微服务调用密钥 +SecretKey: 6ad9529688041483f458f8de11ed16ff + +Token: + Prefix: "/token/" + Expire: 86400 + +# Rpc: +# fts: +# Endpoint: https://api-v2.traingo.cn/fts/v2 +# SecretKey: 4ef05311358cd1c8f787281f08b38b1c + + +# 链路追踪,性能监控,日志收集 +# APM: +# Platform: elasticAPM +# Endpoint: http://127.0.0.1:14268/api/traces diff --git a/etc/sample_prod.yaml b/etc/sample_prod.yaml new file mode 100644 index 0000000..a162ea7 --- /dev/null +++ b/etc/sample_prod.yaml @@ -0,0 +1,44 @@ +Service: sample +Port: 12426 + +Databases: + Driver: postgres + Source: + - host=47.109.77.183 user=postgres password=Weidong2023~! dbname=${BSM_Workspace}_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai + +# cache DB的选择请在后面直接带参数,不带会自动HASH计算选择DB库。 +Cache: redis://null:Weidong2023~!@47.109.77.183:6379/ + +# 微服务设置 +MicroService: + Enable: false + Anonymous: + - sample.ping.hello + +# 微信设置 +WeChatConf: + AppID: 123 + AppSecret: 123 + +# Gateway 设置 +Gateway: + Enable: true + Port: 12425 + +# 微服务调用密钥 +SecretKey: 6ad9529688041483f458f8de11ed16ff + +Token: + Prefix: "/token/" + Expire: 86400 + +# Rpc: +# fts: +# Endpoint: https://api-v2.traingo.cn/fts/v2 +# SecretKey: 4ef05311358cd1c8f787281f08b38b1c + + +# 链路追踪,性能监控,日志收集 +# APM: +# Platform: elasticAPM +# Endpoint: http://127.0.0.1:14268/api/traces diff --git a/etc/sample_test.yaml b/etc/sample_test.yaml new file mode 100644 index 0000000..b17d5ba --- /dev/null +++ b/etc/sample_test.yaml @@ -0,0 +1,44 @@ +Service: sample +Port: 12426 + +Databases: + Driver: postgres + Source: + - host=47.109.77.183 user=postgres password=Weidong2023~! dbname=${BSM_Workspace}_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai + +# cache DB的选择请在后面直接带参数,不带会自动HASH计算选择DB库。 +Cache: redis://null:Weidong2023~!@47.109.77.183:6379/ + +# 微服务设置 +MicroService: + Enable: false + Anonymous: + - sample.ping.hello + +# 微信设置 +WeChatConf: + AppID: 123 + AppSecret: 123 + +# Gateway 设置 +Gateway: + Enable: true + Port: 12425 + +# 微服务调用密钥 +SecretKey: 6ad9529688041483f458f8de11ed16ff + +Token: + Prefix: "/token/" + Expire: 86400 + +# Rpc: +# fts: +# Endpoint: https://api-v2.traingo.cn/fts/v2 +# SecretKey: 4ef05311358cd1c8f787281f08b38b1c + + +# 链路追踪,性能监控,日志收集 +# APM: +# Platform: elasticAPM +# Endpoint: http://127.0.0.1:14268/api/traces diff --git a/etc/supervisor.bsm-apps-sample.conf b/etc/supervisor.bsm-apps-sample.conf new file mode 100644 index 0000000..1e31c80 --- /dev/null +++ b/etc/supervisor.bsm-apps-sample.conf @@ -0,0 +1,8 @@ +[program:bsm-apps-sample] +command=/data/app/bsm-apps-sample +directory=/data/app +autostart=true +autorestart=true +user=root +redirect_stderr=true +stdout_logfile=/data/app/logs/apps-sample.log \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fb64303 --- /dev/null +++ b/go.mod @@ -0,0 +1,70 @@ +module git.apinb.com/bsm-sdk/sample + +go 1.24.6 + +tool ( + git.apinb.com/bsm-tools/protoc-gen-markdown + git.apinb.com/bsm-tools/protoc-gen-slc + git.apinb.com/bsm-tools/protoc-gen-ts + github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway + github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 + github.com/pepabo/protoc-gen-go-client + google.golang.org/grpc/cmd/protoc-gen-go-grpc + google.golang.org/protobuf/cmd/protoc-gen-go +) + +require ( + github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 + gorm.io/driver/mysql v1.6.0 // indirect +) + +require github.com/allegro/bigcache/v3 v3.1.0 + +require ( + filippo.io/edwards25519 v1.1.0 // indirect + git.apinb.com/bsm-tools/protoc-gen-markdown v0.0.0-20250907131213-6c1694ce6bcb // indirect + git.apinb.com/bsm-tools/protoc-gen-slc v0.0.10 // indirect + git.apinb.com/bsm-tools/protoc-gen-ts v0.0.2 // indirect + github.com/coreos/go-semver v0.3.1 // indirect + github.com/coreos/go-systemd/v22 v22.6.0 // indirect + github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/pepabo/protoc-gen-go-client v0.3.0 // indirect + go.etcd.io/etcd/api/v3 v3.6.5 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/mod v0.28.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9 // indirect + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 // indirect +) + +require ( + git.apinb.com/bsm-sdk/core v0.0.85 + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/go-sql-driver/mysql v1.9.3 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/pgx/v5 v5.7.6 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/oklog/ulid/v2 v2.1.1 // indirect + github.com/redis/go-redis/v9 v9.14.0 // indirect + go.etcd.io/etcd/client/pkg/v3 v3.6.5 // indirect + go.etcd.io/etcd/client/v3 v3.6.5 + golang.org/x/crypto v0.42.0 + golang.org/x/net v0.44.0 // indirect + golang.org/x/sync v0.17.0 // indirect + golang.org/x/sys v0.36.0 // indirect + golang.org/x/text v0.29.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 // indirect + google.golang.org/grpc v1.75.1 + google.golang.org/protobuf v1.36.9 + gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/postgres v1.6.0 // indirect + gorm.io/gorm v1.31.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e4994df --- /dev/null +++ b/go.sum @@ -0,0 +1,170 @@ +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +git.apinb.com/bsm-sdk/core v0.0.85 h1:iM4BrF1jVr3UGrCDyN6ILnm+Fcj51oDL878eCl2jcXE= +git.apinb.com/bsm-sdk/core v0.0.85/go.mod h1:Y1D+wBBHhF8+5kNrZaeRoscA2MSI40uy1AYeSpAuvYc= +git.apinb.com/bsm-tools/protoc-gen-markdown v0.0.0-20250907131213-6c1694ce6bcb h1:GoXhkGzI5vZ9JMXCVsSRw/AGsJY0tM2aEv76YaUg2wM= +git.apinb.com/bsm-tools/protoc-gen-markdown v0.0.0-20250907131213-6c1694ce6bcb/go.mod h1:l+84zWPM4F40Ppar+jLapgjRNt6XWDsr+l0vN4Jjlm4= +git.apinb.com/bsm-tools/protoc-gen-slc v0.0.10 h1:95KBYcg/xu3uMt2lbtklOXmzoz5JYB8BQpipFnYwQoY= +git.apinb.com/bsm-tools/protoc-gen-slc v0.0.10/go.mod h1:30pCqqHcsS4Bz2px4K5gHtvQ4dAoJQ1LSJwyhriBxQM= +git.apinb.com/bsm-tools/protoc-gen-ts v0.0.2 h1:T9C1kY6iIHl5cZ7xyNgV2xlPNWxXmaWfTbD8AzpBB9M= +git.apinb.com/bsm-tools/protoc-gen-ts v0.0.2/go.mod h1:5kAPyKSSLL7HcdZvyJa+ICnOiit/O/Z963nQpGJRrao= +github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= +github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= +github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= +github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5zn0bCJWo= +github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c h1:+Zo5Ca9GH0RoeVZQKzFJcTLoAixx5s5Gq3pTIS+n354= +github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c/go.mod h1:HJGU9ULdREjOcVGZVPB5s6zYmHi1RxzT71l2wQyLmnE= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= +github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk= +github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s= +github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ= +github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= +github.com/pepabo/protoc-gen-go-client v0.3.0 h1:BUlzqqgMXWaEYzGXw1vqLIShP18JV7BMDm45OSLr/AU= +github.com/pepabo/protoc-gen-go-client v0.3.0/go.mod h1:NvHW7/gsmZUK2UxafqzUzWD8zEMY0lMmm+2kLVxx8Jc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/redis/go-redis/v9 v9.14.0 h1:u4tNCjXOyzfgeLN+vAZaW1xUooqWDqVEsZN0U01jfAE= +github.com/redis/go-redis/v9 v9.14.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.etcd.io/etcd/api/v3 v3.6.5 h1:pMMc42276sgR1j1raO/Qv3QI9Af/AuyQUW6CBAWuntA= +go.etcd.io/etcd/api/v3 v3.6.5/go.mod h1:ob0/oWA/UQQlT1BmaEkWQzI0sJ1M0Et0mMpaABxguOQ= +go.etcd.io/etcd/client/pkg/v3 v3.6.5 h1:Duz9fAzIZFhYWgRjp/FgNq2gO1jId9Yae/rLn3RrBP8= +go.etcd.io/etcd/client/pkg/v3 v3.6.5/go.mod h1:8Wx3eGRPiy0qOFMZT/hfvdos+DjEaPxdIDiCDUv/FQk= +go.etcd.io/etcd/client/v3 v3.6.5 h1:yRwZNFBx/35VKHTcLDeO7XVLbCBFbPi+XV4OC3QJf2U= +go.etcd.io/etcd/client/v3 v3.6.5/go.mod h1:ZqwG/7TAFZ0BJ0jXRPoJjKQJtbFo/9NIY8uoFFKcCyo= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ= +go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I= +go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE= +go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E= +go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI= +go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg= +go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc= +go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps= +go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4= +go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI= +golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= +golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I= +golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= +golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= +gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= +google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9 h1:jm6v6kMRpTYKxBRrDkYAitNJegUeO1Mf3Kt80obv0gg= +google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9/go.mod h1:LmwNphe5Afor5V3R5BppOULHOnt2mCIf+NxMd4XiygE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 h1:V1jCN2HBa8sySkR5vLcCSqJSTMv093Rw9EJefhQGP7M= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9/go.mod h1:HSkG/KdJWusxU1F6CNrwNDjBMgisKxGnc5dAZfT0mjQ= +google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI= +google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA= +google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw= +google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg= +gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo= +gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4= +gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo= +gorm.io/gorm v1.31.0 h1:0VlycGreVhK7RF/Bwt51Fk8v0xLiiiFdbGDPIZQ7mJY= +gorm.io/gorm v1.31.0/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..8875755 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,41 @@ +package config + +import ( + "net" + + "git.apinb.com/bsm-sdk/core/conf" + "git.apinb.com/bsm-sdk/core/crypto/encipher" + "git.apinb.com/bsm-sdk/core/env" +) + +var ( + Spec SrvConfig +) + +type SrvConfig struct { + conf.Base `yaml:",inline"` + Databases *conf.DBConf `yaml:"Databases"` + MicroService *conf.MicroServiceConf `yaml:"MicroService"` + Rpc map[string]conf.RpcConf `yaml:"Rpc"` + Gateway *conf.GatewayConf `yaml:"Gateway"` + Apm *conf.ApmConf `yaml:"APM"` + Etcd *conf.EtcdConf `yaml:"Etcd"` +} + +func New(srvKey string) { + // 初始化配置 创建一个新的配置实例,用于服务配置 + conf.New(srvKey, &Spec) + + // 配置校验 服务IP,端口; 端口如果不合规,则随机分配端口 + Spec.Port = conf.CheckPort(Spec.Port) + Spec.BindIP = conf.CheckIP(Spec.BindIP) + Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port) + + // 配置校验 服务名称地址及监听地址不能为空 + conf.NotNil(Spec.Service, Spec.Cache) + + // 初始化加密SecretKey + encipher.New(env.Runtime.JwtSecretKey) + + conf.PrintInfo(Spec.Addr) +} diff --git a/internal/impl/impl.go b/internal/impl/impl.go new file mode 100644 index 0000000..a6df9d8 --- /dev/null +++ b/internal/impl/impl.go @@ -0,0 +1,25 @@ +package impl + +import ( + "git.apinb.com/bsm-sdk/core/cache/redis" + "git.apinb.com/bsm-sdk/core/with" + "git.apinb.com/bsm-sdk/sample/internal/config" + "github.com/allegro/bigcache/v3" + clientv3 "go.etcd.io/etcd/client/v3" + "gorm.io/gorm" +) + +var ( + RedisService *redis.RedisClient + EtcdService *clientv3.Client + DBService *gorm.DB + MemorySerice *bigcache.BigCache +) + +func NewImpl() { + // with activating + MemorySerice = with.Memory(nil) + RedisService = with.RedisCache(config.Spec.Cache) // redis cache + DBService = with.Databases(config.Spec.Databases, nil) // model + EtcdService = with.Etcd(config.Spec.Etcd) // etcd +} diff --git a/internal/logic/account/get.go b/internal/logic/account/get.go new file mode 100644 index 0000000..4e78ba4 --- /dev/null +++ b/internal/logic/account/get.go @@ -0,0 +1,69 @@ +package account + +import ( + "context" + + "git.apinb.com/bsm-sdk/core/service" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/models" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 通过会员所有信息 +func Get(ctx context.Context, in *pb.Empty) (reply *pb.GetFullReply, err error) { + AUTH, err := service.ParseMetaCtx(ctx, nil) + if err != nil { + return nil, err + } + + account, err := models.GetsampleAccountByField("id", AUTH.ID) + if err != nil { + return nil, err + } + + verify := models.GetVerifyStatus(AUTH.ID) + + tagRecords := make([]models.sampleTags, 0) + impl.DBService.Model(&models.sampleTags{}).Where("sample_id=?", AUTH.ID).Find(&tagRecords) + + tags := make([]*pb.TagItem, 0) + for _, tag := range tagRecords { + tags = append(tags, &pb.TagItem{ + Name: tag.Name, + Icon: tag.Icon, + }) + } + + reply = &pb.GetFullReply{ + Identity: account.Identity, + Account: account.Account, + Phone: account.Phone, + Email: account.Email, + Rights: account.Rights, + Verify: verify, + Tags: tags, + } + + data := &models.sampleData{} + impl.DBService.Where("sample_id=?", AUTH.ID).First(data) + if data != nil { + bd := data.Birthday.Format("2006-01-02") + if bd == "0001-01-01" { + bd = "" + } + reply.Nickname = data.Nickname + reply.Avatar = data.Avatar + reply.Birthday = bd + reply.Sex = int32(data.Sex) + reply.Country = data.Country + reply.Province = data.Province + reply.City = data.City + reply.Area = data.Area + reply.Sign = data.Sign + reply.Cover = data.Cover + reply.Score = data.Score + reply.Level = data.Level + } + + return +} diff --git a/internal/logic/account/set_data.go b/internal/logic/account/set_data.go new file mode 100644 index 0000000..cde870b --- /dev/null +++ b/internal/logic/account/set_data.go @@ -0,0 +1,65 @@ +package account + +import ( + "context" + "time" + + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/print" + "git.apinb.com/bsm-sdk/core/service" + "git.apinb.com/bsm-sdk/core/vars" + "git.apinb.com/bsm-sdk/sample/internal/impl" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 更新会员的信息数据 +// 字段值为空或是0,将不更新此数据 +func SetData(ctx context.Context, in *pb.SetDataRequest) (reply *pb.StatusReply, err error) { + auth, err := service.ParseMetaCtx(ctx, nil) + if err != nil { + return nil, err + } + var birthday time.Time + if in.Birthday != "" { + birthday, err = time.Parse("2006-01-02", in.Birthday) + if err != nil { + return nil, errcode.ErrInvalidArgument + } + } + + var data = models.sampleData{ + Nickname: in.Nickname, + Avatar: in.Avatar, + Sex: int8(in.Sex), + Birthday: birthday, + Country: in.Country, + Province: in.Province, + City: in.City, + Area: in.Area, + Sign: in.Sign, + Cover: in.Cover, + UpdatedAt: time.Now(), + } + + var cnt int64 + impl.DBService.Model(&models.sampleData{}).Where("sample_id=?", auth.ID).Count(&cnt) + + if cnt == 0 { + data.sampleID = auth.ID + data.sampleIdentity = auth.Identity + err = impl.DBService.Create(&data).Error + } else { + impl.DBService.Where("sample_id=?", auth.ID).Updates(&data) + } + + if err != nil { + print.Error("first or create by sample_id %v error:%v", auth.ID, err) + return nil, errcode.ErrDB + } + + return &pb.StatusReply{ + Data: vars.OK, + Timeseq: time.Now().UnixNano(), + }, nil + +} diff --git a/internal/logic/account/set_password.go b/internal/logic/account/set_password.go new file mode 100644 index 0000000..38e2dfd --- /dev/null +++ b/internal/logic/account/set_password.go @@ -0,0 +1,52 @@ +package account + +import ( + "context" + "time" + + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/print" + "git.apinb.com/bsm-sdk/core/service" + "git.apinb.com/bsm-sdk/core/vars" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/models" + pb "git.apinb.com/bsm-sdk/sample/pb" + "golang.org/x/crypto/bcrypt" +) + +// 更新会员的密码 +func SetPassword(ctx context.Context, in *pb.SetPasswordRequest) (reply *pb.StatusReply, err error) { + if in.OldPassword == "" || in.NewPassword == "" { + return nil, errcode.ErrInvalidArgument + } + auth, err := service.ParseMetaCtx(ctx, nil) + if err != nil { + return nil, err + } + pa, err := models.GetsampleAccountByField("id", auth.ID) + if err != nil { + return nil, err + } + + err = bcrypt.CompareHashAndPassword([]byte(pa.Password), []byte(in.OldPassword+pa.Salt)) + if err != nil { + return nil, errcode.NewError(187, "sample Error") + } + + hashedPassword, err := bcrypt.GenerateFromPassword([]byte(in.NewPassword+pa.Salt), bcrypt.MinCost) + if err != nil { + return nil, errcode.ErrInternal + } + + err = impl.DBService.Model(&models.sampleAccount{}).Where("id = ? ", auth.ID).Update("password", string(hashedPassword)).Error + if err != nil { + print.Error("Update sample account password by id %+v error:%v", auth.ID, err) + return nil, errcode.ErrDB + } + + return &pb.StatusReply{ + Data: vars.OK, + Timeseq: time.Now().UnixNano(), + }, nil + +} diff --git a/internal/logic/account/statistics.go b/internal/logic/account/statistics.go new file mode 100644 index 0000000..0bd91c8 --- /dev/null +++ b/internal/logic/account/statistics.go @@ -0,0 +1,23 @@ +package account + +import ( + "context" + + "git.apinb.com/bsm-sdk/core/service" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 获取会员的相关统计数据 +func Statistics(ctx context.Context, in *pb.StatisticsRequest) (reply *pb.StatisticsReply, err error) { + // parse authorization meta. + _, err = service.ParseMetaCtx(ctx, nil) + if err != nil { + return nil, err + } + + // TODO: valid code + + // TODO: add your logic code & delete this line. + + return +} diff --git a/internal/logic/account/tag_create.go b/internal/logic/account/tag_create.go new file mode 100644 index 0000000..d11be2f --- /dev/null +++ b/internal/logic/account/tag_create.go @@ -0,0 +1,50 @@ +package account + +import ( + "context" + "time" + + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/service" + "git.apinb.com/bsm-sdk/core/utils" + "git.apinb.com/bsm-sdk/core/vars" + "git.apinb.com/bsm-sdk/sample/internal/impl" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 新增标签 +func TagCreate(ctx context.Context, in *pb.TagItem) (reply *pb.StatusReply, err error) { + // parse authorization meta. + AUTH, err := service.ParseMetaCtx(ctx, nil) + if err != nil { + return nil, err + } + + // TODO: valid code + if in.Name == "" { + return nil, errcode.ErrInvalidArgument + } + + // TODO: add your logic code & delete this line. + var cnt int64 + impl.DBService.Model(&models.sampleTags{}).Where("sample_id=? and name = ?", AUTH.ID, in.Name).Count(&cnt) + if cnt == 0 { + record := &models.sampleTags{ + Name: in.Name, + Icon: in.Icon, + } + record.Identity = utils.UUID() + record.sampleID = AUTH.ID + record.sampleIdentity = AUTH.Identity + + impl.DBService.Create(record) + } else { + impl.DBService.Model(&models.sampleTags{}).Where("sample_id=? and name = ?", AUTH.ID, in.Name).Update("icon", in.Icon) + } + + return &pb.StatusReply{ + Data: vars.OK, + Timeseq: time.Now().UnixMilli(), + }, nil + +} diff --git a/internal/logic/account/tag_remove.go b/internal/logic/account/tag_remove.go new file mode 100644 index 0000000..f774622 --- /dev/null +++ b/internal/logic/account/tag_remove.go @@ -0,0 +1,35 @@ +package account + +import ( + "context" + "time" + + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/service" + "git.apinb.com/bsm-sdk/core/vars" + "git.apinb.com/bsm-sdk/sample/internal/impl" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 删除标签 +func TagRemove(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) { + // parse authorization meta. + AUTH, err := service.ParseMetaCtx(ctx, nil) + if err != nil { + return nil, err + } + + // valildate request id,identity. + if in.Identity == "" { + return nil, errcode.ErrInvalidArgument + } + + // TODO: add your logic code & delete this line. + impl.DBService.Model(&models.sampleTags{}).Unscoped().Delete("sample_id=? and identity = ?", AUTH.ID, in.Identity) + + return &pb.StatusReply{ + Data: vars.OK, + Timeseq: time.Now().UnixMilli(), + }, nil + +} diff --git a/internal/logic/common/token.go b/internal/logic/common/token.go new file mode 100644 index 0000000..eed7ae6 --- /dev/null +++ b/internal/logic/common/token.go @@ -0,0 +1,12 @@ +package common + +import "git.apinb.com/bsm-sdk/core/crypto/encipher" + +// GenerateTokenAes . +func GenerateTokenAes(id uint, identity, client, role string, extend map[string]string) (string, error) { + token, err := encipher.GenerateTokenAes(id, identity, client, role, nil, extend) + if err != nil { + return "", err + } + return token, nil +} diff --git a/internal/logic/forget/reset.go b/internal/logic/forget/reset.go new file mode 100644 index 0000000..1567fc9 --- /dev/null +++ b/internal/logic/forget/reset.go @@ -0,0 +1,56 @@ +package forget + +import ( + "context" + + "git.apinb.com/bsm-sdk/core/crypto/encipher" + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/print" + "git.apinb.com/bsm-sdk/core/utils" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/models" + "git.apinb.com/bsm-sdk/sample/internal/vars" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 重罢密码 +func Reset(ctx context.Context, in *pb.ForgetResetRequest) (reply *pb.ForgetReply, err error) { + if in.Identity == "" || in.Password == "" { + return nil, errcode.ErrInvalidArgument + } + + pa, err := models.GetsampleAccountByField("identity", in.Identity) + if err != nil { + return nil, err + } + + if pa.Status == vars.Status_Disable { + return nil, errcode.ErrPermissionDenied + } + + err = impl.DBService.Model(&models.sampleAccount{}).Where("identity = ? ", pa.Identity).Update("password", utils.Md5(in.Password)).Error + if err != nil { + print.Error("Update sample account password by identity %+v error:%v", in.Identity, err) + return nil, errcode.ErrDB + } + paExtend := map[string]string{ + "Rights": pa.Rights, + } + token, err := encipher.GenerateTokenAes(uint(pa.ID), pa.Identity, "", pa.Rights, nil, paExtend) + if err != nil { + print.Error("encipher.GenerateTokenAes by id %v identity %v rights %v extend %v error:%v", pa.ID, pa.Identity, pa.Rights, paExtend, err) + return nil, errcode.ErrDB + } + //save token to cache. + err = impl.RedisService.Client.Set(impl.RedisService.Ctx, vars.TokenPrefix+pa.Identity, token, 0).Err() + if err != nil { + print.Error("Set redis cache by key %v error:%v", vars.TokenPrefix+pa.Identity, err) + return nil, errcode.ErrInternal + } + + return &pb.ForgetReply{ + Identity: pa.Identity, + Token: token, + Extend: paExtend, + }, nil +} diff --git a/internal/logic/forget/verify.go b/internal/logic/forget/verify.go new file mode 100644 index 0000000..0afd57a --- /dev/null +++ b/internal/logic/forget/verify.go @@ -0,0 +1,34 @@ +package forget + +import ( + "context" + "time" + + "git.apinb.com/bsm-sdk/core/errcode" + _vars "git.apinb.com/bsm-sdk/core/vars" + "git.apinb.com/bsm-sdk/sample/internal/models" + "git.apinb.com/bsm-sdk/sample/internal/vars" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 验证手机号和验证码 +func Verify(ctx context.Context, in *pb.VerifyRequest) (reply *pb.StatusReply, err error) { + if in.Phone == "" || in.Code == "" { + return nil, errcode.ErrInvalidArgument + } + + pa, err := models.GetsampleAccountByField("phone", in.Phone) + if err != nil { + return nil, err + } + + if pa.Status == vars.Status_Disable { + return nil, errcode.ErrPermissionDenied + } + + return &pb.StatusReply{ + Data: _vars.OK, + Timeseq: time.Now().UnixNano(), + }, nil + +} diff --git a/internal/logic/login/code.go b/internal/logic/login/code.go new file mode 100644 index 0000000..393b209 --- /dev/null +++ b/internal/logic/login/code.go @@ -0,0 +1,52 @@ +package login + +import ( + "context" + + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/print" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/logic/common" + "git.apinb.com/bsm-sdk/sample/internal/models" + "git.apinb.com/bsm-sdk/sample/internal/vars" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 通过验证码登录 +func Code(ctx context.Context, in *pb.LoginByCodeRequest) (reply *pb.LoginReply, err error) { + if in.Phone == "" || in.Code == "" { + return nil, errcode.ErrInvalidArgument + } + + pa, err := models.GetsampleAccountByField("phone", in.Phone) + if err != nil { + return nil, err + } + + if pa.Status == vars.Status_Disable { + return nil, errcode.ErrPermissionDenied + } + + paExtend := map[string]string{ + "rights": pa.Rights, + } + + token, err := common.GenerateTokenAes(uint(pa.ID), pa.Identity, "", pa.Rights, paExtend) + if err != nil { + return nil, err + } + + //save token to cache. + err = impl.RedisService.Client.Set(impl.RedisService.Ctx, vars.TokenPrefix+pa.Identity, token, 0).Err() + if err != nil { + print.Error("Set redis cache by key %v error:%v", vars.TokenPrefix+pa.Identity, err) + return nil, errcode.ErrInternal + } + + return &pb.LoginReply{ + Id: int64(pa.ID), + Identity: pa.Identity, + Token: token, + Extend: paExtend, + }, nil +} diff --git a/internal/logic/login/code_and_register.go b/internal/logic/login/code_and_register.go new file mode 100644 index 0000000..06b6505 --- /dev/null +++ b/internal/logic/login/code_and_register.go @@ -0,0 +1,61 @@ +package login + +import ( + "context" + "errors" + + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/print" + "git.apinb.com/bsm-sdk/core/utils" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/logic/common" + "git.apinb.com/bsm-sdk/sample/internal/vars" + pb "git.apinb.com/bsm-sdk/sample/pb" + "gorm.io/gorm" +) + +// 通过验证码登录并注册 +func CodeAndRegister(ctx context.Context, in *pb.LoginByCodeRequest) (reply *pb.LoginReply, err error) { + if in.Phone == "" || in.Code == "" { + return nil, errcode.ErrInvalidArgument + } + + var pa models.sampleAccount + err = impl.DBService.Where("phone = ?", in.Phone).First(&pa).Error + if err != nil { + if !errors.Is(err, gorm.ErrRecordNotFound) { + print.Error("Get sample account by phone %v error:%v", in.Phone, err) + return nil, errcode.ErrDB + } + pa = models.sampleAccount{ + Account: in.Phone, + Phone: in.Phone, + } + pa.Identity = utils.UUID() + pa.Status = vars.Status_Normal + + err = impl.DBService.Create(&pa).Error + if err != nil { + print.Error("create sample account and password extend by data %+v error:%v", pa, err) + return nil, errcode.ErrDB + } + } + + if pa.Status == vars.Status_Disable { + return nil, errcode.ErrPermissionDenied + } + paExtend := map[string]string{ + "rights": pa.Rights, + } + token, err := common.GenerateTokenAes(uint(pa.ID), pa.Identity, "", pa.Rights, paExtend) + if err != nil { + return nil, err + } + + return &pb.LoginReply{ + Id: int64(pa.ID), + Identity: pa.Identity, + Token: token, + Extend: paExtend, + }, nil +} diff --git a/internal/logic/login/pwd.go b/internal/logic/login/pwd.go new file mode 100644 index 0000000..2b0b9a9 --- /dev/null +++ b/internal/logic/login/pwd.go @@ -0,0 +1,55 @@ +package login + +import ( + "context" + + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/print" + _vars "git.apinb.com/bsm-sdk/core/vars" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/logic/common" + "git.apinb.com/bsm-sdk/sample/internal/models" + "git.apinb.com/bsm-sdk/sample/internal/vars" + pb "git.apinb.com/bsm-sdk/sample/pb" + "golang.org/x/crypto/bcrypt" +) + +// 通过密码登录 +func Pwd(ctx context.Context, in *pb.LoginByPwdRequest) (reply *pb.LoginReply, err error) { + if in.Account == "" || in.Password == "" { + return nil, errcode.ErrInvalidArgument + } + pa, err := models.GetsampleAccountByField("account", in.Account) + if err != nil { + return nil, err + } + + if pa.Status == vars.Status_Disable { + return nil, errcode.ErrPermissionDenied + } + + err = bcrypt.CompareHashAndPassword([]byte(pa.Password), []byte(in.Password+pa.Salt)) + if err != nil { + return nil, errcode.NewError(187, "sample Error") + } + + extend := map[string]string{ + "rights": pa.Rights, + } + token, err := common.GenerateTokenAes(uint(pa.ID), pa.Identity, "", pa.Rights, extend) + if err != nil { + return nil, err + } + //save token to cache. + err = impl.RedisService.Client.Set(impl.RedisService.Ctx, vars.TokenPrefix+pa.Identity, token, _vars.JwtExpire).Err() + if err != nil { + print.Error("Set redis cache by key %v error:%v", vars.TokenPrefix+pa.Identity, err) + return nil, errcode.ErrInternal + } + + return &pb.LoginReply{ + Id: int64(pa.ID), + Identity: pa.Identity, + Token: token, + }, nil +} diff --git a/internal/logic/register/code.go b/internal/logic/register/code.go new file mode 100644 index 0000000..287431c --- /dev/null +++ b/internal/logic/register/code.go @@ -0,0 +1,30 @@ +package register + +import ( + "context" + "regexp" + + "git.apinb.com/bsm-sdk/core/errcode" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 手机验证码注册 +func Code(ctx context.Context, in *pb.RegisterRequest) (reply *pb.RegisterReply, err error) { + if in.Phone == "" || in.Code == "" { + return nil, errcode.ErrInvalidArgument + } + + //手机号验证 + matched, err := regexp.MatchString("^1[3456789]{1}\\d{9}$", in.Phone) + if err != nil || !matched { + return nil, errcode.ErrInvalidArgument + } + + //账号唯一验证 + found := models.sampleAccountExists("phone", in.Phone) + if found { + return nil, errcode.ErrAlreadyExists + } + + return Do(in) +} diff --git a/internal/logic/register/do.go b/internal/logic/register/do.go new file mode 100644 index 0000000..c3ee509 --- /dev/null +++ b/internal/logic/register/do.go @@ -0,0 +1,81 @@ +/** + * @Author: ZhaoYadong + * @Date: 2024-02-27 21:09:45 + * @LastEditors: ZhaoYadong + * @LastEditTime: 2024-02-28 11:50:05 + * @FilePath: /server/Users/edy/go/src/sample/internal/logic/register/do.go + */ +package register + +import ( + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/print" + "git.apinb.com/bsm-sdk/core/types" + "git.apinb.com/bsm-sdk/core/utils" + _vars "git.apinb.com/bsm-sdk/core/vars" + "git.apinb.com/bsm-sdk/sample/internal/config" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "git.apinb.com/bsm-sdk/sample/internal/logic/common" + "git.apinb.com/bsm-sdk/sample/internal/vars" + pb "git.apinb.com/bsm-sdk/sample/pb" + "golang.org/x/crypto/bcrypt" +) + +// Do . +func Do(in *pb.RegisterRequest) (*pb.RegisterReply, error) { + var salt string + if in.Password != "" { + salt = utils.UUID() + hashedPassword, err := bcrypt.GenerateFromPassword([]byte(in.Password+salt), bcrypt.MinCost) + if err != nil { + return nil, errcode.ErrInternal + } + in.Password = string(hashedPassword) + } + + var account = in.Account + if account == "" { + account = in.Phone + } + pa := models.sampleAccount{ + Std_IICUDS: types.Std_IICUDS{ + Identity: utils.UUID(), + Status: vars.Status_Normal, + }, + Account: account, + Phone: in.Phone, + Password: in.Password, + Salt: salt, + AgencyId: uint(in.AgencyId), + StaffId: uint(in.StaffId), + OwnerId: uint(in.OwnerId), + } + + // 插入sample 基础表 + if err := impl.DBService.Create(&pa).Error; err != nil { + print.Error("create sample account and password extend by data %+v error:%v", pa, err) + return nil, errcode.ErrDB + } + + extend := map[string]string{ + "rights": pa.Rights, + } + token, err := common.GenerateTokenAes(uint(pa.ID), pa.Identity, "", pa.Rights, extend) + if err != nil { + return nil, err + } + + //save token to cache. + err = impl.RedisService.Client.Set(impl.RedisService.Ctx, config.Spec.Token.Prefix+pa.Identity, token, _vars.JwtExpire).Err() + if err != nil { + print.Error("Set redis cache by key %v error:%v", vars.TokenPrefix+pa.Identity, err) + return nil, errcode.ErrInternal + } + + return &pb.RegisterReply{ + Id: int64(pa.ID), + Identity: pa.Identity, + Token: token, + Extend: extend, + }, nil +} diff --git a/internal/logic/register/pwd.go b/internal/logic/register/pwd.go new file mode 100644 index 0000000..92e10eb --- /dev/null +++ b/internal/logic/register/pwd.go @@ -0,0 +1,23 @@ +package register + +import ( + "context" + + "git.apinb.com/bsm-sdk/core/errcode" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +// 帐号密码注册 +func Pwd(ctx context.Context, in *pb.RegisterRequest) (reply *pb.RegisterReply, err error) { + if in.Account == "" || in.Password == "" { + return nil, errcode.ErrInvalidArgument + } + + //账号唯一验证 + found := models.sampleAccountExists("account", in.Account) + if found { + return nil, errcode.ErrAlreadyExists + } + + return Do(in) +} diff --git a/internal/models/passport_account.go b/internal/models/passport_account.go new file mode 100644 index 0000000..250bad7 --- /dev/null +++ b/internal/models/passport_account.go @@ -0,0 +1,64 @@ +/** + * @Author: ZhaoYadong + * @Date: 2024-02-27 21:09:45 + * @LastEditors: ZhaoYadong + * @LastEditTime: 2024-02-28 09:13:35 + * @FilePath: /server/Users/edy/go/src/sample/internal/models/sample_account.go + */ +// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com). +package models + +import ( + "errors" + + "git.apinb.com/bsm-sdk/core/database" + "git.apinb.com/bsm-sdk/core/errcode" + "git.apinb.com/bsm-sdk/core/types" + "git.apinb.com/bsm-sdk/sample/internal/impl" + "gorm.io/gorm" +) + +/* + * sampleAccount + * Comment: 通行证帐号表 + * Version: 10 + * Created: 2022-04-12 10:44:51 , Updated:0001-01-01 00:00:00 + */ +type sampleAccount struct { + types.Std_IICUDS + Account string `gorm:"column:account;type:varchar(255);default:'';" json:"account"` // 帐号 + Phone string `gorm:"column:phone;type:varchar(20);default:'';" json:"phone"` // 手机号 + Email string `gorm:"column:email;type:varchar(255);default:'';" json:"email"` // Email + Password string `gorm:"column:password;type:varchar(255);not null;" json:"password"` // 密码 + Salt string `gorm:"column:salt;type:varchar(255);not null;" json:"salt"` // 密码盐 + Rights string `gorm:"column:rights;type:varchar(255);default:'';" json:"rights"` // 权限 + AgencyId uint `gorm:"column:agency_id;default:0;" json:"agency_id"` // 分销代理id + StaffId uint `gorm:"column:staff_id;default:0;" json:"staff_id"` // 工作人员id + OwnerId uint `gorm:"column:owner_id;default:0;" json:"owner_id"` // 所属唯一id +} + +func init() { + database.MigrateTables = append(database.MigrateTables, &sampleAccount{}) +} + +// TableName . +func (table *sampleAccount) TableName() string { + return "sample_account" //对应数据库表名 +} + +// GetsampleAccountByField 根据特定字段值获取sampleAccount对象 +func GetsampleAccountByField(field string, value interface{}) (*sampleAccount, error) { + var ( + data sampleAccount + condition = map[string]any{field: value} + ) + err := impl.DBService.Where(condition).First(&data).Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errcode.ErrNotFound(404, "Account not found") + } + return nil, errcode.ErrDB + } + + return &data, nil +} diff --git a/internal/models/query.go b/internal/models/query.go new file mode 100644 index 0000000..eeea7ca --- /dev/null +++ b/internal/models/query.go @@ -0,0 +1,7 @@ +package models + +// 初始化数据 +func InitData() error { + + return nil +} diff --git a/internal/server/account_server.go b/internal/server/account_server.go new file mode 100644 index 0000000..b45b2b0 --- /dev/null +++ b/internal/server/account_server.go @@ -0,0 +1,47 @@ +// Code generated by protoc-gen-slc. DO NOT EDIT. +package server + +import ( + "context" + + "git.apinb.com/bsm-sdk/sample/internal/logic/account" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +type AccountServer struct { + pb.UnimplementedAccountServer +} + +func NewAccountServer() *AccountServer { + return &AccountServer{} +} + +// 通过会员所有信息 +func (s *AccountServer) Get(ctx context.Context, in *pb.Empty) (*pb.GetFullReply, error) { + return account.Get(ctx, in) +} + +// 更新会员的信息数据,字段值为空或是0,将不更新此数据 +func (s *AccountServer) SetData(ctx context.Context, in *pb.SetDataRequest) (*pb.StatusReply, error) { + return account.SetData(ctx, in) +} + +// 更新会员的密码 +func (s *AccountServer) SetPassword(ctx context.Context, in *pb.SetPasswordRequest) (*pb.StatusReply, error) { + return account.SetPassword(ctx, in) +} + +// 新增标签 +func (s *AccountServer) TagCreate(ctx context.Context, in *pb.TagItem) (*pb.StatusReply, error) { + return account.TagCreate(ctx, in) +} + +// 删除标签 +func (s *AccountServer) TagRemove(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) { + return account.TagRemove(ctx, in) +} + +// 获取会员的相关统计数据 +func (s *AccountServer) Statistics(ctx context.Context, in *pb.StatisticsRequest) (*pb.StatisticsReply, error) { + return account.Statistics(ctx, in) +} diff --git a/internal/server/forget_server.go b/internal/server/forget_server.go new file mode 100644 index 0000000..b77e789 --- /dev/null +++ b/internal/server/forget_server.go @@ -0,0 +1,27 @@ +// Code generated by protoc-gen-slc. DO NOT EDIT. +package server + +import ( + "context" + + "git.apinb.com/bsm-sdk/sample/internal/logic/forget" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +type ForgetServer struct { + pb.UnimplementedForgetServer +} + +func NewForgetServer() *ForgetServer { + return &ForgetServer{} +} + +// 验证手机号和验证码 +func (s *ForgetServer) Verify(ctx context.Context, in *pb.VerifyRequest) (*pb.StatusReply, error) { + return forget.Verify(ctx, in) +} + +// 重罢密码 +func (s *ForgetServer) Reset(ctx context.Context, in *pb.ForgetResetRequest) (*pb.ForgetReply, error) { + return forget.Reset(ctx, in) +} diff --git a/internal/server/login_server.go b/internal/server/login_server.go new file mode 100644 index 0000000..1ff1989 --- /dev/null +++ b/internal/server/login_server.go @@ -0,0 +1,32 @@ +// Code generated by protoc-gen-slc. DO NOT EDIT. +package server + +import ( + "context" + + "git.apinb.com/bsm-sdk/sample/internal/logic/login" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +type LoginServer struct { + pb.UnimplementedLoginServer +} + +func NewLoginServer() *LoginServer { + return &LoginServer{} +} + +// 通过密码登录 +func (s *LoginServer) Pwd(ctx context.Context, in *pb.LoginByPwdRequest) (*pb.LoginReply, error) { + return login.Pwd(ctx, in) +} + +// 通过验证码登录 +func (s *LoginServer) Code(ctx context.Context, in *pb.LoginByCodeRequest) (*pb.LoginReply, error) { + return login.Code(ctx, in) +} + +// 通过验证码登录并注册 +func (s *LoginServer) CodeAndRegister(ctx context.Context, in *pb.LoginByCodeRequest) (*pb.LoginReply, error) { + return login.CodeAndRegister(ctx, in) +} diff --git a/internal/server/new.go b/internal/server/new.go new file mode 100644 index 0000000..007f48f --- /dev/null +++ b/internal/server/new.go @@ -0,0 +1,78 @@ +// Code generated by protoc-gen-slc. DO NOT EDIT. +package server + +import ( + "context" + "net/http" + "os" + "strings" + + "git.apinb.com/bsm-sdk/core/vars" + pb "git.apinb.com/bsm-sdk/sample/pb" + gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" + "google.golang.org/protobuf/proto" +) + +type Server struct { + Grpc *grpc.Server + Ctx context.Context + Mux *gwRuntime.ServeMux +} + +func New(addr string) *Server { + srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux( + gwRuntime.WithForwardResponseRewriter(responseEnvelope), + )} + + // register service to grpc.Server + pb.RegisterAccountServer(srv.Grpc, NewAccountServer()) + pb.RegisterForgetServer(srv.Grpc, NewForgetServer()) + pb.RegisterLoginServer(srv.Grpc, NewLoginServer()) + pb.RegisterRegisterServer(srv.Grpc, NewRegisterServer()) + + reflection.Register(srv.Grpc) + + // 将服务注册到Gateway + opts := []grpc.DialOption{grpc.WithInsecure()} + pb.RegisterAccountHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts) + pb.RegisterForgetHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts) + pb.RegisterLoginHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts) + pb.RegisterRegisterHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts) + + // Register services swagger + srv.RegisterSwagger() + + return srv +} + +// RegisterSwagger 注册swagger +func (s *Server) RegisterSwagger() { + srvKey := strings.ToLower(vars.ServiceKey) + s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) { + w.Header().Set("Content-Type", "application/json") + bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json") + if err != nil { + w.WriteHeader(http.StatusNotFound) + w.Write([]byte(err.Error())) + return + } + w.Write(bytes) + return + + }) +} + +// response envelope +func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) { + name := string(response.ProtoReflect().Descriptor().Name()) + if name == "Status" || name == "Error" || name == "StatusReply" { + return response, nil + } + return map[string]any{ + "code": 0, + "message": "OK", + "result": response, + }, nil +} diff --git a/internal/server/register_server.go b/internal/server/register_server.go new file mode 100644 index 0000000..1cfc5ef --- /dev/null +++ b/internal/server/register_server.go @@ -0,0 +1,27 @@ +// Code generated by protoc-gen-slc. DO NOT EDIT. +package server + +import ( + "context" + + "git.apinb.com/bsm-sdk/sample/internal/logic/register" + pb "git.apinb.com/bsm-sdk/sample/pb" +) + +type RegisterServer struct { + pb.UnimplementedRegisterServer +} + +func NewRegisterServer() *RegisterServer { + return &RegisterServer{} +} + +// 帐号密码注册 +func (s *RegisterServer) Pwd(ctx context.Context, in *pb.RegisterRequest) (*pb.RegisterReply, error) { + return register.Pwd(ctx, in) +} + +// 手机验证码注册 +func (s *RegisterServer) Code(ctx context.Context, in *pb.RegisterRequest) (*pb.RegisterReply, error) { + return register.Code(ctx, in) +} diff --git a/pb/account.pb.go b/pb/account.pb.go new file mode 100644 index 0000000..d75115a --- /dev/null +++ b/pb/account.pb.go @@ -0,0 +1,676 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.8 +// protoc (unknown) +// source: account.proto + +package sample + +import ( + reflect "reflect" + sync "sync" + unsafe "unsafe" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// 获取会员的完整信息 +type GetFullReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + Identity string `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` // 唯一标识 + Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"` // 帐号 + Phone string `protobuf:"bytes,3,opt,name=phone,proto3" json:"phone,omitempty"` // 手机号码 必填 + Email string `protobuf:"bytes,4,opt,name=email,proto3" json:"email,omitempty"` // 验证码 + Rights string `protobuf:"bytes,5,opt,name=rights,proto3" json:"rights,omitempty"` // 权限 + Nickname string `protobuf:"bytes,6,opt,name=nickname,proto3" json:"nickname,omitempty"` // 昵称 + Avatar string `protobuf:"bytes,7,opt,name=avatar,proto3" json:"avatar,omitempty"` // 头像 + Birthday string `protobuf:"bytes,8,opt,name=birthday,proto3" json:"birthday,omitempty"` // 生日 + Sex int32 `protobuf:"varint,9,opt,name=sex,proto3" json:"sex,omitempty"` // 性别,1为男性,2为女性 + Country int32 `protobuf:"varint,10,opt,name=country,proto3" json:"country,omitempty"` // 国家 + Province int32 `protobuf:"varint,11,opt,name=province,proto3" json:"province,omitempty"` // 省 + City int32 `protobuf:"varint,12,opt,name=city,proto3" json:"city,omitempty"` // 市 + Area int32 `protobuf:"varint,13,opt,name=area,proto3" json:"area,omitempty"` // 区 + Sign string `protobuf:"bytes,14,opt,name=sign,proto3" json:"sign,omitempty"` // 签名 + Cover string `protobuf:"bytes,15,opt,name=cover,proto3" json:"cover,omitempty"` // 背景&封面 + Score int32 `protobuf:"varint,16,opt,name=score,proto3" json:"score,omitempty"` // 积分 + Level int32 `protobuf:"varint,17,opt,name=level,proto3" json:"level,omitempty"` // 等级 + Verify map[string]bool `protobuf:"bytes,18,rep,name=verify,proto3" json:"verify,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` // 数据 + Tags []*TagItem `protobuf:"bytes,19,rep,name=tags,proto3" json:"tags,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetFullReply) Reset() { + *x = GetFullReply{} + mi := &file_account_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetFullReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFullReply) ProtoMessage() {} + +func (x *GetFullReply) ProtoReflect() protoreflect.Message { + mi := &file_account_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetFullReply.ProtoReflect.Descriptor instead. +func (*GetFullReply) Descriptor() ([]byte, []int) { + return file_account_proto_rawDescGZIP(), []int{0} +} + +func (x *GetFullReply) GetIdentity() string { + if x != nil { + return x.Identity + } + return "" +} + +func (x *GetFullReply) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +func (x *GetFullReply) GetPhone() string { + if x != nil { + return x.Phone + } + return "" +} + +func (x *GetFullReply) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *GetFullReply) GetRights() string { + if x != nil { + return x.Rights + } + return "" +} + +func (x *GetFullReply) GetNickname() string { + if x != nil { + return x.Nickname + } + return "" +} + +func (x *GetFullReply) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *GetFullReply) GetBirthday() string { + if x != nil { + return x.Birthday + } + return "" +} + +func (x *GetFullReply) GetSex() int32 { + if x != nil { + return x.Sex + } + return 0 +} + +func (x *GetFullReply) GetCountry() int32 { + if x != nil { + return x.Country + } + return 0 +} + +func (x *GetFullReply) GetProvince() int32 { + if x != nil { + return x.Province + } + return 0 +} + +func (x *GetFullReply) GetCity() int32 { + if x != nil { + return x.City + } + return 0 +} + +func (x *GetFullReply) GetArea() int32 { + if x != nil { + return x.Area + } + return 0 +} + +func (x *GetFullReply) GetSign() string { + if x != nil { + return x.Sign + } + return "" +} + +func (x *GetFullReply) GetCover() string { + if x != nil { + return x.Cover + } + return "" +} + +func (x *GetFullReply) GetScore() int32 { + if x != nil { + return x.Score + } + return 0 +} + +func (x *GetFullReply) GetLevel() int32 { + if x != nil { + return x.Level + } + return 0 +} + +func (x *GetFullReply) GetVerify() map[string]bool { + if x != nil { + return x.Verify + } + return nil +} + +func (x *GetFullReply) GetTags() []*TagItem { + if x != nil { + return x.Tags + } + return nil +} + +type TagItem struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Icon string `protobuf:"bytes,2,opt,name=icon,proto3" json:"icon,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TagItem) Reset() { + *x = TagItem{} + mi := &file_account_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TagItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TagItem) ProtoMessage() {} + +func (x *TagItem) ProtoReflect() protoreflect.Message { + mi := &file_account_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TagItem.ProtoReflect.Descriptor instead. +func (*TagItem) Descriptor() ([]byte, []int) { + return file_account_proto_rawDescGZIP(), []int{1} +} + +func (x *TagItem) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *TagItem) GetIcon() string { + if x != nil { + return x.Icon + } + return "" +} + +type SetDataRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Nickname string `protobuf:"bytes,1,opt,name=nickname,proto3" json:"nickname,omitempty"` //昵称 + Avatar string `protobuf:"bytes,2,opt,name=avatar,proto3" json:"avatar,omitempty"` //头像 + Birthday string `protobuf:"bytes,3,opt,name=birthday,proto3" json:"birthday,omitempty"` //生日 + Sex int32 `protobuf:"varint,4,opt,name=sex,proto3" json:"sex,omitempty"` //性别,1为男性,2为女性 + Country int32 `protobuf:"varint,5,opt,name=country,proto3" json:"country,omitempty"` // 国家 + Province int32 `protobuf:"varint,6,opt,name=province,proto3" json:"province,omitempty"` //省 + City int32 `protobuf:"varint,7,opt,name=city,proto3" json:"city,omitempty"` //市 + Area int32 `protobuf:"varint,8,opt,name=area,proto3" json:"area,omitempty"` //区 + Sign string `protobuf:"bytes,9,opt,name=sign,proto3" json:"sign,omitempty"` //签名 + Cover string `protobuf:"bytes,10,opt,name=cover,proto3" json:"cover,omitempty"` // 背景&封面 + Score int32 `protobuf:"varint,11,opt,name=score,proto3" json:"score,omitempty"` // 积分 + Level int32 `protobuf:"varint,12,opt,name=level,proto3" json:"level,omitempty"` // 等级 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SetDataRequest) Reset() { + *x = SetDataRequest{} + mi := &file_account_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SetDataRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetDataRequest) ProtoMessage() {} + +func (x *SetDataRequest) ProtoReflect() protoreflect.Message { + mi := &file_account_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SetDataRequest.ProtoReflect.Descriptor instead. +func (*SetDataRequest) Descriptor() ([]byte, []int) { + return file_account_proto_rawDescGZIP(), []int{2} +} + +func (x *SetDataRequest) GetNickname() string { + if x != nil { + return x.Nickname + } + return "" +} + +func (x *SetDataRequest) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *SetDataRequest) GetBirthday() string { + if x != nil { + return x.Birthday + } + return "" +} + +func (x *SetDataRequest) GetSex() int32 { + if x != nil { + return x.Sex + } + return 0 +} + +func (x *SetDataRequest) GetCountry() int32 { + if x != nil { + return x.Country + } + return 0 +} + +func (x *SetDataRequest) GetProvince() int32 { + if x != nil { + return x.Province + } + return 0 +} + +func (x *SetDataRequest) GetCity() int32 { + if x != nil { + return x.City + } + return 0 +} + +func (x *SetDataRequest) GetArea() int32 { + if x != nil { + return x.Area + } + return 0 +} + +func (x *SetDataRequest) GetSign() string { + if x != nil { + return x.Sign + } + return "" +} + +func (x *SetDataRequest) GetCover() string { + if x != nil { + return x.Cover + } + return "" +} + +func (x *SetDataRequest) GetScore() int32 { + if x != nil { + return x.Score + } + return 0 +} + +func (x *SetDataRequest) GetLevel() int32 { + if x != nil { + return x.Level + } + return 0 +} + +type SetPasswordRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + OldPassword string `protobuf:"bytes,3,opt,name=old_password,json=oldPassword,proto3" json:"old_password,omitempty"` // 旧密码 + NewPassword string `protobuf:"bytes,4,opt,name=new_password,json=newPassword,proto3" json:"new_password,omitempty"` // 新密码 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SetPasswordRequest) Reset() { + *x = SetPasswordRequest{} + mi := &file_account_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SetPasswordRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetPasswordRequest) ProtoMessage() {} + +func (x *SetPasswordRequest) ProtoReflect() protoreflect.Message { + mi := &file_account_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SetPasswordRequest.ProtoReflect.Descriptor instead. +func (*SetPasswordRequest) Descriptor() ([]byte, []int) { + return file_account_proto_rawDescGZIP(), []int{3} +} + +func (x *SetPasswordRequest) GetOldPassword() string { + if x != nil { + return x.OldPassword + } + return "" +} + +func (x *SetPasswordRequest) GetNewPassword() string { + if x != nil { + return x.NewPassword + } + return "" +} + +type StatisticsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Field []string `protobuf:"bytes,1,rep,name=field,proto3" json:"field,omitempty"` //要获取的统计数据字段。 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *StatisticsRequest) Reset() { + *x = StatisticsRequest{} + mi := &file_account_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *StatisticsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatisticsRequest) ProtoMessage() {} + +func (x *StatisticsRequest) ProtoReflect() protoreflect.Message { + mi := &file_account_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatisticsRequest.ProtoReflect.Descriptor instead. +func (*StatisticsRequest) Descriptor() ([]byte, []int) { + return file_account_proto_rawDescGZIP(), []int{4} +} + +func (x *StatisticsRequest) GetField() []string { + if x != nil { + return x.Field + } + return nil +} + +type StatisticsReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + Data map[string]int64 `protobuf:"bytes,1,rep,name=Data,proto3" json:"Data,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` //数据以Map格式输出 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *StatisticsReply) Reset() { + *x = StatisticsReply{} + mi := &file_account_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *StatisticsReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatisticsReply) ProtoMessage() {} + +func (x *StatisticsReply) ProtoReflect() protoreflect.Message { + mi := &file_account_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatisticsReply.ProtoReflect.Descriptor instead. +func (*StatisticsReply) Descriptor() ([]byte, []int) { + return file_account_proto_rawDescGZIP(), []int{5} +} + +func (x *StatisticsReply) GetData() map[string]int64 { + if x != nil { + return x.Data + } + return nil +} + +var File_account_proto protoreflect.FileDescriptor + +const file_account_proto_rawDesc = "" + + "\n" + + "\raccount.proto\x12\bsample\x1a\fblocks.proto\"\xbc\x04\n" + + "\fGetFullReply\x12\x1a\n" + + "\bidentity\x18\x01 \x01(\tR\bidentity\x12\x18\n" + + "\aaccount\x18\x02 \x01(\tR\aaccount\x12\x14\n" + + "\x05phone\x18\x03 \x01(\tR\x05phone\x12\x14\n" + + "\x05email\x18\x04 \x01(\tR\x05email\x12\x16\n" + + "\x06rights\x18\x05 \x01(\tR\x06rights\x12\x1a\n" + + "\bnickname\x18\x06 \x01(\tR\bnickname\x12\x16\n" + + "\x06avatar\x18\a \x01(\tR\x06avatar\x12\x1a\n" + + "\bbirthday\x18\b \x01(\tR\bbirthday\x12\x10\n" + + "\x03sex\x18\t \x01(\x05R\x03sex\x12\x18\n" + + "\acountry\x18\n" + + " \x01(\x05R\acountry\x12\x1a\n" + + "\bprovince\x18\v \x01(\x05R\bprovince\x12\x12\n" + + "\x04city\x18\f \x01(\x05R\x04city\x12\x12\n" + + "\x04area\x18\r \x01(\x05R\x04area\x12\x12\n" + + "\x04sign\x18\x0e \x01(\tR\x04sign\x12\x14\n" + + "\x05cover\x18\x0f \x01(\tR\x05cover\x12\x14\n" + + "\x05score\x18\x10 \x01(\x05R\x05score\x12\x14\n" + + "\x05level\x18\x11 \x01(\x05R\x05level\x12:\n" + + "\x06verify\x18\x12 \x03(\v2\".sample.GetFullReply.VerifyEntryR\x06verify\x12%\n" + + "\x04tags\x18\x13 \x03(\v2\x11.sample.TagItemR\x04tags\x1a9\n" + + "\vVerifyEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\bR\x05value:\x028\x01\"1\n" + + "\aTagItem\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12\x12\n" + + "\x04icon\x18\x02 \x01(\tR\x04icon\"\xa6\x02\n" + + "\x0eSetDataRequest\x12\x1a\n" + + "\bnickname\x18\x01 \x01(\tR\bnickname\x12\x16\n" + + "\x06avatar\x18\x02 \x01(\tR\x06avatar\x12\x1a\n" + + "\bbirthday\x18\x03 \x01(\tR\bbirthday\x12\x10\n" + + "\x03sex\x18\x04 \x01(\x05R\x03sex\x12\x18\n" + + "\acountry\x18\x05 \x01(\x05R\acountry\x12\x1a\n" + + "\bprovince\x18\x06 \x01(\x05R\bprovince\x12\x12\n" + + "\x04city\x18\a \x01(\x05R\x04city\x12\x12\n" + + "\x04area\x18\b \x01(\x05R\x04area\x12\x12\n" + + "\x04sign\x18\t \x01(\tR\x04sign\x12\x14\n" + + "\x05cover\x18\n" + + " \x01(\tR\x05cover\x12\x14\n" + + "\x05score\x18\v \x01(\x05R\x05score\x12\x14\n" + + "\x05level\x18\f \x01(\x05R\x05level\"Z\n" + + "\x12SetPasswordRequest\x12!\n" + + "\fold_password\x18\x03 \x01(\tR\voldPassword\x12!\n" + + "\fnew_password\x18\x04 \x01(\tR\vnewPassword\")\n" + + "\x11StatisticsRequest\x12\x14\n" + + "\x05field\x18\x01 \x03(\tR\x05field\"\x83\x01\n" + + "\x0fStatisticsReply\x127\n" + + "\x04Data\x18\x01 \x03(\v2#.sample.StatisticsReply.DataEntryR\x04Data\x1a7\n" + + "\tDataEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\x03R\x05value:\x028\x012\xfe\x02\n" + + "\aAccount\x120\n" + + "\x03Get\x12\x0f.sample.Empty\x1a\x16.sample.GetFullReply\"\x00\x12<\n" + + "\aSetData\x12\x18.sample.SetDataRequest\x1a\x15.sample.StatusReply\"\x00\x12D\n" + + "\vSetPassword\x12\x1c.sample.SetPasswordRequest\x1a\x15.sample.StatusReply\"\x00\x127\n" + + "\tTagCreate\x12\x11.sample.TagItem\x1a\x15.sample.StatusReply\"\x00\x12<\n" + + "\tTagRemove\x12\x16.sample.IdentRequest\x1a\x15.sample.StatusReply\"\x00\x12F\n" + + "\n" + + "Statistics\x12\x1b.sample.StatisticsRequest\x1a\x19.sample.StatisticsReply\"\x00B\fZ\n" + + ".;sampleb\x06proto3" + +var ( + file_account_proto_rawDescOnce sync.Once + file_account_proto_rawDescData []byte +) + +func file_account_proto_rawDescGZIP() []byte { + file_account_proto_rawDescOnce.Do(func() { + file_account_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_account_proto_rawDesc), len(file_account_proto_rawDesc))) + }) + return file_account_proto_rawDescData +} + +var file_account_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_account_proto_goTypes = []any{ + (*GetFullReply)(nil), // 0: sample.GetFullReply + (*TagItem)(nil), // 1: sample.TagItem + (*SetDataRequest)(nil), // 2: sample.SetDataRequest + (*SetPasswordRequest)(nil), // 3: sample.SetPasswordRequest + (*StatisticsRequest)(nil), // 4: sample.StatisticsRequest + (*StatisticsReply)(nil), // 5: sample.StatisticsReply + nil, // 6: sample.GetFullReply.VerifyEntry + nil, // 7: sample.StatisticsReply.DataEntry + (*Empty)(nil), // 8: sample.Empty + (*IdentRequest)(nil), // 9: sample.IdentRequest + (*StatusReply)(nil), // 10: sample.StatusReply +} +var file_account_proto_depIdxs = []int32{ + 6, // 0: sample.GetFullReply.verify:type_name -> sample.GetFullReply.VerifyEntry + 1, // 1: sample.GetFullReply.tags:type_name -> sample.TagItem + 7, // 2: sample.StatisticsReply.Data:type_name -> sample.StatisticsReply.DataEntry + 8, // 3: sample.Account.Get:input_type -> sample.Empty + 2, // 4: sample.Account.SetData:input_type -> sample.SetDataRequest + 3, // 5: sample.Account.SetPassword:input_type -> sample.SetPasswordRequest + 1, // 6: sample.Account.TagCreate:input_type -> sample.TagItem + 9, // 7: sample.Account.TagRemove:input_type -> sample.IdentRequest + 4, // 8: sample.Account.Statistics:input_type -> sample.StatisticsRequest + 0, // 9: sample.Account.Get:output_type -> sample.GetFullReply + 10, // 10: sample.Account.SetData:output_type -> sample.StatusReply + 10, // 11: sample.Account.SetPassword:output_type -> sample.StatusReply + 10, // 12: sample.Account.TagCreate:output_type -> sample.StatusReply + 10, // 13: sample.Account.TagRemove:output_type -> sample.StatusReply + 5, // 14: sample.Account.Statistics:output_type -> sample.StatisticsReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_account_proto_init() } +func file_account_proto_init() { + if File_account_proto != nil { + return + } + file_blocks_proto_init() + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_account_proto_rawDesc), len(file_account_proto_rawDesc)), + NumEnums: 0, + NumMessages: 8, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_account_proto_goTypes, + DependencyIndexes: file_account_proto_depIdxs, + MessageInfos: file_account_proto_msgTypes, + }.Build() + File_account_proto = out.File + file_account_proto_goTypes = nil + file_account_proto_depIdxs = nil +} diff --git a/pb/account.pb.gw.go b/pb/account.pb.gw.go new file mode 100644 index 0000000..a759ad5 --- /dev/null +++ b/pb/account.pb.gw.go @@ -0,0 +1,487 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: account.proto + +/* +Package sample is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package sample + +import ( + "context" + "errors" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var ( + _ codes.Code + _ io.Reader + _ status.Status + _ = errors.New + _ = runtime.String + _ = utilities.NewDoubleArray + _ = metadata.Join +) + +func request_Account_Get_0(ctx context.Context, marshaler runtime.Marshaler, client AccountClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq Empty + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Get(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Account_Get_0(ctx context.Context, marshaler runtime.Marshaler, server AccountServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq Empty + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Get(ctx, &protoReq) + return msg, metadata, err +} + +func request_Account_SetData_0(ctx context.Context, marshaler runtime.Marshaler, client AccountClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq SetDataRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.SetData(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Account_SetData_0(ctx context.Context, marshaler runtime.Marshaler, server AccountServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq SetDataRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.SetData(ctx, &protoReq) + return msg, metadata, err +} + +func request_Account_SetPassword_0(ctx context.Context, marshaler runtime.Marshaler, client AccountClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq SetPasswordRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.SetPassword(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Account_SetPassword_0(ctx context.Context, marshaler runtime.Marshaler, server AccountServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq SetPasswordRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.SetPassword(ctx, &protoReq) + return msg, metadata, err +} + +func request_Account_TagCreate_0(ctx context.Context, marshaler runtime.Marshaler, client AccountClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq TagItem + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.TagCreate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Account_TagCreate_0(ctx context.Context, marshaler runtime.Marshaler, server AccountServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq TagItem + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.TagCreate(ctx, &protoReq) + return msg, metadata, err +} + +func request_Account_TagRemove_0(ctx context.Context, marshaler runtime.Marshaler, client AccountClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq IdentRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.TagRemove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Account_TagRemove_0(ctx context.Context, marshaler runtime.Marshaler, server AccountServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq IdentRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.TagRemove(ctx, &protoReq) + return msg, metadata, err +} + +func request_Account_Statistics_0(ctx context.Context, marshaler runtime.Marshaler, client AccountClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq StatisticsRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Statistics(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Account_Statistics_0(ctx context.Context, marshaler runtime.Marshaler, server AccountServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq StatisticsRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Statistics(ctx, &protoReq) + return msg, metadata, err +} + +// RegisterAccountHandlerServer registers the http handlers for service Account to "mux". +// UnaryRPC :call AccountServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterAccountHandlerFromEndpoint instead. +// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. +func RegisterAccountHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AccountServer) error { + mux.Handle(http.MethodPost, pattern_Account_Get_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Account/Get", runtime.WithHTTPPathPattern("/sample.Account/Get")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Account_Get_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_Get_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_SetData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Account/SetData", runtime.WithHTTPPathPattern("/sample.Account/SetData")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Account_SetData_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_SetData_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_SetPassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Account/SetPassword", runtime.WithHTTPPathPattern("/sample.Account/SetPassword")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Account_SetPassword_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_SetPassword_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_TagCreate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Account/TagCreate", runtime.WithHTTPPathPattern("/sample.Account/TagCreate")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Account_TagCreate_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_TagCreate_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_TagRemove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Account/TagRemove", runtime.WithHTTPPathPattern("/sample.Account/TagRemove")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Account_TagRemove_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_TagRemove_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_Statistics_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Account/Statistics", runtime.WithHTTPPathPattern("/sample.Account/Statistics")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Account_Statistics_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_Statistics_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + + return nil +} + +// RegisterAccountHandlerFromEndpoint is same as RegisterAccountHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterAccountHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.NewClient(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + return RegisterAccountHandler(ctx, mux, conn) +} + +// RegisterAccountHandler registers the http handlers for service Account to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterAccountHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterAccountHandlerClient(ctx, mux, NewAccountClient(conn)) +} + +// RegisterAccountHandlerClient registers the http handlers for service Account +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AccountClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AccountClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "AccountClient" to call the correct interceptors. This client ignores the HTTP middlewares. +func RegisterAccountHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AccountClient) error { + mux.Handle(http.MethodPost, pattern_Account_Get_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Account/Get", runtime.WithHTTPPathPattern("/sample.Account/Get")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Account_Get_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_Get_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_SetData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Account/SetData", runtime.WithHTTPPathPattern("/sample.Account/SetData")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Account_SetData_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_SetData_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_SetPassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Account/SetPassword", runtime.WithHTTPPathPattern("/sample.Account/SetPassword")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Account_SetPassword_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_SetPassword_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_TagCreate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Account/TagCreate", runtime.WithHTTPPathPattern("/sample.Account/TagCreate")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Account_TagCreate_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_TagCreate_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_TagRemove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Account/TagRemove", runtime.WithHTTPPathPattern("/sample.Account/TagRemove")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Account_TagRemove_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_TagRemove_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Account_Statistics_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Account/Statistics", runtime.WithHTTPPathPattern("/sample.Account/Statistics")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Account_Statistics_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Account_Statistics_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + return nil +} + +var ( + pattern_Account_Get_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Account", "Get"}, "")) + pattern_Account_SetData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Account", "SetData"}, "")) + pattern_Account_SetPassword_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Account", "SetPassword"}, "")) + pattern_Account_TagCreate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Account", "TagCreate"}, "")) + pattern_Account_TagRemove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Account", "TagRemove"}, "")) + pattern_Account_Statistics_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Account", "Statistics"}, "")) +) + +var ( + forward_Account_Get_0 = runtime.ForwardResponseMessage + forward_Account_SetData_0 = runtime.ForwardResponseMessage + forward_Account_SetPassword_0 = runtime.ForwardResponseMessage + forward_Account_TagCreate_0 = runtime.ForwardResponseMessage + forward_Account_TagRemove_0 = runtime.ForwardResponseMessage + forward_Account_Statistics_0 = runtime.ForwardResponseMessage +) diff --git a/pb/account_grpc.pb.go b/pb/account_grpc.pb.go new file mode 100644 index 0000000..b064cc1 --- /dev/null +++ b/pb/account_grpc.pb.go @@ -0,0 +1,328 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: account.proto + +package sample + +import ( + context "context" + + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Account_Get_FullMethodName = "/sample.Account/Get" + Account_SetData_FullMethodName = "/sample.Account/SetData" + Account_SetPassword_FullMethodName = "/sample.Account/SetPassword" + Account_TagCreate_FullMethodName = "/sample.Account/TagCreate" + Account_TagRemove_FullMethodName = "/sample.Account/TagRemove" + Account_Statistics_FullMethodName = "/sample.Account/Statistics" +) + +// AccountClient is the client API for Account service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// sample(会员通行证)模块-数据 +type AccountClient interface { + // 通过会员所有信息 + Get(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*GetFullReply, error) + // 更新会员的信息数据,字段值为空或是0,将不更新此数据 + SetData(ctx context.Context, in *SetDataRequest, opts ...grpc.CallOption) (*StatusReply, error) + // 更新会员的密码 + SetPassword(ctx context.Context, in *SetPasswordRequest, opts ...grpc.CallOption) (*StatusReply, error) + // 新增标签 + TagCreate(ctx context.Context, in *TagItem, opts ...grpc.CallOption) (*StatusReply, error) + // 删除标签 + TagRemove(ctx context.Context, in *IdentRequest, opts ...grpc.CallOption) (*StatusReply, error) + // 获取会员的相关统计数据 + Statistics(ctx context.Context, in *StatisticsRequest, opts ...grpc.CallOption) (*StatisticsReply, error) +} + +type accountClient struct { + cc grpc.ClientConnInterface +} + +func NewAccountClient(cc grpc.ClientConnInterface) AccountClient { + return &accountClient{cc} +} + +func (c *accountClient) Get(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*GetFullReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetFullReply) + err := c.cc.Invoke(ctx, Account_Get_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountClient) SetData(ctx context.Context, in *SetDataRequest, opts ...grpc.CallOption) (*StatusReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(StatusReply) + err := c.cc.Invoke(ctx, Account_SetData_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountClient) SetPassword(ctx context.Context, in *SetPasswordRequest, opts ...grpc.CallOption) (*StatusReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(StatusReply) + err := c.cc.Invoke(ctx, Account_SetPassword_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountClient) TagCreate(ctx context.Context, in *TagItem, opts ...grpc.CallOption) (*StatusReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(StatusReply) + err := c.cc.Invoke(ctx, Account_TagCreate_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountClient) TagRemove(ctx context.Context, in *IdentRequest, opts ...grpc.CallOption) (*StatusReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(StatusReply) + err := c.cc.Invoke(ctx, Account_TagRemove_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountClient) Statistics(ctx context.Context, in *StatisticsRequest, opts ...grpc.CallOption) (*StatisticsReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(StatisticsReply) + err := c.cc.Invoke(ctx, Account_Statistics_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AccountServer is the server API for Account service. +// All implementations must embed UnimplementedAccountServer +// for forward compatibility. +// +// sample(会员通行证)模块-数据 +type AccountServer interface { + // 通过会员所有信息 + Get(context.Context, *Empty) (*GetFullReply, error) + // 更新会员的信息数据,字段值为空或是0,将不更新此数据 + SetData(context.Context, *SetDataRequest) (*StatusReply, error) + // 更新会员的密码 + SetPassword(context.Context, *SetPasswordRequest) (*StatusReply, error) + // 新增标签 + TagCreate(context.Context, *TagItem) (*StatusReply, error) + // 删除标签 + TagRemove(context.Context, *IdentRequest) (*StatusReply, error) + // 获取会员的相关统计数据 + Statistics(context.Context, *StatisticsRequest) (*StatisticsReply, error) + mustEmbedUnimplementedAccountServer() +} + +// UnimplementedAccountServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedAccountServer struct{} + +func (UnimplementedAccountServer) Get(context.Context, *Empty) (*GetFullReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") +} +func (UnimplementedAccountServer) SetData(context.Context, *SetDataRequest) (*StatusReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetData not implemented") +} +func (UnimplementedAccountServer) SetPassword(context.Context, *SetPasswordRequest) (*StatusReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetPassword not implemented") +} +func (UnimplementedAccountServer) TagCreate(context.Context, *TagItem) (*StatusReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method TagCreate not implemented") +} +func (UnimplementedAccountServer) TagRemove(context.Context, *IdentRequest) (*StatusReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method TagRemove not implemented") +} +func (UnimplementedAccountServer) Statistics(context.Context, *StatisticsRequest) (*StatisticsReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Statistics not implemented") +} +func (UnimplementedAccountServer) mustEmbedUnimplementedAccountServer() {} +func (UnimplementedAccountServer) testEmbeddedByValue() {} + +// UnsafeAccountServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to AccountServer will +// result in compilation errors. +type UnsafeAccountServer interface { + mustEmbedUnimplementedAccountServer() +} + +func RegisterAccountServer(s grpc.ServiceRegistrar, srv AccountServer) { + // If the following call pancis, it indicates UnimplementedAccountServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Account_ServiceDesc, srv) +} + +func _Account_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServer).Get(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Account_Get_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServer).Get(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _Account_SetData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetDataRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServer).SetData(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Account_SetData_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServer).SetData(ctx, req.(*SetDataRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Account_SetPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetPasswordRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServer).SetPassword(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Account_SetPassword_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServer).SetPassword(ctx, req.(*SetPasswordRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Account_TagCreate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TagItem) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServer).TagCreate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Account_TagCreate_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServer).TagCreate(ctx, req.(*TagItem)) + } + return interceptor(ctx, in, info, handler) +} + +func _Account_TagRemove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IdentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServer).TagRemove(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Account_TagRemove_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServer).TagRemove(ctx, req.(*IdentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Account_Statistics_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatisticsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServer).Statistics(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Account_Statistics_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServer).Statistics(ctx, req.(*StatisticsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Account_ServiceDesc is the grpc.ServiceDesc for Account service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Account_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "sample.Account", + HandlerType: (*AccountServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Get", + Handler: _Account_Get_Handler, + }, + { + MethodName: "SetData", + Handler: _Account_SetData_Handler, + }, + { + MethodName: "SetPassword", + Handler: _Account_SetPassword_Handler, + }, + { + MethodName: "TagCreate", + Handler: _Account_TagCreate_Handler, + }, + { + MethodName: "TagRemove", + Handler: _Account_TagRemove_Handler, + }, + { + MethodName: "Statistics", + Handler: _Account_Statistics_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "account.proto", +} diff --git a/pb/blocks.pb.go b/pb/blocks.pb.go new file mode 100644 index 0000000..cda6c02 --- /dev/null +++ b/pb/blocks.pb.go @@ -0,0 +1,391 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.8 +// protoc (unknown) +// source: blocks.proto + +package sample + +import ( + reflect "reflect" + sync "sync" + unsafe "unsafe" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type FetchRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + PageNo int64 `protobuf:"varint,1,opt,name=page_no,json=pageNo,proto3" json:"page_no,omitempty"` // 页数 + PageSize int64 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` // 每页记录数 + Params map[string]string `protobuf:"bytes,3,rep,name=params,proto3" json:"params,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` // 条件参数,key=val,eg key:category_id=?,vlaue=11 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FetchRequest) Reset() { + *x = FetchRequest{} + mi := &file_blocks_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FetchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FetchRequest) ProtoMessage() {} + +func (x *FetchRequest) ProtoReflect() protoreflect.Message { + mi := &file_blocks_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FetchRequest.ProtoReflect.Descriptor instead. +func (*FetchRequest) Descriptor() ([]byte, []int) { + return file_blocks_proto_rawDescGZIP(), []int{0} +} + +func (x *FetchRequest) GetPageNo() int64 { + if x != nil { + return x.PageNo + } + return 0 +} + +func (x *FetchRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *FetchRequest) GetParams() map[string]string { + if x != nil { + return x.Params + } + return nil +} + +type IdentRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // 唯一ID + Identity string `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"` // 唯一码 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *IdentRequest) Reset() { + *x = IdentRequest{} + mi := &file_blocks_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *IdentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IdentRequest) ProtoMessage() {} + +func (x *IdentRequest) ProtoReflect() protoreflect.Message { + mi := &file_blocks_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IdentRequest.ProtoReflect.Descriptor instead. +func (*IdentRequest) Descriptor() ([]byte, []int) { + return file_blocks_proto_rawDescGZIP(), []int{1} +} + +func (x *IdentRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *IdentRequest) GetIdentity() string { + if x != nil { + return x.Identity + } + return "" +} + +type VersionRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Version int64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` // 时序版本号 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *VersionRequest) Reset() { + *x = VersionRequest{} + mi := &file_blocks_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *VersionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*VersionRequest) ProtoMessage() {} + +func (x *VersionRequest) ProtoReflect() protoreflect.Message { + mi := &file_blocks_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use VersionRequest.ProtoReflect.Descriptor instead. +func (*VersionRequest) Descriptor() ([]byte, []int) { + return file_blocks_proto_rawDescGZIP(), []int{2} +} + +func (x *VersionRequest) GetVersion() int64 { + if x != nil { + return x.Version + } + return 0 +} + +type SearchRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Keyword string `protobuf:"bytes,1,opt,name=keyword,proto3" json:"keyword,omitempty"` //关键词 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchRequest) Reset() { + *x = SearchRequest{} + mi := &file_blocks_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchRequest) ProtoMessage() {} + +func (x *SearchRequest) ProtoReflect() protoreflect.Message { + mi := &file_blocks_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SearchRequest.ProtoReflect.Descriptor instead. +func (*SearchRequest) Descriptor() ([]byte, []int) { + return file_blocks_proto_rawDescGZIP(), []int{3} +} + +func (x *SearchRequest) GetKeyword() string { + if x != nil { + return x.Keyword + } + return "" +} + +type StatusReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` // 数据 + Timeseq int64 `protobuf:"varint,2,opt,name=timeseq,proto3" json:"timeseq,omitempty"` // 响应时间序列 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *StatusReply) Reset() { + *x = StatusReply{} + mi := &file_blocks_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *StatusReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatusReply) ProtoMessage() {} + +func (x *StatusReply) ProtoReflect() protoreflect.Message { + mi := &file_blocks_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatusReply.ProtoReflect.Descriptor instead. +func (*StatusReply) Descriptor() ([]byte, []int) { + return file_blocks_proto_rawDescGZIP(), []int{4} +} + +func (x *StatusReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *StatusReply) GetTimeseq() int64 { + if x != nil { + return x.Timeseq + } + return 0 +} + +type Empty struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Empty) Reset() { + *x = Empty{} + mi := &file_blocks_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_blocks_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_blocks_proto_rawDescGZIP(), []int{5} +} + +var File_blocks_proto protoreflect.FileDescriptor + +const file_blocks_proto_rawDesc = "" + + "\n" + + "\fblocks.proto\x12\bsample\"\xbb\x01\n" + + "\fFetchRequest\x12\x17\n" + + "\apage_no\x18\x01 \x01(\x03R\x06pageNo\x12\x1b\n" + + "\tpage_size\x18\x02 \x01(\x03R\bpageSize\x12:\n" + + "\x06params\x18\x03 \x03(\v2\".sample.FetchRequest.ParamsEntryR\x06params\x1a9\n" + + "\vParamsEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\":\n" + + "\fIdentRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x1a\n" + + "\bidentity\x18\x02 \x01(\tR\bidentity\"*\n" + + "\x0eVersionRequest\x12\x18\n" + + "\aversion\x18\x01 \x01(\x03R\aversion\")\n" + + "\rSearchRequest\x12\x18\n" + + "\akeyword\x18\x01 \x01(\tR\akeyword\";\n" + + "\vStatusReply\x12\x12\n" + + "\x04data\x18\x01 \x01(\tR\x04data\x12\x18\n" + + "\atimeseq\x18\x02 \x01(\x03R\atimeseq\"\a\n" + + "\x05EmptyB\fZ\n" + + ".;sampleb\x06proto3" + +var ( + file_blocks_proto_rawDescOnce sync.Once + file_blocks_proto_rawDescData []byte +) + +func file_blocks_proto_rawDescGZIP() []byte { + file_blocks_proto_rawDescOnce.Do(func() { + file_blocks_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_blocks_proto_rawDesc), len(file_blocks_proto_rawDesc))) + }) + return file_blocks_proto_rawDescData +} + +var file_blocks_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_blocks_proto_goTypes = []any{ + (*FetchRequest)(nil), // 0: sample.FetchRequest + (*IdentRequest)(nil), // 1: sample.IdentRequest + (*VersionRequest)(nil), // 2: sample.VersionRequest + (*SearchRequest)(nil), // 3: sample.SearchRequest + (*StatusReply)(nil), // 4: sample.StatusReply + (*Empty)(nil), // 5: sample.Empty + nil, // 6: sample.FetchRequest.ParamsEntry +} +var file_blocks_proto_depIdxs = []int32{ + 6, // 0: sample.FetchRequest.params:type_name -> sample.FetchRequest.ParamsEntry + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_blocks_proto_init() } +func file_blocks_proto_init() { + if File_blocks_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_blocks_proto_rawDesc), len(file_blocks_proto_rawDesc)), + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_blocks_proto_goTypes, + DependencyIndexes: file_blocks_proto_depIdxs, + MessageInfos: file_blocks_proto_msgTypes, + }.Build() + File_blocks_proto = out.File + file_blocks_proto_goTypes = nil + file_blocks_proto_depIdxs = nil +} diff --git a/pb/forget.pb.go b/pb/forget.pb.go new file mode 100644 index 0000000..d166945 --- /dev/null +++ b/pb/forget.pb.go @@ -0,0 +1,277 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.8 +// protoc (unknown) +// source: forget.proto + +package sample + +import ( + reflect "reflect" + sync "sync" + unsafe "unsafe" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type VerifyRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Phone string `protobuf:"bytes,1,opt,name=phone,proto3" json:"phone,omitempty"` //手机号 + Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` // 验证码 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *VerifyRequest) Reset() { + *x = VerifyRequest{} + mi := &file_forget_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *VerifyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*VerifyRequest) ProtoMessage() {} + +func (x *VerifyRequest) ProtoReflect() protoreflect.Message { + mi := &file_forget_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use VerifyRequest.ProtoReflect.Descriptor instead. +func (*VerifyRequest) Descriptor() ([]byte, []int) { + return file_forget_proto_rawDescGZIP(), []int{0} +} + +func (x *VerifyRequest) GetPhone() string { + if x != nil { + return x.Phone + } + return "" +} + +func (x *VerifyRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +type ForgetResetRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Identity string `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` //唯一码 + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` // 密码 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ForgetResetRequest) Reset() { + *x = ForgetResetRequest{} + mi := &file_forget_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ForgetResetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForgetResetRequest) ProtoMessage() {} + +func (x *ForgetResetRequest) ProtoReflect() protoreflect.Message { + mi := &file_forget_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ForgetResetRequest.ProtoReflect.Descriptor instead. +func (*ForgetResetRequest) Descriptor() ([]byte, []int) { + return file_forget_proto_rawDescGZIP(), []int{1} +} + +func (x *ForgetResetRequest) GetIdentity() string { + if x != nil { + return x.Identity + } + return "" +} + +func (x *ForgetResetRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type ForgetReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + Identity string `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` //用户唯一码 + DataBind string `protobuf:"bytes,2,opt,name=data_bind,json=dataBind,proto3" json:"data_bind,omitempty"` // 数据绑定的相关说明,PASS通过,NOPHONE没有绑定手机号,NOPWD没有设置密码,NOBIND没有手机号同时没有密码 + Token string `protobuf:"bytes,3,opt,name=token,proto3" json:"token,omitempty"` //用户凭证 + Extend map[string]string `protobuf:"bytes,4,rep,name=extend,proto3" json:"extend,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` //扩展字段 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ForgetReply) Reset() { + *x = ForgetReply{} + mi := &file_forget_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ForgetReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForgetReply) ProtoMessage() {} + +func (x *ForgetReply) ProtoReflect() protoreflect.Message { + mi := &file_forget_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ForgetReply.ProtoReflect.Descriptor instead. +func (*ForgetReply) Descriptor() ([]byte, []int) { + return file_forget_proto_rawDescGZIP(), []int{2} +} + +func (x *ForgetReply) GetIdentity() string { + if x != nil { + return x.Identity + } + return "" +} + +func (x *ForgetReply) GetDataBind() string { + if x != nil { + return x.DataBind + } + return "" +} + +func (x *ForgetReply) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *ForgetReply) GetExtend() map[string]string { + if x != nil { + return x.Extend + } + return nil +} + +var File_forget_proto protoreflect.FileDescriptor + +const file_forget_proto_rawDesc = "" + + "\n" + + "\fforget.proto\x12\bsample\x1a\fblocks.proto\"9\n" + + "\rVerifyRequest\x12\x14\n" + + "\x05phone\x18\x01 \x01(\tR\x05phone\x12\x12\n" + + "\x04code\x18\x02 \x01(\tR\x04code\"L\n" + + "\x12ForgetResetRequest\x12\x1a\n" + + "\bidentity\x18\x01 \x01(\tR\bidentity\x12\x1a\n" + + "\bpassword\x18\x02 \x01(\tR\bpassword\"\xd2\x01\n" + + "\vForgetReply\x12\x1a\n" + + "\bidentity\x18\x01 \x01(\tR\bidentity\x12\x1b\n" + + "\tdata_bind\x18\x02 \x01(\tR\bdataBind\x12\x14\n" + + "\x05token\x18\x03 \x01(\tR\x05token\x129\n" + + "\x06extend\x18\x04 \x03(\v2!.sample.ForgetReply.ExtendEntryR\x06extend\x1a9\n" + + "\vExtendEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x012\x84\x01\n" + + "\x06Forget\x12:\n" + + "\x06Verify\x12\x17.sample.VerifyRequest\x1a\x15.sample.StatusReply\"\x00\x12>\n" + + "\x05Reset\x12\x1c.sample.ForgetResetRequest\x1a\x15.sample.ForgetReply\"\x00B\fZ\n" + + ".;sampleb\x06proto3" + +var ( + file_forget_proto_rawDescOnce sync.Once + file_forget_proto_rawDescData []byte +) + +func file_forget_proto_rawDescGZIP() []byte { + file_forget_proto_rawDescOnce.Do(func() { + file_forget_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_forget_proto_rawDesc), len(file_forget_proto_rawDesc))) + }) + return file_forget_proto_rawDescData +} + +var file_forget_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_forget_proto_goTypes = []any{ + (*VerifyRequest)(nil), // 0: sample.VerifyRequest + (*ForgetResetRequest)(nil), // 1: sample.ForgetResetRequest + (*ForgetReply)(nil), // 2: sample.ForgetReply + nil, // 3: sample.ForgetReply.ExtendEntry + (*StatusReply)(nil), // 4: sample.StatusReply +} +var file_forget_proto_depIdxs = []int32{ + 3, // 0: sample.ForgetReply.extend:type_name -> sample.ForgetReply.ExtendEntry + 0, // 1: sample.Forget.Verify:input_type -> sample.VerifyRequest + 1, // 2: sample.Forget.Reset:input_type -> sample.ForgetResetRequest + 4, // 3: sample.Forget.Verify:output_type -> sample.StatusReply + 2, // 4: sample.Forget.Reset:output_type -> sample.ForgetReply + 3, // [3:5] is the sub-list for method output_type + 1, // [1:3] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_forget_proto_init() } +func file_forget_proto_init() { + if File_forget_proto != nil { + return + } + file_blocks_proto_init() + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_forget_proto_rawDesc), len(file_forget_proto_rawDesc)), + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_forget_proto_goTypes, + DependencyIndexes: file_forget_proto_depIdxs, + MessageInfos: file_forget_proto_msgTypes, + }.Build() + File_forget_proto = out.File + file_forget_proto_goTypes = nil + file_forget_proto_depIdxs = nil +} diff --git a/pb/forget.pb.gw.go b/pb/forget.pb.gw.go new file mode 100644 index 0000000..cc79ca2 --- /dev/null +++ b/pb/forget.pb.gw.go @@ -0,0 +1,223 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: forget.proto + +/* +Package sample is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package sample + +import ( + "context" + "errors" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var ( + _ codes.Code + _ io.Reader + _ status.Status + _ = errors.New + _ = runtime.String + _ = utilities.NewDoubleArray + _ = metadata.Join +) + +func request_Forget_Verify_0(ctx context.Context, marshaler runtime.Marshaler, client ForgetClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq VerifyRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Verify(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Forget_Verify_0(ctx context.Context, marshaler runtime.Marshaler, server ForgetServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq VerifyRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Verify(ctx, &protoReq) + return msg, metadata, err +} + +func request_Forget_Reset_0(ctx context.Context, marshaler runtime.Marshaler, client ForgetClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq ForgetResetRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Reset(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Forget_Reset_0(ctx context.Context, marshaler runtime.Marshaler, server ForgetServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq ForgetResetRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Reset(ctx, &protoReq) + return msg, metadata, err +} + +// RegisterForgetHandlerServer registers the http handlers for service Forget to "mux". +// UnaryRPC :call ForgetServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterForgetHandlerFromEndpoint instead. +// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. +func RegisterForgetHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ForgetServer) error { + mux.Handle(http.MethodPost, pattern_Forget_Verify_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Forget/Verify", runtime.WithHTTPPathPattern("/sample.Forget/Verify")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Forget_Verify_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Forget_Verify_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Forget_Reset_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Forget/Reset", runtime.WithHTTPPathPattern("/sample.Forget/Reset")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Forget_Reset_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Forget_Reset_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + + return nil +} + +// RegisterForgetHandlerFromEndpoint is same as RegisterForgetHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterForgetHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.NewClient(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + return RegisterForgetHandler(ctx, mux, conn) +} + +// RegisterForgetHandler registers the http handlers for service Forget to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterForgetHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterForgetHandlerClient(ctx, mux, NewForgetClient(conn)) +} + +// RegisterForgetHandlerClient registers the http handlers for service Forget +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ForgetClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ForgetClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "ForgetClient" to call the correct interceptors. This client ignores the HTTP middlewares. +func RegisterForgetHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ForgetClient) error { + mux.Handle(http.MethodPost, pattern_Forget_Verify_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Forget/Verify", runtime.WithHTTPPathPattern("/sample.Forget/Verify")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Forget_Verify_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Forget_Verify_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Forget_Reset_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Forget/Reset", runtime.WithHTTPPathPattern("/sample.Forget/Reset")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Forget_Reset_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Forget_Reset_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + return nil +} + +var ( + pattern_Forget_Verify_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Forget", "Verify"}, "")) + pattern_Forget_Reset_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Forget", "Reset"}, "")) +) + +var ( + forward_Forget_Verify_0 = runtime.ForwardResponseMessage + forward_Forget_Reset_0 = runtime.ForwardResponseMessage +) diff --git a/pb/forget_grpc.pb.go b/pb/forget_grpc.pb.go new file mode 100644 index 0000000..56a3512 --- /dev/null +++ b/pb/forget_grpc.pb.go @@ -0,0 +1,168 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: forget.proto + +package sample + +import ( + context "context" + + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Forget_Verify_FullMethodName = "/sample.Forget/Verify" + Forget_Reset_FullMethodName = "/sample.Forget/Reset" +) + +// ForgetClient is the client API for Forget service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// sample-通行证模块 +type ForgetClient interface { + // 验证手机号和验证码 + Verify(ctx context.Context, in *VerifyRequest, opts ...grpc.CallOption) (*StatusReply, error) + // 重罢密码 + Reset(ctx context.Context, in *ForgetResetRequest, opts ...grpc.CallOption) (*ForgetReply, error) +} + +type forgetClient struct { + cc grpc.ClientConnInterface +} + +func NewForgetClient(cc grpc.ClientConnInterface) ForgetClient { + return &forgetClient{cc} +} + +func (c *forgetClient) Verify(ctx context.Context, in *VerifyRequest, opts ...grpc.CallOption) (*StatusReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(StatusReply) + err := c.cc.Invoke(ctx, Forget_Verify_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forgetClient) Reset(ctx context.Context, in *ForgetResetRequest, opts ...grpc.CallOption) (*ForgetReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ForgetReply) + err := c.cc.Invoke(ctx, Forget_Reset_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ForgetServer is the server API for Forget service. +// All implementations must embed UnimplementedForgetServer +// for forward compatibility. +// +// sample-通行证模块 +type ForgetServer interface { + // 验证手机号和验证码 + Verify(context.Context, *VerifyRequest) (*StatusReply, error) + // 重罢密码 + Reset(context.Context, *ForgetResetRequest) (*ForgetReply, error) + mustEmbedUnimplementedForgetServer() +} + +// UnimplementedForgetServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedForgetServer struct{} + +func (UnimplementedForgetServer) Verify(context.Context, *VerifyRequest) (*StatusReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Verify not implemented") +} +func (UnimplementedForgetServer) Reset(context.Context, *ForgetResetRequest) (*ForgetReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Reset not implemented") +} +func (UnimplementedForgetServer) mustEmbedUnimplementedForgetServer() {} +func (UnimplementedForgetServer) testEmbeddedByValue() {} + +// UnsafeForgetServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ForgetServer will +// result in compilation errors. +type UnsafeForgetServer interface { + mustEmbedUnimplementedForgetServer() +} + +func RegisterForgetServer(s grpc.ServiceRegistrar, srv ForgetServer) { + // If the following call pancis, it indicates UnimplementedForgetServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Forget_ServiceDesc, srv) +} + +func _Forget_Verify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(VerifyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForgetServer).Verify(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forget_Verify_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForgetServer).Verify(ctx, req.(*VerifyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Forget_Reset_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ForgetResetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForgetServer).Reset(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forget_Reset_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForgetServer).Reset(ctx, req.(*ForgetResetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Forget_ServiceDesc is the grpc.ServiceDesc for Forget service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Forget_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "sample.Forget", + HandlerType: (*ForgetServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Verify", + Handler: _Forget_Verify_Handler, + }, + { + MethodName: "Reset", + Handler: _Forget_Reset_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "forget.proto", +} diff --git a/pb/login.pb.go b/pb/login.pb.go new file mode 100644 index 0000000..c6d9b22 --- /dev/null +++ b/pb/login.pb.go @@ -0,0 +1,288 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.8 +// protoc (unknown) +// source: login.proto + +package sample + +import ( + reflect "reflect" + sync "sync" + unsafe "unsafe" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type LoginByPwdRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` // 账号 必填 + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` // 密码 必填 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LoginByPwdRequest) Reset() { + *x = LoginByPwdRequest{} + mi := &file_login_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LoginByPwdRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginByPwdRequest) ProtoMessage() {} + +func (x *LoginByPwdRequest) ProtoReflect() protoreflect.Message { + mi := &file_login_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginByPwdRequest.ProtoReflect.Descriptor instead. +func (*LoginByPwdRequest) Descriptor() ([]byte, []int) { + return file_login_proto_rawDescGZIP(), []int{0} +} + +func (x *LoginByPwdRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +func (x *LoginByPwdRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type LoginByCodeRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Country string `protobuf:"bytes,1,opt,name=country,proto3" json:"country,omitempty"` // 国家 + Phone string `protobuf:"bytes,2,opt,name=phone,proto3" json:"phone,omitempty"` // 手机号码 + Code string `protobuf:"bytes,3,opt,name=code,proto3" json:"code,omitempty"` // 验证码 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LoginByCodeRequest) Reset() { + *x = LoginByCodeRequest{} + mi := &file_login_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LoginByCodeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginByCodeRequest) ProtoMessage() {} + +func (x *LoginByCodeRequest) ProtoReflect() protoreflect.Message { + mi := &file_login_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginByCodeRequest.ProtoReflect.Descriptor instead. +func (*LoginByCodeRequest) Descriptor() ([]byte, []int) { + return file_login_proto_rawDescGZIP(), []int{1} +} + +func (x *LoginByCodeRequest) GetCountry() string { + if x != nil { + return x.Country + } + return "" +} + +func (x *LoginByCodeRequest) GetPhone() string { + if x != nil { + return x.Phone + } + return "" +} + +func (x *LoginByCodeRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +type LoginReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Identity string `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"` //用户唯一码 + Token string `protobuf:"bytes,3,opt,name=token,proto3" json:"token,omitempty"` //用户凭证 + Extend map[string]string `protobuf:"bytes,4,rep,name=extend,proto3" json:"extend,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` //扩展字段 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LoginReply) Reset() { + *x = LoginReply{} + mi := &file_login_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LoginReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginReply) ProtoMessage() {} + +func (x *LoginReply) ProtoReflect() protoreflect.Message { + mi := &file_login_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LoginReply.ProtoReflect.Descriptor instead. +func (*LoginReply) Descriptor() ([]byte, []int) { + return file_login_proto_rawDescGZIP(), []int{2} +} + +func (x *LoginReply) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *LoginReply) GetIdentity() string { + if x != nil { + return x.Identity + } + return "" +} + +func (x *LoginReply) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *LoginReply) GetExtend() map[string]string { + if x != nil { + return x.Extend + } + return nil +} + +var File_login_proto protoreflect.FileDescriptor + +const file_login_proto_rawDesc = "" + + "\n" + + "\vlogin.proto\x12\bsample\"I\n" + + "\x11LoginByPwdRequest\x12\x18\n" + + "\aaccount\x18\x01 \x01(\tR\aaccount\x12\x1a\n" + + "\bpassword\x18\x02 \x01(\tR\bpassword\"X\n" + + "\x12LoginByCodeRequest\x12\x18\n" + + "\acountry\x18\x01 \x01(\tR\acountry\x12\x14\n" + + "\x05phone\x18\x02 \x01(\tR\x05phone\x12\x12\n" + + "\x04code\x18\x03 \x01(\tR\x04code\"\xc3\x01\n" + + "\n" + + "LoginReply\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x1a\n" + + "\bidentity\x18\x02 \x01(\tR\bidentity\x12\x14\n" + + "\x05token\x18\x03 \x01(\tR\x05token\x128\n" + + "\x06extend\x18\x04 \x03(\v2 .sample.LoginReply.ExtendEntryR\x06extend\x1a9\n" + + "\vExtendEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x012\xca\x01\n" + + "\x05Login\x12:\n" + + "\x03Pwd\x12\x1b.sample.LoginByPwdRequest\x1a\x14.sample.LoginReply\"\x00\x12<\n" + + "\x04Code\x12\x1c.sample.LoginByCodeRequest\x1a\x14.sample.LoginReply\"\x00\x12G\n" + + "\x0fCodeAndRegister\x12\x1c.sample.LoginByCodeRequest\x1a\x14.sample.LoginReply\"\x00B\fZ\n" + + ".;sampleb\x06proto3" + +var ( + file_login_proto_rawDescOnce sync.Once + file_login_proto_rawDescData []byte +) + +func file_login_proto_rawDescGZIP() []byte { + file_login_proto_rawDescOnce.Do(func() { + file_login_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_login_proto_rawDesc), len(file_login_proto_rawDesc))) + }) + return file_login_proto_rawDescData +} + +var file_login_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_login_proto_goTypes = []any{ + (*LoginByPwdRequest)(nil), // 0: sample.LoginByPwdRequest + (*LoginByCodeRequest)(nil), // 1: sample.LoginByCodeRequest + (*LoginReply)(nil), // 2: sample.LoginReply + nil, // 3: sample.LoginReply.ExtendEntry +} +var file_login_proto_depIdxs = []int32{ + 3, // 0: sample.LoginReply.extend:type_name -> sample.LoginReply.ExtendEntry + 0, // 1: sample.Login.Pwd:input_type -> sample.LoginByPwdRequest + 1, // 2: sample.Login.Code:input_type -> sample.LoginByCodeRequest + 1, // 3: sample.Login.CodeAndRegister:input_type -> sample.LoginByCodeRequest + 2, // 4: sample.Login.Pwd:output_type -> sample.LoginReply + 2, // 5: sample.Login.Code:output_type -> sample.LoginReply + 2, // 6: sample.Login.CodeAndRegister:output_type -> sample.LoginReply + 4, // [4:7] is the sub-list for method output_type + 1, // [1:4] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_login_proto_init() } +func file_login_proto_init() { + if File_login_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_login_proto_rawDesc), len(file_login_proto_rawDesc)), + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_login_proto_goTypes, + DependencyIndexes: file_login_proto_depIdxs, + MessageInfos: file_login_proto_msgTypes, + }.Build() + File_login_proto = out.File + file_login_proto_goTypes = nil + file_login_proto_depIdxs = nil +} diff --git a/pb/login.pb.gw.go b/pb/login.pb.gw.go new file mode 100644 index 0000000..7e112a1 --- /dev/null +++ b/pb/login.pb.gw.go @@ -0,0 +1,289 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: login.proto + +/* +Package sample is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package sample + +import ( + "context" + "errors" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var ( + _ codes.Code + _ io.Reader + _ status.Status + _ = errors.New + _ = runtime.String + _ = utilities.NewDoubleArray + _ = metadata.Join +) + +func request_Login_Pwd_0(ctx context.Context, marshaler runtime.Marshaler, client LoginClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq LoginByPwdRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Pwd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Login_Pwd_0(ctx context.Context, marshaler runtime.Marshaler, server LoginServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq LoginByPwdRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Pwd(ctx, &protoReq) + return msg, metadata, err +} + +func request_Login_Code_0(ctx context.Context, marshaler runtime.Marshaler, client LoginClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq LoginByCodeRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Code(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Login_Code_0(ctx context.Context, marshaler runtime.Marshaler, server LoginServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq LoginByCodeRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Code(ctx, &protoReq) + return msg, metadata, err +} + +func request_Login_CodeAndRegister_0(ctx context.Context, marshaler runtime.Marshaler, client LoginClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq LoginByCodeRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.CodeAndRegister(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Login_CodeAndRegister_0(ctx context.Context, marshaler runtime.Marshaler, server LoginServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq LoginByCodeRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.CodeAndRegister(ctx, &protoReq) + return msg, metadata, err +} + +// RegisterLoginHandlerServer registers the http handlers for service Login to "mux". +// UnaryRPC :call LoginServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterLoginHandlerFromEndpoint instead. +// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. +func RegisterLoginHandlerServer(ctx context.Context, mux *runtime.ServeMux, server LoginServer) error { + mux.Handle(http.MethodPost, pattern_Login_Pwd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Login/Pwd", runtime.WithHTTPPathPattern("/sample.Login/Pwd")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Login_Pwd_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Login_Pwd_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Login_Code_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Login/Code", runtime.WithHTTPPathPattern("/sample.Login/Code")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Login_Code_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Login_Code_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Login_CodeAndRegister_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Login/CodeAndRegister", runtime.WithHTTPPathPattern("/sample.Login/CodeAndRegister")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Login_CodeAndRegister_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Login_CodeAndRegister_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + + return nil +} + +// RegisterLoginHandlerFromEndpoint is same as RegisterLoginHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterLoginHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.NewClient(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + return RegisterLoginHandler(ctx, mux, conn) +} + +// RegisterLoginHandler registers the http handlers for service Login to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterLoginHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterLoginHandlerClient(ctx, mux, NewLoginClient(conn)) +} + +// RegisterLoginHandlerClient registers the http handlers for service Login +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "LoginClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LoginClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "LoginClient" to call the correct interceptors. This client ignores the HTTP middlewares. +func RegisterLoginHandlerClient(ctx context.Context, mux *runtime.ServeMux, client LoginClient) error { + mux.Handle(http.MethodPost, pattern_Login_Pwd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Login/Pwd", runtime.WithHTTPPathPattern("/sample.Login/Pwd")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Login_Pwd_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Login_Pwd_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Login_Code_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Login/Code", runtime.WithHTTPPathPattern("/sample.Login/Code")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Login_Code_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Login_Code_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Login_CodeAndRegister_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Login/CodeAndRegister", runtime.WithHTTPPathPattern("/sample.Login/CodeAndRegister")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Login_CodeAndRegister_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Login_CodeAndRegister_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + return nil +} + +var ( + pattern_Login_Pwd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Login", "Pwd"}, "")) + pattern_Login_Code_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Login", "Code"}, "")) + pattern_Login_CodeAndRegister_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Login", "CodeAndRegister"}, "")) +) + +var ( + forward_Login_Pwd_0 = runtime.ForwardResponseMessage + forward_Login_Code_0 = runtime.ForwardResponseMessage + forward_Login_CodeAndRegister_0 = runtime.ForwardResponseMessage +) diff --git a/pb/login_grpc.pb.go b/pb/login_grpc.pb.go new file mode 100644 index 0000000..9ff0baf --- /dev/null +++ b/pb/login_grpc.pb.go @@ -0,0 +1,208 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: login.proto + +package sample + +import ( + context "context" + + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Login_Pwd_FullMethodName = "/sample.Login/Pwd" + Login_Code_FullMethodName = "/sample.Login/Code" + Login_CodeAndRegister_FullMethodName = "/sample.Login/CodeAndRegister" +) + +// LoginClient is the client API for Login service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// sample-通行证模块-登录 +type LoginClient interface { + // 通过密码登录 + Pwd(ctx context.Context, in *LoginByPwdRequest, opts ...grpc.CallOption) (*LoginReply, error) + // 通过验证码登录 + Code(ctx context.Context, in *LoginByCodeRequest, opts ...grpc.CallOption) (*LoginReply, error) + // 通过验证码登录并注册 + CodeAndRegister(ctx context.Context, in *LoginByCodeRequest, opts ...grpc.CallOption) (*LoginReply, error) +} + +type loginClient struct { + cc grpc.ClientConnInterface +} + +func NewLoginClient(cc grpc.ClientConnInterface) LoginClient { + return &loginClient{cc} +} + +func (c *loginClient) Pwd(ctx context.Context, in *LoginByPwdRequest, opts ...grpc.CallOption) (*LoginReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(LoginReply) + err := c.cc.Invoke(ctx, Login_Pwd_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *loginClient) Code(ctx context.Context, in *LoginByCodeRequest, opts ...grpc.CallOption) (*LoginReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(LoginReply) + err := c.cc.Invoke(ctx, Login_Code_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *loginClient) CodeAndRegister(ctx context.Context, in *LoginByCodeRequest, opts ...grpc.CallOption) (*LoginReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(LoginReply) + err := c.cc.Invoke(ctx, Login_CodeAndRegister_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// LoginServer is the server API for Login service. +// All implementations must embed UnimplementedLoginServer +// for forward compatibility. +// +// sample-通行证模块-登录 +type LoginServer interface { + // 通过密码登录 + Pwd(context.Context, *LoginByPwdRequest) (*LoginReply, error) + // 通过验证码登录 + Code(context.Context, *LoginByCodeRequest) (*LoginReply, error) + // 通过验证码登录并注册 + CodeAndRegister(context.Context, *LoginByCodeRequest) (*LoginReply, error) + mustEmbedUnimplementedLoginServer() +} + +// UnimplementedLoginServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedLoginServer struct{} + +func (UnimplementedLoginServer) Pwd(context.Context, *LoginByPwdRequest) (*LoginReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Pwd not implemented") +} +func (UnimplementedLoginServer) Code(context.Context, *LoginByCodeRequest) (*LoginReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Code not implemented") +} +func (UnimplementedLoginServer) CodeAndRegister(context.Context, *LoginByCodeRequest) (*LoginReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method CodeAndRegister not implemented") +} +func (UnimplementedLoginServer) mustEmbedUnimplementedLoginServer() {} +func (UnimplementedLoginServer) testEmbeddedByValue() {} + +// UnsafeLoginServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to LoginServer will +// result in compilation errors. +type UnsafeLoginServer interface { + mustEmbedUnimplementedLoginServer() +} + +func RegisterLoginServer(s grpc.ServiceRegistrar, srv LoginServer) { + // If the following call pancis, it indicates UnimplementedLoginServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Login_ServiceDesc, srv) +} + +func _Login_Pwd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginByPwdRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LoginServer).Pwd(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Login_Pwd_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LoginServer).Pwd(ctx, req.(*LoginByPwdRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Login_Code_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginByCodeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LoginServer).Code(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Login_Code_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LoginServer).Code(ctx, req.(*LoginByCodeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Login_CodeAndRegister_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginByCodeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LoginServer).CodeAndRegister(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Login_CodeAndRegister_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LoginServer).CodeAndRegister(ctx, req.(*LoginByCodeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Login_ServiceDesc is the grpc.ServiceDesc for Login service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Login_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "sample.Login", + HandlerType: (*LoginServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Pwd", + Handler: _Login_Pwd_Handler, + }, + { + MethodName: "Code", + Handler: _Login_Code_Handler, + }, + { + MethodName: "CodeAndRegister", + Handler: _Login_CodeAndRegister_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "login.proto", +} diff --git a/pb/register.pb.go b/pb/register.pb.go new file mode 100644 index 0000000..73c5bdc --- /dev/null +++ b/pb/register.pb.go @@ -0,0 +1,282 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.8 +// protoc (unknown) +// source: register.proto + +package sample + +import ( + reflect "reflect" + sync "sync" + unsafe "unsafe" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type RegisterRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` //邮箱 + Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"` //帐号 + Phone string `protobuf:"bytes,3,opt,name=phone,proto3" json:"phone,omitempty"` //手机号 + Password string `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"` //密码 + Code string `protobuf:"bytes,5,opt,name=code,proto3" json:"code,omitempty"` //验证码 + AgencyId int64 `protobuf:"varint,6,opt,name=agency_id,json=agencyId,proto3" json:"agency_id,omitempty"` // 代理ID + StaffId int64 `protobuf:"varint,7,opt,name=staff_id,json=staffId,proto3" json:"staff_id,omitempty"` // 工作人员ID + OwnerId int64 `protobuf:"varint,8,opt,name=owner_id,proto3" json:"owner_id,omitempty"` // 所属ID + OwnerIdentity string `protobuf:"bytes,9,opt,name=owner_identity,proto3" json:"owner_identity,omitempty"` // 所属唯一码 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RegisterRequest) Reset() { + *x = RegisterRequest{} + mi := &file_register_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RegisterRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterRequest) ProtoMessage() {} + +func (x *RegisterRequest) ProtoReflect() protoreflect.Message { + mi := &file_register_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegisterRequest.ProtoReflect.Descriptor instead. +func (*RegisterRequest) Descriptor() ([]byte, []int) { + return file_register_proto_rawDescGZIP(), []int{0} +} + +func (x *RegisterRequest) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *RegisterRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +func (x *RegisterRequest) GetPhone() string { + if x != nil { + return x.Phone + } + return "" +} + +func (x *RegisterRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +func (x *RegisterRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +func (x *RegisterRequest) GetAgencyId() int64 { + if x != nil { + return x.AgencyId + } + return 0 +} + +func (x *RegisterRequest) GetStaffId() int64 { + if x != nil { + return x.StaffId + } + return 0 +} + +func (x *RegisterRequest) GetOwnerId() int64 { + if x != nil { + return x.OwnerId + } + return 0 +} + +func (x *RegisterRequest) GetOwnerIdentity() string { + if x != nil { + return x.OwnerIdentity + } + return "" +} + +type RegisterReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Identity string `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"` //用户唯一码 + Token string `protobuf:"bytes,4,opt,name=token,proto3" json:"token,omitempty"` //用户Header所需Token + Extend map[string]string `protobuf:"bytes,5,rep,name=extend,proto3" json:"extend,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` //扩展字段 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RegisterReply) Reset() { + *x = RegisterReply{} + mi := &file_register_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RegisterReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterReply) ProtoMessage() {} + +func (x *RegisterReply) ProtoReflect() protoreflect.Message { + mi := &file_register_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegisterReply.ProtoReflect.Descriptor instead. +func (*RegisterReply) Descriptor() ([]byte, []int) { + return file_register_proto_rawDescGZIP(), []int{1} +} + +func (x *RegisterReply) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *RegisterReply) GetIdentity() string { + if x != nil { + return x.Identity + } + return "" +} + +func (x *RegisterReply) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *RegisterReply) GetExtend() map[string]string { + if x != nil { + return x.Extend + } + return nil +} + +var File_register_proto protoreflect.FileDescriptor + +const file_register_proto_rawDesc = "" + + "\n" + + "\x0eregister.proto\x12\bsample\"\x83\x02\n" + + "\x0fRegisterRequest\x12\x14\n" + + "\x05email\x18\x01 \x01(\tR\x05email\x12\x18\n" + + "\aaccount\x18\x02 \x01(\tR\aaccount\x12\x14\n" + + "\x05phone\x18\x03 \x01(\tR\x05phone\x12\x1a\n" + + "\bpassword\x18\x04 \x01(\tR\bpassword\x12\x12\n" + + "\x04code\x18\x05 \x01(\tR\x04code\x12\x1b\n" + + "\tagency_id\x18\x06 \x01(\x03R\bagencyId\x12\x19\n" + + "\bstaff_id\x18\a \x01(\x03R\astaffId\x12\x1a\n" + + "\bowner_id\x18\b \x01(\x03R\bowner_id\x12&\n" + + "\x0eowner_identity\x18\t \x01(\tR\x0eowner_identity\"\xc9\x01\n" + + "\rRegisterReply\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x1a\n" + + "\bidentity\x18\x02 \x01(\tR\bidentity\x12\x14\n" + + "\x05token\x18\x04 \x01(\tR\x05token\x12;\n" + + "\x06extend\x18\x05 \x03(\v2#.sample.RegisterReply.ExtendEntryR\x06extend\x1a9\n" + + "\vExtendEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x012\x85\x01\n" + + "\bRegister\x12;\n" + + "\x03Pwd\x12\x19.sample.RegisterRequest\x1a\x17.sample.RegisterReply\"\x00\x12<\n" + + "\x04Code\x12\x19.sample.RegisterRequest\x1a\x17.sample.RegisterReply\"\x00B\fZ\n" + + ".;sampleb\x06proto3" + +var ( + file_register_proto_rawDescOnce sync.Once + file_register_proto_rawDescData []byte +) + +func file_register_proto_rawDescGZIP() []byte { + file_register_proto_rawDescOnce.Do(func() { + file_register_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_register_proto_rawDesc), len(file_register_proto_rawDesc))) + }) + return file_register_proto_rawDescData +} + +var file_register_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_register_proto_goTypes = []any{ + (*RegisterRequest)(nil), // 0: sample.RegisterRequest + (*RegisterReply)(nil), // 1: sample.RegisterReply + nil, // 2: sample.RegisterReply.ExtendEntry +} +var file_register_proto_depIdxs = []int32{ + 2, // 0: sample.RegisterReply.extend:type_name -> sample.RegisterReply.ExtendEntry + 0, // 1: sample.Register.Pwd:input_type -> sample.RegisterRequest + 0, // 2: sample.Register.Code:input_type -> sample.RegisterRequest + 1, // 3: sample.Register.Pwd:output_type -> sample.RegisterReply + 1, // 4: sample.Register.Code:output_type -> sample.RegisterReply + 3, // [3:5] is the sub-list for method output_type + 1, // [1:3] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_register_proto_init() } +func file_register_proto_init() { + if File_register_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_register_proto_rawDesc), len(file_register_proto_rawDesc)), + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_register_proto_goTypes, + DependencyIndexes: file_register_proto_depIdxs, + MessageInfos: file_register_proto_msgTypes, + }.Build() + File_register_proto = out.File + file_register_proto_goTypes = nil + file_register_proto_depIdxs = nil +} diff --git a/pb/register.pb.gw.go b/pb/register.pb.gw.go new file mode 100644 index 0000000..66ca124 --- /dev/null +++ b/pb/register.pb.gw.go @@ -0,0 +1,223 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: register.proto + +/* +Package sample is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package sample + +import ( + "context" + "errors" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var ( + _ codes.Code + _ io.Reader + _ status.Status + _ = errors.New + _ = runtime.String + _ = utilities.NewDoubleArray + _ = metadata.Join +) + +func request_Register_Pwd_0(ctx context.Context, marshaler runtime.Marshaler, client RegisterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq RegisterRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Pwd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Register_Pwd_0(ctx context.Context, marshaler runtime.Marshaler, server RegisterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq RegisterRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Pwd(ctx, &protoReq) + return msg, metadata, err +} + +func request_Register_Code_0(ctx context.Context, marshaler runtime.Marshaler, client RegisterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq RegisterRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + msg, err := client.Code(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Register_Code_0(ctx context.Context, marshaler runtime.Marshaler, server RegisterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq RegisterRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Code(ctx, &protoReq) + return msg, metadata, err +} + +// RegisterRegisterHandlerServer registers the http handlers for service Register to "mux". +// UnaryRPC :call RegisterServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterRegisterHandlerFromEndpoint instead. +// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. +func RegisterRegisterHandlerServer(ctx context.Context, mux *runtime.ServeMux, server RegisterServer) error { + mux.Handle(http.MethodPost, pattern_Register_Pwd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Register/Pwd", runtime.WithHTTPPathPattern("/sample.Register/Pwd")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Register_Pwd_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Register_Pwd_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Register_Code_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sample.Register/Code", runtime.WithHTTPPathPattern("/sample.Register/Code")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Register_Code_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Register_Code_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + + return nil +} + +// RegisterRegisterHandlerFromEndpoint is same as RegisterRegisterHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterRegisterHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.NewClient(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + return RegisterRegisterHandler(ctx, mux, conn) +} + +// RegisterRegisterHandler registers the http handlers for service Register to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterRegisterHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterRegisterHandlerClient(ctx, mux, NewRegisterClient(conn)) +} + +// RegisterRegisterHandlerClient registers the http handlers for service Register +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "RegisterClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "RegisterClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "RegisterClient" to call the correct interceptors. This client ignores the HTTP middlewares. +func RegisterRegisterHandlerClient(ctx context.Context, mux *runtime.ServeMux, client RegisterClient) error { + mux.Handle(http.MethodPost, pattern_Register_Pwd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Register/Pwd", runtime.WithHTTPPathPattern("/sample.Register/Pwd")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Register_Pwd_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Register_Pwd_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPost, pattern_Register_Code_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/sample.Register/Code", runtime.WithHTTPPathPattern("/sample.Register/Code")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Register_Code_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_Register_Code_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + return nil +} + +var ( + pattern_Register_Pwd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Register", "Pwd"}, "")) + pattern_Register_Code_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"sample.Register", "Code"}, "")) +) + +var ( + forward_Register_Pwd_0 = runtime.ForwardResponseMessage + forward_Register_Code_0 = runtime.ForwardResponseMessage +) diff --git a/pb/register_grpc.pb.go b/pb/register_grpc.pb.go new file mode 100644 index 0000000..7471730 --- /dev/null +++ b/pb/register_grpc.pb.go @@ -0,0 +1,168 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: register.proto + +package sample + +import ( + context "context" + + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Register_Pwd_FullMethodName = "/sample.Register/Pwd" + Register_Code_FullMethodName = "/sample.Register/Code" +) + +// RegisterClient is the client API for Register service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// sample-通行证模块-注册 +type RegisterClient interface { + // 帐号密码注册 + Pwd(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterReply, error) + // 手机验证码注册 + Code(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterReply, error) +} + +type registerClient struct { + cc grpc.ClientConnInterface +} + +func NewRegisterClient(cc grpc.ClientConnInterface) RegisterClient { + return ®isterClient{cc} +} + +func (c *registerClient) Pwd(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RegisterReply) + err := c.cc.Invoke(ctx, Register_Pwd_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *registerClient) Code(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RegisterReply) + err := c.cc.Invoke(ctx, Register_Code_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RegisterServer is the server API for Register service. +// All implementations must embed UnimplementedRegisterServer +// for forward compatibility. +// +// sample-通行证模块-注册 +type RegisterServer interface { + // 帐号密码注册 + Pwd(context.Context, *RegisterRequest) (*RegisterReply, error) + // 手机验证码注册 + Code(context.Context, *RegisterRequest) (*RegisterReply, error) + mustEmbedUnimplementedRegisterServer() +} + +// UnimplementedRegisterServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedRegisterServer struct{} + +func (UnimplementedRegisterServer) Pwd(context.Context, *RegisterRequest) (*RegisterReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Pwd not implemented") +} +func (UnimplementedRegisterServer) Code(context.Context, *RegisterRequest) (*RegisterReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method Code not implemented") +} +func (UnimplementedRegisterServer) mustEmbedUnimplementedRegisterServer() {} +func (UnimplementedRegisterServer) testEmbeddedByValue() {} + +// UnsafeRegisterServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to RegisterServer will +// result in compilation errors. +type UnsafeRegisterServer interface { + mustEmbedUnimplementedRegisterServer() +} + +func RegisterRegisterServer(s grpc.ServiceRegistrar, srv RegisterServer) { + // If the following call pancis, it indicates UnimplementedRegisterServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Register_ServiceDesc, srv) +} + +func _Register_Pwd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegisterRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegisterServer).Pwd(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Register_Pwd_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegisterServer).Pwd(ctx, req.(*RegisterRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Register_Code_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegisterRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegisterServer).Code(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Register_Code_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegisterServer).Code(ctx, req.(*RegisterRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Register_ServiceDesc is the grpc.ServiceDesc for Register service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Register_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "sample.Register", + HandlerType: (*RegisterServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Pwd", + Handler: _Register_Pwd_Handler, + }, + { + MethodName: "Code", + Handler: _Register_Code_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "register.proto", +} diff --git a/proto/blocks.proto b/proto/blocks.proto new file mode 100644 index 0000000..0868ea2 --- /dev/null +++ b/proto/blocks.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; +package sample; +option go_package = ".;sample"; + + +message Empty{ +} + +message FetchRequest { + int64 page_no=1; // 页数 + int64 page_size=2; // 每页记录数 + map params=3; // 条件参数,key=val,eg key:category_id=?,vlaue=11 +} + +message IdentRequest{ + int64 id = 1; // 唯一ID + string identity = 2; // 唯一码 +} + +message VersionRequest { + int64 version=1; // 时序版本号 +} + + +message SearchRequest { + string keyword=1; //关键词 +} + + +message StatusReply{ + string data=1; // 数据 + int64 timeseq=2; // 响应时间序列 +} diff --git a/proto/sample.proto b/proto/sample.proto new file mode 100644 index 0000000..b6e2356 --- /dev/null +++ b/proto/sample.proto @@ -0,0 +1,82 @@ +syntax = "proto3"; +package sample; +option go_package = ".;sample"; +import "blocks.proto"; + +// sample(会员通行证)模块-数据 +service Account{ + // 通过会员所有信息 + rpc Get(Empty) returns (GetFullReply) {} + + // 更新会员的信息数据,字段值为空或是0,将不更新此数据 + rpc SetData(SetDataRequest) returns (StatusReply) {} + + // 更新会员的密码 + rpc SetPassword(SetPasswordRequest) returns (StatusReply) {} + + // 新增标签 + rpc TagCreate(TagItem) returns (StatusReply) {} + + // 删除标签 + rpc TagRemove(IdentRequest) returns (StatusReply) {} + + // 获取会员的相关统计数据 + rpc Statistics(StatisticsRequest) returns (StatisticsReply) {} +} + +// 获取会员的完整信息 +message GetFullReply { + string identity = 1; // 唯一标识 + string account = 2; // 帐号 + string phone = 3; // 手机号码 必填 + string email = 4; // 验证码 + string rights = 5; // 权限 + string nickname = 6; // 昵称 + string avatar = 7; // 头像 + string birthday = 8; // 生日 + int32 sex = 9; // 性别,1为男性,2为女性 + int32 country = 10; // 国家 + int32 province = 11; // 省 + int32 city = 12; // 市 + int32 area = 13; // 区 + string sign = 14; // 签名 + string cover = 15; // 背景&封面 + int32 score = 16; // 积分 + int32 level = 17; // 等级 + map verify = 18; // 数据 + repeated TagItem tags = 19; +} + +message TagItem { + string name = 1; + string icon = 2; +} + +message SetDataRequest { + string nickname = 1; //昵称 + string avatar = 2; //头像 + string birthday = 3; //生日 + int32 sex = 4; //性别,1为男性,2为女性 + int32 country = 5; // 国家 + int32 province = 6; //省 + int32 city = 7; //市 + int32 area = 8; //区 + string sign = 9; //签名 + string cover = 10; // 背景&封面 + int32 score = 11; // 积分 + int32 level = 12; // 等级 +} + +message SetPasswordRequest { + string old_password = 3; // 旧密码 + string new_password = 4;// 新密码 +} + + +message StatisticsRequest { + repeated string field = 1; //要获取的统计数据字段。 +} + +message StatisticsReply { + map Data=1; //数据以Map格式输出 +} \ No newline at end of file diff --git a/scripts/filebeat.yaml b/scripts/filebeat.yaml new file mode 100644 index 0000000..103c7da --- /dev/null +++ b/scripts/filebeat.yaml @@ -0,0 +1,32 @@ +filebeat.inputs: +- type: log + enabled: true + # 开启json解析 + json.keys_under_root: true + json.add_error_key: true + # 日志文件路径 + paths: + - ./logs/content/error.log + - ./logs/content/slow.log + +setup.template.settings: + index.number_of_shards: 1 + +# 定义kafka topic field +fields: + log_topic: scf.pb.dev + +# 输出到kafka +output.kafka: + hosts: ["127.0.0.1:9092"] + topic: '%{[fields.log_topic]}' + partition.round_robin: + reachable_only: false + required_acks: 1 + keep_alive: 10s + +# ================================= Processors ================================= +processors: + - decode_json_fields: + fields: ['@timestamp','level','content','trace','span','duration'] + target: "" \ No newline at end of file diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100644 index 0000000..ef3eaa3 --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,5 @@ +#install +go install github.com/securego/gosec/v2/cmd/gosec@latest + +#run +gosec -fmt=json -out=./test/lint/gosec.json ./... \ No newline at end of file diff --git a/swagger/passport.swagger.json b/swagger/passport.swagger.json new file mode 100644 index 0000000..eff227f --- /dev/null +++ b/swagger/passport.swagger.json @@ -0,0 +1,263 @@ +{ + "swagger": "2.0", + "info": { + "title": "blocks.proto", + "version": "version not set" + }, + "tags": [ + { + "name": "Account" + }, + { + "name": "Forget" + }, + { + "name": "Login" + }, + { + "name": "Register" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": {}, + "definitions": { + "sampleForgetReply": { + "type": "object", + "properties": { + "identity": { + "type": "string", + "title": "用户唯一码" + }, + "dataBind": { + "type": "string", + "title": "数据绑定的相关说明,PASS通过,NOPHONE没有绑定手机号,NOPWD没有设置密码,NOBIND没有手机号同时没有密码" + }, + "token": { + "type": "string", + "title": "用户凭证" + }, + "extend": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "title": "扩展字段" + } + } + }, + "sampleGetFullReply": { + "type": "object", + "properties": { + "identity": { + "type": "string", + "title": "唯一标识" + }, + "account": { + "type": "string", + "title": "帐号" + }, + "phone": { + "type": "string", + "title": "手机号码 必填" + }, + "email": { + "type": "string", + "title": "验证码" + }, + "rights": { + "type": "string", + "title": "权限" + }, + "nickname": { + "type": "string", + "title": "昵称" + }, + "avatar": { + "type": "string", + "title": "头像" + }, + "birthday": { + "type": "string", + "title": "生日" + }, + "sex": { + "type": "integer", + "format": "int32", + "title": "性别,1为男性,2为女性" + }, + "country": { + "type": "integer", + "format": "int32", + "title": "国家" + }, + "province": { + "type": "integer", + "format": "int32", + "title": "省" + }, + "city": { + "type": "integer", + "format": "int32", + "title": "市" + }, + "area": { + "type": "integer", + "format": "int32", + "title": "区" + }, + "sign": { + "type": "string", + "title": "签名" + }, + "cover": { + "type": "string", + "title": "背景\u0026封面" + }, + "score": { + "type": "integer", + "format": "int32", + "title": "积分" + }, + "level": { + "type": "integer", + "format": "int32", + "title": "等级" + }, + "verify": { + "type": "object", + "additionalProperties": { + "type": "boolean" + }, + "title": "数据" + }, + "tags": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/sampleTagItem" + } + } + }, + "title": "获取会员的完整信息" + }, + "sampleLoginReply": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "int64" + }, + "identity": { + "type": "string", + "title": "用户唯一码" + }, + "token": { + "type": "string", + "title": "用户凭证" + }, + "extend": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "title": "扩展字段" + } + } + }, + "sampleRegisterReply": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "int64" + }, + "identity": { + "type": "string", + "title": "用户唯一码" + }, + "token": { + "type": "string", + "title": "用户Header所需Token" + }, + "extend": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "title": "扩展字段" + } + } + }, + "sampleStatisticsReply": { + "type": "object", + "properties": { + "Data": { + "type": "object", + "additionalProperties": { + "type": "string", + "format": "int64" + }, + "title": "数据以Map格式输出" + } + } + }, + "sampleStatusReply": { + "type": "object", + "properties": { + "data": { + "type": "string", + "title": "数据" + }, + "timeseq": { + "type": "string", + "format": "int64", + "title": "响应时间序列" + } + } + }, + "sampleTagItem": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "icon": { + "type": "string" + } + } + }, + "protobufAny": { + "type": "object", + "properties": { + "@type": { + "type": "string" + } + }, + "additionalProperties": {} + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/test/login-pwd.http b/test/login-pwd.http new file mode 100644 index 0000000..4c6e129 --- /dev/null +++ b/test/login-pwd.http @@ -0,0 +1,9 @@ +POST http://127.0.0.1:12425/sample.Login/Pwd +content-type: application/json +Authorization:k7941AQvJ0LVU9e0LMVYZHdXQLODADEHq7yOGeXL7IzUVEZMU3pjIWt28Gd+VB7SsUq3xFdFIzBmeq/fpzAlLhv9zELYcrwEXCVWM7W0YK/rx5MgSK2Ji40rpwB1rYaNEFglWh1b70clbGbx2l/GwFmPqcCxyhG9qUIJu59ICmu2OoY3tGJ2eEBXqgHjmcYBFwMULk5YJrhTu2cPEGjQH5vfV8v9YoiJbATqO22bxwpg54ph1KUP4fODFDkYkVWkIjv1gMzJUARjoJiczyCsmW4qw7aDvGMmmcY0AV7W/nuK1byFCQo8La3+kULvY/X6 + +{ + "account": "admin", + "password": "password" + +} \ No newline at end of file diff --git a/test/readme.md b/test/readme.md new file mode 100644 index 0000000..bf52021 --- /dev/null +++ b/test/readme.md @@ -0,0 +1 @@ +restful test \ No newline at end of file