init permission service

This commit is contained in:
daniel.w 2024-08-24 15:14:12 +08:00
parent 942ffab126
commit 229aa6a72b
45 changed files with 2406 additions and 215 deletions

View File

@ -5,8 +5,8 @@ GO ?= go
GOFMT ?= gofmt "-s" GOFMT ?= gofmt "-s"
GOFILES := $(shell find . -name "*.go") GOFILES := $(shell find . -name "*.go")
LDFLAGS := -s -w LDFLAGS := -s -w
VERSION="v1.0.3" VERSION="v1.0.1"
DOCKER_REPO="igs170911/notification" DOCKER_REPO="igs170911/permission"
.PHONY: test .PHONY: test
test: # 進行測試 test: # 進行測試
@ -45,37 +45,30 @@ build-docker:
rm -rf Dockerfile rm -rf Dockerfile
@echo "Generate core-api files successfully" @echo "Generate core-api files successfully"
.PHONY: gen-my-sql-model .PHONY: gen-my-sql-model-up
gen-my-sql-model: # 建立 rpc 資料庫 gen-my-sql-model: # 建立 rpc 資料庫
goctl model mysql ddl -c no -s ./generate/database/mysql/20230529020011_account_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' goctl model mysql ddl -c no -s ./generate/database/mysql/20240816014305_create_permission_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i ''
goctl model mysql ddl -c no -s ./generate/database/mysql/20230529020012_account_uid_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' goctl model mysql ddl -c no -s ./generate/database/mysql/20240819013052_create_roles_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i ''
goctl model mysql ddl -c no -s ./generate/database/mysql/20230529020013_user_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' goctl model mysql ddl -c no -s ./generate/database/mysql/20240819022436_create_user_role_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i ''
goctl model mysql ddl -c no -s ./generate/database/mysql/20230719061241_machine_node.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' goctl model mysql ddl -c no -s ./generate/database/mysql/20240819090248_create_role_permission_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i ''
@echo "Generate mysql model files successfully" @echo "Generate mysql model files successfully"
gen-mongo-model: # 建立 rpc 資料庫
# 只產生 Model 剩下的要自己撰寫,連欄位名稱也是
goctl model mongo -t AutoId --dir ./internal/model/mongo --style $(GO_ZERO_STYLE)
@echo "Generate mongo model files successfully"
#goctl model mysql ddl -s ./generate/database/mysql/20240819090248_create_role_permission_table.up.sql --style go_zero -d ./internal/model -i '' (沒cache)
#goctl model mysql ddl -c no -s ./generate/database/mysql/20240816014305_create_permission_table.up.sql --style go_zero -d ./internal/model -i '' (有cache)
.PHONY: mock-gen .PHONY: mock-gen
mock-gen: # 建立 mock 資料 mock-gen: # 建立 mock 資料
mockgen -source=./internal/domain/usecase/uid_generate.go -destination=./internal/mock/usecase/uid_generate.go -package=mock mockgen -source=./internal/model/permission_model.go -destination=./internal/mock/model/permission_model.go -package=mock
mockgen -source=./internal/model/account_model_gen.go -destination=./internal/mock/model/account_model_gen.go -package=mock mockgen -source=./internal/model/permission_model_gen.go -destination=./internal/mock/model/permission_model_gen.go -package=mock
mockgen -source=./internal/model/account_model.go -destination=./internal/mock/model/account_model.go -package=mock mockgen -source=./internal/model/role_model.go -destination=./internal/mock/model/role_model.go -package=mock
mockgen -source=./internal/model/account_to_uid_model_gen.go -destination=./internal/mock/model/account_to_uid_model_gen.go -package=mock mockgen -source=./internal/model/role_model_gen.go -destination=./internal/mock/model/role_model_gen.go -package=mock
mockgen -source=./internal/model/account_to_uid_model.go -destination=./internal/mock/model/account_to_uidmodel.go -package=mock mockgen -source=./internal/model/role_permission_model.go -destination=./internal/mock/model/role_permission_model.go -package=mock
mockgen -source=./internal/model/machine_node_model_gen.go -destination=./internal/mock/model/machine_node_model_gen.go -package=mock mockgen -source=./internal/model/role_permission_model_gen.go -destination=./internal/mock/model/role_permission_model_gen.go -package=mock
mockgen -source=./internal/model/machine_node_model.go -destination=./internal/mock/model/machine_node_model.go -package=mock mockgen -source=./internal/model/user_role_model.go -destination=./internal/mock/model/user_role_model.go -package=mock
mockgen -source=./internal/model/user_table_model_gen.go -destination=./internal/mock/model/user_table_model_gen.go -package=mock mockgen -source=./internal/model/user_role_model_gen.go -destination=./internal/mock/model/user_role_model_gen.go -package=mock
mockgen -source=./internal/model/user_table_model.go -destination=./internal/mock/model/user_table_model.go -package=mock
mockgen -source=./internal/model/mongo/auto_id_model_gen.go -destination=./internal/mock/model/auto_id_model_gen.go -package=mock
mockgen -source=./internal/model/mongo/auto_id_model.go -destination=./internal/mock/model/auto_id_model.go -package=mock
@echo "Generate mock files successfully" @echo "Generate mock files successfully"
.PHONY: migrate-database .PHONY: migrate-database
migrate-database: migrate-database:
migrate -source file://generate/database/mysql -database 'mysql://root:yytt@tcp(127.0.0.1:3306)/digimon_member' up migrate -source file://generate/database/mysql -database 'mysql://root:yytt@tcp(127.0.0.1:3306)/digimon_member' up
migrate -source file://generate/database/seeders -database 'mysql://root:yytt@tcp(127.0.0.1:3306)/digimon_member' up

View File

@ -0,0 +1 @@
DROP TABLE IF EXISTS `permission`;

View File

@ -0,0 +1,15 @@
-- 通常會把整個表都放到記憶體當中,不常搜尋,不需要加其他搜尋的 index
CREATE TABLE `permission`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK',
`parent` bigint unsigned DEFAULT NULL,
`name` varchar(255) NOT NULL,
`http_method` varchar(255) NOT NULL,
`http_path` text NOT NULL,
`status` tinyint NOT NULL DEFAULT '1' COMMENT '狀態 1: 啟用, 2: 關閉',
`type` tinyint NOT NULL DEFAULT '1' COMMENT '狀態 1: 後台, 2: 前台',
`create_time` bigint DEFAULT 0 NOT NULL COMMENT '創建時間',
`update_time` bigint DEFAULT 0 NOT NULL COMMENT '更新時間',
PRIMARY KEY (`id`),
UNIQUE KEY `name_unique_key` (`name`)
) ENGINE = InnoDB COMMENT ='權限表';

View File

@ -0,0 +1 @@
DROP TABLE IF EXISTS `role`;

View File

@ -0,0 +1,12 @@
CREATE TABLE `role`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK',
`role_id` varchar(50) NOT NULL,
`display_name` varchar(255) NOT NULL COMMENT '名稱',
`status` tinyint NOT NULL DEFAULT '1' COMMENT '狀態 1: 啟用, 2: 禁用',
`create_time` bigint DEFAULT 0 NOT NULL COMMENT '創建時間',
`update_time` bigint DEFAULT 0 NOT NULL COMMENT '更新時間',
PRIMARY KEY (`id`),
UNIQUE KEY `uid_unique_key` (`role_id`),
UNIQUE KEY `name_unique_key` (`display_name`)
) ENGINE = InnoDB COMMENT ='角色';

View File

@ -0,0 +1 @@
DROP TABLE IF EXISTS `user_role`;

View File

@ -0,0 +1,12 @@
CREATE TABLE `user_role`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK',
`brand` varchar(50) DEFAULT '' NOT NULL COMMENT '',
`uid` varchar(50) NOT NULL,
`role_id` varchar(50) NOT NULL,
`status` tinyint NOT NULL DEFAULT '1' COMMENT '狀態 1: 啟用, 2: 禁用',
`create_time` bigint DEFAULT 0 NOT NULL COMMENT '創建時間',
`update_time` bigint DEFAULT 0 NOT NULL COMMENT '更新時間',
PRIMARY KEY (`id`),
UNIQUE KEY `uid_unique_key` (`uid`)
) ENGINE = InnoDB COMMENT ='會員角色';

View File

@ -0,0 +1 @@
DROP TABLE IF EXISTS `role_permission`;

View File

@ -0,0 +1,10 @@
CREATE TABLE `role_permission`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'PK',
`role_id` bigint unsigned DEFAULT NULL COMMENT 'role.id',
`permission_id` bigint unsigned DEFAULT NULL COMMENT 'permission.id',
`create_time` bigint DEFAULT 0 NOT NULL COMMENT '創建時間',
`update_time` bigint DEFAULT 0 NOT NULL COMMENT '更新時間',
PRIMARY KEY (`id`),
KEY `category_id_permission_id_index` (`role_id`, `permission_id`)
) ENGINE = InnoDB COMMENT ='角色權限';

View File

@ -0,0 +1 @@
DELETE FROM `role` WHERE (`role_id` = 'AM000000');

View File

@ -0,0 +1,3 @@
INSERT INTO `role` (`role_id`, `display_name`, `status`, `create_time`, `update_time`)
VALUES ('AM000000', 'admin', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('AM000001', 'visitor', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());

View File

@ -0,0 +1,15 @@
-- 一級分類
INSERT INTO `permission` (`parent`, `name`, `http_method`, `http_path`, `create_time`, `update_time`)
VALUES (0, 'user.info.management', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()); -- 用戶資訊管理
# -- 二級分類 用戶資訊管理
SET @id := (SELECT id FROM `permission` where name = 'user.info.management');
INSERT INTO `permission` (`parent`, `name`, `http_method`, `http_path`, `create_time`, `update_time`)
VALUES (@id, 'user.basic.info', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()); -- 用戶基礎資訊查詢
# -- 三級分類 用戶基礎資訊管理-基礎資訊查詢表
SET @id := (SELECT id FROM `permission` where name = 'user.basic.info');
INSERT INTO `permission` (`parent`, `name`, `http_method`, `http_path`, `create_time`, `update_time`)
VALUES (@id, 'user.info.select', 'GET', '/v1/user', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -- 查詢
(@id, 'user.info.select.plain_code', 'GET', '/v1/user', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()); -- 明碼查詢

View File

@ -1,210 +1,154 @@
syntax = "proto3"; syntax = "proto3";
package member; package permission;
option go_package="./member";
option go_package="./permission";
// OKResp // OKResp
message OKResp {} message OKResp {}
// NoneReq // NoneReq
message NoneReq {} message NoneReq {}
// ================ enum ================ // AuthorizationReq
enum VerifyType { message AuthorizationReq {
VERIFY_NONE = 0; // // grant_type
VERIFY_EMAIL = 1; string grant_type = 1;
VERIFY_PHONE = 2; // device_id ID
VERIFY_GOOGLE = 3; // google string device_id = 2;
VERIFY_NOT = 4; // // scope
string scope = 3;
// data key-value
map<string,string> data = 4;
// expires
int32 expires = 5;
// is_refresh_token
bool is_refresh_token = 6;
} }
enum AlarmType { // TokenResp
ALARM_NONE = 0; // message TokenResp {
ALARM_NOT = 1; // // access_token
ALARM_SYSTEM = 2; // string access_token = 1;
// token_type
string token_type = 2;
// expires_in
int32 expires_in = 3;
// refresh_token
string refresh_token = 4;
} }
enum MemberStatus { // CreateOneTimeTokenReq 使 token,
STATUS_NONE = 0; // // token
STATUS_VERIFY = 1; // message CreateOneTimeTokenReq {
STATUS_COMPLETE = 2; //
STATUS_DISABLE = 3; //
STATUS_EMAIL = 4; //
STATUS_PHONE = 5; //
STATUS_GA = 6; // GA
}
// ================ enum ================
// ================ common ================
message Pager {
int64 total =1;
int64 size=2;
int64 index=3;
}
// ================ common ================
// ================ account ================
message CreateLoginUserReq {
string login_id = 1;
int64 platform = 2;
string token = 3;
}
message BindingUserReq {
string uid = 1;
string login_id = 2;
int64 type = 3;
}
message BindingUserResp {
string uid = 1;
string login_id = 2;
int64 type = 3;
}
message CreateUserInfoReq {
string uid = 1;
VerifyType verify_type = 2;
AlarmType alarm_type = 3;
MemberStatus status = 4;
string language = 5;
string currency = 6;
optional string avatar= 7;
optional string nick_name = 8;
}
message GetAccountInfoResp {
CreateLoginUserReq data = 1;
}
// UpdateUserInfoReq
message UpdateUserInfoReq {
string uid = 1;
optional string language = 2;
optional string currency = 3;
optional string nick_name = 4;
optional string avatar = 5;
optional VerifyType verify_type = 6;
optional AlarmType alarm_type = 7;
optional MemberStatus status = 8;
}
message GetUIDByAccountReq {
string account = 1;
}
message GetUidByAccountResp {
string uid = 1;
string account =2;
}
message UpdateTokenReq {
string account = 1;
string token = 2;
int64 platform=3;
}
message GenerateRefreshCodeReq {
string account = 1;
int32 code_type =2;
}
message VerifyCode {
string verify_code = 1;
}
message GenerateRefreshCodeResp {
VerifyCode data = 1;
}
message VerifyRefreshCodeReq {
string account = 1;
int32 code_type =2;
string verify_code = 3;
}
message UpdateStatusReq {
string uid = 1;
MemberStatus status = 2;
}
message GetUserInfoReq {
string uid = 1;
optional string nick_name =2;
}
message UserInfo {
string uid = 1;
VerifyType verify_type = 2;
AlarmType alarm_type = 3;
MemberStatus status = 4;
string language = 5;
string currency = 6;
string avatar = 7;
int64 create_time=8;
int64 update_time=9;
optional string nick_name = 10;
}
message GetUserInfoResp {
UserInfo data = 1;
}
message ListUserInfoReq {
optional VerifyType verify_type = 1;
optional AlarmType alarm_type = 2;
optional MemberStatus status = 3;
optional int64 create_start_time = 4;
optional int64 create_end_time = 5;
int64 page_size =6;
int64 page_index=7;
}
message ListUserInfoResp {
repeated UserInfo data = 1;
Pager page =2;
}
message VerifyAuthResultReq {
string token = 1; string token = 1;
} }
message VerifyAuthResultResp { message CreateOneTimeTokenResp {
bool status = 1; string one_time_token = 1;
} }
message TwitterAccessTokenResp { // RefreshTokenReq Token
message RefreshTokenReq {
string token = 1;
string scope = 2;
int64 expires = 3;
string device_id = 4;
}
// https://datatracker.ietf.org/doc/html/rfc6749#section-4.3.3
message RefreshTokenResp {
string token =1;
string one_time_token = 2;
int64 expires_in = 3;
string token_type = 4;
}
// CancelTokenReq Token
message CancelTokenReq {
string token = 1; string token = 1;
} }
service Account { // CancelTokenReq Token
// CreateUserAccount -> message DoTokenByUIDReq {
rpc CreateUserAccount(CreateLoginUserReq) returns(OKResp); repeated string ids = 1;
// GetUserAccountInfo string uid = 2;
rpc GetUserAccountInfo(GetUIDByAccountReq) returns(GetAccountInfoResp); }
// UpdateUserToken
rpc UpdateUserToken(UpdateTokenReq) returns(OKResp); // QueryTokenByUIDReq UID Token
// GetUidByAccount UID message QueryTokenByUIDReq {
rpc GetUidByAccount(GetUIDByAccountReq) returns(GetUidByAccountResp); string uid = 1;
// BindAccount -> account bind to UID }
rpc BindAccount(BindingUserReq) returns(BindingUserResp);
// BindUserInfo User Info // ValidationTokenReq Token
rpc BindUserInfo(CreateUserInfoReq) returns(OKResp); message ValidationTokenReq {
// UpdateUserInfo User Info string token = 1;
rpc UpdateUserInfo(UpdateUserInfoReq) returns(OKResp); }
// UpdateStatus
rpc UpdateStatus(UpdateStatusReq) returns(OKResp); // ValidationTokenResp Token
// GetUserInfo message ValidationTokenResp {
rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp); Token token = 1;
// ListMember map<string,string> data = 2;
rpc ListMember(ListUserInfoReq) returns(ListUserInfoResp); }
// GenerateRefreshCode
rpc GenerateRefreshCode(GenerateRefreshCodeReq) returns(GenerateRefreshCodeResp); // Token
// VerifyRefreshCode token message Token {
rpc VerifyRefreshCode(VerifyRefreshCodeReq) returns(OKResp); // ID
// VerifyGoogleAuthResult google string id = 1;
rpc VerifyGoogleAuthResult(VerifyAuthResultReq)returns(VerifyAuthResultResp); // client_id ID
int32 client_id = 2;
// uid ID
string uid = 3;
// device_id ID
string device_id = 4;
// access_token
string access_token = 5;
// expires_in
int32 expires_in = 6;
// access_create_at
int64 access_create_at = 7;
// refresh_token
string refresh_token = 8;
// refresh_expires_in
int32 refresh_expires_in = 9;
// refresh_create_at
int64 refresh_create_at = 10;
}
// DoTokenByDeviceIDReq DeviceID
message DoTokenByDeviceIDReq {
string device_id = 1;
}
message Tokens{
repeated TokenResp token = 1;
}
message CancelOneTimeTokenReq {
repeated string token = 1;
}
// Token
// Biz GW
// access_token -> token , refresh_token -> one_time_token
service TokenService {
// NewToken TokenAccessToken
rpc NewToken(AuthorizationReq) returns(TokenResp);
// RefreshToken token Token
rpc RefreshToken(RefreshTokenReq) returns(RefreshTokenResp);
// CancelToken Token One Time Toke
rpc CancelToken(CancelTokenReq) returns(OKResp);
// ValidationToken Token
rpc ValidationToken(ValidationTokenReq) returns(ValidationTokenResp);
// CancelTokens Token UID token id UID Device ID Token ID UID + Device
rpc CancelTokens(DoTokenByUIDReq) returns(OKResp);
// CancelTokenByDeviceId Token Device Device token Device token
rpc CancelTokenByDeviceId(DoTokenByDeviceIDReq) returns(OKResp);
// GetUserTokensByDeviceId DeviceID Tokens
rpc GetUserTokensByDeviceId(DoTokenByDeviceIDReq) returns(Tokens);
// GetUserTokensByUid UID Tokens
rpc GetUserTokensByUid(QueryTokenByUIDReq) returns(Tokens);
// NewOneTimeToken 使RefreshToken
rpc NewOneTimeToken(CreateOneTimeTokenReq) returns(CreateOneTimeTokenResp);
// CancelOneTimeToken 使
rpc CancelOneTimeToken(CancelOneTimeTokenReq) returns(OKResp);
} }
// ================ account ================

88
go.mod Normal file
View File

@ -0,0 +1,88 @@
module app-cloudep-permission-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,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelOneTimeTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelOneTimeTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelOneTimeTokenLogic {
return &CancelOneTimeTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelOneTimeToken 取消一次性使用
func (l *CancelOneTimeTokenLogic) CancelOneTimeToken(in *permission.CancelOneTimeTokenReq) (*permission.OKResp, error) {
// todo: add your logic here and delete this line
return &permission.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelTokenByDeviceIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelTokenByDeviceIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelTokenByDeviceIdLogic {
return &CancelTokenByDeviceIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelTokenByDeviceId 取消 Token 從 Device 視角出發可以選登出這個Device 下所有 token 登出這個Device 下指定token
func (l *CancelTokenByDeviceIdLogic) CancelTokenByDeviceId(in *permission.DoTokenByDeviceIDReq) (*permission.OKResp, error) {
// todo: add your logic here and delete this line
return &permission.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelTokenLogic {
return &CancelTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelToken 取消 Token也包含他裡面的 One Time Toke
func (l *CancelTokenLogic) CancelToken(in *permission.CancelTokenReq) (*permission.OKResp, error) {
// todo: add your logic here and delete this line
return &permission.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelTokensLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelTokensLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelTokensLogic {
return &CancelTokensLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelTokens 取消 Token 從UID 視角,以及 token id 視角出發, UID 登出,底下所有 Device ID 也要登出, Token ID 登出, 所有 UID + Device 都要登出
func (l *CancelTokensLogic) CancelTokens(in *permission.DoTokenByUIDReq) (*permission.OKResp, error) {
// todo: add your logic here and delete this line
return &permission.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserTokensByDeviceIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserTokensByDeviceIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserTokensByDeviceIdLogic {
return &GetUserTokensByDeviceIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetUserTokensByDeviceId 取得目前所對應的 DeviceID 所存在的 Tokens
func (l *GetUserTokensByDeviceIdLogic) GetUserTokensByDeviceId(in *permission.DoTokenByDeviceIDReq) (*permission.Tokens, error) {
// todo: add your logic here and delete this line
return &permission.Tokens{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserTokensByUidLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserTokensByUidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserTokensByUidLogic {
return &GetUserTokensByUidLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetUserTokensByUid 取得目前所對應的 UID 所存在的 Tokens
func (l *GetUserTokensByUidLogic) GetUserTokensByUid(in *permission.QueryTokenByUIDReq) (*permission.Tokens, error) {
// todo: add your logic here and delete this line
return &permission.Tokens{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type NewOneTimeTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewNewOneTimeTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewOneTimeTokenLogic {
return &NewOneTimeTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// NewOneTimeToken 建立一次性使用例如RefreshToken
func (l *NewOneTimeTokenLogic) NewOneTimeToken(in *permission.CreateOneTimeTokenReq) (*permission.CreateOneTimeTokenResp, error) {
// todo: add your logic here and delete this line
return &permission.CreateOneTimeTokenResp{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type NewTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewNewTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewTokenLogic {
return &NewTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// NewToken 建立一個新的 Token例如AccessToken
func (l *NewTokenLogic) NewToken(in *permission.AuthorizationReq) (*permission.TokenResp, error) {
// todo: add your logic here and delete this line
return &permission.TokenResp{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type RefreshTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewRefreshTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RefreshTokenLogic {
return &RefreshTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// RefreshToken 更新目前的token 以及裡面包含的一次性 Token
func (l *RefreshTokenLogic) RefreshToken(in *permission.RefreshTokenReq) (*permission.RefreshTokenResp, error) {
// todo: add your logic here and delete this line
return &permission.RefreshTokenResp{}, nil
}

View File

@ -0,0 +1,31 @@
package tokenservicelogic
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ValidationTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewValidationTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ValidationTokenLogic {
return &ValidationTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ValidationToken 驗證這個 Token 有沒有效
func (l *ValidationTokenLogic) ValidationToken(in *permission.ValidationTokenReq) (*permission.ValidationTokenResp, error) {
// todo: add your logic here and delete this line
return &permission.ValidationTokenResp{}, nil
}

View File

@ -0,0 +1,115 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/permission_model.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/permission_model.go -destination=./internal/mock/model/permission_model.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockPermissionModel is a mock of PermissionModel interface.
type MockPermissionModel struct {
ctrl *gomock.Controller
recorder *MockPermissionModelMockRecorder
}
// MockPermissionModelMockRecorder is the mock recorder for MockPermissionModel.
type MockPermissionModelMockRecorder struct {
mock *MockPermissionModel
}
// NewMockPermissionModel creates a new mock instance.
func NewMockPermissionModel(ctrl *gomock.Controller) *MockPermissionModel {
mock := &MockPermissionModel{ctrl: ctrl}
mock.recorder = &MockPermissionModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPermissionModel) EXPECT() *MockPermissionModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockPermissionModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockPermissionModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockPermissionModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockPermissionModel) FindOne(ctx context.Context, id int64) (*model.Permission, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.Permission)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockPermissionModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockPermissionModel)(nil).FindOne), ctx, id)
}
// FindOneByName mocks base method.
func (m *MockPermissionModel) FindOneByName(ctx context.Context, name string) (*model.Permission, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByName", ctx, name)
ret0, _ := ret[0].(*model.Permission)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByName indicates an expected call of FindOneByName.
func (mr *MockPermissionModelMockRecorder) FindOneByName(ctx, name any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByName", reflect.TypeOf((*MockPermissionModel)(nil).FindOneByName), ctx, name)
}
// Insert mocks base method.
func (m *MockPermissionModel) Insert(ctx context.Context, data *model.Permission) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockPermissionModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockPermissionModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockPermissionModel) Update(ctx context.Context, data *model.Permission) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockPermissionModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockPermissionModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,115 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/permission_model_gen.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/permission_model_gen.go -destination=./internal/mock/model/permission_model_gen.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockpermissionModel is a mock of permissionModel interface.
type MockpermissionModel struct {
ctrl *gomock.Controller
recorder *MockpermissionModelMockRecorder
}
// MockpermissionModelMockRecorder is the mock recorder for MockpermissionModel.
type MockpermissionModelMockRecorder struct {
mock *MockpermissionModel
}
// NewMockpermissionModel creates a new mock instance.
func NewMockpermissionModel(ctrl *gomock.Controller) *MockpermissionModel {
mock := &MockpermissionModel{ctrl: ctrl}
mock.recorder = &MockpermissionModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockpermissionModel) EXPECT() *MockpermissionModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockpermissionModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockpermissionModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockpermissionModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockpermissionModel) FindOne(ctx context.Context, id int64) (*model.Permission, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.Permission)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockpermissionModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockpermissionModel)(nil).FindOne), ctx, id)
}
// FindOneByName mocks base method.
func (m *MockpermissionModel) FindOneByName(ctx context.Context, name string) (*model.Permission, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByName", ctx, name)
ret0, _ := ret[0].(*model.Permission)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByName indicates an expected call of FindOneByName.
func (mr *MockpermissionModelMockRecorder) FindOneByName(ctx, name any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByName", reflect.TypeOf((*MockpermissionModel)(nil).FindOneByName), ctx, name)
}
// Insert mocks base method.
func (m *MockpermissionModel) Insert(ctx context.Context, data *model.Permission) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockpermissionModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockpermissionModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockpermissionModel) Update(ctx context.Context, data *model.Permission) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockpermissionModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockpermissionModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,130 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/role_model.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/role_model.go -destination=./internal/mock/model/role_model.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockRoleModel is a mock of RoleModel interface.
type MockRoleModel struct {
ctrl *gomock.Controller
recorder *MockRoleModelMockRecorder
}
// MockRoleModelMockRecorder is the mock recorder for MockRoleModel.
type MockRoleModelMockRecorder struct {
mock *MockRoleModel
}
// NewMockRoleModel creates a new mock instance.
func NewMockRoleModel(ctrl *gomock.Controller) *MockRoleModel {
mock := &MockRoleModel{ctrl: ctrl}
mock.recorder = &MockRoleModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockRoleModel) EXPECT() *MockRoleModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockRoleModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockRoleModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRoleModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockRoleModel) FindOne(ctx context.Context, id int64) (*model.Role, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.Role)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockRoleModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockRoleModel)(nil).FindOne), ctx, id)
}
// FindOneByDisplayName mocks base method.
func (m *MockRoleModel) FindOneByDisplayName(ctx context.Context, displayName string) (*model.Role, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByDisplayName", ctx, displayName)
ret0, _ := ret[0].(*model.Role)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByDisplayName indicates an expected call of FindOneByDisplayName.
func (mr *MockRoleModelMockRecorder) FindOneByDisplayName(ctx, displayName any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByDisplayName", reflect.TypeOf((*MockRoleModel)(nil).FindOneByDisplayName), ctx, displayName)
}
// FindOneByRoleId mocks base method.
func (m *MockRoleModel) FindOneByRoleId(ctx context.Context, roleId string) (*model.Role, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByRoleId", ctx, roleId)
ret0, _ := ret[0].(*model.Role)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByRoleId indicates an expected call of FindOneByRoleId.
func (mr *MockRoleModelMockRecorder) FindOneByRoleId(ctx, roleId any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByRoleId", reflect.TypeOf((*MockRoleModel)(nil).FindOneByRoleId), ctx, roleId)
}
// Insert mocks base method.
func (m *MockRoleModel) Insert(ctx context.Context, data *model.Role) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockRoleModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockRoleModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockRoleModel) Update(ctx context.Context, data *model.Role) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockRoleModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRoleModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,130 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/role_model_gen.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/role_model_gen.go -destination=./internal/mock/model/role_model_gen.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockroleModel is a mock of roleModel interface.
type MockroleModel struct {
ctrl *gomock.Controller
recorder *MockroleModelMockRecorder
}
// MockroleModelMockRecorder is the mock recorder for MockroleModel.
type MockroleModelMockRecorder struct {
mock *MockroleModel
}
// NewMockroleModel creates a new mock instance.
func NewMockroleModel(ctrl *gomock.Controller) *MockroleModel {
mock := &MockroleModel{ctrl: ctrl}
mock.recorder = &MockroleModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockroleModel) EXPECT() *MockroleModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockroleModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockroleModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockroleModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockroleModel) FindOne(ctx context.Context, id int64) (*model.Role, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.Role)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockroleModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockroleModel)(nil).FindOne), ctx, id)
}
// FindOneByDisplayName mocks base method.
func (m *MockroleModel) FindOneByDisplayName(ctx context.Context, displayName string) (*model.Role, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByDisplayName", ctx, displayName)
ret0, _ := ret[0].(*model.Role)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByDisplayName indicates an expected call of FindOneByDisplayName.
func (mr *MockroleModelMockRecorder) FindOneByDisplayName(ctx, displayName any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByDisplayName", reflect.TypeOf((*MockroleModel)(nil).FindOneByDisplayName), ctx, displayName)
}
// FindOneByRoleId mocks base method.
func (m *MockroleModel) FindOneByRoleId(ctx context.Context, roleId string) (*model.Role, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByRoleId", ctx, roleId)
ret0, _ := ret[0].(*model.Role)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByRoleId indicates an expected call of FindOneByRoleId.
func (mr *MockroleModelMockRecorder) FindOneByRoleId(ctx, roleId any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByRoleId", reflect.TypeOf((*MockroleModel)(nil).FindOneByRoleId), ctx, roleId)
}
// Insert mocks base method.
func (m *MockroleModel) Insert(ctx context.Context, data *model.Role) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockroleModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockroleModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockroleModel) Update(ctx context.Context, data *model.Role) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockroleModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockroleModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,100 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/role_permission_model.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/role_permission_model.go -destination=./internal/mock/model/role_permission_model.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockRolePermissionModel is a mock of RolePermissionModel interface.
type MockRolePermissionModel struct {
ctrl *gomock.Controller
recorder *MockRolePermissionModelMockRecorder
}
// MockRolePermissionModelMockRecorder is the mock recorder for MockRolePermissionModel.
type MockRolePermissionModelMockRecorder struct {
mock *MockRolePermissionModel
}
// NewMockRolePermissionModel creates a new mock instance.
func NewMockRolePermissionModel(ctrl *gomock.Controller) *MockRolePermissionModel {
mock := &MockRolePermissionModel{ctrl: ctrl}
mock.recorder = &MockRolePermissionModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockRolePermissionModel) EXPECT() *MockRolePermissionModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockRolePermissionModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockRolePermissionModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRolePermissionModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockRolePermissionModel) FindOne(ctx context.Context, id int64) (*model.RolePermission, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.RolePermission)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockRolePermissionModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockRolePermissionModel)(nil).FindOne), ctx, id)
}
// Insert mocks base method.
func (m *MockRolePermissionModel) Insert(ctx context.Context, data *model.RolePermission) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockRolePermissionModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockRolePermissionModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockRolePermissionModel) Update(ctx context.Context, data *model.RolePermission) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockRolePermissionModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRolePermissionModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,100 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/role_permission_model_gen.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/role_permission_model_gen.go -destination=./internal/mock/model/role_permission_model_gen.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockrolePermissionModel is a mock of rolePermissionModel interface.
type MockrolePermissionModel struct {
ctrl *gomock.Controller
recorder *MockrolePermissionModelMockRecorder
}
// MockrolePermissionModelMockRecorder is the mock recorder for MockrolePermissionModel.
type MockrolePermissionModelMockRecorder struct {
mock *MockrolePermissionModel
}
// NewMockrolePermissionModel creates a new mock instance.
func NewMockrolePermissionModel(ctrl *gomock.Controller) *MockrolePermissionModel {
mock := &MockrolePermissionModel{ctrl: ctrl}
mock.recorder = &MockrolePermissionModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockrolePermissionModel) EXPECT() *MockrolePermissionModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockrolePermissionModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockrolePermissionModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockrolePermissionModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockrolePermissionModel) FindOne(ctx context.Context, id int64) (*model.RolePermission, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.RolePermission)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockrolePermissionModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockrolePermissionModel)(nil).FindOne), ctx, id)
}
// Insert mocks base method.
func (m *MockrolePermissionModel) Insert(ctx context.Context, data *model.RolePermission) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockrolePermissionModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockrolePermissionModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockrolePermissionModel) Update(ctx context.Context, data *model.RolePermission) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockrolePermissionModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockrolePermissionModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,115 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/user_role_model.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/user_role_model.go -destination=./internal/mock/model/user_role_model.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockUserRoleModel is a mock of UserRoleModel interface.
type MockUserRoleModel struct {
ctrl *gomock.Controller
recorder *MockUserRoleModelMockRecorder
}
// MockUserRoleModelMockRecorder is the mock recorder for MockUserRoleModel.
type MockUserRoleModelMockRecorder struct {
mock *MockUserRoleModel
}
// NewMockUserRoleModel creates a new mock instance.
func NewMockUserRoleModel(ctrl *gomock.Controller) *MockUserRoleModel {
mock := &MockUserRoleModel{ctrl: ctrl}
mock.recorder = &MockUserRoleModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockUserRoleModel) EXPECT() *MockUserRoleModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockUserRoleModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockUserRoleModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockUserRoleModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockUserRoleModel) FindOne(ctx context.Context, id int64) (*model.UserRole, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.UserRole)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockUserRoleModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockUserRoleModel)(nil).FindOne), ctx, id)
}
// FindOneByUid mocks base method.
func (m *MockUserRoleModel) FindOneByUid(ctx context.Context, uid string) (*model.UserRole, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByUid", ctx, uid)
ret0, _ := ret[0].(*model.UserRole)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByUid indicates an expected call of FindOneByUid.
func (mr *MockUserRoleModelMockRecorder) FindOneByUid(ctx, uid any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByUid", reflect.TypeOf((*MockUserRoleModel)(nil).FindOneByUid), ctx, uid)
}
// Insert mocks base method.
func (m *MockUserRoleModel) Insert(ctx context.Context, data *model.UserRole) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockUserRoleModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockUserRoleModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockUserRoleModel) Update(ctx context.Context, data *model.UserRole) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockUserRoleModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockUserRoleModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,115 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: ./internal/model/user_role_model_gen.go
//
// Generated by this command:
//
// mockgen -source=./internal/model/user_role_model_gen.go -destination=./internal/mock/model/user_role_model_gen.go -package=mock
//
// Package mock is a generated GoMock package.
package mock
import (
model "app-cloudep-permission-server/internal/model"
context "context"
sql "database/sql"
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockuserRoleModel is a mock of userRoleModel interface.
type MockuserRoleModel struct {
ctrl *gomock.Controller
recorder *MockuserRoleModelMockRecorder
}
// MockuserRoleModelMockRecorder is the mock recorder for MockuserRoleModel.
type MockuserRoleModelMockRecorder struct {
mock *MockuserRoleModel
}
// NewMockuserRoleModel creates a new mock instance.
func NewMockuserRoleModel(ctrl *gomock.Controller) *MockuserRoleModel {
mock := &MockuserRoleModel{ctrl: ctrl}
mock.recorder = &MockuserRoleModelMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockuserRoleModel) EXPECT() *MockuserRoleModelMockRecorder {
return m.recorder
}
// Delete mocks base method.
func (m *MockuserRoleModel) Delete(ctx context.Context, id int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delete", ctx, id)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete.
func (mr *MockuserRoleModelMockRecorder) Delete(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockuserRoleModel)(nil).Delete), ctx, id)
}
// FindOne mocks base method.
func (m *MockuserRoleModel) FindOne(ctx context.Context, id int64) (*model.UserRole, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOne", ctx, id)
ret0, _ := ret[0].(*model.UserRole)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOne indicates an expected call of FindOne.
func (mr *MockuserRoleModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockuserRoleModel)(nil).FindOne), ctx, id)
}
// FindOneByUid mocks base method.
func (m *MockuserRoleModel) FindOneByUid(ctx context.Context, uid string) (*model.UserRole, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FindOneByUid", ctx, uid)
ret0, _ := ret[0].(*model.UserRole)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FindOneByUid indicates an expected call of FindOneByUid.
func (mr *MockuserRoleModelMockRecorder) FindOneByUid(ctx, uid any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneByUid", reflect.TypeOf((*MockuserRoleModel)(nil).FindOneByUid), ctx, uid)
}
// Insert mocks base method.
func (m *MockuserRoleModel) Insert(ctx context.Context, data *model.UserRole) (sql.Result, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Insert", ctx, data)
ret0, _ := ret[0].(sql.Result)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Insert indicates an expected call of Insert.
func (mr *MockuserRoleModelMockRecorder) Insert(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockuserRoleModel)(nil).Insert), ctx, data)
}
// Update mocks base method.
func (m *MockuserRoleModel) Update(ctx context.Context, data *model.UserRole) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Update", ctx, data)
ret0, _ := ret[0].(error)
return ret0
}
// Update indicates an expected call of Update.
func (mr *MockuserRoleModelMockRecorder) Update(ctx, data any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockuserRoleModel)(nil).Update), ctx, data)
}

View File

@ -0,0 +1,27 @@
package model
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ PermissionModel = (*customPermissionModel)(nil)
type (
// PermissionModel is an interface to be customized, add more methods here,
// and implement the added methods in customPermissionModel.
PermissionModel interface {
permissionModel
}
customPermissionModel struct {
*defaultPermissionModel
}
)
// NewPermissionModel returns a model for the database table.
func NewPermissionModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) PermissionModel {
return &customPermissionModel{
defaultPermissionModel: newPermissionModel(conn, c, opts...),
}
}

View File

@ -0,0 +1,157 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
permissionFieldNames = builder.RawFieldNames(&Permission{})
permissionRows = strings.Join(permissionFieldNames, ",")
permissionRowsExpectAutoSet = strings.Join(stringx.Remove(permissionFieldNames, "`id`"), ",")
permissionRowsWithPlaceHolder = strings.Join(stringx.Remove(permissionFieldNames, "`id`"), "=?,") + "=?"
cachePermissionIdPrefix = "cache:permission:id:"
cachePermissionNamePrefix = "cache:permission:name:"
)
type (
permissionModel interface {
Insert(ctx context.Context, data *Permission) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*Permission, error)
FindOneByName(ctx context.Context, name string) (*Permission, error)
Update(ctx context.Context, data *Permission) error
Delete(ctx context.Context, id int64) error
}
defaultPermissionModel struct {
sqlc.CachedConn
table string
}
Permission struct {
Id int64 `db:"id"` // PK
Parent sql.NullInt64 `db:"parent"`
Name string `db:"name"`
HttpMethod string `db:"http_method"`
HttpPath string `db:"http_path"`
Status int64 `db:"status"` // 狀態 1: 啟用, 2: 關閉
Type int64 `db:"type"` // 狀態 1: 後台, 2: 前台
CreateTime int64 `db:"create_time"` // 創建時間
UpdateTime int64 `db:"update_time"` // 更新時間
}
)
func newPermissionModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultPermissionModel {
return &defaultPermissionModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`permission`",
}
}
func (m *defaultPermissionModel) withSession(session sqlx.Session) *defaultPermissionModel {
return &defaultPermissionModel{
CachedConn: m.CachedConn.WithSession(session),
table: "`permission`",
}
}
func (m *defaultPermissionModel) Delete(ctx context.Context, id int64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
permissionIdKey := fmt.Sprintf("%s%v", cachePermissionIdPrefix, id)
permissionNameKey := fmt.Sprintf("%s%v", cachePermissionNamePrefix, data.Name)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, permissionIdKey, permissionNameKey)
return err
}
func (m *defaultPermissionModel) FindOne(ctx context.Context, id int64) (*Permission, error) {
permissionIdKey := fmt.Sprintf("%s%v", cachePermissionIdPrefix, id)
var resp Permission
err := m.QueryRowCtx(ctx, &resp, permissionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", permissionRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultPermissionModel) FindOneByName(ctx context.Context, name string) (*Permission, error) {
permissionNameKey := fmt.Sprintf("%s%v", cachePermissionNamePrefix, name)
var resp Permission
err := m.QueryRowIndexCtx(ctx, &resp, permissionNameKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `name` = ? limit 1", permissionRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, name); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultPermissionModel) Insert(ctx context.Context, data *Permission) (sql.Result, error) {
permissionIdKey := fmt.Sprintf("%s%v", cachePermissionIdPrefix, data.Id)
permissionNameKey := fmt.Sprintf("%s%v", cachePermissionNamePrefix, data.Name)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, permissionRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Parent, data.Name, data.HttpMethod, data.HttpPath, data.Status, data.Type, data.CreateTime, data.UpdateTime)
}, permissionIdKey, permissionNameKey)
return ret, err
}
func (m *defaultPermissionModel) Update(ctx context.Context, newData *Permission) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
permissionIdKey := fmt.Sprintf("%s%v", cachePermissionIdPrefix, data.Id)
permissionNameKey := fmt.Sprintf("%s%v", cachePermissionNamePrefix, data.Name)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, permissionRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.Parent, newData.Name, newData.HttpMethod, newData.HttpPath, newData.Status, newData.Type, newData.CreateTime, newData.UpdateTime, newData.Id)
}, permissionIdKey, permissionNameKey)
return err
}
func (m *defaultPermissionModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cachePermissionIdPrefix, primary)
}
func (m *defaultPermissionModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", permissionRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultPermissionModel) tableName() string {
return m.table
}

27
internal/model/role_model.go Executable file
View File

@ -0,0 +1,27 @@
package model
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ RoleModel = (*customRoleModel)(nil)
type (
// RoleModel is an interface to be customized, add more methods here,
// and implement the added methods in customRoleModel.
RoleModel interface {
roleModel
}
customRoleModel struct {
*defaultRoleModel
}
)
// NewRoleModel returns a model for the database table.
func NewRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) RoleModel {
return &customRoleModel{
defaultRoleModel: newRoleModel(conn, c, opts...),
}
}

179
internal/model/role_model_gen.go Executable file
View File

@ -0,0 +1,179 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
roleFieldNames = builder.RawFieldNames(&Role{})
roleRows = strings.Join(roleFieldNames, ",")
roleRowsExpectAutoSet = strings.Join(stringx.Remove(roleFieldNames, "`id`"), ",")
roleRowsWithPlaceHolder = strings.Join(stringx.Remove(roleFieldNames, "`id`"), "=?,") + "=?"
cacheRoleIdPrefix = "cache:role:id:"
cacheRoleDisplayNamePrefix = "cache:role:displayName:"
cacheRoleRoleIdPrefix = "cache:role:roleId:"
)
type (
roleModel interface {
Insert(ctx context.Context, data *Role) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*Role, error)
FindOneByDisplayName(ctx context.Context, displayName string) (*Role, error)
FindOneByRoleId(ctx context.Context, roleId string) (*Role, error)
Update(ctx context.Context, data *Role) error
Delete(ctx context.Context, id int64) error
}
defaultRoleModel struct {
sqlc.CachedConn
table string
}
Role struct {
Id int64 `db:"id"` // PK
RoleId string `db:"role_id"`
DisplayName string `db:"display_name"` // 名稱
Status int64 `db:"status"` // 狀態 1: 啟用, 2: 禁用
CreateTime int64 `db:"create_time"` // 創建時間
UpdateTime int64 `db:"update_time"` // 更新時間
}
)
func newRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultRoleModel {
return &defaultRoleModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`role`",
}
}
func (m *defaultRoleModel) withSession(session sqlx.Session) *defaultRoleModel {
return &defaultRoleModel{
CachedConn: m.CachedConn.WithSession(session),
table: "`role`",
}
}
func (m *defaultRoleModel) Delete(ctx context.Context, id int64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
roleDisplayNameKey := fmt.Sprintf("%s%v", cacheRoleDisplayNamePrefix, data.DisplayName)
roleIdKey := fmt.Sprintf("%s%v", cacheRoleIdPrefix, id)
roleRoleIdKey := fmt.Sprintf("%s%v", cacheRoleRoleIdPrefix, data.RoleId)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, roleDisplayNameKey, roleIdKey, roleRoleIdKey)
return err
}
func (m *defaultRoleModel) FindOne(ctx context.Context, id int64) (*Role, error) {
roleIdKey := fmt.Sprintf("%s%v", cacheRoleIdPrefix, id)
var resp Role
err := m.QueryRowCtx(ctx, &resp, roleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", roleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultRoleModel) FindOneByDisplayName(ctx context.Context, displayName string) (*Role, error) {
roleDisplayNameKey := fmt.Sprintf("%s%v", cacheRoleDisplayNamePrefix, displayName)
var resp Role
err := m.QueryRowIndexCtx(ctx, &resp, roleDisplayNameKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `display_name` = ? limit 1", roleRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, displayName); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultRoleModel) FindOneByRoleId(ctx context.Context, roleId string) (*Role, error) {
roleRoleIdKey := fmt.Sprintf("%s%v", cacheRoleRoleIdPrefix, roleId)
var resp Role
err := m.QueryRowIndexCtx(ctx, &resp, roleRoleIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `role_id` = ? limit 1", roleRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, roleId); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultRoleModel) Insert(ctx context.Context, data *Role) (sql.Result, error) {
roleDisplayNameKey := fmt.Sprintf("%s%v", cacheRoleDisplayNamePrefix, data.DisplayName)
roleIdKey := fmt.Sprintf("%s%v", cacheRoleIdPrefix, data.Id)
roleRoleIdKey := fmt.Sprintf("%s%v", cacheRoleRoleIdPrefix, data.RoleId)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, roleRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.RoleId, data.DisplayName, data.Status, data.CreateTime, data.UpdateTime)
}, roleDisplayNameKey, roleIdKey, roleRoleIdKey)
return ret, err
}
func (m *defaultRoleModel) Update(ctx context.Context, newData *Role) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
roleDisplayNameKey := fmt.Sprintf("%s%v", cacheRoleDisplayNamePrefix, data.DisplayName)
roleIdKey := fmt.Sprintf("%s%v", cacheRoleIdPrefix, data.Id)
roleRoleIdKey := fmt.Sprintf("%s%v", cacheRoleRoleIdPrefix, data.RoleId)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, roleRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.RoleId, newData.DisplayName, newData.Status, newData.CreateTime, newData.UpdateTime, newData.Id)
}, roleDisplayNameKey, roleIdKey, roleRoleIdKey)
return err
}
func (m *defaultRoleModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheRoleIdPrefix, primary)
}
func (m *defaultRoleModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", roleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultRoleModel) tableName() string {
return m.table
}

View File

@ -0,0 +1,27 @@
package model
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ RolePermissionModel = (*customRolePermissionModel)(nil)
type (
// RolePermissionModel is an interface to be customized, add more methods here,
// and implement the added methods in customRolePermissionModel.
RolePermissionModel interface {
rolePermissionModel
}
customRolePermissionModel struct {
*defaultRolePermissionModel
}
)
// NewRolePermissionModel returns a model for the database table.
func NewRolePermissionModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) RolePermissionModel {
return &customRolePermissionModel{
defaultRolePermissionModel: newRolePermissionModel(conn, c, opts...),
}
}

View File

@ -0,0 +1,118 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
rolePermissionFieldNames = builder.RawFieldNames(&RolePermission{})
rolePermissionRows = strings.Join(rolePermissionFieldNames, ",")
rolePermissionRowsExpectAutoSet = strings.Join(stringx.Remove(rolePermissionFieldNames, "`id`"), ",")
rolePermissionRowsWithPlaceHolder = strings.Join(stringx.Remove(rolePermissionFieldNames, "`id`"), "=?,") + "=?"
cacheRolePermissionIdPrefix = "cache:rolePermission:id:"
)
type (
rolePermissionModel interface {
Insert(ctx context.Context, data *RolePermission) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*RolePermission, error)
Update(ctx context.Context, data *RolePermission) error
Delete(ctx context.Context, id int64) error
}
defaultRolePermissionModel struct {
sqlc.CachedConn
table string
}
RolePermission struct {
Id int64 `db:"id"` // PK
RoleId sql.NullInt64 `db:"role_id"` // role.id
PermissionId sql.NullInt64 `db:"permission_id"` // permission.id
CreateTime int64 `db:"create_time"` // 創建時間
UpdateTime int64 `db:"update_time"` // 更新時間
}
)
func newRolePermissionModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultRolePermissionModel {
return &defaultRolePermissionModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`role_permission`",
}
}
func (m *defaultRolePermissionModel) withSession(session sqlx.Session) *defaultRolePermissionModel {
return &defaultRolePermissionModel{
CachedConn: m.CachedConn.WithSession(session),
table: "`role_permission`",
}
}
func (m *defaultRolePermissionModel) Delete(ctx context.Context, id int64) error {
rolePermissionIdKey := fmt.Sprintf("%s%v", cacheRolePermissionIdPrefix, id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, rolePermissionIdKey)
return err
}
func (m *defaultRolePermissionModel) FindOne(ctx context.Context, id int64) (*RolePermission, error) {
rolePermissionIdKey := fmt.Sprintf("%s%v", cacheRolePermissionIdPrefix, id)
var resp RolePermission
err := m.QueryRowCtx(ctx, &resp, rolePermissionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", rolePermissionRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultRolePermissionModel) Insert(ctx context.Context, data *RolePermission) (sql.Result, error) {
rolePermissionIdKey := fmt.Sprintf("%s%v", cacheRolePermissionIdPrefix, data.Id)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, rolePermissionRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.RoleId, data.PermissionId, data.CreateTime, data.UpdateTime)
}, rolePermissionIdKey)
return ret, err
}
func (m *defaultRolePermissionModel) Update(ctx context.Context, data *RolePermission) error {
rolePermissionIdKey := fmt.Sprintf("%s%v", cacheRolePermissionIdPrefix, data.Id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, rolePermissionRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.RoleId, data.PermissionId, data.CreateTime, data.UpdateTime, data.Id)
}, rolePermissionIdKey)
return err
}
func (m *defaultRolePermissionModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheRolePermissionIdPrefix, primary)
}
func (m *defaultRolePermissionModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", rolePermissionRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultRolePermissionModel) tableName() string {
return m.table
}

View File

@ -0,0 +1,27 @@
package model
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ UserRoleModel = (*customUserRoleModel)(nil)
type (
// UserRoleModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserRoleModel.
UserRoleModel interface {
userRoleModel
}
customUserRoleModel struct {
*defaultUserRoleModel
}
)
// NewUserRoleModel returns a model for the database table.
func NewUserRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) UserRoleModel {
return &customUserRoleModel{
defaultUserRoleModel: newUserRoleModel(conn, c, opts...),
}
}

View File

@ -0,0 +1,155 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
userRoleFieldNames = builder.RawFieldNames(&UserRole{})
userRoleRows = strings.Join(userRoleFieldNames, ",")
userRoleRowsExpectAutoSet = strings.Join(stringx.Remove(userRoleFieldNames, "`id`"), ",")
userRoleRowsWithPlaceHolder = strings.Join(stringx.Remove(userRoleFieldNames, "`id`"), "=?,") + "=?"
cacheUserRoleIdPrefix = "cache:userRole:id:"
cacheUserRoleUidPrefix = "cache:userRole:uid:"
)
type (
userRoleModel interface {
Insert(ctx context.Context, data *UserRole) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*UserRole, error)
FindOneByUid(ctx context.Context, uid string) (*UserRole, error)
Update(ctx context.Context, data *UserRole) error
Delete(ctx context.Context, id int64) error
}
defaultUserRoleModel struct {
sqlc.CachedConn
table string
}
UserRole struct {
Id int64 `db:"id"` // PK
Brand string `db:"brand"`
Uid string `db:"uid"`
RoleId string `db:"role_id"`
Status int64 `db:"status"` // 狀態 1: 啟用, 2: 禁用
CreateTime int64 `db:"create_time"` // 創建時間
UpdateTime int64 `db:"update_time"` // 更新時間
}
)
func newUserRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultUserRoleModel {
return &defaultUserRoleModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`user_role`",
}
}
func (m *defaultUserRoleModel) withSession(session sqlx.Session) *defaultUserRoleModel {
return &defaultUserRoleModel{
CachedConn: m.CachedConn.WithSession(session),
table: "`user_role`",
}
}
func (m *defaultUserRoleModel) Delete(ctx context.Context, id int64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
userRoleIdKey := fmt.Sprintf("%s%v", cacheUserRoleIdPrefix, id)
userRoleUidKey := fmt.Sprintf("%s%v", cacheUserRoleUidPrefix, data.Uid)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, userRoleIdKey, userRoleUidKey)
return err
}
func (m *defaultUserRoleModel) FindOne(ctx context.Context, id int64) (*UserRole, error) {
userRoleIdKey := fmt.Sprintf("%s%v", cacheUserRoleIdPrefix, id)
var resp UserRole
err := m.QueryRowCtx(ctx, &resp, userRoleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRoleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserRoleModel) FindOneByUid(ctx context.Context, uid string) (*UserRole, error) {
userRoleUidKey := fmt.Sprintf("%s%v", cacheUserRoleUidPrefix, uid)
var resp UserRole
err := m.QueryRowIndexCtx(ctx, &resp, userRoleUidKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `uid` = ? limit 1", userRoleRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, uid); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserRoleModel) Insert(ctx context.Context, data *UserRole) (sql.Result, error) {
userRoleIdKey := fmt.Sprintf("%s%v", cacheUserRoleIdPrefix, data.Id)
userRoleUidKey := fmt.Sprintf("%s%v", cacheUserRoleUidPrefix, data.Uid)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, userRoleRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Brand, data.Uid, data.RoleId, data.Status, data.CreateTime, data.UpdateTime)
}, userRoleIdKey, userRoleUidKey)
return ret, err
}
func (m *defaultUserRoleModel) Update(ctx context.Context, newData *UserRole) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
userRoleIdKey := fmt.Sprintf("%s%v", cacheUserRoleIdPrefix, data.Id)
userRoleUidKey := fmt.Sprintf("%s%v", cacheUserRoleUidPrefix, data.Uid)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userRoleRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.Brand, newData.Uid, newData.RoleId, newData.Status, newData.CreateTime, newData.UpdateTime, newData.Id)
}, userRoleIdKey, userRoleUidKey)
return err
}
func (m *defaultUserRoleModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheUserRoleIdPrefix, primary)
}
func (m *defaultUserRoleModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRoleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultUserRoleModel) tableName() string {
return m.table
}

5
internal/model/vars.go Normal file
View File

@ -0,0 +1,5 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var ErrNotFound = sqlx.ErrNotFound

View File

@ -0,0 +1,83 @@
// Code generated by goctl. DO NOT EDIT.
// Source: service.proto
package server
import (
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/logic/tokenservice"
"app-cloudep-permission-server/internal/svc"
)
type TokenServiceServer struct {
svcCtx *svc.ServiceContext
permission.UnimplementedTokenServiceServer
}
func NewTokenServiceServer(svcCtx *svc.ServiceContext) *TokenServiceServer {
return &TokenServiceServer{
svcCtx: svcCtx,
}
}
// NewToken 建立一個新的 Token例如AccessToken
func (s *TokenServiceServer) NewToken(ctx context.Context, in *permission.AuthorizationReq) (*permission.TokenResp, error) {
l := tokenservicelogic.NewNewTokenLogic(ctx, s.svcCtx)
return l.NewToken(in)
}
// RefreshToken 更新目前的token 以及裡面包含的一次性 Token
func (s *TokenServiceServer) RefreshToken(ctx context.Context, in *permission.RefreshTokenReq) (*permission.RefreshTokenResp, error) {
l := tokenservicelogic.NewRefreshTokenLogic(ctx, s.svcCtx)
return l.RefreshToken(in)
}
// CancelToken 取消 Token也包含他裡面的 One Time Toke
func (s *TokenServiceServer) CancelToken(ctx context.Context, in *permission.CancelTokenReq) (*permission.OKResp, error) {
l := tokenservicelogic.NewCancelTokenLogic(ctx, s.svcCtx)
return l.CancelToken(in)
}
// ValidationToken 驗證這個 Token 有沒有效
func (s *TokenServiceServer) ValidationToken(ctx context.Context, in *permission.ValidationTokenReq) (*permission.ValidationTokenResp, error) {
l := tokenservicelogic.NewValidationTokenLogic(ctx, s.svcCtx)
return l.ValidationToken(in)
}
// CancelTokens 取消 Token 從UID 視角,以及 token id 視角出發, UID 登出,底下所有 Device ID 也要登出, Token ID 登出, 所有 UID + Device 都要登出
func (s *TokenServiceServer) CancelTokens(ctx context.Context, in *permission.DoTokenByUIDReq) (*permission.OKResp, error) {
l := tokenservicelogic.NewCancelTokensLogic(ctx, s.svcCtx)
return l.CancelTokens(in)
}
// CancelTokenByDeviceId 取消 Token 從 Device 視角出發可以選登出這個Device 下所有 token 登出這個Device 下指定token
func (s *TokenServiceServer) CancelTokenByDeviceId(ctx context.Context, in *permission.DoTokenByDeviceIDReq) (*permission.OKResp, error) {
l := tokenservicelogic.NewCancelTokenByDeviceIdLogic(ctx, s.svcCtx)
return l.CancelTokenByDeviceId(in)
}
// GetUserTokensByDeviceId 取得目前所對應的 DeviceID 所存在的 Tokens
func (s *TokenServiceServer) GetUserTokensByDeviceId(ctx context.Context, in *permission.DoTokenByDeviceIDReq) (*permission.Tokens, error) {
l := tokenservicelogic.NewGetUserTokensByDeviceIdLogic(ctx, s.svcCtx)
return l.GetUserTokensByDeviceId(in)
}
// GetUserTokensByUid 取得目前所對應的 UID 所存在的 Tokens
func (s *TokenServiceServer) GetUserTokensByUid(ctx context.Context, in *permission.QueryTokenByUIDReq) (*permission.Tokens, error) {
l := tokenservicelogic.NewGetUserTokensByUidLogic(ctx, s.svcCtx)
return l.GetUserTokensByUid(in)
}
// NewOneTimeToken 建立一次性使用例如RefreshToken
func (s *TokenServiceServer) NewOneTimeToken(ctx context.Context, in *permission.CreateOneTimeTokenReq) (*permission.CreateOneTimeTokenResp, error) {
l := tokenservicelogic.NewNewOneTimeTokenLogic(ctx, s.svcCtx)
return l.NewOneTimeToken(in)
}
// CancelOneTimeToken 取消一次性使用
func (s *TokenServiceServer) CancelOneTimeToken(ctx context.Context, in *permission.CancelOneTimeTokenReq) (*permission.OKResp, error) {
l := tokenservicelogic.NewCancelOneTimeTokenLogic(ctx, s.svcCtx)
return l.CancelOneTimeToken(in)
}

View File

@ -0,0 +1,13 @@
package svc
import "app-cloudep-permission-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-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/config"
tokenserviceServer "app-cloudep-permission-server/internal/server/tokenservice"
"app-cloudep-permission-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) {
permission.RegisterTokenServiceServer(grpcServer, tokenserviceServer.NewTokenServiceServer(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()
}