feature/init_member #1
|
@ -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"
|
|
@ -2,6 +2,7 @@ CREATE TABLE `account_to_uid` (
|
||||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||||
`account` VARCHAR(50) NOT NULL,
|
`account` VARCHAR(50) NOT NULL,
|
||||||
`uid` VARCHAR(255) NOT NULL,
|
`uid` VARCHAR(255) NOT NULL,
|
||||||
|
`type` tinyint DEFAULT 0 NOT NULL COMMENT '1 手機 2 信箱 3 自定義帳號',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE INDEX `uk_account` (`account` ASC),
|
UNIQUE INDEX `uk_account` (`account` ASC),
|
||||||
INDEX `idx_uid` (`uid` ASC)
|
INDEX `idx_uid` (`uid` ASC)
|
||||||
|
|
|
@ -3,12 +3,11 @@ CREATE TABLE `user_table` (
|
||||||
`verify_type` tinyint DEFAULT 0 NOT NULL COMMENT '驗證類型 0. 異常 1.信箱 2.手機 3. GA 4.不驗證',
|
`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.系統告警中',
|
`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 以驗證',
|
`status` tinyint DEFAULT 0 NOT NULL COMMENT '會員狀態 0. 異常 1. 尚未驗證 2. 啟用 3. 停權中 4. 信箱以驗證 5. 手機以驗證 6. GA 以驗證',
|
||||||
`uid` VARCHAR(255) NOT NULL,
|
`uid` VARCHAR(255) NOT NULL COMMENT '唯一辨識碼',
|
||||||
`language` VARCHAR(255) NOT NULL DEFAULT '',
|
`nick_name` VARCHAR(255) DEFAULT '' COMMENT '暱稱',
|
||||||
`currency` VARCHAR(255) NOT NULL DEFAULT '',
|
`language` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '使用語言',
|
||||||
`nick_name` VARCHAR(255) DEFAULT '',
|
`currency` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '使用幣別',
|
||||||
`gender` tinyint DEFAULT 0 NOT NULL COMMENT '0. 不願透露, 1 男 2 女',
|
`avatar` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '會員頭像',
|
||||||
`birthday` INT NOT NULL DEFAULT 0,
|
|
||||||
`create_time` BIGINT NOT NULL DEFAULT 0,
|
`create_time` BIGINT NOT NULL DEFAULT 0,
|
||||||
`update_time` BIGINT NOT NULL DEFAULT 0,
|
`update_time` BIGINT NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
|
|
|
@ -8,7 +8,7 @@ enum VerifyType {
|
||||||
VERIFY_NONE = 0; // 初始(異常)
|
VERIFY_NONE = 0; // 初始(異常)
|
||||||
VERIFY_EMAIL = 1;
|
VERIFY_EMAIL = 1;
|
||||||
VERIFY_PHONE = 2;
|
VERIFY_PHONE = 2;
|
||||||
VERIFY_GOOGLE = 3;
|
VERIFY_GOOGLE = 3; // google 驗證器
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AlarmType {
|
enum AlarmType {
|
||||||
|
@ -65,6 +65,7 @@ message CreateLoginUserReq {
|
||||||
message BindingUserReq {
|
message BindingUserReq {
|
||||||
string uid = 1;
|
string uid = 1;
|
||||||
string login_id = 2;
|
string login_id = 2;
|
||||||
|
int64 type = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateUserInfoReq {
|
message CreateUserInfoReq {
|
||||||
|
@ -152,9 +153,8 @@ message UserInfo {
|
||||||
MemberStatus status = 4;
|
MemberStatus status = 4;
|
||||||
string language = 5;
|
string language = 5;
|
||||||
string currency = 6;
|
string currency = 6;
|
||||||
optional string nick_name = 7;
|
string avatar = 7;
|
||||||
optional uint32 gender = 8;
|
optional string nick_name = 8;
|
||||||
optional int64 birthday = 9;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetUserInfoResp {
|
message GetUserInfoResp {
|
||||||
|
@ -186,25 +186,20 @@ service Account {
|
||||||
rpc GetUserAccountInfo(GetUIDByAccountReq) returns(GetAccountInfoResp);
|
rpc GetUserAccountInfo(GetUIDByAccountReq) returns(GetAccountInfoResp);
|
||||||
// UpdateUserToken 更新密碼
|
// UpdateUserToken 更新密碼
|
||||||
rpc UpdateUserToken(UpdateTokenReq) returns(Response);
|
rpc UpdateUserToken(UpdateTokenReq) returns(Response);
|
||||||
|
|
||||||
|
|
||||||
// GetUidByAccount 用帳號換取 UID
|
// GetUidByAccount 用帳號換取 UID
|
||||||
rpc GetUidByAccount(GetUIDByAccountReq) returns(GetUidByAccountResp);
|
rpc GetUidByAccount(GetUIDByAccountReq) returns(GetUidByAccountResp);
|
||||||
// BindAccount 綁定帳號 -> account bind to UID
|
// BindAccount 綁定帳號 -> account bind to UID
|
||||||
rpc BindAccount(BindingUserReq) returns(Response);
|
rpc BindAccount(BindingUserReq) returns(Response);
|
||||||
|
|
||||||
|
|
||||||
// BindUserInfo 初次,綁定 User Info
|
// BindUserInfo 初次,綁定 User Info
|
||||||
rpc BindUserInfo(CreateUserInfoReq) returns(Response);
|
rpc BindUserInfo(CreateUserInfoReq) returns(Response);
|
||||||
// UpdateUserInfo 更新 User Info
|
// UpdateUserInfo 更新 User Info
|
||||||
rpc UpdateUserInfo(UpdateUserInfoReq) returns(Response);
|
rpc UpdateUserInfo(UpdateUserInfoReq) returns(Response);
|
||||||
// UpdateStatus 修改狀態
|
// UpdateStatus 修改狀態
|
||||||
rpc UpdateStatus(UpdateStatusReq) returns(Response);
|
rpc UpdateStatus(UpdateStatusReq) returns(Response);
|
||||||
// UpdateStatus 取得會員資訊
|
// GetUserInfo 取得會員資訊
|
||||||
rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
|
rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
|
||||||
// ListMember 取得會員列表
|
// ListMember 取得會員列表
|
||||||
rpc ListMember(ListUserInfoReq) returns(ListUserInfoResp);
|
rpc ListMember(ListUserInfoReq) returns(ListUserInfoResp);
|
||||||
|
|
||||||
// GenerateRefreshCode 這個帳號驗證碼(十分鐘),通用的
|
// GenerateRefreshCode 這個帳號驗證碼(十分鐘),通用的
|
||||||
rpc GenerateRefreshCode(GenerateRefreshCodeReq) returns(GenerateRefreshCodeResp);
|
rpc GenerateRefreshCode(GenerateRefreshCodeReq) returns(GenerateRefreshCodeResp);
|
||||||
// VerifyRefreshCode 驗證忘記密碼 token
|
// VerifyRefreshCode 驗證忘記密碼 token
|
|
@ -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
|
||||||
|
)
|
|
@ -0,0 +1,7 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import "github.com/zeromicro/go-zero/zrpc"
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
zrpc.RpcServerConf
|
||||||
|
}
|
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue