generate account

This commit is contained in:
daniel.w 2024-08-21 08:21:29 +08:00
parent acd5976a9e
commit 518cb03b4b
8 changed files with 207 additions and 16 deletions

49
Makefile Normal file
View File

@ -0,0 +1,49 @@
GO_CTL_NAME=goctl
# go-zero 生成風格
GO_ZERO_STYLE=go_zero
GO ?= go
GOFMT ?= gofmt "-s"
GOFILES := $(shell find . -name "*.go")
LDFLAGS := -s -w
VERSION="v1.0.3"
DOCKER_REPO="igs170911/notification"
.PHONY: test
test: # 進行測試
go test -v --cover ./...
.PHONY: fmt
fmt: # 格式優化
$(GOFMT) -w $(GOFILES)
goimports -w ./
.PHONY: gen-rpc
gen-rpc: # 建立 rpc code
$(GO_CTL_NAME) rpc protoc ./generate/protobuf/service.proto -m --style=$(GO_ZERO_STYLE) --go_out=./gen_result/pb --go-grpc_out=./gen_result/pb --zrpc_out=.
copy ./etc/service.yaml ./etc/service.example.yaml
go mod tidy
@echo "Generate core-api files successfully"
.PHONY: gen-clean
gen-clean: # 建立 rpc code
rm -rf ./client
rm -rf ./etc
rm -rf ./gen_result
rm -rf ./internal
rm -rf go.mod
rm -rf go.sum
rm -rf service.go
@echo "Generate core-api files successfully"
.PHONY: run-docker
run-docker: # 建立 rpc code
docker run --platform=linux/arm64/v8 -p 8080:8080 $(DOCKER_REPO):$(VERSION)
.PHONY: build-docker
build-docker:
cp ./build/Dockerfile Dockerfile
docker buildx build -t $(DOCKER_REPO):$(VERSION) --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/ed_25519)" .
rm -rf Dockerfile
@echo "Generate core-api files successfully"

View File

@ -2,6 +2,7 @@ CREATE TABLE `account_to_uid` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`account` VARCHAR(50) NOT NULL,
`uid` VARCHAR(255) NOT NULL,
`type` tinyint DEFAULT 0 NOT NULL COMMENT '1 手機 2 信箱 3 自定義帳號',
PRIMARY KEY (`id`),
UNIQUE INDEX `uk_account` (`account` ASC),
INDEX `idx_uid` (`uid` ASC)

View File

@ -3,12 +3,11 @@ CREATE TABLE `user_table` (
`verify_type` tinyint DEFAULT 0 NOT NULL COMMENT '驗證類型 0. 異常 1.信箱 2.手機 3. GA 4.不驗證',
`alarm_type` tinyint DEFAULT 0 NOT NULL COMMENT '告警狀態 0. 異常 1. 正常(未告警) 2.系統告警中',
`status` tinyint DEFAULT 0 NOT NULL COMMENT '會員狀態 0. 異常 1. 尚未驗證 2. 啟用 3. 停權中 4. 信箱以驗證 5. 手機以驗證 6. GA 以驗證',
`uid` VARCHAR(255) NOT NULL,
`language` VARCHAR(255) NOT NULL DEFAULT '',
`currency` VARCHAR(255) NOT NULL DEFAULT '',
`nick_name` VARCHAR(255) DEFAULT '',
`gender` tinyint DEFAULT 0 NOT NULL COMMENT '0. 不願透露, 1 男 2 女',
`birthday` INT NOT NULL DEFAULT 0,
`uid` VARCHAR(255) NOT NULL COMMENT '唯一辨識碼',
`nick_name` VARCHAR(255) DEFAULT '' COMMENT '暱稱',
`language` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '使用語言',
`currency` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '使用幣別',
`avatar` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '會員頭像',
`create_time` BIGINT NOT NULL DEFAULT 0,
`update_time` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),

View File

@ -8,7 +8,7 @@ enum VerifyType {
VERIFY_NONE = 0; //
VERIFY_EMAIL = 1;
VERIFY_PHONE = 2;
VERIFY_GOOGLE = 3;
VERIFY_GOOGLE = 3; // google
}
enum AlarmType {
@ -65,6 +65,7 @@ message CreateLoginUserReq {
message BindingUserReq {
string uid = 1;
string login_id = 2;
int64 type = 3;
}
message CreateUserInfoReq {
@ -152,9 +153,8 @@ message UserInfo {
MemberStatus status = 4;
string language = 5;
string currency = 6;
optional string nick_name = 7;
optional uint32 gender = 8;
optional int64 birthday = 9;
string avatar = 7;
optional string nick_name = 8;
}
message GetUserInfoResp {
@ -186,25 +186,20 @@ service Account {
rpc GetUserAccountInfo(GetUIDByAccountReq) returns(GetAccountInfoResp);
// UpdateUserToken
rpc UpdateUserToken(UpdateTokenReq) returns(Response);
// GetUidByAccount UID
rpc GetUidByAccount(GetUIDByAccountReq) returns(GetUidByAccountResp);
// BindAccount -> account bind to UID
rpc BindAccount(BindingUserReq) returns(Response);
// BindUserInfo User Info
rpc BindUserInfo(CreateUserInfoReq) returns(Response);
// UpdateUserInfo User Info
rpc UpdateUserInfo(UpdateUserInfoReq) returns(Response);
// UpdateStatus
rpc UpdateStatus(UpdateStatusReq) returns(Response);
// UpdateStatus
// GetUserInfo
rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
// ListMember
rpc ListMember(ListUserInfoReq) returns(ListUserInfoResp);
// GenerateRefreshCode
rpc GenerateRefreshCode(GenerateRefreshCodeReq) returns(GenerateRefreshCodeResp);
// VerifyRefreshCode token

88
go.mod Normal file
View File

@ -0,0 +1,88 @@
module app-cloudep-member-server
go 1.22.3
require (
github.com/zeromicro/go-zero v1.7.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
)
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/redis/go-redis/v9 v9.6.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.15 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
go.etcd.io/etcd/client/v3 v3.5.15 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.3 // indirect
k8s.io/apimachinery v0.29.4 // indirect
k8s.io/client-go v0.29.3 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

7
internal/config/config.go Executable file
View File

@ -0,0 +1,7 @@
package config
import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
}

View File

@ -0,0 +1,13 @@
package svc
import "app-cloudep-member-server/internal/config"
type ServiceContext struct {
Config config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}

39
service.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"flag"
"fmt"
"app-cloudep-member-server/gen_result/pb/member"
"app-cloudep-member-server/internal/config"
accountServer "app-cloudep-member-server/internal/server/account"
"app-cloudep-member-server/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/service.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
member.RegisterAccountServer(grpcServer, accountServer.NewAccountServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}