From a59d2ae8cde54f3644ab245216f92bb58c90418c Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 1 Feb 2023 11:11:59 +0800 Subject: [PATCH 01/10] casbin --- bizdemo/hertz_casbin/.gitignore | 37 + bizdemo/hertz_casbin/.hz | 3 + bizdemo/hertz_casbin/Makefile | 5 + bizdemo/hertz_casbin/README.md | 83 + bizdemo/hertz_casbin/biz/dal/init.go | 24 + bizdemo/hertz_casbin/biz/dal/mysql/init.go | 45 + bizdemo/hertz_casbin/biz/dal/mysql/user.go | 70 + .../biz/handler/middle_service.go | 50 + bizdemo/hertz_casbin/biz/handler/ping.go | 33 + .../biz/handler/user/user_service.go | 199 ++ bizdemo/hertz_casbin/biz/model/sql/user.sql | 46 + bizdemo/hertz_casbin/biz/model/user/user.go | 2963 +++++++++++++++++ bizdemo/hertz_casbin/biz/mw/casbin.go | 22 + bizdemo/hertz_casbin/biz/mw/session.go | 35 + bizdemo/hertz_casbin/biz/router/register.go | 14 + .../biz/router/user/middleware.go | 63 + bizdemo/hertz_casbin/biz/router/user/user.go | 31 + bizdemo/hertz_casbin/conf/auth_model.conf | 13 + bizdemo/hertz_casbin/conf/policy.csv | 7 + bizdemo/hertz_casbin/docker-compose.yml | 16 + bizdemo/hertz_casbin/go.mod | 45 + bizdemo/hertz_casbin/go.sum | 107 + bizdemo/hertz_casbin/idl/user.thrift | 50 + bizdemo/hertz_casbin/main.go | 39 + bizdemo/hertz_casbin/pkg/consts/consts.go | 43 + bizdemo/hertz_casbin/pkg/utils/utils.go | 47 + bizdemo/hertz_casbin/router.go | 33 + bizdemo/hertz_casbin/router_gen.go | 19 + 28 files changed, 4142 insertions(+) create mode 100644 bizdemo/hertz_casbin/.gitignore create mode 100755 bizdemo/hertz_casbin/.hz create mode 100644 bizdemo/hertz_casbin/Makefile create mode 100644 bizdemo/hertz_casbin/README.md create mode 100644 bizdemo/hertz_casbin/biz/dal/init.go create mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/init.go create mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/user.go create mode 100644 bizdemo/hertz_casbin/biz/handler/middle_service.go create mode 100644 bizdemo/hertz_casbin/biz/handler/ping.go create mode 100644 bizdemo/hertz_casbin/biz/handler/user/user_service.go create mode 100644 bizdemo/hertz_casbin/biz/model/sql/user.sql create mode 100644 bizdemo/hertz_casbin/biz/model/user/user.go create mode 100644 bizdemo/hertz_casbin/biz/mw/casbin.go create mode 100644 bizdemo/hertz_casbin/biz/mw/session.go create mode 100644 bizdemo/hertz_casbin/biz/router/register.go create mode 100644 bizdemo/hertz_casbin/biz/router/user/middleware.go create mode 100644 bizdemo/hertz_casbin/biz/router/user/user.go create mode 100644 bizdemo/hertz_casbin/conf/auth_model.conf create mode 100644 bizdemo/hertz_casbin/conf/policy.csv create mode 100644 bizdemo/hertz_casbin/docker-compose.yml create mode 100644 bizdemo/hertz_casbin/go.mod create mode 100644 bizdemo/hertz_casbin/go.sum create mode 100644 bizdemo/hertz_casbin/idl/user.thrift create mode 100644 bizdemo/hertz_casbin/main.go create mode 100644 bizdemo/hertz_casbin/pkg/consts/consts.go create mode 100644 bizdemo/hertz_casbin/pkg/utils/utils.go create mode 100644 bizdemo/hertz_casbin/router.go create mode 100644 bizdemo/hertz_casbin/router_gen.go diff --git a/bizdemo/hertz_casbin/.gitignore b/bizdemo/hertz_casbin/.gitignore new file mode 100644 index 00000000..101ea87c --- /dev/null +++ b/bizdemo/hertz_casbin/.gitignore @@ -0,0 +1,37 @@ +*.o +*.a +*.so +_obj +_test +*.[568vq] +[568vq].out +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* +_testmain.go +*.exe +*.exe~ +*.test +*.prof +*.rar +*.zip +*.gz +*.psd +*.bmd +*.cfg +*.pptx +*.log +*nohup.out +*settings.pyc +*.sublime-project +*.sublime-workspace +!.gitkeep +.DS_Store +/.idea +/.vscode +/output +*.local.yml +dumped_hertz_remote_config.json + \ No newline at end of file diff --git a/bizdemo/hertz_casbin/.hz b/bizdemo/hertz_casbin/.hz new file mode 100755 index 00000000..9285a978 --- /dev/null +++ b/bizdemo/hertz_casbin/.hz @@ -0,0 +1,3 @@ +// Code generated by hz. DO NOT EDIT. + +hz version: v0.5.1 diff --git a/bizdemo/hertz_casbin/Makefile b/bizdemo/hertz_casbin/Makefile new file mode 100644 index 00000000..c35ed315 --- /dev/null +++ b/bizdemo/hertz_casbin/Makefile @@ -0,0 +1,5 @@ +init_api: + hz new -mod hertz-examples/bizdemo/hertz_session -idl idl/user.thrift + +update_api: + hz update -I -idl idl/user.thrift \ No newline at end of file diff --git a/bizdemo/hertz_casbin/README.md b/bizdemo/hertz_casbin/README.md new file mode 100644 index 00000000..c126747e --- /dev/null +++ b/bizdemo/hertz_casbin/README.md @@ -0,0 +1,83 @@ +# hertz_session + +## Introduce + +A demo with `Hertz` and `Casbin`, this demo aims to demonstrate a distributed session solution based on the `hertz-contrib/sessions`. + +The distributed session solution based on redis is to store the sessions of different servers in redis or redis cluster, +which aims to solve the problem that the sessions of multiple servers are not synchronized in the case of distributed system. + +- Use `thrift` IDL to define `HTTP` interface +- Use `hz` to generate code +- Use `hertz-contrib/sessions` to store sessions +- Use `casbin` to judgment authority +- Use `Gorm` and `MySQL` + +## hertz-contrib/sessions + +Use Hertz's sessions extension, refer to [hertz-contrib/sessions](https://github.com/hertz-contrib/sessions) + +## casbin + +Simplistic Example of role-based HTTP Authorization with [casbin](https://github.com/casbin/casbin) using [scs](https://github.com/alexedwards/scs) for session handling. + +## IDL + +This demo use `thrift` IDL to define `HTTP` interface. The specific interface define in [user.thrift](idl/user.thrift) + +### Generate MySQL table + +Connect MySQL and execute [user.sql](biz/model/sql/user.sql) + +### Permission list + +This is where the permissions are defined [policy.csv](conf/policy.csv),each http request is determined. + + + +## Code generation tool + +This demo use `hz` to generate code. The use of `hz` refers to [hz](https://www.cloudwego.io/docs/hertz/tutorials/toolkit/toolkit/) + +The `hz` commands used can be found in [Makefile](Makefile) + +## Binding and Validate + +The use of binding and Validate refers +to [Binding and Validate](https://www.cloudwego.io/docs/hertz/tutorials/basic-feature/binding-and-validate/) + +## Gorm + +This demo use `Gorm` to operate `MySQL` and refers to [Gorm](https://gorm.io/) + +## AdminLTE + +This demo captures the [AdminLTE](https://github.com/ColorlibHQ/AdminLTE) login and registration page as the front-end page. + +## How to run + +### Run MySQL and Redis docker + +```bash +cd bizdemo/hertz_casbin && docker-compose up +``` + +### Run demo + +```bash +cd bizdemo/hertz_casbin +go run . +``` + +Which starts a server at `http://localhost:8888` with the following routes: + +* `POST /login` - accessible if not logged in + * takes `username` as a form-data parameter - password is 123 + * Valid Users: + * `admin` ID: `1`, Role: `admin` + * `darren` ID: `2`, Role: `member` +* `POST /logout` - accessible if logged in +* `GET /findUser` - accessible if logged in as a member +* `GET /member/list` - accessible if logged in as a member && admin +* `GET /admin/list` - accessible if logged in as an admin + \ No newline at end of file diff --git a/bizdemo/hertz_casbin/biz/dal/init.go b/bizdemo/hertz_casbin/biz/dal/init.go new file mode 100644 index 00000000..739e93a3 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/init.go @@ -0,0 +1,24 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dal + +import "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal/mysql" + +// Init init mysql +func Init() { + mysql.Init() +} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/init.go b/bizdemo/hertz_casbin/biz/dal/mysql/init.go new file mode 100644 index 00000000..e66802de --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/mysql/init.go @@ -0,0 +1,45 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package mysql + +import ( + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" + "gorm.io/driver/mysql" + "gorm.io/gorm" + "gorm.io/gorm/logger" +) + +var DB *gorm.DB + +func Init() { + var err error + DB, err = gorm.Open(mysql.Open(consts.MySQLDefaultDSN), &gorm.Config{ + SkipDefaultTransaction: true, + PrepareStmt: true, + Logger: logger.Default.LogMode(logger.Info), + }) + if err != nil { + panic(err) + } + m := DB.Migrator() + if m.HasTable(&User{}) { + return + } + if err = m.CreateTable(&User{}); err != nil { + panic(err) + } +} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/user.go b/bizdemo/hertz_casbin/biz/dal/mysql/user.go new file mode 100644 index 00000000..72b287c8 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/mysql/user.go @@ -0,0 +1,70 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package mysql + +import ( + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" + "gorm.io/gorm" +) + +type User struct { + gorm.Model + Username string `json:"username"` + Password string `json:"password"` + Email string `json:"email"` + Role string `json:"role"` +} + +func (u *User) TableName() string { + return consts.UserTableName +} + +func CreateUsers(users []*User) error { + return DB.Create(users).Error +} + +func FindUserByNameOrEmail(username, email string) ([]*User, error) { + res := make([]*User, 0) + if err := DB.Where("username = ?", username).Or("email = ?", email).Find(&res).Error; err != nil { + return nil, err + } + return res, nil +} + +func CheckUser(username, password string) ([]*User, error) { + res := make([]*User, 0) + if err := DB.Where("username = ? AND password = ?", username, password).Find(&res).Error; err != nil { + return nil, err + } + return res, nil +} + +func CheckUserExists(username string) ([]*User, error) { + res := make([]*User, 0) + if err := DB.Where("username = ? ", username).Limit(1).Find(&res).Error; err != nil { + return nil, err + } + return res, nil +} + +func RoleList(role string) ([]*User, error) { + res := make([]*User, 0) + if err := DB.Where("role = ? ", role).Find(&res).Error; err != nil { + return nil, err + } + return res, nil +} diff --git a/bizdemo/hertz_casbin/biz/handler/middle_service.go b/bizdemo/hertz_casbin/biz/handler/middle_service.go new file mode 100644 index 00000000..bdc31bb5 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/handler/middle_service.go @@ -0,0 +1,50 @@ +package handler + +import ( + "context" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal/mysql" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/mw" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/common/utils" + "github.com/hertz-contrib/sessions" +) + +func Auth(_ context.Context, c *app.RequestContext) map[string]interface{} { + + session := sessions.Default(c) + + role := session.Get(consts.Role) + if role == "" || role == nil { + role = "anonymous" + } + + if c.FullPath() == "/login" || c.FullPath() == "/register" { + role = "anonymous" + } + + // if it's a member, check if the user still exists + if role == "member" { + username := session.Get(consts.Username) + + _, err := mysql.CheckUserExists(username.(string)) + + if err != nil { + + return utils.H{"code": 1, "message": "FORBIDDEN"} + } + } + + // casbin enforce + res, err := mw.Authorize(role, c.FullPath(), string(c.Request.Header.Method())) + if err != nil { + return utils.H{"code": 1, "message": "ERROR"} + } + + if res { + return utils.H{"code": 0, "message": "ok"} + } else { + + return utils.H{"code": 1, "message": "FORBIDDEN"} + } +} diff --git a/bizdemo/hertz_casbin/biz/handler/ping.go b/bizdemo/hertz_casbin/biz/handler/ping.go new file mode 100644 index 00000000..425d50f5 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/handler/ping.go @@ -0,0 +1,33 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by hertz generator. + +package handler + +import ( + "context" + + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/common/utils" +) + +// Ping . +func Ping(ctx context.Context, c *app.RequestContext) { + c.JSON(200, utils.H{ + "message": "pong", + }) +} diff --git a/bizdemo/hertz_casbin/biz/handler/user/user_service.go b/bizdemo/hertz_casbin/biz/handler/user/user_service.go new file mode 100644 index 00000000..8eab8691 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/handler/user/user_service.go @@ -0,0 +1,199 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by hertz generator. + +package user + +import ( + "context" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler" + "net/http" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal/mysql" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/model/user" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/utils" + "github.com/cloudwego/hertz/pkg/app" + result "github.com/cloudwego/hertz/pkg/common/utils" + "github.com/hertz-contrib/sessions" +) + +// Register . +// @router /register [POST] +func Register(ctx context.Context, c *app.RequestContext) { + res := handler.Auth(ctx, c) + if res["code"] != 0 { + c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) + return + } + var err error + var req user.RegisterRequest + + err = c.BindAndValidate(&req) + if err != nil { + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + users, err := mysql.FindUserByNameOrEmail(req.Username, req.Email) + if err != nil { + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + if len(users) != 0 { + c.JSON(http.StatusOK, user.BaseResp{1, consts.RegisterErr}) + return + } + if err = mysql.CreateUsers([]*mysql.User{ + { + Username: req.Username, + Password: utils.MD5(req.Password), + Email: req.Email, + }, + }); err != nil { + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + c.JSON(http.StatusOK, user.BaseResp{0, consts.Success}) +} + +// Login . +// @router /login [POST] +func Login(ctx context.Context, c *app.RequestContext) { + res := handler.Auth(ctx, c) + if res["code"] != 0 { + c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) + return + } + + var err error + var req user.LoginRequest + + err = c.BindAndValidate(&req) + if err != nil { + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + users, err := mysql.CheckUser(req.Username, utils.MD5(req.Password)) + if err != nil { + + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + if len(users) == 0 { + c.JSON(http.StatusOK, user.BaseResp{1, consts.LoginErr}) + return + } + session := sessions.Default(c) + session.Set(consts.Username, req.Username) + session.Set(consts.Role, users[0].Role) + _ = session.Save() + c.JSON(http.StatusOK, user.BaseResp{0, consts.Success}) +} + +// Logout . +// @router /logout [GET] +func Logout(ctx context.Context, c *app.RequestContext) { + res := handler.Auth(ctx, c) + if res["code"] != 0 { + c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) + return + } + + session := sessions.Default(c) + session.Delete(consts.Username) + session.Clear() + session.Delete(consts.Role) + _ = session.Save() + c.JSON(http.StatusOK, user.BaseResp{0, consts.Success}) + +} + +// FindUser . +// @router /findUser [GET] +func FindUser(ctx context.Context, c *app.RequestContext) { + + res := handler.Auth(ctx, c) + if res["code"] != 0 { + c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) + return + } + + session := sessions.Default(c) + + username := session.Get(consts.Username) + + var err error + users, err := mysql.CheckUserExists(username.(string)) + if err != nil { + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + c.JSON(http.StatusOK, result.H{"code": 0, "message": consts.Success, "data": users[0]}) + +} + +// MemberList . +// @router /member/list [GET] +func MemberList(ctx context.Context, c *app.RequestContext) { + res := handler.Auth(ctx, c) + if res["code"] != 0 { + c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) + return + } + + var err error + + session := sessions.Default(c) + + role := session.Get(consts.Role) + + users, err := mysql.RoleList(role.(string)) + + if err != nil { + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + + c.JSON(http.StatusOK, result.H{"code": 0, "message": consts.Success, "data": users}) + +} + +// AdminList . +// @router /admin/list [GET] +func AdminList(ctx context.Context, c *app.RequestContext) { + + res := handler.Auth(ctx, c) + if res["code"] != 0 { + c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) + return + } + + var err error + + session := sessions.Default(c) + + role := session.Get(consts.Role) + + users, err := mysql.RoleList(role.(string)) + + if err != nil { + c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) + return + } + + c.JSON(http.StatusOK, result.H{"code": 0, "message": consts.Success, "data": users}) +} diff --git a/bizdemo/hertz_casbin/biz/model/sql/user.sql b/bizdemo/hertz_casbin/biz/model/sql/user.sql new file mode 100644 index 00000000..a803046a --- /dev/null +++ b/bizdemo/hertz_casbin/biz/model/sql/user.sql @@ -0,0 +1,46 @@ +/* + Navicat Premium Data Transfer + + Source Server : 9911 + Source Server Type : MySQL + Source Server Version : 80032 + Source Host : localhost:9911 + Source Schema : gorm + + Target Server Type : MySQL + Target Server Version : 80032 + File Encoding : 65001 + + Date: 01/02/2023 10:58:17 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( + `ID` bigint NOT NULL AUTO_INCREMENT, + `username` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, + `password` varchar(255) DEFAULT NULL, + `email` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, + `role` varchar(30) DEFAULT NULL, + `deleted_at` datetime DEFAULT NULL, + `updated_at` datetime DEFAULT NULL, + `created_at` datetime DEFAULT NULL, + PRIMARY KEY (`ID`), + UNIQUE KEY `username` (`username`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- ---------------------------- +-- Records of users +-- ---------------------------- +BEGIN; +INSERT INTO `users` (`ID`, `username`, `password`, `email`, `role`, `deleted_at`, `updated_at`, `created_at`) VALUES (1, 'admin', '202cb962ac59075b964b07152d234b70', 'darren94me@gmail.com', 'admin', NULL, '2023-01-31 15:46:06', '2023-01-31 15:46:06'); +INSERT INTO `users` (`ID`, `username`, `password`, `email`, `role`, `deleted_at`, `updated_at`, `created_at`) VALUES (2, 'darren', '202cb962ac59075b964b07152d234b70', 'darren@11.com', 'member', NULL, '2023-01-31 17:39:39', '2023-01-31 17:39:39'); +INSERT INTO `users` (`ID`, `username`, `password`, `email`, `role`, `deleted_at`, `updated_at`, `created_at`) VALUES (3, 'zhangsan', '202cb962ac59075b964b07152d234b70', 'zhangsan@163.com', 'member', NULL, '2023-01-31 18:05:39', '2023-01-31 18:05:39'); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/bizdemo/hertz_casbin/biz/model/user/user.go b/bizdemo/hertz_casbin/biz/model/user/user.go new file mode 100644 index 00000000..6ab17dc2 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/model/user/user.go @@ -0,0 +1,2963 @@ +// Code generated by thriftgo (0.2.5). DO NOT EDIT. + +package user + +import ( + "context" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +type BaseResp struct { + Code int64 `thrift:"code,1" form:"code" json:"code" query:"code"` + Message string `thrift:"message,2" form:"message" json:"message" query:"message"` +} + +func NewBaseResp() *BaseResp { + return &BaseResp{} +} + +func (p *BaseResp) GetCode() (v int64) { + return p.Code +} + +func (p *BaseResp) GetMessage() (v string) { + return p.Message +} + +var fieldIDToName_BaseResp = map[int16]string{ + 1: "code", + 2: "message", +} + +func (p *BaseResp) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I64 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_BaseResp[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *BaseResp) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.Code = v + } + return nil +} + +func (p *BaseResp) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *BaseResp) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BaseResp"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *BaseResp) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I64, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.Code); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *BaseResp) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *BaseResp) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("BaseResp(%+v)", *p) +} + +type RegisterRequest struct { + Username string `thrift:"username,1" form:"username" json:"username" vd:"(len($) > 0 && len($) < 128); msg:'Illegal format'"` + Password string `thrift:"password,2" form:"password" json:"password" vd:"(len($) > 0 && len($) < 128); msg:'Illegal format'"` + Email string `thrift:"email,3" form:"email" json:"email" vd:"(len($) > 0 && len($) < 128) && email($); msg:'Illegal format'"` +} + +func NewRegisterRequest() *RegisterRequest { + return &RegisterRequest{} +} + +func (p *RegisterRequest) GetUsername() (v string) { + return p.Username +} + +func (p *RegisterRequest) GetPassword() (v string) { + return p.Password +} + +func (p *RegisterRequest) GetEmail() (v string) { + return p.Email +} + +var fieldIDToName_RegisterRequest = map[int16]string{ + 1: "username", + 2: "password", + 3: "email", +} + +func (p *RegisterRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRING { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RegisterRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *RegisterRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Username = v + } + return nil +} + +func (p *RegisterRequest) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Password = v + } + return nil +} + +func (p *RegisterRequest) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Email = v + } + return nil +} + +func (p *RegisterRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("RegisterRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *RegisterRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("username", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Username); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *RegisterRequest) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("password", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Password); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *RegisterRequest) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("email", thrift.STRING, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Email); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *RegisterRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("RegisterRequest(%+v)", *p) +} + +type RegisterResponse struct { + Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` +} + +func NewRegisterResponse() *RegisterResponse { + return &RegisterResponse{} +} + +var RegisterResponse_Baseresp_DEFAULT *BaseResp + +func (p *RegisterResponse) GetBaseresp() (v *BaseResp) { + if !p.IsSetBaseresp() { + return RegisterResponse_Baseresp_DEFAULT + } + return p.Baseresp +} + +var fieldIDToName_RegisterResponse = map[int16]string{ + 1: "baseresp", +} + +func (p *RegisterResponse) IsSetBaseresp() bool { + return p.Baseresp != nil +} + +func (p *RegisterResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RegisterResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *RegisterResponse) ReadField1(iprot thrift.TProtocol) error { + p.Baseresp = NewBaseResp() + if err := p.Baseresp.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *RegisterResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("RegisterResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *RegisterResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Baseresp.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *RegisterResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("RegisterResponse(%+v)", *p) +} + +type LoginRequest struct { + Username string `thrift:"username,1" form:"username" json:"username" vd:"(len($) > 0 && len($) < 30); msg:'Illegal format'"` + Password string `thrift:"password,2" form:"password" json:"password" vd:"(len($) > 0 && len($) < 30); msg:'Illegal format'"` +} + +func NewLoginRequest() *LoginRequest { + return &LoginRequest{} +} + +func (p *LoginRequest) GetUsername() (v string) { + return p.Username +} + +func (p *LoginRequest) GetPassword() (v string) { + return p.Password +} + +var fieldIDToName_LoginRequest = map[int16]string{ + 1: "username", + 2: "password", +} + +func (p *LoginRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_LoginRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *LoginRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Username = v + } + return nil +} + +func (p *LoginRequest) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Password = v + } + return nil +} + +func (p *LoginRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("LoginRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *LoginRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("username", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Username); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *LoginRequest) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("password", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Password); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *LoginRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("LoginRequest(%+v)", *p) +} + +type LoginResponse struct { + Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` +} + +func NewLoginResponse() *LoginResponse { + return &LoginResponse{} +} + +var LoginResponse_Baseresp_DEFAULT *BaseResp + +func (p *LoginResponse) GetBaseresp() (v *BaseResp) { + if !p.IsSetBaseresp() { + return LoginResponse_Baseresp_DEFAULT + } + return p.Baseresp +} + +var fieldIDToName_LoginResponse = map[int16]string{ + 1: "baseresp", +} + +func (p *LoginResponse) IsSetBaseresp() bool { + return p.Baseresp != nil +} + +func (p *LoginResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_LoginResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *LoginResponse) ReadField1(iprot thrift.TProtocol) error { + p.Baseresp = NewBaseResp() + if err := p.Baseresp.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *LoginResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("LoginResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *LoginResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Baseresp.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *LoginResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("LoginResponse(%+v)", *p) +} + +type FindUserResponse struct { + Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` +} + +func NewFindUserResponse() *FindUserResponse { + return &FindUserResponse{} +} + +var FindUserResponse_Baseresp_DEFAULT *BaseResp + +func (p *FindUserResponse) GetBaseresp() (v *BaseResp) { + if !p.IsSetBaseresp() { + return FindUserResponse_Baseresp_DEFAULT + } + return p.Baseresp +} + +var fieldIDToName_FindUserResponse = map[int16]string{ + 1: "baseresp", +} + +func (p *FindUserResponse) IsSetBaseresp() bool { + return p.Baseresp != nil +} + +func (p *FindUserResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_FindUserResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *FindUserResponse) ReadField1(iprot thrift.TProtocol) error { + p.Baseresp = NewBaseResp() + if err := p.Baseresp.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *FindUserResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("FindUserResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *FindUserResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Baseresp.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *FindUserResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("FindUserResponse(%+v)", *p) +} + +type MemberListResponse struct { + Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` +} + +func NewMemberListResponse() *MemberListResponse { + return &MemberListResponse{} +} + +var MemberListResponse_Baseresp_DEFAULT *BaseResp + +func (p *MemberListResponse) GetBaseresp() (v *BaseResp) { + if !p.IsSetBaseresp() { + return MemberListResponse_Baseresp_DEFAULT + } + return p.Baseresp +} + +var fieldIDToName_MemberListResponse = map[int16]string{ + 1: "baseresp", +} + +func (p *MemberListResponse) IsSetBaseresp() bool { + return p.Baseresp != nil +} + +func (p *MemberListResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_MemberListResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *MemberListResponse) ReadField1(iprot thrift.TProtocol) error { + p.Baseresp = NewBaseResp() + if err := p.Baseresp.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *MemberListResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("MemberListResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *MemberListResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Baseresp.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *MemberListResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("MemberListResponse(%+v)", *p) +} + +type AdminListResponse struct { + Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` +} + +func NewAdminListResponse() *AdminListResponse { + return &AdminListResponse{} +} + +var AdminListResponse_Baseresp_DEFAULT *BaseResp + +func (p *AdminListResponse) GetBaseresp() (v *BaseResp) { + if !p.IsSetBaseresp() { + return AdminListResponse_Baseresp_DEFAULT + } + return p.Baseresp +} + +var fieldIDToName_AdminListResponse = map[int16]string{ + 1: "baseresp", +} + +func (p *AdminListResponse) IsSetBaseresp() bool { + return p.Baseresp != nil +} + +func (p *AdminListResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_AdminListResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *AdminListResponse) ReadField1(iprot thrift.TProtocol) error { + p.Baseresp = NewBaseResp() + if err := p.Baseresp.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *AdminListResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("AdminListResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *AdminListResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Baseresp.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *AdminListResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AdminListResponse(%+v)", *p) +} + +type UserService interface { + Register(ctx context.Context, req *RegisterRequest) (r *RegisterResponse, err error) + + Login(ctx context.Context, req *LoginRequest) (r *LoginResponse, err error) + + FindUser(ctx context.Context) (r *FindUserResponse, err error) + + MemberList(ctx context.Context) (r *MemberListResponse, err error) + + AdminList(ctx context.Context) (r *AdminListResponse, err error) +} + +type UserServiceClient struct { + c thrift.TClient +} + +func NewUserServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *UserServiceClient { + return &UserServiceClient{ + c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), + } +} + +func NewUserServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *UserServiceClient { + return &UserServiceClient{ + c: thrift.NewTStandardClient(iprot, oprot), + } +} + +func NewUserServiceClient(c thrift.TClient) *UserServiceClient { + return &UserServiceClient{ + c: c, + } +} + +func (p *UserServiceClient) Client_() thrift.TClient { + return p.c +} + +func (p *UserServiceClient) Register(ctx context.Context, req *RegisterRequest) (r *RegisterResponse, err error) { + var _args UserServiceRegisterArgs + _args.Req = req + var _result UserServiceRegisterResult + if err = p.Client_().Call(ctx, "register", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *UserServiceClient) Login(ctx context.Context, req *LoginRequest) (r *LoginResponse, err error) { + var _args UserServiceLoginArgs + _args.Req = req + var _result UserServiceLoginResult + if err = p.Client_().Call(ctx, "login", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *UserServiceClient) FindUser(ctx context.Context) (r *FindUserResponse, err error) { + var _args UserServiceFindUserArgs + var _result UserServiceFindUserResult + if err = p.Client_().Call(ctx, "findUser", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *UserServiceClient) MemberList(ctx context.Context) (r *MemberListResponse, err error) { + var _args UserServiceMemberListArgs + var _result UserServiceMemberListResult + if err = p.Client_().Call(ctx, "memberList", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *UserServiceClient) AdminList(ctx context.Context) (r *AdminListResponse, err error) { + var _args UserServiceAdminListArgs + var _result UserServiceAdminListResult + if err = p.Client_().Call(ctx, "adminList", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +type UserServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler UserService +} + +func (p *UserServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *UserServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *UserServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewUserServiceProcessor(handler UserService) *UserServiceProcessor { + self := &UserServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self.AddToProcessorMap("register", &userServiceProcessorRegister{handler: handler}) + self.AddToProcessorMap("login", &userServiceProcessorLogin{handler: handler}) + self.AddToProcessorMap("findUser", &userServiceProcessorFindUser{handler: handler}) + self.AddToProcessorMap("memberList", &userServiceProcessorMemberList{handler: handler}) + self.AddToProcessorMap("adminList", &userServiceProcessorAdminList{handler: handler}) + return self +} +func (p *UserServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(ctx, seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, x +} + +type userServiceProcessorRegister struct { + handler UserService +} + +func (p *userServiceProcessorRegister) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := UserServiceRegisterArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("register", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := UserServiceRegisterResult{} + var retval *RegisterResponse + if retval, err2 = p.handler.Register(ctx, args.Req); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing register: "+err2.Error()) + oprot.WriteMessageBegin("register", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("register", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type userServiceProcessorLogin struct { + handler UserService +} + +func (p *userServiceProcessorLogin) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := UserServiceLoginArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("login", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := UserServiceLoginResult{} + var retval *LoginResponse + if retval, err2 = p.handler.Login(ctx, args.Req); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing login: "+err2.Error()) + oprot.WriteMessageBegin("login", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("login", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type userServiceProcessorFindUser struct { + handler UserService +} + +func (p *userServiceProcessorFindUser) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := UserServiceFindUserArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("findUser", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := UserServiceFindUserResult{} + var retval *FindUserResponse + if retval, err2 = p.handler.FindUser(ctx); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing findUser: "+err2.Error()) + oprot.WriteMessageBegin("findUser", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("findUser", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type userServiceProcessorMemberList struct { + handler UserService +} + +func (p *userServiceProcessorMemberList) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := UserServiceMemberListArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("memberList", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := UserServiceMemberListResult{} + var retval *MemberListResponse + if retval, err2 = p.handler.MemberList(ctx); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing memberList: "+err2.Error()) + oprot.WriteMessageBegin("memberList", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("memberList", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type userServiceProcessorAdminList struct { + handler UserService +} + +func (p *userServiceProcessorAdminList) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := UserServiceAdminListArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("adminList", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := UserServiceAdminListResult{} + var retval *AdminListResponse + if retval, err2 = p.handler.AdminList(ctx); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing adminList: "+err2.Error()) + oprot.WriteMessageBegin("adminList", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("adminList", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type UserServiceRegisterArgs struct { + Req *RegisterRequest `thrift:"req,1"` +} + +func NewUserServiceRegisterArgs() *UserServiceRegisterArgs { + return &UserServiceRegisterArgs{} +} + +var UserServiceRegisterArgs_Req_DEFAULT *RegisterRequest + +func (p *UserServiceRegisterArgs) GetReq() (v *RegisterRequest) { + if !p.IsSetReq() { + return UserServiceRegisterArgs_Req_DEFAULT + } + return p.Req +} + +var fieldIDToName_UserServiceRegisterArgs = map[int16]string{ + 1: "req", +} + +func (p *UserServiceRegisterArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *UserServiceRegisterArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceRegisterArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceRegisterArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req = NewRegisterRequest() + if err := p.Req.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceRegisterArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("register_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceRegisterArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *UserServiceRegisterArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceRegisterArgs(%+v)", *p) +} + +type UserServiceRegisterResult struct { + Success *RegisterResponse `thrift:"success,0,optional"` +} + +func NewUserServiceRegisterResult() *UserServiceRegisterResult { + return &UserServiceRegisterResult{} +} + +var UserServiceRegisterResult_Success_DEFAULT *RegisterResponse + +func (p *UserServiceRegisterResult) GetSuccess() (v *RegisterResponse) { + if !p.IsSetSuccess() { + return UserServiceRegisterResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_UserServiceRegisterResult = map[int16]string{ + 0: "success", +} + +func (p *UserServiceRegisterResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *UserServiceRegisterResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceRegisterResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceRegisterResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewRegisterResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceRegisterResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("register_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceRegisterResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *UserServiceRegisterResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceRegisterResult(%+v)", *p) +} + +type UserServiceLoginArgs struct { + Req *LoginRequest `thrift:"req,1"` +} + +func NewUserServiceLoginArgs() *UserServiceLoginArgs { + return &UserServiceLoginArgs{} +} + +var UserServiceLoginArgs_Req_DEFAULT *LoginRequest + +func (p *UserServiceLoginArgs) GetReq() (v *LoginRequest) { + if !p.IsSetReq() { + return UserServiceLoginArgs_Req_DEFAULT + } + return p.Req +} + +var fieldIDToName_UserServiceLoginArgs = map[int16]string{ + 1: "req", +} + +func (p *UserServiceLoginArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *UserServiceLoginArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceLoginArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceLoginArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req = NewLoginRequest() + if err := p.Req.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceLoginArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("login_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceLoginArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *UserServiceLoginArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceLoginArgs(%+v)", *p) +} + +type UserServiceLoginResult struct { + Success *LoginResponse `thrift:"success,0,optional"` +} + +func NewUserServiceLoginResult() *UserServiceLoginResult { + return &UserServiceLoginResult{} +} + +var UserServiceLoginResult_Success_DEFAULT *LoginResponse + +func (p *UserServiceLoginResult) GetSuccess() (v *LoginResponse) { + if !p.IsSetSuccess() { + return UserServiceLoginResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_UserServiceLoginResult = map[int16]string{ + 0: "success", +} + +func (p *UserServiceLoginResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *UserServiceLoginResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceLoginResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceLoginResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewLoginResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceLoginResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("login_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceLoginResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *UserServiceLoginResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceLoginResult(%+v)", *p) +} + +type UserServiceFindUserArgs struct { +} + +func NewUserServiceFindUserArgs() *UserServiceFindUserArgs { + return &UserServiceFindUserArgs{} +} + +var fieldIDToName_UserServiceFindUserArgs = map[int16]string{} + +func (p *UserServiceFindUserArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceFindUserArgs) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("findUser_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceFindUserArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceFindUserArgs(%+v)", *p) +} + +type UserServiceFindUserResult struct { + Success *FindUserResponse `thrift:"success,0,optional"` +} + +func NewUserServiceFindUserResult() *UserServiceFindUserResult { + return &UserServiceFindUserResult{} +} + +var UserServiceFindUserResult_Success_DEFAULT *FindUserResponse + +func (p *UserServiceFindUserResult) GetSuccess() (v *FindUserResponse) { + if !p.IsSetSuccess() { + return UserServiceFindUserResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_UserServiceFindUserResult = map[int16]string{ + 0: "success", +} + +func (p *UserServiceFindUserResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *UserServiceFindUserResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceFindUserResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceFindUserResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewFindUserResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceFindUserResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("findUser_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceFindUserResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *UserServiceFindUserResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceFindUserResult(%+v)", *p) +} + +type UserServiceMemberListArgs struct { +} + +func NewUserServiceMemberListArgs() *UserServiceMemberListArgs { + return &UserServiceMemberListArgs{} +} + +var fieldIDToName_UserServiceMemberListArgs = map[int16]string{} + +func (p *UserServiceMemberListArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceMemberListArgs) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("memberList_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceMemberListArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceMemberListArgs(%+v)", *p) +} + +type UserServiceMemberListResult struct { + Success *MemberListResponse `thrift:"success,0,optional"` +} + +func NewUserServiceMemberListResult() *UserServiceMemberListResult { + return &UserServiceMemberListResult{} +} + +var UserServiceMemberListResult_Success_DEFAULT *MemberListResponse + +func (p *UserServiceMemberListResult) GetSuccess() (v *MemberListResponse) { + if !p.IsSetSuccess() { + return UserServiceMemberListResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_UserServiceMemberListResult = map[int16]string{ + 0: "success", +} + +func (p *UserServiceMemberListResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *UserServiceMemberListResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceMemberListResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceMemberListResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewMemberListResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceMemberListResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("memberList_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceMemberListResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *UserServiceMemberListResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceMemberListResult(%+v)", *p) +} + +type UserServiceAdminListArgs struct { +} + +func NewUserServiceAdminListArgs() *UserServiceAdminListArgs { + return &UserServiceAdminListArgs{} +} + +var fieldIDToName_UserServiceAdminListArgs = map[int16]string{} + +func (p *UserServiceAdminListArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceAdminListArgs) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("adminList_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceAdminListArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceAdminListArgs(%+v)", *p) +} + +type UserServiceAdminListResult struct { + Success *AdminListResponse `thrift:"success,0,optional"` +} + +func NewUserServiceAdminListResult() *UserServiceAdminListResult { + return &UserServiceAdminListResult{} +} + +var UserServiceAdminListResult_Success_DEFAULT *AdminListResponse + +func (p *UserServiceAdminListResult) GetSuccess() (v *AdminListResponse) { + if !p.IsSetSuccess() { + return UserServiceAdminListResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_UserServiceAdminListResult = map[int16]string{ + 0: "success", +} + +func (p *UserServiceAdminListResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *UserServiceAdminListResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceAdminListResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceAdminListResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewAdminListResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceAdminListResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("adminList_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceAdminListResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *UserServiceAdminListResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceAdminListResult(%+v)", *p) +} diff --git a/bizdemo/hertz_casbin/biz/mw/casbin.go b/bizdemo/hertz_casbin/biz/mw/casbin.go new file mode 100644 index 00000000..1edc14b3 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/mw/casbin.go @@ -0,0 +1,22 @@ +package mw + +import ( + "github.com/casbin/casbin" + "log" +) + +var authEnforcer *casbin.Enforcer + +func InitCasbin() { + var err error + authEnforcer, err = casbin.NewEnforcerSafe("./conf/auth_model.conf", "./conf/policy.csv") + if err != nil { + log.Fatal(err) + } +} + +func Authorize(rvals ...interface{}) (result bool, err error) { + // casbin enforce + res, err1 := authEnforcer.EnforceSafe(rvals[0], rvals[1], rvals[2]) + return res, err1 +} diff --git a/bizdemo/hertz_casbin/biz/mw/session.go b/bizdemo/hertz_casbin/biz/mw/session.go new file mode 100644 index 00000000..648c5a63 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/mw/session.go @@ -0,0 +1,35 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package mw + +import ( + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" + "github.com/cloudwego/hertz/pkg/app/server" + "github.com/hertz-contrib/sessions" + "github.com/hertz-contrib/sessions/redis" + "math/rand" + "strconv" +) + +func InitSession(h *server.Hertz) { + store, err := redis.NewStore(consts.MaxIdleNum, consts.TCP, consts.RedisAddr, consts.RedisPasswd, []byte(consts.SessionSecretKey)) + if err != nil { + panic(err) + } + h.Use(sessions.New(consts.HertzSession+strconv.Itoa(rand.Int()), store)) + +} diff --git a/bizdemo/hertz_casbin/biz/router/register.go b/bizdemo/hertz_casbin/biz/router/register.go new file mode 100644 index 00000000..5cd9b100 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/router/register.go @@ -0,0 +1,14 @@ +// Code generated by hertz generator. DO NOT EDIT. + +package router + +import ( + user "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/router/user" + "github.com/cloudwego/hertz/pkg/app/server" +) + +// GeneratedRegister registers routers generated by IDL. +func GeneratedRegister(r *server.Hertz) { + //INSERT_POINT: DO NOT DELETE THIS LINE! + user.Register(r) +} diff --git a/bizdemo/hertz_casbin/biz/router/user/middleware.go b/bizdemo/hertz_casbin/biz/router/user/middleware.go new file mode 100644 index 00000000..94dff128 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/router/user/middleware.go @@ -0,0 +1,63 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by hertz generator. + +package User + +import ( + "github.com/cloudwego/hertz/pkg/app" +) + +func rootMw() []app.HandlerFunc { + // your code... + return nil +} + +func _loginMw() []app.HandlerFunc { + // your code... + return nil +} + +func _registerMw() []app.HandlerFunc { + // your code... + return nil +} + +func _finduserMw() []app.HandlerFunc { + // your code... + return nil +} + +func _adminMw() []app.HandlerFunc { + // your code... + return nil +} + +func __dminlistMw() []app.HandlerFunc { + // your code... + return nil +} + +func _memberMw() []app.HandlerFunc { + // your code... + return nil +} + +func _memberlistMw() []app.HandlerFunc { + // your code... + return nil +} diff --git a/bizdemo/hertz_casbin/biz/router/user/user.go b/bizdemo/hertz_casbin/biz/router/user/user.go new file mode 100644 index 00000000..8636f1dc --- /dev/null +++ b/bizdemo/hertz_casbin/biz/router/user/user.go @@ -0,0 +1,31 @@ +// Code generated by hertz generator. DO NOT EDIT. + +package User + +import ( + user "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler/user" + "github.com/cloudwego/hertz/pkg/app/server" +) + +/* + This file will register all the routes of the services in the master idl. + And it will update automatically when you use the "update" command for the idl. + So don't modify the contents of the file, or your code will be deleted when it is updated. +*/ + +// Register register routes based on the IDL 'api.${HTTP Method}' annotation. +func Register(r *server.Hertz) { + + root := r.Group("/", rootMw()...) + root.GET("/findUser", append(_finduserMw(), user.FindUser)...) + root.POST("/login", append(_loginMw(), user.Login)...) + root.POST("/register", append(_registerMw(), user.Register)...) + { + _admin := root.Group("/admin", _adminMw()...) + _admin.GET("/list", append(__dminlistMw(), user.AdminList)...) + } + { + _member := root.Group("/member", _memberMw()...) + _member.GET("/list", append(_memberlistMw(), user.MemberList)...) + } +} diff --git a/bizdemo/hertz_casbin/conf/auth_model.conf b/bizdemo/hertz_casbin/conf/auth_model.conf new file mode 100644 index 00000000..5498ccd3 --- /dev/null +++ b/bizdemo/hertz_casbin/conf/auth_model.conf @@ -0,0 +1,13 @@ +#request input +[request_definition] +r = sub, obj, act + +[policy_definition] +p = sub, obj, act + +[policy_effect] +e = some(where (p.eft == allow)) + +[matchers] +m = r.sub == p.sub && keyMatch(r.obj, p.obj) && (r.act == p.act || p.act == "*") + diff --git a/bizdemo/hertz_casbin/conf/policy.csv b/bizdemo/hertz_casbin/conf/policy.csv new file mode 100644 index 00000000..f6219e32 --- /dev/null +++ b/bizdemo/hertz_casbin/conf/policy.csv @@ -0,0 +1,7 @@ +p, admin, /*, * +p, anonymous, /login, * +p, member, /logout, * +p, anonymous, /register, * +p, member, /findUser, * +p, admin, /admin/*, * +p, member, /member/*, * \ No newline at end of file diff --git a/bizdemo/hertz_casbin/docker-compose.yml b/bizdemo/hertz_casbin/docker-compose.yml new file mode 100644 index 00000000..2923e188 --- /dev/null +++ b/bizdemo/hertz_casbin/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' + +services: + mysql: + image: 'mysql:latest' + ports: + - 9911:3306 + environment: + - MYSQL_DATABASE=gorm + - MYSQL_USER=gorm + - MYSQL_PASSWORD=gorm + - MYSQL_RANDOM_ROOT_PASSWORD="yes" + redis: + image: 'redis:latest' + ports: + - 6379:6379 \ No newline at end of file diff --git a/bizdemo/hertz_casbin/go.mod b/bizdemo/hertz_casbin/go.mod new file mode 100644 index 00000000..0b00b4e5 --- /dev/null +++ b/bizdemo/hertz_casbin/go.mod @@ -0,0 +1,45 @@ +module github.com/cloudwego/hertz-examples/bizdemo/hertz_session + +go 1.18 + +replace github.com/apache/thrift => github.com/apache/thrift v0.13.0 + +require ( + github.com/apache/thrift v0.0.0-00010101000000-000000000000 + github.com/casbin/casbin v1.3.0 + github.com/cloudwego/hertz v0.4.1 + github.com/hertz-contrib/csrf v0.1.1 + github.com/hertz-contrib/sessions v1.0.1 + gorm.io/driver/mysql v1.4.4 + gorm.io/gorm v1.24.2 +) + +require ( + github.com/Knetic/govaluate v3.0.0+incompatible // indirect + github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect + github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect + github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 // indirect + github.com/bytedance/sonic v1.5.0 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06 // indirect + github.com/cloudwego/netpoll v0.3.1 // indirect + github.com/fsnotify/fsnotify v1.5.4 // indirect + github.com/go-sql-driver/mysql v1.6.0 // indirect + github.com/golang/protobuf v1.5.0 // indirect + github.com/gomodule/redigo v2.0.0+incompatible // indirect + github.com/gorilla/context v1.1.1 // indirect + github.com/gorilla/securecookie v1.1.1 // indirect + github.com/gorilla/sessions v1.2.1 // indirect + github.com/henrylee2cn/ameda v1.4.10 // indirect + github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/klauspost/cpuid/v2 v2.0.9 // indirect + github.com/nyaruka/phonenumbers v1.0.55 // indirect + github.com/tidwall/gjson v1.13.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect + golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/bizdemo/hertz_casbin/go.sum b/bizdemo/hertz_casbin/go.sum new file mode 100644 index 00000000..15e40dd0 --- /dev/null +++ b/bizdemo/hertz_casbin/go.sum @@ -0,0 +1,107 @@ +github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg= +github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +github.com/apache/thrift v0.13.0 h1:5hryIiq9gtn+MiLVn0wP37kb/uTeRZgN08WoCsAhIhI= +github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04= +github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw= +github.com/bytedance/go-tagexpr/v2 v2.9.2 h1:QySJaAIQgOEDQBLS3x9BxOWrnhqu5sQ+f6HaZIxD39I= +github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM= +github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 h1:PtwsQyQJGxf8iaPptPNaduEIu9BnrNms+pcRdHAxZaM= +github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q= +github.com/bytedance/sonic v1.3.0/go.mod h1:V973WhNhGmvHxW6nQmsHEfHaoU9F3zTF+93rH03hcUQ= +github.com/bytedance/sonic v1.5.0 h1:XWdTi8bwPgxIML+eNV1IwNuTROK6EUrQ65ey8yd6fRQ= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/casbin/casbin v1.3.0 h1:EQmPGgOo8/veRZbg+w2aspCFHducIoq6a4wEYRcD3RM= +github.com/casbin/casbin v1.3.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06 h1:1sDoSuDPWzhkdzNVxCxtIaKiAe96ESVPv8coGwc1gZ4= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/cloudwego/hertz v0.3.0/go.mod h1:GWWYlAVkq1gDu6vJd/XNciWsP6q0d4TrEKk5fpJYF04= +github.com/cloudwego/hertz v0.4.1 h1:EcL7v+MGeCt+qsLC1JGvlkPTm3kHmwNQg43FcrMyd+s= +github.com/cloudwego/hertz v0.4.1/go.mod h1:K1U0RlU07CDeBINfHNbafH/3j9uSgIW8otbjUys3OPY= +github.com/cloudwego/netpoll v0.2.4/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= +github.com/cloudwego/netpoll v0.3.1 h1:xByoORmCLIyKZ8gS+da06WDo3j+jvmhaqS2KeKejtBk= +github.com/cloudwego/netpoll v0.3.1/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/goccy/go-json v0.9.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= +github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= +github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= +github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/henrylee2cn/ameda v1.4.8/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4= +github.com/henrylee2cn/ameda v1.4.10 h1:JdvI2Ekq7tapdPsuhrc4CaFiqw6QXFvZIULWJgQyCAk= +github.com/henrylee2cn/ameda v1.4.10/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4= +github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 h1:yE9ULgp02BhYIrO6sdV/FPe0xQM6fNHkVQW2IAymfM0= +github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/DM3671a5udlv2AdV2ni/MZzgfv2qrPL5nIi3EGQ= +github.com/hertz-contrib/csrf v0.1.1 h1:53HxseVzpW4JEUJ7ONAaQCyNBWXl+rn42LVqgwEQzRg= +github.com/hertz-contrib/csrf v0.1.1/go.mod h1:z6CW935kPp1qy1XHXL7memdWInXXTc3OiMLp/cEmZQY= +github.com/hertz-contrib/sessions v1.0.1 h1:2puqvNqzyuPC3+5gzMRS+xhvGdNq3Ux7OVEewLSJbAk= +github.com/hertz-contrib/sessions v1.0.1/go.mod h1:gyVq7zq5emvSTLpp4VrlLOXjnajorYZ1hH4ZSX9Afb0= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg= +github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M= +github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/mysql v1.4.4 h1:MX0K9Qvy0Na4o7qSC/YI7XxqUw5KDw01umqgID+svdQ= +gorm.io/driver/mysql v1.4.4/go.mod h1:BCg8cKI+R0j/rZRQxeKis/forqRwRSYOR8OM3Wo6hOM= +gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= +gorm.io/gorm v1.24.2 h1:9wR6CFD+G8nOusLdvkZelOEhpJVwwHzpQOUM+REd6U0= +gorm.io/gorm v1.24.2/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/bizdemo/hertz_casbin/idl/user.thrift b/bizdemo/hertz_casbin/idl/user.thrift new file mode 100644 index 00000000..190eae3b --- /dev/null +++ b/bizdemo/hertz_casbin/idl/user.thrift @@ -0,0 +1,50 @@ +namespace go user + + + + +struct BaseResp { + 1: i64 code + 2: string message +} + +struct RegisterRequest { + 1: string username (api.form="username", api.vd="(len($) > 0 && len($) < 128); msg:'Illegal format'") + 2: string password (api.form="password", api.vd="(len($) > 0 && len($) < 128); msg:'Illegal format'") + 3: string email (api.form="email", api.vd="(len($) > 0 && len($) < 128) && email($); msg:'Illegal format'") +} + +struct RegisterResponse { + 1: BaseResp baseresp +} + +struct LoginRequest { + 1: string username (api.form="username", api.vd="(len($) > 0 && len($) < 30); msg:'Illegal format'") + 2: string password (api.form="password", api.vd="(len($) > 0 && len($) < 30); msg:'Illegal format'") +} + +struct LoginResponse { + 1: BaseResp baseresp +} + +struct FindUserResponse { + 1: BaseResp baseresp +} + + +struct MemberListResponse { + 1: BaseResp baseresp +} + +struct AdminListResponse { + 1: BaseResp baseresp +} + + +service UserService { + RegisterResponse register(1: RegisterRequest req) (api.post="/register") + LoginResponse login(1: LoginRequest req) (api.post="/login") + FindUserResponse findUser() (api.get="/findUser") + MemberListResponse memberList() (api.get="/member/list") + AdminListResponse adminList() (api.get="/admin/list") +} \ No newline at end of file diff --git a/bizdemo/hertz_casbin/main.go b/bizdemo/hertz_casbin/main.go new file mode 100644 index 00000000..38e14342 --- /dev/null +++ b/bizdemo/hertz_casbin/main.go @@ -0,0 +1,39 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by hertz generator. + +package main + +import ( + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/mw" + "github.com/cloudwego/hertz/pkg/app/server" +) + +func Init(h *server.Hertz) { + dal.Init() + mw.InitCasbin() + mw.InitSession(h) + +} + +func main() { + h := server.Default() + Init(h) + register(h) + h.Spin() +} diff --git a/bizdemo/hertz_casbin/pkg/consts/consts.go b/bizdemo/hertz_casbin/pkg/consts/consts.go new file mode 100644 index 00000000..49d9fdce --- /dev/null +++ b/bizdemo/hertz_casbin/pkg/consts/consts.go @@ -0,0 +1,43 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package consts + +// constants +const ( + TCP = "tcp" + UserTableName = "users" + RedisAddr = "127.0.0.1:6379" + MaxIdleNum = 10 + RedisPasswd = "" + SessionSecretKey = "session-secret" + CSRFSecretKey = "csrf-secret" + CSRFKeyLookUp = "form:csrf" + Username = "username" + Role = "role" + HertzSession = "HERTZ-SESSION" + MySQLDefaultDSN = "gorm:gorm@tcp(localhost:9911)/gorm?charset=utf8&parseTime=True&loc=Local" +) + +// error msg +const ( + StatusOK = "ok" + Success = "success" + RegisterErr = "user already exists" + LoginErr = "wrong username or password" + PageErr = "please login first" + CSRFErr = "csrf exception" +) diff --git a/bizdemo/hertz_casbin/pkg/utils/utils.go b/bizdemo/hertz_casbin/pkg/utils/utils.go new file mode 100644 index 00000000..6b6dd932 --- /dev/null +++ b/bizdemo/hertz_casbin/pkg/utils/utils.go @@ -0,0 +1,47 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package utils + +import ( + "context" + "crypto/md5" + "encoding/hex" + "fmt" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" + "github.com/cloudwego/hertz/pkg/app" +) + +// MD5 use md5 to encrypt strings +func MD5(str string) string { + h := md5.New() + h.Write([]byte(str)) + return hex.EncodeToString(h.Sum(nil)) +} + +// BuildMsg render message for the html page +func BuildMsg(msg string) string { + return fmt.Sprintf("%v", msg) +} + +// IsLogout if user already login then return false +func IsLogout(_ context.Context, c *app.RequestContext) bool { + if string(c.Cookie(consts.HertzSession)) == "" { + return true + } + return false +} diff --git a/bizdemo/hertz_casbin/router.go b/bizdemo/hertz_casbin/router.go new file mode 100644 index 00000000..6f2b3396 --- /dev/null +++ b/bizdemo/hertz_casbin/router.go @@ -0,0 +1,33 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by hertz generator. + +package main + +import ( + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler/user" + "github.com/cloudwego/hertz/pkg/app/server" +) + +// customizeRegister registers customize routers. +func customizedRegister(r *server.Hertz) { + r.GET("/ping", handler.Ping) + + // your code ... + r.POST("/logout", user.Logout) +} diff --git a/bizdemo/hertz_casbin/router_gen.go b/bizdemo/hertz_casbin/router_gen.go new file mode 100644 index 00000000..42b02a48 --- /dev/null +++ b/bizdemo/hertz_casbin/router_gen.go @@ -0,0 +1,19 @@ +// Code generated by hertz generator. DO NOT EDIT. + +package main + +import ( + + router "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/router" + "github.com/cloudwego/hertz/pkg/app/server" +) + +// register registers all routers. +func register(r *server.Hertz) { + + + + router.GeneratedRegister(r) + + customizedRegister(r) +} From 8ed7987007c640e31fc196bd0567770b01125f32 Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 1 Feb 2023 11:22:34 +0800 Subject: [PATCH 02/10] readme --- bizdemo/hertz_casbin/README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bizdemo/hertz_casbin/README.md b/bizdemo/hertz_casbin/README.md index c126747e..db5c3edd 100644 --- a/bizdemo/hertz_casbin/README.md +++ b/bizdemo/hertz_casbin/README.md @@ -2,10 +2,9 @@ ## Introduce -A demo with `Hertz` and `Casbin`, this demo aims to demonstrate a distributed session solution based on the `hertz-contrib/sessions`. +A demo with `Hertz` and `Casbin`, this demo aims to understand the application of rbac. -The distributed session solution based on redis is to store the sessions of different servers in redis or redis cluster, -which aims to solve the problem that the sessions of multiple servers are not synchronized in the case of distributed system. +Casbin is a powerful and efficient open-source access control library for Golang projects. It provides support for enforcing authorization based on various access control models. - Use `thrift` IDL to define `HTTP` interface - Use `hz` to generate code @@ -33,8 +32,6 @@ Connect MySQL and execute [user.sql](biz/model/sql/user.sql) This is where the permissions are defined [policy.csv](conf/policy.csv),each http request is determined. - - ## Code generation tool This demo use `hz` to generate code. The use of `hz` refers to [hz](https://www.cloudwego.io/docs/hertz/tutorials/toolkit/toolkit/) @@ -62,6 +59,11 @@ This demo captures the [AdminLTE](https://github.com/ColorlibHQ/AdminLTE) login cd bizdemo/hertz_casbin && docker-compose up ``` +### Generate MySQL table + +Connect MySQL and execute [user.sql](biz/model/sql/user.sql) + + ### Run demo ```bash From 4a8522f79aadc95cfaa93a5506de1d7a9b71e5d7 Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 1 Feb 2023 11:29:29 +0800 Subject: [PATCH 03/10] readme --- bizdemo/hertz_casbin/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bizdemo/hertz_casbin/README.md b/bizdemo/hertz_casbin/README.md index db5c3edd..56f2397c 100644 --- a/bizdemo/hertz_casbin/README.md +++ b/bizdemo/hertz_casbin/README.md @@ -1,8 +1,8 @@ -# hertz_session +# hertz_casbin ## Introduce -A demo with `Hertz` and `Casbin`, this demo aims to understand the application of rbac. +A demo with `Hertz` and `Casbin`, this demo aims to understand the application of permissions. Casbin is a powerful and efficient open-source access control library for Golang projects. It provides support for enforcing authorization based on various access control models. @@ -73,7 +73,8 @@ go run . Which starts a server at `http://localhost:8888` with the following routes: -* `POST /login` - accessible if not logged in +* `POST /register` - accessible if not logged in as a anonymous +* `POST /login` - accessible if not logged in as a anonymous * takes `username` as a form-data parameter - password is 123 * Valid Users: * `admin` ID: `1`, Role: `admin` From 55562a6e0efce365224e374edc13e397444bc898 Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 3 Feb 2023 12:12:52 +0800 Subject: [PATCH 04/10] casbin --- bizdemo/hertz_casbin/.gitignore | 0 bizdemo/hertz_casbin/Makefile | 5 - bizdemo/hertz_casbin/README.md | 86 - bizdemo/hertz_casbin/biz/dal/init.go | 4 +- bizdemo/hertz_casbin/biz/dal/mysql/init.go | 9 +- .../hertz_casbin/biz/dal/mysql/permission.go | 39 + .../biz/dal/mysql/permission_test.go | 85 + bizdemo/hertz_casbin/biz/dal/mysql/role.go | 69 + .../hertz_casbin/biz/dal/mysql/role_test.go | 90 + bizdemo/hertz_casbin/biz/dal/mysql/user.go | 58 +- .../hertz_casbin/biz/dal/mysql/user_test.go | 55 + .../biz/handler/casbin/permission_service.go | 134 + .../biz/handler/casbin/role_service.go | 76 + .../biz/handler/casbin/user_service.go | 58 + .../biz/handler/middle_service.go | 50 - bizdemo/hertz_casbin/biz/handler/ping.go | 19 +- .../biz/handler/user/user_service.go | 199 - .../hertz_casbin/biz/model/casbin/casbin.go | 5302 +++++++++++++++++ bizdemo/hertz_casbin/biz/model/sql/user.sql | 46 - bizdemo/hertz_casbin/biz/model/user/user.go | 2963 --------- bizdemo/hertz_casbin/biz/mw/casbin.go | 17 +- bizdemo/hertz_casbin/biz/mw/session.go | 35 - .../hertz_casbin/biz/router/casbin/casbin.go | 49 + .../biz/router/casbin/middleware.go | 171 + bizdemo/hertz_casbin/biz/router/register.go | 5 +- .../biz/router/user/middleware.go | 63 - bizdemo/hertz_casbin/biz/router/user/user.go | 31 - bizdemo/hertz_casbin/conf/policy.csv | 7 - bizdemo/hertz_casbin/docker-compose.yml | 13 +- bizdemo/hertz_casbin/go.mod | 31 +- bizdemo/hertz_casbin/go.sum | 186 +- bizdemo/hertz_casbin/idl/casbin.thrift | 135 + bizdemo/hertz_casbin/idl/user.thrift | 50 - bizdemo/hertz_casbin/main.go | 21 +- bizdemo/hertz_casbin/pkg/consts/consts.go | 42 +- bizdemo/hertz_casbin/pkg/utils/utils.go | 148 +- bizdemo/hertz_casbin/router.go | 20 +- bizdemo/hertz_casbin/router_gen.go | 5 +- bizdemo/hertz_casbin/test/common.go | 16 + bizdemo/hertz_casbin/test/permission_test.go | 41 + bizdemo/hertz_casbin/test/role_test.go | 26 + bizdemo/hertz_casbin/test/user_test.go | 54 + 42 files changed, 6743 insertions(+), 3770 deletions(-) mode change 100644 => 100755 bizdemo/hertz_casbin/.gitignore delete mode 100644 bizdemo/hertz_casbin/Makefile delete mode 100644 bizdemo/hertz_casbin/README.md create mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/permission.go create mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go create mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/role.go create mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/role_test.go create mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/user_test.go create mode 100644 bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go create mode 100644 bizdemo/hertz_casbin/biz/handler/casbin/role_service.go create mode 100644 bizdemo/hertz_casbin/biz/handler/casbin/user_service.go delete mode 100644 bizdemo/hertz_casbin/biz/handler/middle_service.go mode change 100644 => 100755 bizdemo/hertz_casbin/biz/handler/ping.go delete mode 100644 bizdemo/hertz_casbin/biz/handler/user/user_service.go create mode 100644 bizdemo/hertz_casbin/biz/model/casbin/casbin.go delete mode 100644 bizdemo/hertz_casbin/biz/model/sql/user.sql delete mode 100644 bizdemo/hertz_casbin/biz/model/user/user.go delete mode 100644 bizdemo/hertz_casbin/biz/mw/session.go create mode 100644 bizdemo/hertz_casbin/biz/router/casbin/casbin.go create mode 100644 bizdemo/hertz_casbin/biz/router/casbin/middleware.go mode change 100644 => 100755 bizdemo/hertz_casbin/biz/router/register.go delete mode 100644 bizdemo/hertz_casbin/biz/router/user/middleware.go delete mode 100644 bizdemo/hertz_casbin/biz/router/user/user.go delete mode 100644 bizdemo/hertz_casbin/conf/policy.csv mode change 100644 => 100755 bizdemo/hertz_casbin/go.mod create mode 100644 bizdemo/hertz_casbin/idl/casbin.thrift delete mode 100644 bizdemo/hertz_casbin/idl/user.thrift mode change 100644 => 100755 bizdemo/hertz_casbin/main.go mode change 100644 => 100755 bizdemo/hertz_casbin/router.go mode change 100644 => 100755 bizdemo/hertz_casbin/router_gen.go create mode 100644 bizdemo/hertz_casbin/test/common.go create mode 100644 bizdemo/hertz_casbin/test/permission_test.go create mode 100644 bizdemo/hertz_casbin/test/role_test.go create mode 100644 bizdemo/hertz_casbin/test/user_test.go diff --git a/bizdemo/hertz_casbin/.gitignore b/bizdemo/hertz_casbin/.gitignore old mode 100644 new mode 100755 diff --git a/bizdemo/hertz_casbin/Makefile b/bizdemo/hertz_casbin/Makefile deleted file mode 100644 index c35ed315..00000000 --- a/bizdemo/hertz_casbin/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -init_api: - hz new -mod hertz-examples/bizdemo/hertz_session -idl idl/user.thrift - -update_api: - hz update -I -idl idl/user.thrift \ No newline at end of file diff --git a/bizdemo/hertz_casbin/README.md b/bizdemo/hertz_casbin/README.md deleted file mode 100644 index 56f2397c..00000000 --- a/bizdemo/hertz_casbin/README.md +++ /dev/null @@ -1,86 +0,0 @@ -# hertz_casbin - -## Introduce - -A demo with `Hertz` and `Casbin`, this demo aims to understand the application of permissions. - -Casbin is a powerful and efficient open-source access control library for Golang projects. It provides support for enforcing authorization based on various access control models. - -- Use `thrift` IDL to define `HTTP` interface -- Use `hz` to generate code -- Use `hertz-contrib/sessions` to store sessions -- Use `casbin` to judgment authority -- Use `Gorm` and `MySQL` - -## hertz-contrib/sessions - -Use Hertz's sessions extension, refer to [hertz-contrib/sessions](https://github.com/hertz-contrib/sessions) - -## casbin - -Simplistic Example of role-based HTTP Authorization with [casbin](https://github.com/casbin/casbin) using [scs](https://github.com/alexedwards/scs) for session handling. - -## IDL - -This demo use `thrift` IDL to define `HTTP` interface. The specific interface define in [user.thrift](idl/user.thrift) - -### Generate MySQL table - -Connect MySQL and execute [user.sql](biz/model/sql/user.sql) - -### Permission list - -This is where the permissions are defined [policy.csv](conf/policy.csv),each http request is determined. - -## Code generation tool - -This demo use `hz` to generate code. The use of `hz` refers to [hz](https://www.cloudwego.io/docs/hertz/tutorials/toolkit/toolkit/) - -The `hz` commands used can be found in [Makefile](Makefile) - -## Binding and Validate - -The use of binding and Validate refers -to [Binding and Validate](https://www.cloudwego.io/docs/hertz/tutorials/basic-feature/binding-and-validate/) - -## Gorm - -This demo use `Gorm` to operate `MySQL` and refers to [Gorm](https://gorm.io/) - -## AdminLTE - -This demo captures the [AdminLTE](https://github.com/ColorlibHQ/AdminLTE) login and registration page as the front-end page. - -## How to run - -### Run MySQL and Redis docker - -```bash -cd bizdemo/hertz_casbin && docker-compose up -``` - -### Generate MySQL table - -Connect MySQL and execute [user.sql](biz/model/sql/user.sql) - - -### Run demo - -```bash -cd bizdemo/hertz_casbin -go run . -``` - -Which starts a server at `http://localhost:8888` with the following routes: - -* `POST /register` - accessible if not logged in as a anonymous -* `POST /login` - accessible if not logged in as a anonymous - * takes `username` as a form-data parameter - password is 123 - * Valid Users: - * `admin` ID: `1`, Role: `admin` - * `darren` ID: `2`, Role: `member` -* `POST /logout` - accessible if logged in -* `GET /findUser` - accessible if logged in as a member -* `GET /member/list` - accessible if logged in as a member && admin -* `GET /admin/list` - accessible if logged in as an admin - \ No newline at end of file diff --git a/bizdemo/hertz_casbin/biz/dal/init.go b/bizdemo/hertz_casbin/biz/dal/init.go index 739e93a3..b6013c92 100644 --- a/bizdemo/hertz_casbin/biz/dal/init.go +++ b/bizdemo/hertz_casbin/biz/dal/init.go @@ -16,9 +16,9 @@ package dal -import "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal/mysql" +import "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" -// Init init mysql func Init() { mysql.Init() + } diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/init.go b/bizdemo/hertz_casbin/biz/dal/mysql/init.go index e66802de..228514c8 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/init.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/init.go @@ -17,7 +17,8 @@ package mysql import ( - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/logger" @@ -27,7 +28,7 @@ var DB *gorm.DB func Init() { var err error - DB, err = gorm.Open(mysql.Open(consts.MySQLDefaultDSN), &gorm.Config{ + DB, err = gorm.Open(mysql.Open(consts.MysqlDSN), &gorm.Config{ SkipDefaultTransaction: true, PrepareStmt: true, Logger: logger.Default.LogMode(logger.Info), @@ -36,10 +37,10 @@ func Init() { panic(err) } m := DB.Migrator() - if m.HasTable(&User{}) { + if m.HasTable(&casbin.User{}) { return } - if err = m.CreateTable(&User{}); err != nil { + if err = m.CreateTable(&casbin.User{}, &casbin.Role{}, &casbin.Permission{}, &casbin.UserRole{}, &casbin.PermissionRole{}); err != nil { panic(err) } } diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go new file mode 100644 index 00000000..8d5bfc19 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go @@ -0,0 +1,39 @@ +package mysql + +import "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + +func CreatePermisson(permission *casbin.Permission) error { + return DB.Create(permission).Error +} + +func BindPermissionRole(permissionRole *casbin.PermissionRole) error { + return DB.Create(permissionRole).Error +} + +func QueryPermissionById(id int) (*casbin.Permission, error) { + var permission casbin.Permission + DB.First(&permission, id) + return &permission, nil +} + +func QueryPermissionByV(v1 string, v2 string) (*casbin.Permission, error) { + var permission casbin.Permission + DB.Where("v1= ? AND v2 =?", v1, v2).First(&permission) + return &permission, nil +} + +func QuerypermissionRoleByIds(pid, rid int) []casbin.PermissionRole { + + var permissionRole []casbin.PermissionRole + tx := DB.Model(new(casbin.PermissionRole)) + if pid != 0 { + tx.Where("pid= ?", pid) + } + if rid != 0 { + tx.Where("rid= ?", rid) + } + + tx.Select("pid,rid,id").Find(&permissionRole) + + return permissionRole +} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go new file mode 100644 index 00000000..5aa9c34e --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go @@ -0,0 +1,85 @@ +package mysql + +import ( + "fmt" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "testing" +) + +func init() { + Init() +} + +func TestCreatePermission(t *testing.T) { + + permission := casbin.Permission{ + V1: "/1", + V2: "/2", + } + + qRole, err := QueryPermissionByV(permission.V1, permission.V2) + if err != nil { + t.Fatal(err) + } + + if qRole.ID != 0 { + fmt.Println("Permission already exists") + return + } + err = CreatePermisson(&permission) + if err != nil { + t.Fatal(err) + } + +} + +func TestQueryPermission(t *testing.T) { + qRole, err := QueryPermissionByV("/v1/role/create", "POST") + if err != nil { + t.Fatal(err) + } + + fmt.Println(qRole) + +} + +func TestBindPermission(t *testing.T) { + + permissionRole := casbin.PermissionRole{ + Pid: 1, + Rid: 1, + } + + rpermissionRole := QuerypermissionRoleByIds(int(permissionRole.Pid), int(permissionRole.Rid)) + + if len(rpermissionRole) > 0 { + t.Fatal("Data already exists") + } + + // 检查用户 + role, err := QueryRoleById(int(permissionRole.Rid)) + if err != nil { + t.Fatal(err) + } + + if role.ID == 0 { + t.Fatal("role data does not exist ") + } + + rPermission, err := QueryPermissionById(int(permissionRole.Pid)) + if err != nil { + t.Fatal(err) + } + + if rPermission.ID == 0 { + t.Fatal("Permission data does not exist") + } + + err = BindPermissionRole(&permissionRole) + if err != nil { + t.Fatal(err) + } + + fmt.Println(permissionRole) + +} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/role.go b/bizdemo/hertz_casbin/biz/dal/mysql/role.go new file mode 100644 index 00000000..a4a7aa9f --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/mysql/role.go @@ -0,0 +1,69 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package mysql + +import ( + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" +) + +func CreateRole(role *casbin.Role) error { + return DB.Create(role).Error +} + +func BindRole(userRole *casbin.UserRole) error { + return DB.Create(userRole).Error +} + +func QueryRoleById(id int) (*casbin.Role, error) { + var role casbin.Role + DB.First(&role, id) + return &role, nil +} + +func QueryRoleByName(name string) (*casbin.Role, error) { + var role casbin.Role + DB.Where("name= ?", name).First(&role) + return &role, nil +} + +func QueryUserRoleByIds(uid, rid int) []casbin.UserRole { + + var userRole []casbin.UserRole + tx := DB.Model(new(casbin.UserRole)) + if uid != 0 { + tx.Where("uid= ?", uid) + } + if rid != 0 { + tx.Where("rid= ?", rid) + } + + tx.Select("rid,uid,id").Find(&userRole) + + return userRole +} + +func QueryRolesByUid(uid int) []casbin.Role { + + var userRole []casbin.Role + _ = DB.Model(new(casbin.UserRole)). + Joins("LEFT JOIN roles on roles.id=user_roles.rid "). + Select("roles.id,roles.name"). + Where("user_roles.uid=?", uid). + Scan(&userRole) + + return userRole +} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go new file mode 100644 index 00000000..597ea194 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go @@ -0,0 +1,90 @@ +package mysql + +import ( + "fmt" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "testing" +) + +func init() { + Init() +} + +func TestCreateRole(t *testing.T) { + + role := casbin.Role{ + Name: "admin", + } + + qRole, err := QueryRoleByName(role.Name) + if err != nil { + t.Fatal(err) + } + + if qRole.ID != 0 { + fmt.Println("User already exists") + return + } + err = CreateRole(&role) + if err != nil { + t.Fatal(err) + } + +} + +func TestQueryRole(t *testing.T) { + qRole, err := QueryRoleByName("admin") + if err != nil { + t.Fatal(err) + } + + fmt.Println(qRole) + +} + +func TestQueryRolesByUid(t *testing.T) { + qRoles := QueryRolesByUid(int(5)) + + fmt.Println(qRoles) + +} +func TestBindUserRole(t *testing.T) { + + userRole := casbin.UserRole{ + UID: 5, + Rid: 1, + } + + userRoles1 := QueryUserRoleByIds(int(userRole.UID), int(userRole.Rid)) + + if len(userRoles1) > 0 { + t.Fatal("Data already exists") + } + + // check user + user, err := QueryUserById(int(userRole.UID)) + if err != nil { + t.Fatal(err) + } + + if user.ID == 0 { + t.Fatal("User data does not exist") + } + + crrole, err := QueryRoleById(int(userRole.Rid)) + if err != nil { + t.Fatal(err) + } + + if crrole.ID == 0 { + t.Fatal("Role data does not exist") + } + + err = BindRole(&userRole) + if err != nil { + t.Fatal(err) + } + + fmt.Println(userRole) + +} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/user.go b/bizdemo/hertz_casbin/biz/dal/mysql/user.go index 72b287c8..e16d0115 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/user.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/user.go @@ -16,55 +16,27 @@ package mysql -import ( - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" - "gorm.io/gorm" -) +import "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" -type User struct { - gorm.Model - Username string `json:"username"` - Password string `json:"password"` - Email string `json:"email"` - Role string `json:"role"` -} - -func (u *User) TableName() string { - return consts.UserTableName -} - -func CreateUsers(users []*User) error { - return DB.Create(users).Error -} +func CreateUser(user *casbin.User) error { + return DB.Create(user).Error -func FindUserByNameOrEmail(username, email string) ([]*User, error) { - res := make([]*User, 0) - if err := DB.Where("username = ?", username).Or("email = ?", email).Find(&res).Error; err != nil { - return nil, err - } - return res, nil } -func CheckUser(username, password string) ([]*User, error) { - res := make([]*User, 0) - if err := DB.Where("username = ? AND password = ?", username, password).Find(&res).Error; err != nil { - return nil, err - } - return res, nil +func QueryUser(username, password string) (*casbin.User, error) { + var user casbin.User + DB.Where("username=? AND password =? ", username, password).First(&user) + return &user, nil } -func CheckUserExists(username string) ([]*User, error) { - res := make([]*User, 0) - if err := DB.Where("username = ? ", username).Limit(1).Find(&res).Error; err != nil { - return nil, err - } - return res, nil +func QueryUserByUsername(username string) (*casbin.User, error) { + var user casbin.User + DB.Where("username = ?", username).First(&user) + return &user, nil } -func RoleList(role string) ([]*User, error) { - res := make([]*User, 0) - if err := DB.Where("role = ? ", role).Find(&res).Error; err != nil { - return nil, err - } - return res, nil +func QueryUserById(id int) (*casbin.User, error) { + var user casbin.User + DB.First(&user, id) + return &user, nil } diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go new file mode 100644 index 00000000..f262528c --- /dev/null +++ b/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go @@ -0,0 +1,55 @@ +package mysql + +import ( + "fmt" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" + "testing" +) + +func init() { + Init() +} + +func TestCreateUser(t *testing.T) { + + user := casbin.User{ + Username: "admin", + Password: utils.Md5("123"), + } + + qUser, err := QueryUserByUsername(user.Username) + if err != nil { + t.Fatal(err) + } + + if qUser.ID != 0 { + fmt.Println("User already exists") + return + } + err = CreateUser(&user) + if err != nil { + t.Fatal(err) + } + + rUser, err := QueryUser(user.Username, user.Password) + if err != nil { + t.Fatal(err) + } + fmt.Println(rUser) + +} + +func TestQueryUser(t *testing.T) { + qUser, err := QueryUserByUsername("admin") + if err != nil { + t.Fatal(err) + } + + if qUser.ID != 0 { + fmt.Println("User already exists") + } + + fmt.Println(qUser) + +} diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go new file mode 100644 index 00000000..697b8b31 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go @@ -0,0 +1,134 @@ +// Code generated by hertz generator. + +package casbin + +import ( + "context" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/protocol/consts" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" + casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/mw" + "strconv" +) + +// CreatePermission . +// @router /v1/permission/create/ [POST] +func CreatePermission(ctx context.Context, c *app.RequestContext) { + var err error + var req casbin.CreatePermissionRequest + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + resp := new(casbin.CreatePermissionResponse) + resp.Code = 0 + resp.Msg = "ok" + + rpermission := casbin.Permission{ + V1: req.V1, + V2: req.V2, + } + cPermission, err := mysql.QueryPermissionByV(req.V1, req.V2) + if err != nil { + resp.Code = 2 + resp.Msg = "create failed" + c.JSON(consts.StatusOK, resp) + return + } + + if cPermission.ID > 0 { + resp.Code = 3 + resp.Msg = "Data already exists" + c.JSON(consts.StatusOK, resp) + return + } + + err = mysql.CreatePermisson(&rpermission) + if err != nil { + resp.Code = 4 + resp.Msg = "create failed" + c.JSON(consts.StatusOK, resp) + return + } + resp.Permission = &casbin.Permission{ + V1: req.V1, + V2: req.V2, + } + + c.JSON(consts.StatusOK, resp) +} + +// BindPermissionRole . +// @router /v1/permissionrole/bind/ [POST] +func BindPermissionRole(ctx context.Context, c *app.RequestContext) { + var err error + var req casbin.BindPermissionRoleRequest + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + resp := new(casbin.BindPermissionRoleResponse) + resp.Code = 0 + resp.Msg = "ok" + + rid, _ := strconv.Atoi(req.Rid) + pid, _ := strconv.Atoi(req.Pid) + + cRole, err := mysql.QueryRoleById(rid) + if cRole.ID == 0 { + resp.Code = 2 + resp.Msg = "Role data is null" + c.JSON(consts.StatusOK, resp) + return + } + + cPermission, err := mysql.QueryPermissionById(pid) + if cPermission.ID == 0 { + resp.Code = 2 + resp.Msg = "Permission data is null" + c.JSON(consts.StatusOK, resp) + return + } + + permissionRole := mysql.QuerypermissionRoleByIds(pid, rid) + if len(permissionRole) > 0 { + resp.Code = 2 + resp.Msg = "Data already exists " + c.JSON(consts.StatusOK, resp) + return + } + + permissionRoleReq := casbin.PermissionRole{ + Rid: int64(rid), + Pid: int64(pid), + } + + err = mysql.BindPermissionRole(&permissionRoleReq) + if err != nil { + resp.Code = 7 + resp.Msg = "Bind failed " + c.JSON(consts.StatusOK, resp) + return + } + + // add policy + if ok := mw.AuthEnforcer.AddPolicy(cRole.Name, cPermission.V1, cPermission.V2); !ok { + resp.Code = 7 + resp.Msg = "Policy insert failed " + c.JSON(consts.StatusOK, resp) + return + } else { + resp.Code = 0 + resp.Msg = "Policy insert successfully " + resp.PermissionRole.Rid = int64(rid) + resp.PermissionRole.Pid = int64(pid) + c.JSON(consts.StatusOK, resp) + return + } + +} diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go new file mode 100644 index 00000000..f09b6a07 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go @@ -0,0 +1,76 @@ +// Code generated by hertz generator. + +package casbin + +import ( + "context" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" + + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/protocol/consts" + casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" +) + +// CreateRole . +// @router /v1/role/create/ [POST] +func CreateRole(ctx context.Context, c *app.RequestContext) { + var err error + var req casbin.CreateRoleRequest + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + resp := new(casbin.CreateRoleResponse) + resp.Code = 0 + resp.Msg = "ok" + + roleReq := casbin.Role{ + Name: req.Name, + } + + cRole, err := mysql.QueryRoleByName(req.Name) + if err != nil { + resp.Code = 2 + resp.Msg = "create failed" + c.JSON(consts.StatusOK, resp) + return + } + + if cRole.ID > 0 { + resp.Code = 3 + resp.Msg = "Role data already exists" + c.JSON(consts.StatusOK, resp) + return + } + + err = mysql.CreateRole(&roleReq) + if err != nil { + resp.Code = 1 + resp.Msg = "create failed" + c.JSON(consts.StatusOK, resp) + return + } + resp.Role = &casbin.Role{ + Name: req.Name, + } + + c.JSON(consts.StatusOK, resp) +} + +// BindRole . +// @router /v1/role/bind/ [POST] +func BindRole(ctx context.Context, c *app.RequestContext) { + var err error + var req casbin.BindRoleRequest + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + resp := new(casbin.BindRoleResponse) + + c.JSON(consts.StatusOK, resp) +} diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go new file mode 100644 index 00000000..054bcea3 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go @@ -0,0 +1,58 @@ +// Code generated by hertz generator. + +package casbin + +import ( + "context" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" + + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/protocol/consts" + casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" +) + +// Login . +// @router /v1/login [POST] +func Login(ctx context.Context, c *app.RequestContext) { + var err error + var req casbin.LoginRequest + err = c.BindAndValidate(&req) + if err != nil { + c.String(consts.StatusBadRequest, err.Error()) + return + } + + resp := new(casbin.QueryUserResponse) + resp.Code = 0 + resp.Msg = "ok" + + ruser, err := mysql.QueryUser(req.Username, utils.Md5(req.Password)) + if ruser.ID == 0 { + resp.Code = 2 + resp.Msg = "username or password is wrong" + c.JSON(consts.StatusOK, resp) + return + } + + // get role ids + rroles := mysql.QueryRolesByUid(int(ruser.ID)) + if len(rroles) < 1 { + resp.Code = 5 + resp.Msg = "please assign role " + c.JSON(consts.StatusOK, resp) + return + } + + token, err := utils.GenerateToken(uint(ruser.ID), rroles, ruser.Username, 3600*24*30) + if err != nil { + resp.Code = 2 + resp.Msg = "username or password is wrong" + c.JSON(consts.StatusOK, resp) + return + } + + resp.Token = token + c.JSON(consts.StatusOK, resp) + return +} diff --git a/bizdemo/hertz_casbin/biz/handler/middle_service.go b/bizdemo/hertz_casbin/biz/handler/middle_service.go deleted file mode 100644 index bdc31bb5..00000000 --- a/bizdemo/hertz_casbin/biz/handler/middle_service.go +++ /dev/null @@ -1,50 +0,0 @@ -package handler - -import ( - "context" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal/mysql" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/mw" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" - "github.com/cloudwego/hertz/pkg/app" - "github.com/cloudwego/hertz/pkg/common/utils" - "github.com/hertz-contrib/sessions" -) - -func Auth(_ context.Context, c *app.RequestContext) map[string]interface{} { - - session := sessions.Default(c) - - role := session.Get(consts.Role) - if role == "" || role == nil { - role = "anonymous" - } - - if c.FullPath() == "/login" || c.FullPath() == "/register" { - role = "anonymous" - } - - // if it's a member, check if the user still exists - if role == "member" { - username := session.Get(consts.Username) - - _, err := mysql.CheckUserExists(username.(string)) - - if err != nil { - - return utils.H{"code": 1, "message": "FORBIDDEN"} - } - } - - // casbin enforce - res, err := mw.Authorize(role, c.FullPath(), string(c.Request.Header.Method())) - if err != nil { - return utils.H{"code": 1, "message": "ERROR"} - } - - if res { - return utils.H{"code": 0, "message": "ok"} - } else { - - return utils.H{"code": 1, "message": "FORBIDDEN"} - } -} diff --git a/bizdemo/hertz_casbin/biz/handler/ping.go b/bizdemo/hertz_casbin/biz/handler/ping.go old mode 100644 new mode 100755 index 425d50f5..950d4767 --- a/bizdemo/hertz_casbin/biz/handler/ping.go +++ b/bizdemo/hertz_casbin/biz/handler/ping.go @@ -1,19 +1,3 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - // Code generated by hertz generator. package handler @@ -23,11 +7,12 @@ import ( "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/common/utils" + "github.com/cloudwego/hertz/pkg/protocol/consts" ) // Ping . func Ping(ctx context.Context, c *app.RequestContext) { - c.JSON(200, utils.H{ + c.JSON(consts.StatusOK, utils.H{ "message": "pong", }) } diff --git a/bizdemo/hertz_casbin/biz/handler/user/user_service.go b/bizdemo/hertz_casbin/biz/handler/user/user_service.go deleted file mode 100644 index 8eab8691..00000000 --- a/bizdemo/hertz_casbin/biz/handler/user/user_service.go +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Code generated by hertz generator. - -package user - -import ( - "context" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler" - "net/http" - - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal/mysql" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/model/user" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/utils" - "github.com/cloudwego/hertz/pkg/app" - result "github.com/cloudwego/hertz/pkg/common/utils" - "github.com/hertz-contrib/sessions" -) - -// Register . -// @router /register [POST] -func Register(ctx context.Context, c *app.RequestContext) { - res := handler.Auth(ctx, c) - if res["code"] != 0 { - c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) - return - } - var err error - var req user.RegisterRequest - - err = c.BindAndValidate(&req) - if err != nil { - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - users, err := mysql.FindUserByNameOrEmail(req.Username, req.Email) - if err != nil { - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - if len(users) != 0 { - c.JSON(http.StatusOK, user.BaseResp{1, consts.RegisterErr}) - return - } - if err = mysql.CreateUsers([]*mysql.User{ - { - Username: req.Username, - Password: utils.MD5(req.Password), - Email: req.Email, - }, - }); err != nil { - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - c.JSON(http.StatusOK, user.BaseResp{0, consts.Success}) -} - -// Login . -// @router /login [POST] -func Login(ctx context.Context, c *app.RequestContext) { - res := handler.Auth(ctx, c) - if res["code"] != 0 { - c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) - return - } - - var err error - var req user.LoginRequest - - err = c.BindAndValidate(&req) - if err != nil { - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - users, err := mysql.CheckUser(req.Username, utils.MD5(req.Password)) - if err != nil { - - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - if len(users) == 0 { - c.JSON(http.StatusOK, user.BaseResp{1, consts.LoginErr}) - return - } - session := sessions.Default(c) - session.Set(consts.Username, req.Username) - session.Set(consts.Role, users[0].Role) - _ = session.Save() - c.JSON(http.StatusOK, user.BaseResp{0, consts.Success}) -} - -// Logout . -// @router /logout [GET] -func Logout(ctx context.Context, c *app.RequestContext) { - res := handler.Auth(ctx, c) - if res["code"] != 0 { - c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) - return - } - - session := sessions.Default(c) - session.Delete(consts.Username) - session.Clear() - session.Delete(consts.Role) - _ = session.Save() - c.JSON(http.StatusOK, user.BaseResp{0, consts.Success}) - -} - -// FindUser . -// @router /findUser [GET] -func FindUser(ctx context.Context, c *app.RequestContext) { - - res := handler.Auth(ctx, c) - if res["code"] != 0 { - c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) - return - } - - session := sessions.Default(c) - - username := session.Get(consts.Username) - - var err error - users, err := mysql.CheckUserExists(username.(string)) - if err != nil { - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - c.JSON(http.StatusOK, result.H{"code": 0, "message": consts.Success, "data": users[0]}) - -} - -// MemberList . -// @router /member/list [GET] -func MemberList(ctx context.Context, c *app.RequestContext) { - res := handler.Auth(ctx, c) - if res["code"] != 0 { - c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) - return - } - - var err error - - session := sessions.Default(c) - - role := session.Get(consts.Role) - - users, err := mysql.RoleList(role.(string)) - - if err != nil { - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - - c.JSON(http.StatusOK, result.H{"code": 0, "message": consts.Success, "data": users}) - -} - -// AdminList . -// @router /admin/list [GET] -func AdminList(ctx context.Context, c *app.RequestContext) { - - res := handler.Auth(ctx, c) - if res["code"] != 0 { - c.JSON(http.StatusOK, user.BaseResp{1, res["message"].(string)}) - return - } - - var err error - - session := sessions.Default(c) - - role := session.Get(consts.Role) - - users, err := mysql.RoleList(role.(string)) - - if err != nil { - c.JSON(http.StatusOK, user.BaseResp{2, err.Error()}) - return - } - - c.JSON(http.StatusOK, result.H{"code": 0, "message": consts.Success, "data": users}) -} diff --git a/bizdemo/hertz_casbin/biz/model/casbin/casbin.go b/bizdemo/hertz_casbin/biz/model/casbin/casbin.go new file mode 100644 index 00000000..5c9629b3 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/model/casbin/casbin.go @@ -0,0 +1,5302 @@ +// Code generated by thriftgo (0.2.5). DO NOT EDIT. + +package casbin + +import ( + "context" + "database/sql" + "database/sql/driver" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +type Code int64 + +const ( + Code_Success Code = 1 + Code_ParamInvalid Code = 2 + Code_DBErr Code = 3 +) + +func (p Code) String() string { + switch p { + case Code_Success: + return "Success" + case Code_ParamInvalid: + return "ParamInvalid" + case Code_DBErr: + return "DBErr" + } + return "" +} + +func CodeFromString(s string) (Code, error) { + switch s { + case "Success": + return Code_Success, nil + case "ParamInvalid": + return Code_ParamInvalid, nil + case "DBErr": + return Code_DBErr, nil + } + return Code(0), fmt.Errorf("not a valid Code string") +} + +func CodePtr(v Code) *Code { return &v } +func (p *Code) Scan(value interface{}) (err error) { + var result sql.NullInt64 + err = result.Scan(value) + *p = Code(result.Int64) + return +} + +func (p *Code) Value() (driver.Value, error) { + if p == nil { + return nil, nil + } + return int64(*p), nil +} + +type BasicResponse struct { + Code Code `thrift:"code,1" form:"code" json:"code" query:"code"` + Msg string `thrift:"msg,2" form:"msg" json:"msg" query:"msg"` +} + +func NewBasicResponse() *BasicResponse { + return &BasicResponse{} +} + +func (p *BasicResponse) GetCode() (v Code) { + return p.Code +} + +func (p *BasicResponse) GetMsg() (v string) { + return p.Msg +} + +var fieldIDToName_BasicResponse = map[int16]string{ + 1: "code", + 2: "msg", +} + +func (p *BasicResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I32 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_BasicResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *BasicResponse) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + p.Code = Code(v) + } + return nil +} + +func (p *BasicResponse) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Msg = v + } + return nil +} + +func (p *BasicResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BasicResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *BasicResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I32, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(int32(p.Code)); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *BasicResponse) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("msg", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Msg); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *BasicResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("BasicResponse(%+v)", *p) +} + +/***********Permission***************/ +type Permission struct { + ID int64 `thrift:"id,1" form:"id" json:"id" query:"id"` + V1 string `thrift:"v1,2" form:"v1" json:"v1" query:"v1"` + V2 string `thrift:"v2,3" form:"v2" json:"v2" query:"v2"` +} + +func NewPermission() *Permission { + return &Permission{} +} + +func (p *Permission) GetID() (v int64) { + return p.ID +} + +func (p *Permission) GetV1() (v string) { + return p.V1 +} + +func (p *Permission) GetV2() (v string) { + return p.V2 +} + +var fieldIDToName_Permission = map[int16]string{ + 1: "id", + 2: "v1", + 3: "v2", +} + +func (p *Permission) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I64 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRING { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Permission[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *Permission) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.ID = v + } + return nil +} + +func (p *Permission) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.V1 = v + } + return nil +} + +func (p *Permission) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.V2 = v + } + return nil +} + +func (p *Permission) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("Permission"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *Permission) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.ID); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *Permission) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("v1", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.V1); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *Permission) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("v2", thrift.STRING, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.V2); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *Permission) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Permission(%+v)", *p) +} + +type PermissionRole struct { + ID int64 `thrift:"id,1" form:"id" json:"id" query:"id"` + Rid int64 `thrift:"rid,2" form:"rid" json:"rid" query:"rid"` + Pid int64 `thrift:"pid,3" form:"pid" json:"pid" query:"pid"` +} + +func NewPermissionRole() *PermissionRole { + return &PermissionRole{} +} + +func (p *PermissionRole) GetID() (v int64) { + return p.ID +} + +func (p *PermissionRole) GetRid() (v int64) { + return p.Rid +} + +func (p *PermissionRole) GetPid() (v int64) { + return p.Pid +} + +var fieldIDToName_PermissionRole = map[int16]string{ + 1: "id", + 2: "rid", + 3: "pid", +} + +func (p *PermissionRole) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I64 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.I64 { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.I64 { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PermissionRole[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PermissionRole) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.ID = v + } + return nil +} + +func (p *PermissionRole) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.Rid = v + } + return nil +} + +func (p *PermissionRole) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.Pid = v + } + return nil +} + +func (p *PermissionRole) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("PermissionRole"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *PermissionRole) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.ID); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *PermissionRole) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("rid", thrift.I64, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.Rid); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *PermissionRole) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("pid", thrift.I64, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.Pid); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *PermissionRole) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PermissionRole(%+v)", *p) +} + +type CreatePermissionRequest struct { + V1 string `thrift:"v1,1" form:"v1" json:"v1" vd:"(len($) > 0 && len($) < 100)"` + V2 string `thrift:"v2,2" form:"v2" json:"v2" vd:"(len($) > 0 && len($) < 100)"` +} + +func NewCreatePermissionRequest() *CreatePermissionRequest { + return &CreatePermissionRequest{} +} + +func (p *CreatePermissionRequest) GetV1() (v string) { + return p.V1 +} + +func (p *CreatePermissionRequest) GetV2() (v string) { + return p.V2 +} + +var fieldIDToName_CreatePermissionRequest = map[int16]string{ + 1: "v1", + 2: "v2", +} + +func (p *CreatePermissionRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_CreatePermissionRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *CreatePermissionRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.V1 = v + } + return nil +} + +func (p *CreatePermissionRequest) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.V2 = v + } + return nil +} + +func (p *CreatePermissionRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreatePermissionRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *CreatePermissionRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("v1", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.V1); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *CreatePermissionRequest) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("v2", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.V2); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *CreatePermissionRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("CreatePermissionRequest(%+v)", *p) +} + +type CreatePermissionResponse struct { + Code Code `thrift:"code,1" form:"code" json:"code" query:"code"` + Msg string `thrift:"msg,2" form:"msg" json:"msg" query:"msg"` + Permission *Permission `thrift:"permission,3" form:"permission" json:"permission" query:"permission"` +} + +func NewCreatePermissionResponse() *CreatePermissionResponse { + return &CreatePermissionResponse{} +} + +func (p *CreatePermissionResponse) GetCode() (v Code) { + return p.Code +} + +func (p *CreatePermissionResponse) GetMsg() (v string) { + return p.Msg +} + +var CreatePermissionResponse_Permission_DEFAULT *Permission + +func (p *CreatePermissionResponse) GetPermission() (v *Permission) { + if !p.IsSetPermission() { + return CreatePermissionResponse_Permission_DEFAULT + } + return p.Permission +} + +var fieldIDToName_CreatePermissionResponse = map[int16]string{ + 1: "code", + 2: "msg", + 3: "permission", +} + +func (p *CreatePermissionResponse) IsSetPermission() bool { + return p.Permission != nil +} + +func (p *CreatePermissionResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I32 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_CreatePermissionResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *CreatePermissionResponse) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + p.Code = Code(v) + } + return nil +} + +func (p *CreatePermissionResponse) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Msg = v + } + return nil +} + +func (p *CreatePermissionResponse) ReadField3(iprot thrift.TProtocol) error { + p.Permission = NewPermission() + if err := p.Permission.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *CreatePermissionResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreatePermissionResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *CreatePermissionResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I32, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(int32(p.Code)); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *CreatePermissionResponse) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("msg", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Msg); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *CreatePermissionResponse) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("permission", thrift.STRUCT, 3); err != nil { + goto WriteFieldBeginError + } + if err := p.Permission.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *CreatePermissionResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("CreatePermissionResponse(%+v)", *p) +} + +type BindPermissionRoleRequest struct { + Pid string `thrift:"pid,1" form:"pid" json:"pid" vd:"($ > 0 && $ < 100)"` + Rid string `thrift:"rid,2" form:"rid" json:"rid" vd:"($ > 0 && $ < 100)"` +} + +func NewBindPermissionRoleRequest() *BindPermissionRoleRequest { + return &BindPermissionRoleRequest{} +} + +func (p *BindPermissionRoleRequest) GetPid() (v string) { + return p.Pid +} + +func (p *BindPermissionRoleRequest) GetRid() (v string) { + return p.Rid +} + +var fieldIDToName_BindPermissionRoleRequest = map[int16]string{ + 1: "pid", + 2: "rid", +} + +func (p *BindPermissionRoleRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_BindPermissionRoleRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *BindPermissionRoleRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Pid = v + } + return nil +} + +func (p *BindPermissionRoleRequest) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Rid = v + } + return nil +} + +func (p *BindPermissionRoleRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindPermissionRoleRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *BindPermissionRoleRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("pid", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Pid); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *BindPermissionRoleRequest) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("rid", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Rid); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *BindPermissionRoleRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("BindPermissionRoleRequest(%+v)", *p) +} + +type BindPermissionRoleResponse struct { + Code Code `thrift:"code,1" form:"code" json:"code" query:"code"` + Msg string `thrift:"msg,2" form:"msg" json:"msg" query:"msg"` + PermissionRole *PermissionRole `thrift:"permissionRole,3" form:"permissionRole" json:"permissionRole" query:"permissionRole"` +} + +func NewBindPermissionRoleResponse() *BindPermissionRoleResponse { + return &BindPermissionRoleResponse{} +} + +func (p *BindPermissionRoleResponse) GetCode() (v Code) { + return p.Code +} + +func (p *BindPermissionRoleResponse) GetMsg() (v string) { + return p.Msg +} + +var BindPermissionRoleResponse_PermissionRole_DEFAULT *PermissionRole + +func (p *BindPermissionRoleResponse) GetPermissionRole() (v *PermissionRole) { + if !p.IsSetPermissionRole() { + return BindPermissionRoleResponse_PermissionRole_DEFAULT + } + return p.PermissionRole +} + +var fieldIDToName_BindPermissionRoleResponse = map[int16]string{ + 1: "code", + 2: "msg", + 3: "permissionRole", +} + +func (p *BindPermissionRoleResponse) IsSetPermissionRole() bool { + return p.PermissionRole != nil +} + +func (p *BindPermissionRoleResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I32 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_BindPermissionRoleResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *BindPermissionRoleResponse) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + p.Code = Code(v) + } + return nil +} + +func (p *BindPermissionRoleResponse) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Msg = v + } + return nil +} + +func (p *BindPermissionRoleResponse) ReadField3(iprot thrift.TProtocol) error { + p.PermissionRole = NewPermissionRole() + if err := p.PermissionRole.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *BindPermissionRoleResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindPermissionRoleResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *BindPermissionRoleResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I32, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(int32(p.Code)); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *BindPermissionRoleResponse) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("msg", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Msg); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *BindPermissionRoleResponse) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("permissionRole", thrift.STRUCT, 3); err != nil { + goto WriteFieldBeginError + } + if err := p.PermissionRole.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *BindPermissionRoleResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("BindPermissionRoleResponse(%+v)", *p) +} + +/***********Role***************/ +type Role struct { + ID int64 `thrift:"id,1" form:"id" json:"id" query:"id"` + Name string `thrift:"name,2" form:"name" json:"name" query:"name"` +} + +func NewRole() *Role { + return &Role{} +} + +func (p *Role) GetID() (v int64) { + return p.ID +} + +func (p *Role) GetName() (v string) { + return p.Name +} + +var fieldIDToName_Role = map[int16]string{ + 1: "id", + 2: "name", +} + +func (p *Role) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I64 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Role[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *Role) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.ID = v + } + return nil +} + +func (p *Role) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Name = v + } + return nil +} + +func (p *Role) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("Role"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *Role) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.ID); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *Role) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("name", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Name); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *Role) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Role(%+v)", *p) +} + +type CreateRoleRequest struct { + Name string `thrift:"name,1" form:"name" json:"name" vd:"(len($) > 0 && len($) < 100)"` +} + +func NewCreateRoleRequest() *CreateRoleRequest { + return &CreateRoleRequest{} +} + +func (p *CreateRoleRequest) GetName() (v string) { + return p.Name +} + +var fieldIDToName_CreateRoleRequest = map[int16]string{ + 1: "name", +} + +func (p *CreateRoleRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_CreateRoleRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *CreateRoleRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Name = v + } + return nil +} + +func (p *CreateRoleRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreateRoleRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *CreateRoleRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("name", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Name); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *CreateRoleRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("CreateRoleRequest(%+v)", *p) +} + +type CreateRoleResponse struct { + Code Code `thrift:"code,1" form:"code" json:"code" query:"code"` + Msg string `thrift:"msg,2" form:"msg" json:"msg" query:"msg"` + Role *Role `thrift:"role,3" form:"role" json:"role" query:"role"` +} + +func NewCreateRoleResponse() *CreateRoleResponse { + return &CreateRoleResponse{} +} + +func (p *CreateRoleResponse) GetCode() (v Code) { + return p.Code +} + +func (p *CreateRoleResponse) GetMsg() (v string) { + return p.Msg +} + +var CreateRoleResponse_Role_DEFAULT *Role + +func (p *CreateRoleResponse) GetRole() (v *Role) { + if !p.IsSetRole() { + return CreateRoleResponse_Role_DEFAULT + } + return p.Role +} + +var fieldIDToName_CreateRoleResponse = map[int16]string{ + 1: "code", + 2: "msg", + 3: "role", +} + +func (p *CreateRoleResponse) IsSetRole() bool { + return p.Role != nil +} + +func (p *CreateRoleResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I32 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_CreateRoleResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *CreateRoleResponse) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + p.Code = Code(v) + } + return nil +} + +func (p *CreateRoleResponse) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Msg = v + } + return nil +} + +func (p *CreateRoleResponse) ReadField3(iprot thrift.TProtocol) error { + p.Role = NewRole() + if err := p.Role.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *CreateRoleResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreateRoleResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *CreateRoleResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I32, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(int32(p.Code)); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *CreateRoleResponse) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("msg", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Msg); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *CreateRoleResponse) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("role", thrift.STRUCT, 3); err != nil { + goto WriteFieldBeginError + } + if err := p.Role.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *CreateRoleResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("CreateRoleResponse(%+v)", *p) +} + +type BindRoleRequest struct { + UID int64 `thrift:"uid,1" form:"uid" json:"uid" vd:"($ > 0)"` + Rid int64 `thrift:"rid,2" form:"rid" form:"rid" json:"rid" vd:"($ > 0)"` +} + +func NewBindRoleRequest() *BindRoleRequest { + return &BindRoleRequest{} +} + +func (p *BindRoleRequest) GetUID() (v int64) { + return p.UID +} + +func (p *BindRoleRequest) GetRid() (v int64) { + return p.Rid +} + +var fieldIDToName_BindRoleRequest = map[int16]string{ + 1: "uid", + 2: "rid", +} + +func (p *BindRoleRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I64 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.I64 { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_BindRoleRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *BindRoleRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.UID = v + } + return nil +} + +func (p *BindRoleRequest) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.Rid = v + } + return nil +} + +func (p *BindRoleRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindRoleRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *BindRoleRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("uid", thrift.I64, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.UID); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *BindRoleRequest) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("rid", thrift.I64, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.Rid); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *BindRoleRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("BindRoleRequest(%+v)", *p) +} + +type BindRoleResponse struct { + Code Code `thrift:"code,1" form:"code" json:"code" query:"code"` + Msg string `thrift:"msg,2" form:"msg" json:"msg" query:"msg"` +} + +func NewBindRoleResponse() *BindRoleResponse { + return &BindRoleResponse{} +} + +func (p *BindRoleResponse) GetCode() (v Code) { + return p.Code +} + +func (p *BindRoleResponse) GetMsg() (v string) { + return p.Msg +} + +var fieldIDToName_BindRoleResponse = map[int16]string{ + 1: "code", + 2: "msg", +} + +func (p *BindRoleResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I32 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_BindRoleResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *BindRoleResponse) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + p.Code = Code(v) + } + return nil +} + +func (p *BindRoleResponse) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Msg = v + } + return nil +} + +func (p *BindRoleResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindRoleResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *BindRoleResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I32, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(int32(p.Code)); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *BindRoleResponse) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("msg", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Msg); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *BindRoleResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("BindRoleResponse(%+v)", *p) +} + +/***********user***************/ +type User struct { + ID int64 `thrift:"id,1" form:"id" json:"id" query:"id"` + Username string `thrift:"username,2" form:"username" json:"username" query:"username"` + Password string `thrift:"password,3" form:"password" json:"password" query:"password"` +} + +func NewUser() *User { + return &User{} +} + +func (p *User) GetID() (v int64) { + return p.ID +} + +func (p *User) GetUsername() (v string) { + return p.Username +} + +func (p *User) GetPassword() (v string) { + return p.Password +} + +var fieldIDToName_User = map[int16]string{ + 1: "id", + 2: "username", + 3: "password", +} + +func (p *User) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I64 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRING { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_User[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *User) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.ID = v + } + return nil +} + +func (p *User) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Username = v + } + return nil +} + +func (p *User) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Password = v + } + return nil +} + +func (p *User) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("User"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *User) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.ID); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *User) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("username", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Username); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *User) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("password", thrift.STRING, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Password); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *User) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("User(%+v)", *p) +} + +type UserRole struct { + ID int64 `thrift:"id,1" form:"id" json:"id" query:"id"` + Rid int64 `thrift:"rid,2" form:"rid" json:"rid" query:"rid"` + UID int64 `thrift:"uid,3" form:"uid" json:"uid" query:"uid"` +} + +func NewUserRole() *UserRole { + return &UserRole{} +} + +func (p *UserRole) GetID() (v int64) { + return p.ID +} + +func (p *UserRole) GetRid() (v int64) { + return p.Rid +} + +func (p *UserRole) GetUID() (v int64) { + return p.UID +} + +var fieldIDToName_UserRole = map[int16]string{ + 1: "id", + 2: "rid", + 3: "uid", +} + +func (p *UserRole) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I64 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.I64 { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.I64 { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserRole[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserRole) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.ID = v + } + return nil +} + +func (p *UserRole) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.Rid = v + } + return nil +} + +func (p *UserRole) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + p.UID = v + } + return nil +} + +func (p *UserRole) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("UserRole"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserRole) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.ID); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *UserRole) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("rid", thrift.I64, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.Rid); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *UserRole) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("uid", thrift.I64, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.UID); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *UserRole) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserRole(%+v)", *p) +} + +type LoginRequest struct { + Username string `thrift:"username,1" form:"username" form:"username" json:"username" vd:"(len($) > 0 && len($) < 100)"` + Password string `thrift:"password,2" form:"password" json:"password" vd:"(len($) > 0 && len($) < 100)"` +} + +func NewLoginRequest() *LoginRequest { + return &LoginRequest{} +} + +func (p *LoginRequest) GetUsername() (v string) { + return p.Username +} + +func (p *LoginRequest) GetPassword() (v string) { + return p.Password +} + +var fieldIDToName_LoginRequest = map[int16]string{ + 1: "username", + 2: "password", +} + +func (p *LoginRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_LoginRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *LoginRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Username = v + } + return nil +} + +func (p *LoginRequest) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Password = v + } + return nil +} + +func (p *LoginRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("LoginRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *LoginRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("username", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Username); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *LoginRequest) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("password", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Password); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *LoginRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("LoginRequest(%+v)", *p) +} + +type QueryUserResponse struct { + Code Code `thrift:"code,1" form:"code" json:"code" query:"code"` + Msg string `thrift:"msg,2" form:"msg" json:"msg" query:"msg"` + Token string `thrift:"token,3" form:"token" json:"token" query:"token"` +} + +func NewQueryUserResponse() *QueryUserResponse { + return &QueryUserResponse{} +} + +func (p *QueryUserResponse) GetCode() (v Code) { + return p.Code +} + +func (p *QueryUserResponse) GetMsg() (v string) { + return p.Msg +} + +func (p *QueryUserResponse) GetToken() (v string) { + return p.Token +} + +var fieldIDToName_QueryUserResponse = map[int16]string{ + 1: "code", + 2: "msg", + 3: "token", +} + +func (p *QueryUserResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.I32 { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRING { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + case 3: + if fieldTypeId == thrift.STRING { + if err = p.ReadField3(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_QueryUserResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *QueryUserResponse) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + p.Code = Code(v) + } + return nil +} + +func (p *QueryUserResponse) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Msg = v + } + return nil +} + +func (p *QueryUserResponse) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Token = v + } + return nil +} + +func (p *QueryUserResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("QueryUserResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + if err = p.writeField3(oprot); err != nil { + fieldId = 3 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *QueryUserResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("code", thrift.I32, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(int32(p.Code)); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *QueryUserResponse) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("msg", thrift.STRING, 2); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Msg); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *QueryUserResponse) writeField3(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("token", thrift.STRING, 3); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Token); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) +} + +func (p *QueryUserResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("QueryUserResponse(%+v)", *p) +} + +type PermissionService interface { + CreatePermission(ctx context.Context, req *CreatePermissionRequest) (r *CreatePermissionResponse, err error) + + BindPermissionRole(ctx context.Context, req *BindPermissionRoleRequest) (r *BindPermissionRoleResponse, err error) +} + +type PermissionServiceClient struct { + c thrift.TClient +} + +func NewPermissionServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *PermissionServiceClient { + return &PermissionServiceClient{ + c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), + } +} + +func NewPermissionServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *PermissionServiceClient { + return &PermissionServiceClient{ + c: thrift.NewTStandardClient(iprot, oprot), + } +} + +func NewPermissionServiceClient(c thrift.TClient) *PermissionServiceClient { + return &PermissionServiceClient{ + c: c, + } +} + +func (p *PermissionServiceClient) Client_() thrift.TClient { + return p.c +} + +func (p *PermissionServiceClient) CreatePermission(ctx context.Context, req *CreatePermissionRequest) (r *CreatePermissionResponse, err error) { + var _args PermissionServiceCreatePermissionArgs + _args.Req = req + var _result PermissionServiceCreatePermissionResult + if err = p.Client_().Call(ctx, "CreatePermission", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *PermissionServiceClient) BindPermissionRole(ctx context.Context, req *BindPermissionRoleRequest) (r *BindPermissionRoleResponse, err error) { + var _args PermissionServiceBindPermissionRoleArgs + _args.Req = req + var _result PermissionServiceBindPermissionRoleResult + if err = p.Client_().Call(ctx, "BindPermissionRole", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +type RoleService interface { + CreateRole(ctx context.Context, req *CreateRoleRequest) (r *CreateRoleResponse, err error) + + BindRole(ctx context.Context, req *BindRoleRequest) (r *BindRoleResponse, err error) +} + +type RoleServiceClient struct { + c thrift.TClient +} + +func NewRoleServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *RoleServiceClient { + return &RoleServiceClient{ + c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), + } +} + +func NewRoleServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *RoleServiceClient { + return &RoleServiceClient{ + c: thrift.NewTStandardClient(iprot, oprot), + } +} + +func NewRoleServiceClient(c thrift.TClient) *RoleServiceClient { + return &RoleServiceClient{ + c: c, + } +} + +func (p *RoleServiceClient) Client_() thrift.TClient { + return p.c +} + +func (p *RoleServiceClient) CreateRole(ctx context.Context, req *CreateRoleRequest) (r *CreateRoleResponse, err error) { + var _args RoleServiceCreateRoleArgs + _args.Req = req + var _result RoleServiceCreateRoleResult + if err = p.Client_().Call(ctx, "CreateRole", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *RoleServiceClient) BindRole(ctx context.Context, req *BindRoleRequest) (r *BindRoleResponse, err error) { + var _args RoleServiceBindRoleArgs + _args.Req = req + var _result RoleServiceBindRoleResult + if err = p.Client_().Call(ctx, "BindRole", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +type UserService interface { + Login(ctx context.Context, req *LoginRequest) (r *QueryUserResponse, err error) +} + +type UserServiceClient struct { + c thrift.TClient +} + +func NewUserServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *UserServiceClient { + return &UserServiceClient{ + c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), + } +} + +func NewUserServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *UserServiceClient { + return &UserServiceClient{ + c: thrift.NewTStandardClient(iprot, oprot), + } +} + +func NewUserServiceClient(c thrift.TClient) *UserServiceClient { + return &UserServiceClient{ + c: c, + } +} + +func (p *UserServiceClient) Client_() thrift.TClient { + return p.c +} + +func (p *UserServiceClient) Login(ctx context.Context, req *LoginRequest) (r *QueryUserResponse, err error) { + var _args UserServiceLoginArgs + _args.Req = req + var _result UserServiceLoginResult + if err = p.Client_().Call(ctx, "Login", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +type PermissionServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler PermissionService +} + +func (p *PermissionServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *PermissionServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *PermissionServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewPermissionServiceProcessor(handler PermissionService) *PermissionServiceProcessor { + self := &PermissionServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self.AddToProcessorMap("CreatePermission", &permissionServiceProcessorCreatePermission{handler: handler}) + self.AddToProcessorMap("BindPermissionRole", &permissionServiceProcessorBindPermissionRole{handler: handler}) + return self +} +func (p *PermissionServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(ctx, seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, x +} + +type permissionServiceProcessorCreatePermission struct { + handler PermissionService +} + +func (p *permissionServiceProcessorCreatePermission) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := PermissionServiceCreatePermissionArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("CreatePermission", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := PermissionServiceCreatePermissionResult{} + var retval *CreatePermissionResponse + if retval, err2 = p.handler.CreatePermission(ctx, args.Req); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing CreatePermission: "+err2.Error()) + oprot.WriteMessageBegin("CreatePermission", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("CreatePermission", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type permissionServiceProcessorBindPermissionRole struct { + handler PermissionService +} + +func (p *permissionServiceProcessorBindPermissionRole) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := PermissionServiceBindPermissionRoleArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("BindPermissionRole", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := PermissionServiceBindPermissionRoleResult{} + var retval *BindPermissionRoleResponse + if retval, err2 = p.handler.BindPermissionRole(ctx, args.Req); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing BindPermissionRole: "+err2.Error()) + oprot.WriteMessageBegin("BindPermissionRole", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("BindPermissionRole", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type PermissionServiceCreatePermissionArgs struct { + Req *CreatePermissionRequest `thrift:"req,1"` +} + +func NewPermissionServiceCreatePermissionArgs() *PermissionServiceCreatePermissionArgs { + return &PermissionServiceCreatePermissionArgs{} +} + +var PermissionServiceCreatePermissionArgs_Req_DEFAULT *CreatePermissionRequest + +func (p *PermissionServiceCreatePermissionArgs) GetReq() (v *CreatePermissionRequest) { + if !p.IsSetReq() { + return PermissionServiceCreatePermissionArgs_Req_DEFAULT + } + return p.Req +} + +var fieldIDToName_PermissionServiceCreatePermissionArgs = map[int16]string{ + 1: "req", +} + +func (p *PermissionServiceCreatePermissionArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *PermissionServiceCreatePermissionArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PermissionServiceCreatePermissionArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PermissionServiceCreatePermissionArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req = NewCreatePermissionRequest() + if err := p.Req.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *PermissionServiceCreatePermissionArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreatePermission_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *PermissionServiceCreatePermissionArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *PermissionServiceCreatePermissionArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PermissionServiceCreatePermissionArgs(%+v)", *p) +} + +type PermissionServiceCreatePermissionResult struct { + Success *CreatePermissionResponse `thrift:"success,0,optional"` +} + +func NewPermissionServiceCreatePermissionResult() *PermissionServiceCreatePermissionResult { + return &PermissionServiceCreatePermissionResult{} +} + +var PermissionServiceCreatePermissionResult_Success_DEFAULT *CreatePermissionResponse + +func (p *PermissionServiceCreatePermissionResult) GetSuccess() (v *CreatePermissionResponse) { + if !p.IsSetSuccess() { + return PermissionServiceCreatePermissionResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_PermissionServiceCreatePermissionResult = map[int16]string{ + 0: "success", +} + +func (p *PermissionServiceCreatePermissionResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *PermissionServiceCreatePermissionResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PermissionServiceCreatePermissionResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PermissionServiceCreatePermissionResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewCreatePermissionResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *PermissionServiceCreatePermissionResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreatePermission_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *PermissionServiceCreatePermissionResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *PermissionServiceCreatePermissionResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PermissionServiceCreatePermissionResult(%+v)", *p) +} + +type PermissionServiceBindPermissionRoleArgs struct { + Req *BindPermissionRoleRequest `thrift:"req,1"` +} + +func NewPermissionServiceBindPermissionRoleArgs() *PermissionServiceBindPermissionRoleArgs { + return &PermissionServiceBindPermissionRoleArgs{} +} + +var PermissionServiceBindPermissionRoleArgs_Req_DEFAULT *BindPermissionRoleRequest + +func (p *PermissionServiceBindPermissionRoleArgs) GetReq() (v *BindPermissionRoleRequest) { + if !p.IsSetReq() { + return PermissionServiceBindPermissionRoleArgs_Req_DEFAULT + } + return p.Req +} + +var fieldIDToName_PermissionServiceBindPermissionRoleArgs = map[int16]string{ + 1: "req", +} + +func (p *PermissionServiceBindPermissionRoleArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *PermissionServiceBindPermissionRoleArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PermissionServiceBindPermissionRoleArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PermissionServiceBindPermissionRoleArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req = NewBindPermissionRoleRequest() + if err := p.Req.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *PermissionServiceBindPermissionRoleArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindPermissionRole_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *PermissionServiceBindPermissionRoleArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *PermissionServiceBindPermissionRoleArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PermissionServiceBindPermissionRoleArgs(%+v)", *p) +} + +type PermissionServiceBindPermissionRoleResult struct { + Success *BindPermissionRoleResponse `thrift:"success,0,optional"` +} + +func NewPermissionServiceBindPermissionRoleResult() *PermissionServiceBindPermissionRoleResult { + return &PermissionServiceBindPermissionRoleResult{} +} + +var PermissionServiceBindPermissionRoleResult_Success_DEFAULT *BindPermissionRoleResponse + +func (p *PermissionServiceBindPermissionRoleResult) GetSuccess() (v *BindPermissionRoleResponse) { + if !p.IsSetSuccess() { + return PermissionServiceBindPermissionRoleResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_PermissionServiceBindPermissionRoleResult = map[int16]string{ + 0: "success", +} + +func (p *PermissionServiceBindPermissionRoleResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *PermissionServiceBindPermissionRoleResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PermissionServiceBindPermissionRoleResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *PermissionServiceBindPermissionRoleResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewBindPermissionRoleResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *PermissionServiceBindPermissionRoleResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindPermissionRole_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *PermissionServiceBindPermissionRoleResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *PermissionServiceBindPermissionRoleResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PermissionServiceBindPermissionRoleResult(%+v)", *p) +} + +type RoleServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler RoleService +} + +func (p *RoleServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *RoleServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *RoleServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewRoleServiceProcessor(handler RoleService) *RoleServiceProcessor { + self := &RoleServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self.AddToProcessorMap("CreateRole", &roleServiceProcessorCreateRole{handler: handler}) + self.AddToProcessorMap("BindRole", &roleServiceProcessorBindRole{handler: handler}) + return self +} +func (p *RoleServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(ctx, seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, x +} + +type roleServiceProcessorCreateRole struct { + handler RoleService +} + +func (p *roleServiceProcessorCreateRole) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := RoleServiceCreateRoleArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("CreateRole", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := RoleServiceCreateRoleResult{} + var retval *CreateRoleResponse + if retval, err2 = p.handler.CreateRole(ctx, args.Req); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing CreateRole: "+err2.Error()) + oprot.WriteMessageBegin("CreateRole", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("CreateRole", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type roleServiceProcessorBindRole struct { + handler RoleService +} + +func (p *roleServiceProcessorBindRole) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := RoleServiceBindRoleArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("BindRole", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := RoleServiceBindRoleResult{} + var retval *BindRoleResponse + if retval, err2 = p.handler.BindRole(ctx, args.Req); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing BindRole: "+err2.Error()) + oprot.WriteMessageBegin("BindRole", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("BindRole", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type RoleServiceCreateRoleArgs struct { + Req *CreateRoleRequest `thrift:"req,1"` +} + +func NewRoleServiceCreateRoleArgs() *RoleServiceCreateRoleArgs { + return &RoleServiceCreateRoleArgs{} +} + +var RoleServiceCreateRoleArgs_Req_DEFAULT *CreateRoleRequest + +func (p *RoleServiceCreateRoleArgs) GetReq() (v *CreateRoleRequest) { + if !p.IsSetReq() { + return RoleServiceCreateRoleArgs_Req_DEFAULT + } + return p.Req +} + +var fieldIDToName_RoleServiceCreateRoleArgs = map[int16]string{ + 1: "req", +} + +func (p *RoleServiceCreateRoleArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *RoleServiceCreateRoleArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RoleServiceCreateRoleArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *RoleServiceCreateRoleArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req = NewCreateRoleRequest() + if err := p.Req.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *RoleServiceCreateRoleArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreateRole_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *RoleServiceCreateRoleArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *RoleServiceCreateRoleArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("RoleServiceCreateRoleArgs(%+v)", *p) +} + +type RoleServiceCreateRoleResult struct { + Success *CreateRoleResponse `thrift:"success,0,optional"` +} + +func NewRoleServiceCreateRoleResult() *RoleServiceCreateRoleResult { + return &RoleServiceCreateRoleResult{} +} + +var RoleServiceCreateRoleResult_Success_DEFAULT *CreateRoleResponse + +func (p *RoleServiceCreateRoleResult) GetSuccess() (v *CreateRoleResponse) { + if !p.IsSetSuccess() { + return RoleServiceCreateRoleResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_RoleServiceCreateRoleResult = map[int16]string{ + 0: "success", +} + +func (p *RoleServiceCreateRoleResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *RoleServiceCreateRoleResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RoleServiceCreateRoleResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *RoleServiceCreateRoleResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewCreateRoleResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *RoleServiceCreateRoleResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("CreateRole_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *RoleServiceCreateRoleResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *RoleServiceCreateRoleResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("RoleServiceCreateRoleResult(%+v)", *p) +} + +type RoleServiceBindRoleArgs struct { + Req *BindRoleRequest `thrift:"req,1"` +} + +func NewRoleServiceBindRoleArgs() *RoleServiceBindRoleArgs { + return &RoleServiceBindRoleArgs{} +} + +var RoleServiceBindRoleArgs_Req_DEFAULT *BindRoleRequest + +func (p *RoleServiceBindRoleArgs) GetReq() (v *BindRoleRequest) { + if !p.IsSetReq() { + return RoleServiceBindRoleArgs_Req_DEFAULT + } + return p.Req +} + +var fieldIDToName_RoleServiceBindRoleArgs = map[int16]string{ + 1: "req", +} + +func (p *RoleServiceBindRoleArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *RoleServiceBindRoleArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RoleServiceBindRoleArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *RoleServiceBindRoleArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req = NewBindRoleRequest() + if err := p.Req.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *RoleServiceBindRoleArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindRole_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *RoleServiceBindRoleArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *RoleServiceBindRoleArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("RoleServiceBindRoleArgs(%+v)", *p) +} + +type RoleServiceBindRoleResult struct { + Success *BindRoleResponse `thrift:"success,0,optional"` +} + +func NewRoleServiceBindRoleResult() *RoleServiceBindRoleResult { + return &RoleServiceBindRoleResult{} +} + +var RoleServiceBindRoleResult_Success_DEFAULT *BindRoleResponse + +func (p *RoleServiceBindRoleResult) GetSuccess() (v *BindRoleResponse) { + if !p.IsSetSuccess() { + return RoleServiceBindRoleResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_RoleServiceBindRoleResult = map[int16]string{ + 0: "success", +} + +func (p *RoleServiceBindRoleResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *RoleServiceBindRoleResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RoleServiceBindRoleResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *RoleServiceBindRoleResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewBindRoleResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *RoleServiceBindRoleResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("BindRole_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *RoleServiceBindRoleResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *RoleServiceBindRoleResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("RoleServiceBindRoleResult(%+v)", *p) +} + +type UserServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler UserService +} + +func (p *UserServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *UserServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *UserServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewUserServiceProcessor(handler UserService) *UserServiceProcessor { + self := &UserServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self.AddToProcessorMap("Login", &userServiceProcessorLogin{handler: handler}) + return self +} +func (p *UserServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(ctx, seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, x +} + +type userServiceProcessorLogin struct { + handler UserService +} + +func (p *userServiceProcessorLogin) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := UserServiceLoginArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("Login", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := UserServiceLoginResult{} + var retval *QueryUserResponse + if retval, err2 = p.handler.Login(ctx, args.Req); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Login: "+err2.Error()) + oprot.WriteMessageBegin("Login", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("Login", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type UserServiceLoginArgs struct { + Req *LoginRequest `thrift:"req,1"` +} + +func NewUserServiceLoginArgs() *UserServiceLoginArgs { + return &UserServiceLoginArgs{} +} + +var UserServiceLoginArgs_Req_DEFAULT *LoginRequest + +func (p *UserServiceLoginArgs) GetReq() (v *LoginRequest) { + if !p.IsSetReq() { + return UserServiceLoginArgs_Req_DEFAULT + } + return p.Req +} + +var fieldIDToName_UserServiceLoginArgs = map[int16]string{ + 1: "req", +} + +func (p *UserServiceLoginArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *UserServiceLoginArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceLoginArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceLoginArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req = NewLoginRequest() + if err := p.Req.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceLoginArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("Login_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceLoginArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *UserServiceLoginArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceLoginArgs(%+v)", *p) +} + +type UserServiceLoginResult struct { + Success *QueryUserResponse `thrift:"success,0,optional"` +} + +func NewUserServiceLoginResult() *UserServiceLoginResult { + return &UserServiceLoginResult{} +} + +var UserServiceLoginResult_Success_DEFAULT *QueryUserResponse + +func (p *UserServiceLoginResult) GetSuccess() (v *QueryUserResponse) { + if !p.IsSetSuccess() { + return UserServiceLoginResult_Success_DEFAULT + } + return p.Success +} + +var fieldIDToName_UserServiceLoginResult = map[int16]string{ + 0: "success", +} + +func (p *UserServiceLoginResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *UserServiceLoginResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else { + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceLoginResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *UserServiceLoginResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewQueryUserResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *UserServiceLoginResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("Login_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *UserServiceLoginResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *UserServiceLoginResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("UserServiceLoginResult(%+v)", *p) +} diff --git a/bizdemo/hertz_casbin/biz/model/sql/user.sql b/bizdemo/hertz_casbin/biz/model/sql/user.sql deleted file mode 100644 index a803046a..00000000 --- a/bizdemo/hertz_casbin/biz/model/sql/user.sql +++ /dev/null @@ -1,46 +0,0 @@ -/* - Navicat Premium Data Transfer - - Source Server : 9911 - Source Server Type : MySQL - Source Server Version : 80032 - Source Host : localhost:9911 - Source Schema : gorm - - Target Server Type : MySQL - Target Server Version : 80032 - File Encoding : 65001 - - Date: 01/02/2023 10:58:17 -*/ - -SET NAMES utf8mb4; -SET FOREIGN_KEY_CHECKS = 0; - --- ---------------------------- --- Table structure for users --- ---------------------------- -DROP TABLE IF EXISTS `users`; -CREATE TABLE `users` ( - `ID` bigint NOT NULL AUTO_INCREMENT, - `username` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - `email` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, - `role` varchar(30) DEFAULT NULL, - `deleted_at` datetime DEFAULT NULL, - `updated_at` datetime DEFAULT NULL, - `created_at` datetime DEFAULT NULL, - PRIMARY KEY (`ID`), - UNIQUE KEY `username` (`username`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - --- ---------------------------- --- Records of users --- ---------------------------- -BEGIN; -INSERT INTO `users` (`ID`, `username`, `password`, `email`, `role`, `deleted_at`, `updated_at`, `created_at`) VALUES (1, 'admin', '202cb962ac59075b964b07152d234b70', 'darren94me@gmail.com', 'admin', NULL, '2023-01-31 15:46:06', '2023-01-31 15:46:06'); -INSERT INTO `users` (`ID`, `username`, `password`, `email`, `role`, `deleted_at`, `updated_at`, `created_at`) VALUES (2, 'darren', '202cb962ac59075b964b07152d234b70', 'darren@11.com', 'member', NULL, '2023-01-31 17:39:39', '2023-01-31 17:39:39'); -INSERT INTO `users` (`ID`, `username`, `password`, `email`, `role`, `deleted_at`, `updated_at`, `created_at`) VALUES (3, 'zhangsan', '202cb962ac59075b964b07152d234b70', 'zhangsan@163.com', 'member', NULL, '2023-01-31 18:05:39', '2023-01-31 18:05:39'); -COMMIT; - -SET FOREIGN_KEY_CHECKS = 1; diff --git a/bizdemo/hertz_casbin/biz/model/user/user.go b/bizdemo/hertz_casbin/biz/model/user/user.go deleted file mode 100644 index 6ab17dc2..00000000 --- a/bizdemo/hertz_casbin/biz/model/user/user.go +++ /dev/null @@ -1,2963 +0,0 @@ -// Code generated by thriftgo (0.2.5). DO NOT EDIT. - -package user - -import ( - "context" - "fmt" - "github.com/apache/thrift/lib/go/thrift" -) - -type BaseResp struct { - Code int64 `thrift:"code,1" form:"code" json:"code" query:"code"` - Message string `thrift:"message,2" form:"message" json:"message" query:"message"` -} - -func NewBaseResp() *BaseResp { - return &BaseResp{} -} - -func (p *BaseResp) GetCode() (v int64) { - return p.Code -} - -func (p *BaseResp) GetMessage() (v string) { - return p.Message -} - -var fieldIDToName_BaseResp = map[int16]string{ - 1: "code", - 2: "message", -} - -func (p *BaseResp) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.I64 { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err = p.ReadField2(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_BaseResp[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *BaseResp) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return err - } else { - p.Code = v - } - return nil -} - -func (p *BaseResp) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return err - } else { - p.Message = v - } - return nil -} - -func (p *BaseResp) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("BaseResp"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - if err = p.writeField2(oprot); err != nil { - fieldId = 2 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *BaseResp) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("code", thrift.I64, 1); err != nil { - goto WriteFieldBeginError - } - if err := oprot.WriteI64(p.Code); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *BaseResp) writeField2(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("message", thrift.STRING, 2); err != nil { - goto WriteFieldBeginError - } - if err := oprot.WriteString(p.Message); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) -} - -func (p *BaseResp) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("BaseResp(%+v)", *p) -} - -type RegisterRequest struct { - Username string `thrift:"username,1" form:"username" json:"username" vd:"(len($) > 0 && len($) < 128); msg:'Illegal format'"` - Password string `thrift:"password,2" form:"password" json:"password" vd:"(len($) > 0 && len($) < 128); msg:'Illegal format'"` - Email string `thrift:"email,3" form:"email" json:"email" vd:"(len($) > 0 && len($) < 128) && email($); msg:'Illegal format'"` -} - -func NewRegisterRequest() *RegisterRequest { - return &RegisterRequest{} -} - -func (p *RegisterRequest) GetUsername() (v string) { - return p.Username -} - -func (p *RegisterRequest) GetPassword() (v string) { - return p.Password -} - -func (p *RegisterRequest) GetEmail() (v string) { - return p.Email -} - -var fieldIDToName_RegisterRequest = map[int16]string{ - 1: "username", - 2: "password", - 3: "email", -} - -func (p *RegisterRequest) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRING { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err = p.ReadField2(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - case 3: - if fieldTypeId == thrift.STRING { - if err = p.ReadField3(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RegisterRequest[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *RegisterRequest) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return err - } else { - p.Username = v - } - return nil -} - -func (p *RegisterRequest) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return err - } else { - p.Password = v - } - return nil -} - -func (p *RegisterRequest) ReadField3(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return err - } else { - p.Email = v - } - return nil -} - -func (p *RegisterRequest) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("RegisterRequest"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - if err = p.writeField2(oprot); err != nil { - fieldId = 2 - goto WriteFieldError - } - if err = p.writeField3(oprot); err != nil { - fieldId = 3 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *RegisterRequest) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("username", thrift.STRING, 1); err != nil { - goto WriteFieldBeginError - } - if err := oprot.WriteString(p.Username); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *RegisterRequest) writeField2(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("password", thrift.STRING, 2); err != nil { - goto WriteFieldBeginError - } - if err := oprot.WriteString(p.Password); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) -} - -func (p *RegisterRequest) writeField3(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("email", thrift.STRING, 3); err != nil { - goto WriteFieldBeginError - } - if err := oprot.WriteString(p.Email); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err) -} - -func (p *RegisterRequest) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("RegisterRequest(%+v)", *p) -} - -type RegisterResponse struct { - Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` -} - -func NewRegisterResponse() *RegisterResponse { - return &RegisterResponse{} -} - -var RegisterResponse_Baseresp_DEFAULT *BaseResp - -func (p *RegisterResponse) GetBaseresp() (v *BaseResp) { - if !p.IsSetBaseresp() { - return RegisterResponse_Baseresp_DEFAULT - } - return p.Baseresp -} - -var fieldIDToName_RegisterResponse = map[int16]string{ - 1: "baseresp", -} - -func (p *RegisterResponse) IsSetBaseresp() bool { - return p.Baseresp != nil -} - -func (p *RegisterResponse) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_RegisterResponse[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *RegisterResponse) ReadField1(iprot thrift.TProtocol) error { - p.Baseresp = NewBaseResp() - if err := p.Baseresp.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *RegisterResponse) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("RegisterResponse"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *RegisterResponse) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { - goto WriteFieldBeginError - } - if err := p.Baseresp.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *RegisterResponse) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("RegisterResponse(%+v)", *p) -} - -type LoginRequest struct { - Username string `thrift:"username,1" form:"username" json:"username" vd:"(len($) > 0 && len($) < 30); msg:'Illegal format'"` - Password string `thrift:"password,2" form:"password" json:"password" vd:"(len($) > 0 && len($) < 30); msg:'Illegal format'"` -} - -func NewLoginRequest() *LoginRequest { - return &LoginRequest{} -} - -func (p *LoginRequest) GetUsername() (v string) { - return p.Username -} - -func (p *LoginRequest) GetPassword() (v string) { - return p.Password -} - -var fieldIDToName_LoginRequest = map[int16]string{ - 1: "username", - 2: "password", -} - -func (p *LoginRequest) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRING { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - case 2: - if fieldTypeId == thrift.STRING { - if err = p.ReadField2(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_LoginRequest[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *LoginRequest) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return err - } else { - p.Username = v - } - return nil -} - -func (p *LoginRequest) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadString(); err != nil { - return err - } else { - p.Password = v - } - return nil -} - -func (p *LoginRequest) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("LoginRequest"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - if err = p.writeField2(oprot); err != nil { - fieldId = 2 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *LoginRequest) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("username", thrift.STRING, 1); err != nil { - goto WriteFieldBeginError - } - if err := oprot.WriteString(p.Username); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *LoginRequest) writeField2(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("password", thrift.STRING, 2); err != nil { - goto WriteFieldBeginError - } - if err := oprot.WriteString(p.Password); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) -} - -func (p *LoginRequest) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("LoginRequest(%+v)", *p) -} - -type LoginResponse struct { - Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` -} - -func NewLoginResponse() *LoginResponse { - return &LoginResponse{} -} - -var LoginResponse_Baseresp_DEFAULT *BaseResp - -func (p *LoginResponse) GetBaseresp() (v *BaseResp) { - if !p.IsSetBaseresp() { - return LoginResponse_Baseresp_DEFAULT - } - return p.Baseresp -} - -var fieldIDToName_LoginResponse = map[int16]string{ - 1: "baseresp", -} - -func (p *LoginResponse) IsSetBaseresp() bool { - return p.Baseresp != nil -} - -func (p *LoginResponse) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_LoginResponse[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *LoginResponse) ReadField1(iprot thrift.TProtocol) error { - p.Baseresp = NewBaseResp() - if err := p.Baseresp.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *LoginResponse) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("LoginResponse"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *LoginResponse) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { - goto WriteFieldBeginError - } - if err := p.Baseresp.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *LoginResponse) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("LoginResponse(%+v)", *p) -} - -type FindUserResponse struct { - Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` -} - -func NewFindUserResponse() *FindUserResponse { - return &FindUserResponse{} -} - -var FindUserResponse_Baseresp_DEFAULT *BaseResp - -func (p *FindUserResponse) GetBaseresp() (v *BaseResp) { - if !p.IsSetBaseresp() { - return FindUserResponse_Baseresp_DEFAULT - } - return p.Baseresp -} - -var fieldIDToName_FindUserResponse = map[int16]string{ - 1: "baseresp", -} - -func (p *FindUserResponse) IsSetBaseresp() bool { - return p.Baseresp != nil -} - -func (p *FindUserResponse) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_FindUserResponse[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *FindUserResponse) ReadField1(iprot thrift.TProtocol) error { - p.Baseresp = NewBaseResp() - if err := p.Baseresp.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *FindUserResponse) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("FindUserResponse"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *FindUserResponse) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { - goto WriteFieldBeginError - } - if err := p.Baseresp.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *FindUserResponse) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("FindUserResponse(%+v)", *p) -} - -type MemberListResponse struct { - Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` -} - -func NewMemberListResponse() *MemberListResponse { - return &MemberListResponse{} -} - -var MemberListResponse_Baseresp_DEFAULT *BaseResp - -func (p *MemberListResponse) GetBaseresp() (v *BaseResp) { - if !p.IsSetBaseresp() { - return MemberListResponse_Baseresp_DEFAULT - } - return p.Baseresp -} - -var fieldIDToName_MemberListResponse = map[int16]string{ - 1: "baseresp", -} - -func (p *MemberListResponse) IsSetBaseresp() bool { - return p.Baseresp != nil -} - -func (p *MemberListResponse) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_MemberListResponse[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *MemberListResponse) ReadField1(iprot thrift.TProtocol) error { - p.Baseresp = NewBaseResp() - if err := p.Baseresp.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *MemberListResponse) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("MemberListResponse"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *MemberListResponse) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { - goto WriteFieldBeginError - } - if err := p.Baseresp.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *MemberListResponse) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("MemberListResponse(%+v)", *p) -} - -type AdminListResponse struct { - Baseresp *BaseResp `thrift:"baseresp,1" form:"baseresp" json:"baseresp" query:"baseresp"` -} - -func NewAdminListResponse() *AdminListResponse { - return &AdminListResponse{} -} - -var AdminListResponse_Baseresp_DEFAULT *BaseResp - -func (p *AdminListResponse) GetBaseresp() (v *BaseResp) { - if !p.IsSetBaseresp() { - return AdminListResponse_Baseresp_DEFAULT - } - return p.Baseresp -} - -var fieldIDToName_AdminListResponse = map[int16]string{ - 1: "baseresp", -} - -func (p *AdminListResponse) IsSetBaseresp() bool { - return p.Baseresp != nil -} - -func (p *AdminListResponse) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_AdminListResponse[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *AdminListResponse) ReadField1(iprot thrift.TProtocol) error { - p.Baseresp = NewBaseResp() - if err := p.Baseresp.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *AdminListResponse) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("AdminListResponse"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *AdminListResponse) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("baseresp", thrift.STRUCT, 1); err != nil { - goto WriteFieldBeginError - } - if err := p.Baseresp.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *AdminListResponse) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AdminListResponse(%+v)", *p) -} - -type UserService interface { - Register(ctx context.Context, req *RegisterRequest) (r *RegisterResponse, err error) - - Login(ctx context.Context, req *LoginRequest) (r *LoginResponse, err error) - - FindUser(ctx context.Context) (r *FindUserResponse, err error) - - MemberList(ctx context.Context) (r *MemberListResponse, err error) - - AdminList(ctx context.Context) (r *AdminListResponse, err error) -} - -type UserServiceClient struct { - c thrift.TClient -} - -func NewUserServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *UserServiceClient { - return &UserServiceClient{ - c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), - } -} - -func NewUserServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *UserServiceClient { - return &UserServiceClient{ - c: thrift.NewTStandardClient(iprot, oprot), - } -} - -func NewUserServiceClient(c thrift.TClient) *UserServiceClient { - return &UserServiceClient{ - c: c, - } -} - -func (p *UserServiceClient) Client_() thrift.TClient { - return p.c -} - -func (p *UserServiceClient) Register(ctx context.Context, req *RegisterRequest) (r *RegisterResponse, err error) { - var _args UserServiceRegisterArgs - _args.Req = req - var _result UserServiceRegisterResult - if err = p.Client_().Call(ctx, "register", &_args, &_result); err != nil { - return - } - return _result.GetSuccess(), nil -} -func (p *UserServiceClient) Login(ctx context.Context, req *LoginRequest) (r *LoginResponse, err error) { - var _args UserServiceLoginArgs - _args.Req = req - var _result UserServiceLoginResult - if err = p.Client_().Call(ctx, "login", &_args, &_result); err != nil { - return - } - return _result.GetSuccess(), nil -} -func (p *UserServiceClient) FindUser(ctx context.Context) (r *FindUserResponse, err error) { - var _args UserServiceFindUserArgs - var _result UserServiceFindUserResult - if err = p.Client_().Call(ctx, "findUser", &_args, &_result); err != nil { - return - } - return _result.GetSuccess(), nil -} -func (p *UserServiceClient) MemberList(ctx context.Context) (r *MemberListResponse, err error) { - var _args UserServiceMemberListArgs - var _result UserServiceMemberListResult - if err = p.Client_().Call(ctx, "memberList", &_args, &_result); err != nil { - return - } - return _result.GetSuccess(), nil -} -func (p *UserServiceClient) AdminList(ctx context.Context) (r *AdminListResponse, err error) { - var _args UserServiceAdminListArgs - var _result UserServiceAdminListResult - if err = p.Client_().Call(ctx, "adminList", &_args, &_result); err != nil { - return - } - return _result.GetSuccess(), nil -} - -type UserServiceProcessor struct { - processorMap map[string]thrift.TProcessorFunction - handler UserService -} - -func (p *UserServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { - p.processorMap[key] = processor -} - -func (p *UserServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { - processor, ok = p.processorMap[key] - return processor, ok -} - -func (p *UserServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { - return p.processorMap -} - -func NewUserServiceProcessor(handler UserService) *UserServiceProcessor { - self := &UserServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} - self.AddToProcessorMap("register", &userServiceProcessorRegister{handler: handler}) - self.AddToProcessorMap("login", &userServiceProcessorLogin{handler: handler}) - self.AddToProcessorMap("findUser", &userServiceProcessorFindUser{handler: handler}) - self.AddToProcessorMap("memberList", &userServiceProcessorMemberList{handler: handler}) - self.AddToProcessorMap("adminList", &userServiceProcessorAdminList{handler: handler}) - return self -} -func (p *UserServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - name, _, seqId, err := iprot.ReadMessageBegin() - if err != nil { - return false, err - } - if processor, ok := p.GetProcessorFunction(name); ok { - return processor.Process(ctx, seqId, iprot, oprot) - } - iprot.Skip(thrift.STRUCT) - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) - oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, x -} - -type userServiceProcessorRegister struct { - handler UserService -} - -func (p *userServiceProcessorRegister) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := UserServiceRegisterArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("register", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - var err2 error - result := UserServiceRegisterResult{} - var retval *RegisterResponse - if retval, err2 = p.handler.Register(ctx, args.Req); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing register: "+err2.Error()) - oprot.WriteMessageBegin("register", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval - } - if err2 = oprot.WriteMessageBegin("register", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -type userServiceProcessorLogin struct { - handler UserService -} - -func (p *userServiceProcessorLogin) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := UserServiceLoginArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("login", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - var err2 error - result := UserServiceLoginResult{} - var retval *LoginResponse - if retval, err2 = p.handler.Login(ctx, args.Req); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing login: "+err2.Error()) - oprot.WriteMessageBegin("login", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval - } - if err2 = oprot.WriteMessageBegin("login", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -type userServiceProcessorFindUser struct { - handler UserService -} - -func (p *userServiceProcessorFindUser) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := UserServiceFindUserArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("findUser", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - var err2 error - result := UserServiceFindUserResult{} - var retval *FindUserResponse - if retval, err2 = p.handler.FindUser(ctx); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing findUser: "+err2.Error()) - oprot.WriteMessageBegin("findUser", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval - } - if err2 = oprot.WriteMessageBegin("findUser", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -type userServiceProcessorMemberList struct { - handler UserService -} - -func (p *userServiceProcessorMemberList) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := UserServiceMemberListArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("memberList", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - var err2 error - result := UserServiceMemberListResult{} - var retval *MemberListResponse - if retval, err2 = p.handler.MemberList(ctx); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing memberList: "+err2.Error()) - oprot.WriteMessageBegin("memberList", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval - } - if err2 = oprot.WriteMessageBegin("memberList", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -type userServiceProcessorAdminList struct { - handler UserService -} - -func (p *userServiceProcessorAdminList) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := UserServiceAdminListArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("adminList", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return false, err - } - - iprot.ReadMessageEnd() - var err2 error - result := UserServiceAdminListResult{} - var retval *AdminListResponse - if retval, err2 = p.handler.AdminList(ctx); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing adminList: "+err2.Error()) - oprot.WriteMessageBegin("adminList", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush(ctx) - return true, err2 - } else { - result.Success = retval - } - if err2 = oprot.WriteMessageBegin("adminList", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(ctx); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -type UserServiceRegisterArgs struct { - Req *RegisterRequest `thrift:"req,1"` -} - -func NewUserServiceRegisterArgs() *UserServiceRegisterArgs { - return &UserServiceRegisterArgs{} -} - -var UserServiceRegisterArgs_Req_DEFAULT *RegisterRequest - -func (p *UserServiceRegisterArgs) GetReq() (v *RegisterRequest) { - if !p.IsSetReq() { - return UserServiceRegisterArgs_Req_DEFAULT - } - return p.Req -} - -var fieldIDToName_UserServiceRegisterArgs = map[int16]string{ - 1: "req", -} - -func (p *UserServiceRegisterArgs) IsSetReq() bool { - return p.Req != nil -} - -func (p *UserServiceRegisterArgs) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceRegisterArgs[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceRegisterArgs) ReadField1(iprot thrift.TProtocol) error { - p.Req = NewRegisterRequest() - if err := p.Req.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *UserServiceRegisterArgs) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("register_args"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceRegisterArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { - goto WriteFieldBeginError - } - if err := p.Req.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *UserServiceRegisterArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceRegisterArgs(%+v)", *p) -} - -type UserServiceRegisterResult struct { - Success *RegisterResponse `thrift:"success,0,optional"` -} - -func NewUserServiceRegisterResult() *UserServiceRegisterResult { - return &UserServiceRegisterResult{} -} - -var UserServiceRegisterResult_Success_DEFAULT *RegisterResponse - -func (p *UserServiceRegisterResult) GetSuccess() (v *RegisterResponse) { - if !p.IsSetSuccess() { - return UserServiceRegisterResult_Success_DEFAULT - } - return p.Success -} - -var fieldIDToName_UserServiceRegisterResult = map[int16]string{ - 0: "success", -} - -func (p *UserServiceRegisterResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *UserServiceRegisterResult) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField0(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceRegisterResult[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceRegisterResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = NewRegisterResponse() - if err := p.Success.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *UserServiceRegisterResult) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("register_result"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField0(oprot); err != nil { - fieldId = 0 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceRegisterResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - goto WriteFieldBeginError - } - if err := p.Success.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) -} - -func (p *UserServiceRegisterResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceRegisterResult(%+v)", *p) -} - -type UserServiceLoginArgs struct { - Req *LoginRequest `thrift:"req,1"` -} - -func NewUserServiceLoginArgs() *UserServiceLoginArgs { - return &UserServiceLoginArgs{} -} - -var UserServiceLoginArgs_Req_DEFAULT *LoginRequest - -func (p *UserServiceLoginArgs) GetReq() (v *LoginRequest) { - if !p.IsSetReq() { - return UserServiceLoginArgs_Req_DEFAULT - } - return p.Req -} - -var fieldIDToName_UserServiceLoginArgs = map[int16]string{ - 1: "req", -} - -func (p *UserServiceLoginArgs) IsSetReq() bool { - return p.Req != nil -} - -func (p *UserServiceLoginArgs) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 1: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField1(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceLoginArgs[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceLoginArgs) ReadField1(iprot thrift.TProtocol) error { - p.Req = NewLoginRequest() - if err := p.Req.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *UserServiceLoginArgs) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("login_args"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField1(oprot); err != nil { - fieldId = 1 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceLoginArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { - goto WriteFieldBeginError - } - if err := p.Req.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) -} - -func (p *UserServiceLoginArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceLoginArgs(%+v)", *p) -} - -type UserServiceLoginResult struct { - Success *LoginResponse `thrift:"success,0,optional"` -} - -func NewUserServiceLoginResult() *UserServiceLoginResult { - return &UserServiceLoginResult{} -} - -var UserServiceLoginResult_Success_DEFAULT *LoginResponse - -func (p *UserServiceLoginResult) GetSuccess() (v *LoginResponse) { - if !p.IsSetSuccess() { - return UserServiceLoginResult_Success_DEFAULT - } - return p.Success -} - -var fieldIDToName_UserServiceLoginResult = map[int16]string{ - 0: "success", -} - -func (p *UserServiceLoginResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *UserServiceLoginResult) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField0(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceLoginResult[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceLoginResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = NewLoginResponse() - if err := p.Success.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *UserServiceLoginResult) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("login_result"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField0(oprot); err != nil { - fieldId = 0 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceLoginResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - goto WriteFieldBeginError - } - if err := p.Success.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) -} - -func (p *UserServiceLoginResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceLoginResult(%+v)", *p) -} - -type UserServiceFindUserArgs struct { -} - -func NewUserServiceFindUserArgs() *UserServiceFindUserArgs { - return &UserServiceFindUserArgs{} -} - -var fieldIDToName_UserServiceFindUserArgs = map[int16]string{} - -func (p *UserServiceFindUserArgs) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldTypeError - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -SkipFieldTypeError: - return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceFindUserArgs) Write(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteStructBegin("findUser_args"); err != nil { - goto WriteStructBeginError - } - if p != nil { - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceFindUserArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceFindUserArgs(%+v)", *p) -} - -type UserServiceFindUserResult struct { - Success *FindUserResponse `thrift:"success,0,optional"` -} - -func NewUserServiceFindUserResult() *UserServiceFindUserResult { - return &UserServiceFindUserResult{} -} - -var UserServiceFindUserResult_Success_DEFAULT *FindUserResponse - -func (p *UserServiceFindUserResult) GetSuccess() (v *FindUserResponse) { - if !p.IsSetSuccess() { - return UserServiceFindUserResult_Success_DEFAULT - } - return p.Success -} - -var fieldIDToName_UserServiceFindUserResult = map[int16]string{ - 0: "success", -} - -func (p *UserServiceFindUserResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *UserServiceFindUserResult) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField0(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceFindUserResult[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceFindUserResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = NewFindUserResponse() - if err := p.Success.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *UserServiceFindUserResult) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("findUser_result"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField0(oprot); err != nil { - fieldId = 0 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceFindUserResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - goto WriteFieldBeginError - } - if err := p.Success.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) -} - -func (p *UserServiceFindUserResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceFindUserResult(%+v)", *p) -} - -type UserServiceMemberListArgs struct { -} - -func NewUserServiceMemberListArgs() *UserServiceMemberListArgs { - return &UserServiceMemberListArgs{} -} - -var fieldIDToName_UserServiceMemberListArgs = map[int16]string{} - -func (p *UserServiceMemberListArgs) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldTypeError - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -SkipFieldTypeError: - return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceMemberListArgs) Write(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteStructBegin("memberList_args"); err != nil { - goto WriteStructBeginError - } - if p != nil { - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceMemberListArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceMemberListArgs(%+v)", *p) -} - -type UserServiceMemberListResult struct { - Success *MemberListResponse `thrift:"success,0,optional"` -} - -func NewUserServiceMemberListResult() *UserServiceMemberListResult { - return &UserServiceMemberListResult{} -} - -var UserServiceMemberListResult_Success_DEFAULT *MemberListResponse - -func (p *UserServiceMemberListResult) GetSuccess() (v *MemberListResponse) { - if !p.IsSetSuccess() { - return UserServiceMemberListResult_Success_DEFAULT - } - return p.Success -} - -var fieldIDToName_UserServiceMemberListResult = map[int16]string{ - 0: "success", -} - -func (p *UserServiceMemberListResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *UserServiceMemberListResult) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField0(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceMemberListResult[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceMemberListResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = NewMemberListResponse() - if err := p.Success.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *UserServiceMemberListResult) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("memberList_result"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField0(oprot); err != nil { - fieldId = 0 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceMemberListResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - goto WriteFieldBeginError - } - if err := p.Success.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) -} - -func (p *UserServiceMemberListResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceMemberListResult(%+v)", *p) -} - -type UserServiceAdminListArgs struct { -} - -func NewUserServiceAdminListArgs() *UserServiceAdminListArgs { - return &UserServiceAdminListArgs{} -} - -var fieldIDToName_UserServiceAdminListArgs = map[int16]string{} - -func (p *UserServiceAdminListArgs) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldTypeError - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -SkipFieldTypeError: - return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceAdminListArgs) Write(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteStructBegin("adminList_args"); err != nil { - goto WriteStructBeginError - } - if p != nil { - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceAdminListArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceAdminListArgs(%+v)", *p) -} - -type UserServiceAdminListResult struct { - Success *AdminListResponse `thrift:"success,0,optional"` -} - -func NewUserServiceAdminListResult() *UserServiceAdminListResult { - return &UserServiceAdminListResult{} -} - -var UserServiceAdminListResult_Success_DEFAULT *AdminListResponse - -func (p *UserServiceAdminListResult) GetSuccess() (v *AdminListResponse) { - if !p.IsSetSuccess() { - return UserServiceAdminListResult_Success_DEFAULT - } - return p.Success -} - -var fieldIDToName_UserServiceAdminListResult = map[int16]string{ - 0: "success", -} - -func (p *UserServiceAdminListResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *UserServiceAdminListResult) Read(iprot thrift.TProtocol) (err error) { - - var fieldTypeId thrift.TType - var fieldId int16 - - if _, err = iprot.ReadStructBegin(); err != nil { - goto ReadStructBeginError - } - - for { - _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() - if err != nil { - goto ReadFieldBeginError - } - if fieldTypeId == thrift.STOP { - break - } - - switch fieldId { - case 0: - if fieldTypeId == thrift.STRUCT { - if err = p.ReadField0(iprot); err != nil { - goto ReadFieldError - } - } else { - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - default: - if err = iprot.Skip(fieldTypeId); err != nil { - goto SkipFieldError - } - } - - if err = iprot.ReadFieldEnd(); err != nil { - goto ReadFieldEndError - } - } - if err = iprot.ReadStructEnd(); err != nil { - goto ReadStructEndError - } - - return nil -ReadStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) -ReadFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) -ReadFieldError: - return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_UserServiceAdminListResult[fieldId]), err) -SkipFieldError: - return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) - -ReadFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) -ReadStructEndError: - return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) -} - -func (p *UserServiceAdminListResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = NewAdminListResponse() - if err := p.Success.Read(iprot); err != nil { - return err - } - return nil -} - -func (p *UserServiceAdminListResult) Write(oprot thrift.TProtocol) (err error) { - var fieldId int16 - if err = oprot.WriteStructBegin("adminList_result"); err != nil { - goto WriteStructBeginError - } - if p != nil { - if err = p.writeField0(oprot); err != nil { - fieldId = 0 - goto WriteFieldError - } - - } - if err = oprot.WriteFieldStop(); err != nil { - goto WriteFieldStopError - } - if err = oprot.WriteStructEnd(); err != nil { - goto WriteStructEndError - } - return nil -WriteStructBeginError: - return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) -WriteFieldError: - return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) -WriteFieldStopError: - return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) -WriteStructEndError: - return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) -} - -func (p *UserServiceAdminListResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - goto WriteFieldBeginError - } - if err := p.Success.Write(oprot); err != nil { - return err - } - if err = oprot.WriteFieldEnd(); err != nil { - goto WriteFieldEndError - } - } - return nil -WriteFieldBeginError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) -WriteFieldEndError: - return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) -} - -func (p *UserServiceAdminListResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("UserServiceAdminListResult(%+v)", *p) -} diff --git a/bizdemo/hertz_casbin/biz/mw/casbin.go b/bizdemo/hertz_casbin/biz/mw/casbin.go index 1edc14b3..eb5cb624 100644 --- a/bizdemo/hertz_casbin/biz/mw/casbin.go +++ b/bizdemo/hertz_casbin/biz/mw/casbin.go @@ -2,21 +2,22 @@ package mw import ( "github.com/casbin/casbin" - "log" + xormadapter "github.com/casbin/xorm-adapter" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" ) -var authEnforcer *casbin.Enforcer +var AuthEnforcer *casbin.Enforcer func InitCasbin() { - var err error - authEnforcer, err = casbin.NewEnforcerSafe("./conf/auth_model.conf", "./conf/policy.csv") - if err != nil { - log.Fatal(err) - } + adapter := xormadapter.NewAdapter("mysql", consts.MysqlDSN, true) + + enforcer := casbin.NewEnforcer("conf/auth_model.conf", adapter) + + AuthEnforcer = enforcer } func Authorize(rvals ...interface{}) (result bool, err error) { // casbin enforce - res, err1 := authEnforcer.EnforceSafe(rvals[0], rvals[1], rvals[2]) + res, err1 := AuthEnforcer.EnforceSafe(rvals[0], rvals[1], rvals[2]) return res, err1 } diff --git a/bizdemo/hertz_casbin/biz/mw/session.go b/bizdemo/hertz_casbin/biz/mw/session.go deleted file mode 100644 index 648c5a63..00000000 --- a/bizdemo/hertz_casbin/biz/mw/session.go +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package mw - -import ( - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" - "github.com/cloudwego/hertz/pkg/app/server" - "github.com/hertz-contrib/sessions" - "github.com/hertz-contrib/sessions/redis" - "math/rand" - "strconv" -) - -func InitSession(h *server.Hertz) { - store, err := redis.NewStore(consts.MaxIdleNum, consts.TCP, consts.RedisAddr, consts.RedisPasswd, []byte(consts.SessionSecretKey)) - if err != nil { - panic(err) - } - h.Use(sessions.New(consts.HertzSession+strconv.Itoa(rand.Int()), store)) - -} diff --git a/bizdemo/hertz_casbin/biz/router/casbin/casbin.go b/bizdemo/hertz_casbin/biz/router/casbin/casbin.go new file mode 100644 index 00000000..462cb203 --- /dev/null +++ b/bizdemo/hertz_casbin/biz/router/casbin/casbin.go @@ -0,0 +1,49 @@ +// Code generated by hertz generator. DO NOT EDIT. + +package Casbin + +import ( + "github.com/cloudwego/hertz/pkg/app/server" + casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/handler/casbin" +) + +/* + This file will register all the routes of the services in the master idl. + And it will update automatically when you use the "update" command for the idl. + So don't modify the contents of the file, or your code will be deleted when it is updated. +*/ + +// Register register routes based on the IDL 'api.${HTTP Method}' annotation. +func Register(r *server.Hertz) { + + root := r.Group("/", rootMw()...) + { + _v1 := root.Group("/v1", _v1Mw()...) + _v1.POST("/login", append(_loginMw(), casbin.Login)...) + { + _permission := _v1.Group("/permission", _permissionMw()...) + { + _create := _permission.Group("/create", _createMw()...) + _create.POST("/", append(_createpermissionMw(), casbin.CreatePermission)...) + } + } + { + _permissionrole := _v1.Group("/permissionrole", _permissionroleMw()...) + { + _bind := _permissionrole.Group("/bind", _bindMw()...) + _bind.POST("/", append(_bindpermissionroleMw(), casbin.BindPermissionRole)...) + } + } + { + _role := _v1.Group("/role", _roleMw()...) + { + _bind0 := _role.Group("/bind", _bind0Mw()...) + _bind0.POST("/", append(_bindroleMw(), casbin.BindRole)...) + } + { + _create0 := _role.Group("/create", _create0Mw()...) + _create0.POST("/", append(_createroleMw(), casbin.CreateRole)...) + } + } + } +} diff --git a/bizdemo/hertz_casbin/biz/router/casbin/middleware.go b/bizdemo/hertz_casbin/biz/router/casbin/middleware.go new file mode 100644 index 00000000..f1233d1c --- /dev/null +++ b/bizdemo/hertz_casbin/biz/router/casbin/middleware.go @@ -0,0 +1,171 @@ +// Code generated by hertz generator. + +package Casbin + +import ( + "context" + "fmt" + "github.com/cloudwego/hertz/pkg/app" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/mw" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" + + "net/http" +) + +func rootMw() []app.HandlerFunc { + + fmt.Println("group middleware start ") + return []app.HandlerFunc{func(ctx context.Context, c *app.RequestContext) { + + if c.FullPath() == "/v1/login" { + c.Next(ctx) + return + } + + token := c.Request.Header.Get("token") + if token == "" { + c.JSON(http.StatusInternalServerError, casbin.BasicResponse{ + Code: 2, + Msg: "token is not null ", + }) + c.Abort() + return + } + + claim, err := utils.AnalyzeToken(token) + + if err != nil { + c.JSON(http.StatusInternalServerError, casbin.BasicResponse{ + Code: 2, + Msg: "token is not valid ", + }) + c.Abort() + return + } + + roles := claim.Roles + + // casbin enforce + var isAuth bool = false + + for _, v := range roles { + res, err := mw.Authorize(v.Name, c.FullPath(), string(c.Request.Header.Method())) + if err != nil { + c.JSON(http.StatusInternalServerError, casbin.BasicResponse{ + Code: 3, + Msg: "Authorize is error ", + }) + c.Abort() + return + } + if res { + isAuth = true + break + } + } + + if isAuth { + c.Next(ctx) + } else { + c.JSON(http.StatusInternalServerError, casbin.BasicResponse{ + Code: 4, + Msg: "FORBIDDEN ", + }) + c.Abort() + return + } + + }} + +} + +func _v1Mw() []app.HandlerFunc { + // your code... + return nil +} + +func _userMw() []app.HandlerFunc { + // your code... + return nil +} + +func _createMw() []app.HandlerFunc { + // your code... + return nil +} + +func _createuserMw() []app.HandlerFunc { + // your code... + return nil +} + +func _queryMw() []app.HandlerFunc { + // your code... + return nil +} + +func _queryuserMw() []app.HandlerFunc { + // your code... + return nil +} + +func _loginMw() []app.HandlerFunc { + // your code... + return nil +} + +func _roleMw() []app.HandlerFunc { + // your code... + return nil +} + +func _bindMw() []app.HandlerFunc { + // your code... + return nil +} + +func _bindroleMw() []app.HandlerFunc { + // your code... + return nil +} + +func _createroleMw() []app.HandlerFunc { + // your code... + return nil +} + +func _create0Mw() []app.HandlerFunc { + // your code... + return nil +} + +func _permissionMw() []app.HandlerFunc { + // your code... + return nil +} + +func _createpermissionMw() []app.HandlerFunc { + // your code... + return nil +} + +func _permissionroleMw() []app.HandlerFunc { + // your code... + return nil +} + +func _bindpermissionroleMw() []app.HandlerFunc { + // your code... + return nil +} + +func _bind0Mw() []app.HandlerFunc { + // your code... + return nil +} + +func _create1Mw() []app.HandlerFunc { + // your code... + return nil +} diff --git a/bizdemo/hertz_casbin/biz/router/register.go b/bizdemo/hertz_casbin/biz/router/register.go old mode 100644 new mode 100755 index 5cd9b100..9ec3e5f2 --- a/bizdemo/hertz_casbin/biz/router/register.go +++ b/bizdemo/hertz_casbin/biz/router/register.go @@ -3,12 +3,13 @@ package router import ( - user "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/router/user" "github.com/cloudwego/hertz/pkg/app/server" + casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/router/casbin" ) // GeneratedRegister registers routers generated by IDL. func GeneratedRegister(r *server.Hertz) { //INSERT_POINT: DO NOT DELETE THIS LINE! - user.Register(r) + casbin.Register(r) + } diff --git a/bizdemo/hertz_casbin/biz/router/user/middleware.go b/bizdemo/hertz_casbin/biz/router/user/middleware.go deleted file mode 100644 index 94dff128..00000000 --- a/bizdemo/hertz_casbin/biz/router/user/middleware.go +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Code generated by hertz generator. - -package User - -import ( - "github.com/cloudwego/hertz/pkg/app" -) - -func rootMw() []app.HandlerFunc { - // your code... - return nil -} - -func _loginMw() []app.HandlerFunc { - // your code... - return nil -} - -func _registerMw() []app.HandlerFunc { - // your code... - return nil -} - -func _finduserMw() []app.HandlerFunc { - // your code... - return nil -} - -func _adminMw() []app.HandlerFunc { - // your code... - return nil -} - -func __dminlistMw() []app.HandlerFunc { - // your code... - return nil -} - -func _memberMw() []app.HandlerFunc { - // your code... - return nil -} - -func _memberlistMw() []app.HandlerFunc { - // your code... - return nil -} diff --git a/bizdemo/hertz_casbin/biz/router/user/user.go b/bizdemo/hertz_casbin/biz/router/user/user.go deleted file mode 100644 index 8636f1dc..00000000 --- a/bizdemo/hertz_casbin/biz/router/user/user.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by hertz generator. DO NOT EDIT. - -package User - -import ( - user "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler/user" - "github.com/cloudwego/hertz/pkg/app/server" -) - -/* - This file will register all the routes of the services in the master idl. - And it will update automatically when you use the "update" command for the idl. - So don't modify the contents of the file, or your code will be deleted when it is updated. -*/ - -// Register register routes based on the IDL 'api.${HTTP Method}' annotation. -func Register(r *server.Hertz) { - - root := r.Group("/", rootMw()...) - root.GET("/findUser", append(_finduserMw(), user.FindUser)...) - root.POST("/login", append(_loginMw(), user.Login)...) - root.POST("/register", append(_registerMw(), user.Register)...) - { - _admin := root.Group("/admin", _adminMw()...) - _admin.GET("/list", append(__dminlistMw(), user.AdminList)...) - } - { - _member := root.Group("/member", _memberMw()...) - _member.GET("/list", append(_memberlistMw(), user.MemberList)...) - } -} diff --git a/bizdemo/hertz_casbin/conf/policy.csv b/bizdemo/hertz_casbin/conf/policy.csv deleted file mode 100644 index f6219e32..00000000 --- a/bizdemo/hertz_casbin/conf/policy.csv +++ /dev/null @@ -1,7 +0,0 @@ -p, admin, /*, * -p, anonymous, /login, * -p, member, /logout, * -p, anonymous, /register, * -p, member, /findUser, * -p, admin, /admin/*, * -p, member, /member/*, * \ No newline at end of file diff --git a/bizdemo/hertz_casbin/docker-compose.yml b/bizdemo/hertz_casbin/docker-compose.yml index 2923e188..f65db9ed 100644 --- a/bizdemo/hertz_casbin/docker-compose.yml +++ b/bizdemo/hertz_casbin/docker-compose.yml @@ -4,13 +4,8 @@ services: mysql: image: 'mysql:latest' ports: - - 9911:3306 + - 9912:3306 environment: - - MYSQL_DATABASE=gorm - - MYSQL_USER=gorm - - MYSQL_PASSWORD=gorm - - MYSQL_RANDOM_ROOT_PASSWORD="yes" - redis: - image: 'redis:latest' - ports: - - 6379:6379 \ No newline at end of file + - MYSQL_DATABASE=casbin + - MYSQL_ROOT_PASSWORD=casbin + diff --git a/bizdemo/hertz_casbin/go.mod b/bizdemo/hertz_casbin/go.mod old mode 100644 new mode 100755 index 0b00b4e5..4f16fd96 --- a/bizdemo/hertz_casbin/go.mod +++ b/bizdemo/hertz_casbin/go.mod @@ -1,39 +1,36 @@ -module github.com/cloudwego/hertz-examples/bizdemo/hertz_session +module github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin -go 1.18 +go 1.19 replace github.com/apache/thrift => github.com/apache/thrift v0.13.0 require ( - github.com/apache/thrift v0.0.0-00010101000000-000000000000 - github.com/casbin/casbin v1.3.0 - github.com/cloudwego/hertz v0.4.1 - github.com/hertz-contrib/csrf v0.1.1 - github.com/hertz-contrib/sessions v1.0.1 - gorm.io/driver/mysql v1.4.4 - gorm.io/gorm v1.24.2 + github.com/apache/thrift v0.12.0 + github.com/casbin/casbin v1.9.1 + github.com/casbin/xorm-adapter v1.0.0 + github.com/cloudwego/hertz v0.5.1 + github.com/golang-jwt/jwt/v4 v4.4.3 + gorm.io/driver/mysql v1.4.5 + gorm.io/gorm v1.24.3 ) require ( - github.com/Knetic/govaluate v3.0.0+incompatible // indirect - github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect + github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 // indirect github.com/bytedance/sonic v1.5.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06 // indirect github.com/cloudwego/netpoll v0.3.1 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect + github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/go-xorm/xorm v0.7.9 // indirect github.com/golang/protobuf v1.5.0 // indirect - github.com/gomodule/redigo v2.0.0+incompatible // indirect - github.com/gorilla/context v1.1.1 // indirect - github.com/gorilla/securecookie v1.1.1 // indirect - github.com/gorilla/sessions v1.2.1 // indirect github.com/henrylee2cn/ameda v1.4.10 // indirect github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect + github.com/lib/pq v1.10.7 // indirect github.com/nyaruka/phonenumbers v1.0.55 // indirect github.com/tidwall/gjson v1.13.0 // indirect github.com/tidwall/match v1.1.1 // indirect @@ -42,4 +39,6 @@ require ( golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect google.golang.org/protobuf v1.27.1 // indirect + xorm.io/builder v0.3.6 // indirect + xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect ) diff --git a/bizdemo/hertz_casbin/go.sum b/bizdemo/hertz_casbin/go.sum index 15e40dd0..d7bb9e65 100644 --- a/bizdemo/hertz_casbin/go.sum +++ b/bizdemo/hertz_casbin/go.sum @@ -1,107 +1,221 @@ -github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg= -github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.37.4 h1:glPeL3BQJsbF6aIIYfZizMwc5LTYz250bDMjttbBGAU= +cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= +github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/apache/thrift v0.13.0 h1:5hryIiq9gtn+MiLVn0wP37kb/uTeRZgN08WoCsAhIhI= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04= -github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bytedance/go-tagexpr/v2 v2.9.2 h1:QySJaAIQgOEDQBLS3x9BxOWrnhqu5sQ+f6HaZIxD39I= github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM= github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 h1:PtwsQyQJGxf8iaPptPNaduEIu9BnrNms+pcRdHAxZaM= github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q= -github.com/bytedance/sonic v1.3.0/go.mod h1:V973WhNhGmvHxW6nQmsHEfHaoU9F3zTF+93rH03hcUQ= github.com/bytedance/sonic v1.5.0 h1:XWdTi8bwPgxIML+eNV1IwNuTROK6EUrQ65ey8yd6fRQ= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/casbin/casbin v1.3.0 h1:EQmPGgOo8/veRZbg+w2aspCFHducIoq6a4wEYRcD3RM= -github.com/casbin/casbin v1.3.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE= +github.com/casbin/casbin v1.9.1 h1:ucjbS5zTrmSLtH4XogqOG920Poe6QatdXtz1FEbApeM= +github.com/casbin/casbin v1.9.1/go.mod h1:z8uPsfBJGUsnkagrt3G8QvjgTKFMBJ32UP8HpZllfog= +github.com/casbin/xorm-adapter v1.0.0 h1:AJq8+6BhmjD6Oajth8UUpuE/2RAX3PR+s/T98+4tQr8= +github.com/casbin/xorm-adapter v1.0.0/go.mod h1:6sy40UQdWR0blO1DJdEzbcu6rcEW89odCMcEdoB1qdM= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06 h1:1sDoSuDPWzhkdzNVxCxtIaKiAe96ESVPv8coGwc1gZ4= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/cloudwego/hertz v0.3.0/go.mod h1:GWWYlAVkq1gDu6vJd/XNciWsP6q0d4TrEKk5fpJYF04= -github.com/cloudwego/hertz v0.4.1 h1:EcL7v+MGeCt+qsLC1JGvlkPTm3kHmwNQg43FcrMyd+s= -github.com/cloudwego/hertz v0.4.1/go.mod h1:K1U0RlU07CDeBINfHNbafH/3j9uSgIW8otbjUys3OPY= -github.com/cloudwego/netpoll v0.2.4/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudwego/hertz v0.5.1 h1:Jpnq5pdO8ARnPEGFZLEL8g3jCQcagOst0Iq1YXyBIJI= +github.com/cloudwego/hertz v0.5.1/go.mod h1:K1U0RlU07CDeBINfHNbafH/3j9uSgIW8otbjUys3OPY= github.com/cloudwego/netpoll v0.3.1 h1:xByoORmCLIyKZ8gS+da06WDo3j+jvmhaqS2KeKejtBk= github.com/cloudwego/netpoll v0.3.1/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADGYw5LqMnHqSkyIELsHCGF6PkrmM31V8rF7o= +github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= +github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= +github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/goccy/go-json v0.9.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y= +github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM= +github.com/go-xorm/xorm v0.7.9 h1:LZze6n1UvRmM5gpL9/U9Gucwqo6aWlFVlfcHKH10qA0= +github.com/go-xorm/xorm v0.7.9/go.mod h1:XiVxrMMIhFkwSkh96BW7PACl7UhLtx2iJIHMdmjh5sQ= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU= +github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= -github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= -github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= -github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= -github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= -github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/henrylee2cn/ameda v1.4.8/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4= github.com/henrylee2cn/ameda v1.4.10 h1:JdvI2Ekq7tapdPsuhrc4CaFiqw6QXFvZIULWJgQyCAk= github.com/henrylee2cn/ameda v1.4.10/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4= github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 h1:yE9ULgp02BhYIrO6sdV/FPe0xQM6fNHkVQW2IAymfM0= github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/DM3671a5udlv2AdV2ni/MZzgfv2qrPL5nIi3EGQ= -github.com/hertz-contrib/csrf v0.1.1 h1:53HxseVzpW4JEUJ7ONAaQCyNBWXl+rn42LVqgwEQzRg= -github.com/hertz-contrib/csrf v0.1.1/go.mod h1:z6CW935kPp1qy1XHXL7memdWInXXTc3OiMLp/cEmZQY= -github.com/hertz-contrib/sessions v1.0.1 h1:2puqvNqzyuPC3+5gzMRS+xhvGdNq3Ux7OVEewLSJbAk= -github.com/hertz-contrib/sessions v1.0.1/go.mod h1:gyVq7zq5emvSTLpp4VrlLOXjnajorYZ1hH4ZSX9Afb0= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ= +github.com/jackc/pgx v3.6.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= +github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= +github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg= github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= +github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M= github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= +github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= +go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/mysql v1.4.4 h1:MX0K9Qvy0Na4o7qSC/YI7XxqUw5KDw01umqgID+svdQ= -gorm.io/driver/mysql v1.4.4/go.mod h1:BCg8cKI+R0j/rZRQxeKis/forqRwRSYOR8OM3Wo6hOM= +gorm.io/driver/mysql v1.4.5 h1:u1lytId4+o9dDaNcPCFzNv7h6wvmc92UjNk3z8enSBU= +gorm.io/driver/mysql v1.4.5/go.mod h1:SxzItlnT1cb6e1e4ZRpgJN2VYtcqJgqnHxWr4wsP8oc= gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= -gorm.io/gorm v1.24.2 h1:9wR6CFD+G8nOusLdvkZelOEhpJVwwHzpQOUM+REd6U0= -gorm.io/gorm v1.24.2/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +gorm.io/gorm v1.24.3 h1:WL2ifUmzR/SLp85CSURAfybcHnGZ+yLSGSxgYXlFBHg= +gorm.io/gorm v1.24.3/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8= +xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU= +xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb h1:msX3zG3BPl8Ti+LDzP33/9K7BzO/WqFXk610K1kYKfo= +xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM= diff --git a/bizdemo/hertz_casbin/idl/casbin.thrift b/bizdemo/hertz_casbin/idl/casbin.thrift new file mode 100644 index 00000000..629649c1 --- /dev/null +++ b/bizdemo/hertz_casbin/idl/casbin.thrift @@ -0,0 +1,135 @@ + +namespace go casbin + +enum Code { + Success = 1 + ParamInvalid = 2 + DBErr = 3 +} + + + +struct BasicResponse{ + 1: Code code + 2: string msg +} + + + +/***********Permission***************/ +struct Permission { + 1: i64 id + 2: string v1 + 3: string v2 +} + +struct PermissionRole { + 1: i64 id + 2: i64 rid + 3: i64 pid +} + + +struct CreatePermissionRequest{ + 1: string v1 (api.body="v1", api.form="v1",api.vd="(len($) > 0 && len($) < 100)") + 2: string v2 (api.body="v2", api.form="v2",api.vd="(len($) > 0 && len($) < 100)") +} + + +struct CreatePermissionResponse{ + 1: Code code + 2: string msg + 3: Permission permission +} + + + +struct BindPermissionRoleRequest{ + 1: string pid (api.body="pid", api.form="pid",api.vd="($ > 0 && $ < 100)") + 2: string rid (api.body="rid", api.form="rid",api.vd="($ > 0 && $ < 100)") +} + + +struct BindPermissionRoleResponse{ + 1: Code code + 2: string msg + 3: PermissionRole permissionRole +} + + +service PermissionService { + CreatePermissionResponse CreatePermission(1:CreatePermissionRequest req)(api.post="/v1/permission/create/") + BindPermissionRoleResponse BindPermissionRole(1:BindPermissionRoleRequest req)(api.post="/v1/permissionrole/bind/") +} + + + +/***********Role***************/ +struct Role { + 1: i64 id + 2: string name +} + +struct CreateRoleRequest{ + 1: string name (api.body="name", api.form="name",api.vd="(len($) > 0 && len($) < 100)") +} + + +struct CreateRoleResponse{ + 1: Code code + 2: string msg + 3: Role role +} + + +struct BindRoleRequest{ + 1: i64 uid (api.body="uid", api.form="uid",api.vd="($ > 0)") + 2: i64 rid (api.body="rid", api.form="rid",api.vd="($ > 0)") +} + +struct BindRoleResponse{ + 1: Code code + 2: string msg +} + + + + +service RoleService { + CreateRoleResponse CreateRole(1:CreateRoleRequest req)(api.post="/v1/role/create/") + BindRoleResponse BindRole(1:BindRoleRequest req)(api.post="/v1/role/bind/") + +} + + + +/***********user***************/ +struct User { + 1: i64 id + 2: string username + 3: string password +} + +struct UserRole { + 1: i64 id + 2: i64 rid + 3: i64 uid +} + + + +struct LoginRequest{ + 1: string username (api.body="username", api.form="username",api.vd="(len($) > 0 && len($) < 100)") + 2: string password (api.body="password", api.form="password",api.vd="(len($) > 0 && len($) < 100)") +} + +struct QueryUserResponse{ + 1: Code code + 2: string msg + 3: string token +} + +service UserService { + QueryUserResponse Login(1: LoginRequest req)(api.post="/v1/login") +} + diff --git a/bizdemo/hertz_casbin/idl/user.thrift b/bizdemo/hertz_casbin/idl/user.thrift deleted file mode 100644 index 190eae3b..00000000 --- a/bizdemo/hertz_casbin/idl/user.thrift +++ /dev/null @@ -1,50 +0,0 @@ -namespace go user - - - - -struct BaseResp { - 1: i64 code - 2: string message -} - -struct RegisterRequest { - 1: string username (api.form="username", api.vd="(len($) > 0 && len($) < 128); msg:'Illegal format'") - 2: string password (api.form="password", api.vd="(len($) > 0 && len($) < 128); msg:'Illegal format'") - 3: string email (api.form="email", api.vd="(len($) > 0 && len($) < 128) && email($); msg:'Illegal format'") -} - -struct RegisterResponse { - 1: BaseResp baseresp -} - -struct LoginRequest { - 1: string username (api.form="username", api.vd="(len($) > 0 && len($) < 30); msg:'Illegal format'") - 2: string password (api.form="password", api.vd="(len($) > 0 && len($) < 30); msg:'Illegal format'") -} - -struct LoginResponse { - 1: BaseResp baseresp -} - -struct FindUserResponse { - 1: BaseResp baseresp -} - - -struct MemberListResponse { - 1: BaseResp baseresp -} - -struct AdminListResponse { - 1: BaseResp baseresp -} - - -service UserService { - RegisterResponse register(1: RegisterRequest req) (api.post="/register") - LoginResponse login(1: LoginRequest req) (api.post="/login") - FindUserResponse findUser() (api.get="/findUser") - MemberListResponse memberList() (api.get="/member/list") - AdminListResponse adminList() (api.get="/admin/list") -} \ No newline at end of file diff --git a/bizdemo/hertz_casbin/main.go b/bizdemo/hertz_casbin/main.go old mode 100644 new mode 100755 index 38e14342..9ea57ffa --- a/bizdemo/hertz_casbin/main.go +++ b/bizdemo/hertz_casbin/main.go @@ -1,33 +1,16 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - // Code generated by hertz generator. package main import ( - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/dal" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/mw" "github.com/cloudwego/hertz/pkg/app/server" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/mw" ) func Init(h *server.Hertz) { dal.Init() mw.InitCasbin() - mw.InitSession(h) } diff --git a/bizdemo/hertz_casbin/pkg/consts/consts.go b/bizdemo/hertz_casbin/pkg/consts/consts.go index 49d9fdce..235df664 100644 --- a/bizdemo/hertz_casbin/pkg/consts/consts.go +++ b/bizdemo/hertz_casbin/pkg/consts/consts.go @@ -16,28 +16,26 @@ package consts -// constants -const ( - TCP = "tcp" - UserTableName = "users" - RedisAddr = "127.0.0.1:6379" - MaxIdleNum = 10 - RedisPasswd = "" - SessionSecretKey = "session-secret" - CSRFSecretKey = "csrf-secret" - CSRFKeyLookUp = "form:csrf" - Username = "username" - Role = "role" - HertzSession = "HERTZ-SESSION" - MySQLDefaultDSN = "gorm:gorm@tcp(localhost:9911)/gorm?charset=utf8&parseTime=True&loc=Local" +import ( + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/golang-jwt/jwt/v4" ) -// error msg -const ( - StatusOK = "ok" - Success = "success" - RegisterErr = "user already exists" - LoginErr = "wrong username or password" - PageErr = "please login first" - CSRFErr = "csrf exception" +var ( + MysqlDSN = "root:casbin@tcp(localhost:9912)/casbin?charset=utf8&parseTime=True&loc=Local" + EmqxKey = "1f9c5b734fe27865" + EmqxSecret = "lV9C2iefOp9Cr9BeiB5rr3N9CBolJjKk3HruhqEpHQxsuVD" +) + +type M map[string]interface{} + +type UserClaim struct { + Id uint `json:"id"` + Username string `json:"username"` + Roles []casbin.Role `json:"rids"` + jwt.RegisteredClaims +} + +var ( + JwtKey = "darren" ) diff --git a/bizdemo/hertz_casbin/pkg/utils/utils.go b/bizdemo/hertz_casbin/pkg/utils/utils.go index 6b6dd932..8b36b725 100644 --- a/bizdemo/hertz_casbin/pkg/utils/utils.go +++ b/bizdemo/hertz_casbin/pkg/utils/utils.go @@ -1,47 +1,127 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package utils import ( - "context" + "bytes" "crypto/md5" - "encoding/hex" + "encoding/json" + "errors" "fmt" - - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/pkg/consts" - "github.com/cloudwego/hertz/pkg/app" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/golang-jwt/jwt/v4" + "io/ioutil" + "net/http" + "strings" + "time" ) -// MD5 use md5 to encrypt strings -func MD5(str string) string { - h := md5.New() - h.Write([]byte(str)) - return hex.EncodeToString(h.Sum(nil)) +func Md5(s string) string { + return fmt.Sprintf("%x", md5.Sum([]byte(s))) } -// BuildMsg render message for the html page -func BuildMsg(msg string) string { - return fmt.Sprintf("%v", msg) +func If(condition bool, trueValue, falseValue interface{}) interface{} { + if condition { + return trueValue + } + return falseValue } -// IsLogout if user already login then return false -func IsLogout(_ context.Context, c *app.RequestContext) bool { - if string(c.Cookie(consts.HertzSession)) == "" { - return true +// RFC3339ToNormalTime RFC3339 日期格式标准化 +func RFC3339ToNormalTime(rfc3339 string) string { + if len(rfc3339) < 19 || rfc3339 == "" || !strings.Contains(rfc3339, "T") { + return rfc3339 } - return false + return strings.Split(rfc3339, "T")[0] + " " + strings.Split(rfc3339, "T")[1][:8] +} + +func GenerateToken(id uint, roles []casbin.Role, username string, second int) (string, error) { + + uc := consts.UserClaim{ + Id: id, + Username: username, + Roles: roles, + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Second * time.Duration(second))), + }, + } + token := jwt.NewWithClaims(jwt.SigningMethodHS256, uc) + tokenString, err := token.SignedString([]byte(consts.JwtKey)) + if err != nil { + return "", err + } + + return tokenString, nil +} + +func AnalyzeToken(token string) (*consts.UserClaim, error) { + uc := new(consts.UserClaim) + claims, err := jwt.ParseWithClaims(token, uc, func(token *jwt.Token) (interface{}, error) { + return []byte(consts.JwtKey), nil + }) + + if err != nil { + return nil, err + } + if !claims.Valid { + return uc, errors.New("token is invalid") + } + + return uc, err +} + +// httpRequest . +func httpRequest(url, method string, data, header []byte) ([]byte, error) { + var err error + reader := bytes.NewBuffer(data) + request, err := http.NewRequest(method, url, reader) + if err != nil { + return nil, err + } + request.Header.Set("Content-Type", "application/json;charset=UTF-8") + // 处理 header + if len(header) > 0 { + headerMap := new(map[string]interface{}) + err = json.Unmarshal(header, headerMap) + + if err != nil { + return nil, err + } + for k, v := range *headerMap { + if k == "" || v == "" { + continue + } + request.Header.Set(k, v.(string)) + } + } + request.SetBasicAuth(consts.EmqxKey, consts.EmqxSecret) + + client := http.Client{} + resp, err := client.Do(request) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + respBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + return respBytes, nil +} + +func HttpDelete(url string, data []byte, header ...byte) ([]byte, error) { + return httpRequest(url, "DELETE", data, header) +} + +func HttpPut(url string, data []byte, header ...byte) ([]byte, error) { + return httpRequest(url, "PUT", data, header) +} + +func HttpPost(url string, data []byte, header ...byte) ([]byte, error) { + return httpRequest(url, "POST", data, header) +} + +func HttpGet(url string, header ...byte) ([]byte, error) { + return httpRequest(url, "GET", []byte{}, header) } diff --git a/bizdemo/hertz_casbin/router.go b/bizdemo/hertz_casbin/router.go old mode 100644 new mode 100755 index 6f2b3396..12f2985b --- a/bizdemo/hertz_casbin/router.go +++ b/bizdemo/hertz_casbin/router.go @@ -1,27 +1,10 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - // Code generated by hertz generator. package main import ( - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/handler/user" "github.com/cloudwego/hertz/pkg/app/server" + handler "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/handler" ) // customizeRegister registers customize routers. @@ -29,5 +12,4 @@ func customizedRegister(r *server.Hertz) { r.GET("/ping", handler.Ping) // your code ... - r.POST("/logout", user.Logout) } diff --git a/bizdemo/hertz_casbin/router_gen.go b/bizdemo/hertz_casbin/router_gen.go old mode 100644 new mode 100755 index 42b02a48..7cb68ed3 --- a/bizdemo/hertz_casbin/router_gen.go +++ b/bizdemo/hertz_casbin/router_gen.go @@ -3,16 +3,13 @@ package main import ( - - router "github.com/cloudwego/hertz-examples/bizdemo/hertz_session/biz/router" "github.com/cloudwego/hertz/pkg/app/server" + router "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/router" ) // register registers all routers. func register(r *server.Hertz) { - - router.GeneratedRegister(r) customizedRegister(r) diff --git a/bizdemo/hertz_casbin/test/common.go b/bizdemo/hertz_casbin/test/common.go new file mode 100644 index 00000000..f2daadb9 --- /dev/null +++ b/bizdemo/hertz_casbin/test/common.go @@ -0,0 +1,16 @@ +package test + +const userServiceAddr = "http://127.0.0.1:8888" + +var m1 = map[string]string{ + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcm5hbWUiOiJhZG1pbiIsInJpZHMiOlt7ImlkIjoxLCJuYW1lIjoiYWRtaW4ifSx7ImlkIjoyLCJuYW1lIjoicm9sZSJ9XSwiZXhwIjoxNjc3OTgzMTg5fQ.l9dJnbXyAIW-KqOXZ1jQzWwCWiyi84zLI8akWX2bfwM", +} + +var rolem1 = map[string]string{ + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NiwidXNlcm5hbWUiOiJyb2xlX3VzZXIiLCJyaWRzIjpbeyJpZCI6MiwibmFtZSI6InJvbGUifV0sImV4cCI6MTY3Nzk4NzQ2MH0.9CDKrUldcxg4dX2vqNWCBfuy44f3G7uwUqah6FhZb5c", +} + +var permissionm1 = map[string]string{ + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywidXNlcm5hbWUiOiJwZXJtaXNzaW9uX3VzZXIiLCJyaWRzIjpbeyJpZCI6MywibmFtZSI6InBlcm1pc3Npb24ifV0sImV4cCI6MTY3Nzk4ODQzN30.86z5EECrvRZuIiLDHYjwccbu81LoP6zxIuwjykA0fSk", +} +var header []byte diff --git a/bizdemo/hertz_casbin/test/permission_test.go b/bizdemo/hertz_casbin/test/permission_test.go new file mode 100644 index 00000000..1478f8f2 --- /dev/null +++ b/bizdemo/hertz_casbin/test/permission_test.go @@ -0,0 +1,41 @@ +package test + +import ( + "encoding/json" + "fmt" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" + "testing" +) + +func TestPermissionAdd(t *testing.T) { + + header, _ = json.Marshal(rolem1) + m := consts.M{ + "v1": "/v1/permission/create/", + "v2": "POST", + } + + data, _ := json.Marshal(m) + rep, err := utils.HttpPost(userServiceAddr+"/v1/permission/create", data, header...) + if err != nil { + t.Fatal(err) + } + + fmt.Println(string(rep)) +} + +func TestPermissionBind(t *testing.T) { + m := consts.M{ + "pid": "1", + "rid": "1", + } + + data, _ := json.Marshal(m) + rep, err := utils.HttpPost(userServiceAddr+"/v1/permissionrole/bind/", data, header...) + if err != nil { + t.Fatal(err) + } + + fmt.Println(string(rep)) +} diff --git a/bizdemo/hertz_casbin/test/role_test.go b/bizdemo/hertz_casbin/test/role_test.go new file mode 100644 index 00000000..3bfb2318 --- /dev/null +++ b/bizdemo/hertz_casbin/test/role_test.go @@ -0,0 +1,26 @@ +package test + +import ( + "encoding/json" + "fmt" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" + "testing" +) + +func TestRoleAdd(t *testing.T) { + + header, _ = json.Marshal(rolem1) + + m := consts.M{ + "name": "admin", + } + + data, _ := json.Marshal(m) + rep, err := utils.HttpPost(userServiceAddr+"/v1/role/create", data, header...) + if err != nil { + t.Fatal(err) + } + + fmt.Println(string(rep)) +} diff --git a/bizdemo/hertz_casbin/test/user_test.go b/bizdemo/hertz_casbin/test/user_test.go new file mode 100644 index 00000000..c90aee74 --- /dev/null +++ b/bizdemo/hertz_casbin/test/user_test.go @@ -0,0 +1,54 @@ +package test + +import ( + "encoding/json" + "fmt" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" + "testing" +) + +func TestUserLogin(t *testing.T) { + m := consts.M{ + "username": "admin", + "password": "123", + } + + data, _ := json.Marshal(m) + rep, err := utils.HttpPost(userServiceAddr+"/v1/login", data) + if err != nil { + t.Fatal(err) + } + + fmt.Println(string(rep)) +} + +func TestRoleUserLogin(t *testing.T) { + m := consts.M{ + "username": "role_user", + "password": "123", + } + + data, _ := json.Marshal(m) + rep, err := utils.HttpPost(userServiceAddr+"/v1/login", data) + if err != nil { + t.Fatal(err) + } + + fmt.Println(string(rep)) +} + +func TestPermissionUserLogin(t *testing.T) { + m := consts.M{ + "username": "permission_user", + "password": "123", + } + + data, _ := json.Marshal(m) + rep, err := utils.HttpPost(userServiceAddr+"/v1/login", data) + if err != nil { + t.Fatal(err) + } + + fmt.Println(string(rep)) +} From f8dd0b87e0f97744ef624f9f66fc5de8727130c7 Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 3 Feb 2023 12:27:58 +0800 Subject: [PATCH 05/10] add comment --- bizdemo/hertz_casbin/README.md | 61 +++++++ bizdemo/hertz_casbin/biz/model/sql/casbin.sql | 151 ++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 bizdemo/hertz_casbin/README.md create mode 100644 bizdemo/hertz_casbin/biz/model/sql/casbin.sql diff --git a/bizdemo/hertz_casbin/README.md b/bizdemo/hertz_casbin/README.md new file mode 100644 index 00000000..adce86be --- /dev/null +++ b/bizdemo/hertz_casbin/README.md @@ -0,0 +1,61 @@ +# hertz_casbin + +## Introduce + +A demo with `Hertz` and `Casbin`, this demo aims to understand the application of rbac. + +Casbin is a powerful and efficient open-source access control library for Golang projects. It provides support for enforcing authorization based on various access control models. + +- Use `thrift` IDL to define `HTTP` interface +- Use `hz` to generate code +- Use `casbin` to judgment authority +- Use `Gorm` and `MySQL` +- Use `JWT` to complete login and authentication + + +## casbin + +Simplistic Example of role-based HTTP Authorization with [casbin](https://github.com/casbin/casbin) using [scs](https://github.com/alexedwards/scs) for session handling. + +## IDL + +This demo use `thrift` IDL to define `HTTP` interface. The specific interface define in [user.thrift](idl/casbin.thrift) + +## Code generation tool + +This demo use `hz` to generate code. The use of `hz` refers to [hz](https://www.cloudwego.io/docs/hertz/tutorials/toolkit/toolkit/) + +The `hz` commands used can be found in [Makefile](Makefile) + +## Binding and Validate + +The use of binding and Validate refers +to [Binding and Validate](https://www.cloudwego.io/docs/hertz/tutorials/basic-feature/binding-and-validate/) + +## Gorm + +This demo use `Gorm` to operate `MySQL` and refers to [Gorm](https://gorm.io/) + + +## How to run + +### Run MySQL + +```bash +cd bizdemo/hertz_casbin && docker-compose up +``` + +### Generate MySQL table + +Connect MySQL and execute [casbin.sql](biz/model/sql/casbin.sql) + +### Run demo + +```bash +cd bizdemo/hertz_casbin +go run . + +``` + + + \ No newline at end of file diff --git a/bizdemo/hertz_casbin/biz/model/sql/casbin.sql b/bizdemo/hertz_casbin/biz/model/sql/casbin.sql new file mode 100644 index 00000000..6f1409cb --- /dev/null +++ b/bizdemo/hertz_casbin/biz/model/sql/casbin.sql @@ -0,0 +1,151 @@ +/* + Navicat Premium Data Transfer + + Source Server : 9912 + Source Server Type : MySQL + Source Server Version : 80032 + Source Host : localhost:9912 + Source Schema : casbin + + Target Server Type : MySQL + Target Server Version : 80032 + File Encoding : 65001 + + Date: 03/02/2023 12:19:00 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for casbin_rule +-- ---------------------------- +DROP TABLE IF EXISTS `casbin_rule`; +CREATE TABLE `casbin_rule` ( + `p_type` varchar(100) DEFAULT NULL, + `v0` varchar(100) DEFAULT NULL, + `v1` varchar(100) DEFAULT NULL, + `v2` varchar(100) DEFAULT NULL, + `v3` varchar(100) DEFAULT NULL, + `v4` varchar(100) DEFAULT NULL, + `v5` varchar(100) DEFAULT NULL, + KEY `IDX_casbin_rule_v5` (`v5`), + KEY `IDX_casbin_rule_p_type` (`p_type`), + KEY `IDX_casbin_rule_v0` (`v0`), + KEY `IDX_casbin_rule_v1` (`v1`), + KEY `IDX_casbin_rule_v2` (`v2`), + KEY `IDX_casbin_rule_v3` (`v3`), + KEY `IDX_casbin_rule_v4` (`v4`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +-- ---------------------------- +-- Records of casbin_rule +-- ---------------------------- +BEGIN; +INSERT INTO `casbin_rule` (`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'admin', '/*', '*', '', '', ''); +INSERT INTO `casbin_rule` (`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'role', '/v1/role/create/', 'POST', NULL, NULL, NULL); +INSERT INTO `casbin_rule` (`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'permission', '/v1/permission/create/', 'POST', NULL, NULL, NULL); +COMMIT; + +-- ---------------------------- +-- Table structure for permission_roles +-- ---------------------------- +DROP TABLE IF EXISTS `permission_roles`; +CREATE TABLE `permission_roles` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `rid` bigint DEFAULT NULL, + `pid` bigint DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- ---------------------------- +-- Records of permission_roles +-- ---------------------------- +BEGIN; +INSERT INTO `permission_roles` (`id`, `rid`, `pid`) VALUES (6, 1, 1); +INSERT INTO `permission_roles` (`id`, `rid`, `pid`) VALUES (7, 2, 2); +INSERT INTO `permission_roles` (`id`, `rid`, `pid`) VALUES (8, 3, 3); +COMMIT; + +-- ---------------------------- +-- Table structure for permissions +-- ---------------------------- +DROP TABLE IF EXISTS `permissions`; +CREATE TABLE `permissions` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `v1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, + `v2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- ---------------------------- +-- Records of permissions +-- ---------------------------- +BEGIN; +INSERT INTO `permissions` (`id`, `v1`, `v2`) VALUES (1, '/*', '*'); +INSERT INTO `permissions` (`id`, `v1`, `v2`) VALUES (2, '/v1/role/create/', 'POST'); +INSERT INTO `permissions` (`id`, `v1`, `v2`) VALUES (3, '/v1/permission/create/', 'POST'); +COMMIT; + +-- ---------------------------- +-- Table structure for roles +-- ---------------------------- +DROP TABLE IF EXISTS `roles`; +CREATE TABLE `roles` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `name` longtext, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- ---------------------------- +-- Records of roles +-- ---------------------------- +BEGIN; +INSERT INTO `roles` (`id`, `name`) VALUES (1, 'admin'); +INSERT INTO `roles` (`id`, `name`) VALUES (2, 'role'); +INSERT INTO `roles` (`id`, `name`) VALUES (3, 'permission'); +INSERT INTO `roles` (`id`, `name`) VALUES (7, 'admin123'); +COMMIT; + +-- ---------------------------- +-- Table structure for user_roles +-- ---------------------------- +DROP TABLE IF EXISTS `user_roles`; +CREATE TABLE `user_roles` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `rid` bigint DEFAULT NULL, + `uid` bigint DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- ---------------------------- +-- Records of user_roles +-- ---------------------------- +BEGIN; +INSERT INTO `user_roles` (`id`, `rid`, `uid`) VALUES (1, 1, 5); +INSERT INTO `user_roles` (`id`, `rid`, `uid`) VALUES (5, 2, 6); +INSERT INTO `user_roles` (`id`, `rid`, `uid`) VALUES (6, 3, 7); +COMMIT; + +-- ---------------------------- +-- Table structure for users +-- ---------------------------- +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, + `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +-- ---------------------------- +-- Records of users +-- ---------------------------- +BEGIN; +INSERT INTO `users` (`id`, `username`, `password`) VALUES (5, 'admin', '202cb962ac59075b964b07152d234b70'); +INSERT INTO `users` (`id`, `username`, `password`) VALUES (6, 'role_user', '202cb962ac59075b964b07152d234b70'); +INSERT INTO `users` (`id`, `username`, `password`) VALUES (7, 'permission_user', '202cb962ac59075b964b07152d234b70'); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; From a88185b669adc0bf2314eb0110ff2cc18a10125b Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 3 Feb 2023 13:40:54 +0800 Subject: [PATCH 06/10] Copyright --- .../hertz_casbin/biz/dal/mysql/permission.go | 16 ++++++++++++++++ .../biz/dal/mysql/permission_test.go | 16 ++++++++++++++++ .../hertz_casbin/biz/dal/mysql/role_test.go | 16 ++++++++++++++++ .../hertz_casbin/biz/dal/mysql/user_test.go | 16 ++++++++++++++++ .../biz/handler/casbin/permission_service.go | 16 ++++++++++++++++ .../biz/handler/casbin/role_service.go | 16 ++++++++++++++++ .../biz/handler/casbin/user_service.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/biz/handler/ping.go | 15 +++++++++++++++ .../hertz_casbin/biz/model/casbin/casbin.go | 15 +++++++++++++++ bizdemo/hertz_casbin/biz/mw/casbin.go | 16 ++++++++++++++++ .../biz/router/casbin/middleware.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/biz/router/register.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/main.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/pkg/utils/utils.go | 18 +++++++++++++++++- bizdemo/hertz_casbin/router.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/router_gen.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/test/common.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/test/permission_test.go | 16 ++++++++++++++++ bizdemo/hertz_casbin/test/role_test.go | 18 +++++++++++++++++- bizdemo/hertz_casbin/test/user_test.go | 16 ++++++++++++++++ 20 files changed, 320 insertions(+), 2 deletions(-) diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go index 8d5bfc19..312bf484 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/permission.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package mysql import "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go index 5aa9c34e..0f183c8b 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package mysql import ( diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go index 597ea194..6c093610 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package mysql import ( diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go index f262528c..9be0feaa 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package mysql import ( diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go index 697b8b31..588e8b30 100644 --- a/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go +++ b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // Code generated by hertz generator. package casbin diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go index f09b6a07..c65117fc 100644 --- a/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go +++ b/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // Code generated by hertz generator. package casbin diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go index 054bcea3..2d094491 100644 --- a/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go +++ b/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // Code generated by hertz generator. package casbin diff --git a/bizdemo/hertz_casbin/biz/handler/ping.go b/bizdemo/hertz_casbin/biz/handler/ping.go index 950d4767..98703ccf 100755 --- a/bizdemo/hertz_casbin/biz/handler/ping.go +++ b/bizdemo/hertz_casbin/biz/handler/ping.go @@ -1,3 +1,18 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by hertz generator. package handler diff --git a/bizdemo/hertz_casbin/biz/model/casbin/casbin.go b/bizdemo/hertz_casbin/biz/model/casbin/casbin.go index 5c9629b3..10c562d2 100644 --- a/bizdemo/hertz_casbin/biz/model/casbin/casbin.go +++ b/bizdemo/hertz_casbin/biz/model/casbin/casbin.go @@ -1,3 +1,18 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by thriftgo (0.2.5). DO NOT EDIT. package casbin diff --git a/bizdemo/hertz_casbin/biz/mw/casbin.go b/bizdemo/hertz_casbin/biz/mw/casbin.go index eb5cb624..bff4b1fd 100644 --- a/bizdemo/hertz_casbin/biz/mw/casbin.go +++ b/bizdemo/hertz_casbin/biz/mw/casbin.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package mw import ( diff --git a/bizdemo/hertz_casbin/biz/router/casbin/middleware.go b/bizdemo/hertz_casbin/biz/router/casbin/middleware.go index f1233d1c..1e4b4e43 100644 --- a/bizdemo/hertz_casbin/biz/router/casbin/middleware.go +++ b/bizdemo/hertz_casbin/biz/router/casbin/middleware.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // Code generated by hertz generator. package Casbin diff --git a/bizdemo/hertz_casbin/biz/router/register.go b/bizdemo/hertz_casbin/biz/router/register.go index 9ec3e5f2..4f0375ec 100755 --- a/bizdemo/hertz_casbin/biz/router/register.go +++ b/bizdemo/hertz_casbin/biz/router/register.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // Code generated by hertz generator. DO NOT EDIT. package router diff --git a/bizdemo/hertz_casbin/main.go b/bizdemo/hertz_casbin/main.go index 9ea57ffa..21c23a76 100755 --- a/bizdemo/hertz_casbin/main.go +++ b/bizdemo/hertz_casbin/main.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // Code generated by hertz generator. package main diff --git a/bizdemo/hertz_casbin/pkg/utils/utils.go b/bizdemo/hertz_casbin/pkg/utils/utils.go index 8b36b725..20142c01 100644 --- a/bizdemo/hertz_casbin/pkg/utils/utils.go +++ b/bizdemo/hertz_casbin/pkg/utils/utils.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package utils import ( @@ -26,7 +42,7 @@ func If(condition bool, trueValue, falseValue interface{}) interface{} { return falseValue } -// RFC3339ToNormalTime RFC3339 日期格式标准化 +// RFC3339ToNormalTime func RFC3339ToNormalTime(rfc3339 string) string { if len(rfc3339) < 19 || rfc3339 == "" || !strings.Contains(rfc3339, "T") { return rfc3339 diff --git a/bizdemo/hertz_casbin/router.go b/bizdemo/hertz_casbin/router.go index 12f2985b..866e377a 100755 --- a/bizdemo/hertz_casbin/router.go +++ b/bizdemo/hertz_casbin/router.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // Code generated by hertz generator. package main diff --git a/bizdemo/hertz_casbin/router_gen.go b/bizdemo/hertz_casbin/router_gen.go index 7cb68ed3..c7f5196b 100755 --- a/bizdemo/hertz_casbin/router_gen.go +++ b/bizdemo/hertz_casbin/router_gen.go @@ -1,3 +1,19 @@ + +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by hertz generator. DO NOT EDIT. package main diff --git a/bizdemo/hertz_casbin/test/common.go b/bizdemo/hertz_casbin/test/common.go index f2daadb9..254b759c 100644 --- a/bizdemo/hertz_casbin/test/common.go +++ b/bizdemo/hertz_casbin/test/common.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package test const userServiceAddr = "http://127.0.0.1:8888" diff --git a/bizdemo/hertz_casbin/test/permission_test.go b/bizdemo/hertz_casbin/test/permission_test.go index 1478f8f2..476878e7 100644 --- a/bizdemo/hertz_casbin/test/permission_test.go +++ b/bizdemo/hertz_casbin/test/permission_test.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package test import ( diff --git a/bizdemo/hertz_casbin/test/role_test.go b/bizdemo/hertz_casbin/test/role_test.go index 3bfb2318..02da1f41 100644 --- a/bizdemo/hertz_casbin/test/role_test.go +++ b/bizdemo/hertz_casbin/test/role_test.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package test import ( @@ -9,7 +25,7 @@ import ( ) func TestRoleAdd(t *testing.T) { - + header, _ = json.Marshal(rolem1) m := consts.M{ diff --git a/bizdemo/hertz_casbin/test/user_test.go b/bizdemo/hertz_casbin/test/user_test.go index c90aee74..b35aa4dd 100644 --- a/bizdemo/hertz_casbin/test/user_test.go +++ b/bizdemo/hertz_casbin/test/user_test.go @@ -1,3 +1,19 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package test import ( From c0139954a3b0c33eac94faa7d915937a341f5beb Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 3 Feb 2023 14:56:19 +0800 Subject: [PATCH 07/10] comment ci import package ci --- bizdemo/hertz_casbin/biz/dal/init.go | 2 +- bizdemo/hertz_casbin/biz/dal/mysql/init.go | 4 +-- .../hertz_casbin/biz/dal/mysql/permission.go | 2 +- .../biz/dal/mysql/permission_test.go | 6 ++++- bizdemo/hertz_casbin/biz/dal/mysql/role.go | 2 +- .../hertz_casbin/biz/dal/mysql/role_test.go | 8 +++++- bizdemo/hertz_casbin/biz/dal/mysql/user.go | 2 +- .../hertz_casbin/biz/dal/mysql/user_test.go | 7 ++++-- .../biz/handler/casbin/permission_service.go | 9 ++++--- .../biz/handler/casbin/role_service.go | 4 +-- .../biz/handler/casbin/user_service.go | 6 ++--- .../hertz_casbin/biz/model/casbin/casbin.go | 2 ++ bizdemo/hertz_casbin/biz/mw/casbin.go | 2 +- .../hertz_casbin/biz/router/casbin/casbin.go | 19 +++++++++++++- .../biz/router/casbin/middleware.go | 7 +++--- bizdemo/hertz_casbin/biz/router/register.go | 2 +- bizdemo/hertz_casbin/go.mod | 2 +- bizdemo/hertz_casbin/main.go | 4 +-- bizdemo/hertz_casbin/pkg/consts/consts.go | 2 +- bizdemo/hertz_casbin/pkg/utils/utils.go | 25 +++++++++---------- bizdemo/hertz_casbin/router.go | 2 +- bizdemo/hertz_casbin/router_gen.go | 2 +- bizdemo/hertz_casbin/test/permission_test.go | 7 ++++-- bizdemo/hertz_casbin/test/role_test.go | 6 +++-- bizdemo/hertz_casbin/test/user_test.go | 8 ++++-- 25 files changed, 92 insertions(+), 50 deletions(-) diff --git a/bizdemo/hertz_casbin/biz/dal/init.go b/bizdemo/hertz_casbin/biz/dal/init.go index b6013c92..f802adf1 100644 --- a/bizdemo/hertz_casbin/biz/dal/init.go +++ b/bizdemo/hertz_casbin/biz/dal/init.go @@ -16,7 +16,7 @@ package dal -import "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" +import "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" func Init() { mysql.Init() diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/init.go b/bizdemo/hertz_casbin/biz/dal/mysql/init.go index 228514c8..237a2cb5 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/init.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/init.go @@ -17,8 +17,8 @@ package mysql import ( - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/consts" "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/logger" diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go index 312bf484..9b4a556d 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/permission.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go @@ -16,7 +16,7 @@ package mysql -import "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" +import "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" func CreatePermisson(permission *casbin.Permission) error { return DB.Create(permission).Error diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go index 0f183c8b..3badb751 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go @@ -18,14 +18,16 @@ package mysql import ( "fmt" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" "testing" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" ) func init() { Init() } +// create permission data func TestCreatePermission(t *testing.T) { permission := casbin.Permission{ @@ -49,6 +51,7 @@ func TestCreatePermission(t *testing.T) { } +// query permission data func TestQueryPermission(t *testing.T) { qRole, err := QueryPermissionByV("/v1/role/create", "POST") if err != nil { @@ -59,6 +62,7 @@ func TestQueryPermission(t *testing.T) { } +// bind permission and role func TestBindPermission(t *testing.T) { permissionRole := casbin.PermissionRole{ diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/role.go b/bizdemo/hertz_casbin/biz/dal/mysql/role.go index a4a7aa9f..a8a39eeb 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/role.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/role.go @@ -17,7 +17,7 @@ package mysql import ( - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" ) func CreateRole(role *casbin.Role) error { diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go index 6c093610..f90d8389 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go @@ -18,14 +18,16 @@ package mysql import ( "fmt" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" "testing" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" ) func init() { Init() } +// craete role data func TestCreateRole(t *testing.T) { role := casbin.Role{ @@ -48,6 +50,7 @@ func TestCreateRole(t *testing.T) { } +// query role by the name of the role func TestQueryRole(t *testing.T) { qRole, err := QueryRoleByName("admin") if err != nil { @@ -58,12 +61,15 @@ func TestQueryRole(t *testing.T) { } +// query roles by the id of the user func TestQueryRolesByUid(t *testing.T) { qRoles := QueryRolesByUid(int(5)) fmt.Println(qRoles) } + +// bind role by the id of the role and id of the user func TestBindUserRole(t *testing.T) { userRole := casbin.UserRole{ diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/user.go b/bizdemo/hertz_casbin/biz/dal/mysql/user.go index e16d0115..52929a79 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/user.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/user.go @@ -16,7 +16,7 @@ package mysql -import "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" +import "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" func CreateUser(user *casbin.User) error { return DB.Create(user).Error diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go index 9be0feaa..185323e8 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go @@ -18,15 +18,17 @@ package mysql import ( "fmt" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" "testing" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/utils" ) func init() { Init() } +// create the user data func TestCreateUser(t *testing.T) { user := casbin.User{ @@ -56,6 +58,7 @@ func TestCreateUser(t *testing.T) { } +// query user by the username of user func TestQueryUser(t *testing.T) { qUser, err := QueryUserByUsername("admin") if err != nil { diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go index 588e8b30..e31c597e 100644 --- a/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go +++ b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go @@ -20,12 +20,13 @@ package casbin import ( "context" + "strconv" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" + casbin "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/mw" "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/protocol/consts" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" - casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/mw" - "strconv" ) // CreatePermission . diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go index c65117fc..7d5b523a 100644 --- a/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go +++ b/bizdemo/hertz_casbin/biz/handler/casbin/role_service.go @@ -20,11 +20,11 @@ package casbin import ( "context" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" + casbin "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/protocol/consts" - casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" ) // CreateRole . diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go index 2d094491..4f12e1fe 100644 --- a/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go +++ b/bizdemo/hertz_casbin/biz/handler/casbin/user_service.go @@ -20,12 +20,12 @@ package casbin import ( "context" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/dal/mysql" + casbin "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/utils" "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/protocol/consts" - casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" ) // Login . diff --git a/bizdemo/hertz_casbin/biz/model/casbin/casbin.go b/bizdemo/hertz_casbin/biz/model/casbin/casbin.go index 10c562d2..498a66b4 100644 --- a/bizdemo/hertz_casbin/biz/model/casbin/casbin.go +++ b/bizdemo/hertz_casbin/biz/model/casbin/casbin.go @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + // Code generated by thriftgo (0.2.5). DO NOT EDIT. package casbin @@ -22,6 +23,7 @@ import ( "database/sql" "database/sql/driver" "fmt" + "github.com/apache/thrift/lib/go/thrift" ) diff --git a/bizdemo/hertz_casbin/biz/mw/casbin.go b/bizdemo/hertz_casbin/biz/mw/casbin.go index bff4b1fd..20197077 100644 --- a/bizdemo/hertz_casbin/biz/mw/casbin.go +++ b/bizdemo/hertz_casbin/biz/mw/casbin.go @@ -19,7 +19,7 @@ package mw import ( "github.com/casbin/casbin" xormadapter "github.com/casbin/xorm-adapter" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/consts" ) var AuthEnforcer *casbin.Enforcer diff --git a/bizdemo/hertz_casbin/biz/router/casbin/casbin.go b/bizdemo/hertz_casbin/biz/router/casbin/casbin.go index 462cb203..4254f428 100644 --- a/bizdemo/hertz_casbin/biz/router/casbin/casbin.go +++ b/bizdemo/hertz_casbin/biz/router/casbin/casbin.go @@ -1,10 +1,27 @@ +/* + * Copyright 2022 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + // Code generated by hertz generator. DO NOT EDIT. package Casbin import ( "github.com/cloudwego/hertz/pkg/app/server" - casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/handler/casbin" + casbin "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/handler/casbin" ) /* diff --git a/bizdemo/hertz_casbin/biz/router/casbin/middleware.go b/bizdemo/hertz_casbin/biz/router/casbin/middleware.go index 1e4b4e43..f8fe38b3 100644 --- a/bizdemo/hertz_casbin/biz/router/casbin/middleware.go +++ b/bizdemo/hertz_casbin/biz/router/casbin/middleware.go @@ -21,10 +21,11 @@ package Casbin import ( "context" "fmt" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/mw" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/utils" "github.com/cloudwego/hertz/pkg/app" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/mw" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" "net/http" ) diff --git a/bizdemo/hertz_casbin/biz/router/register.go b/bizdemo/hertz_casbin/biz/router/register.go index 4f0375ec..686f60b2 100755 --- a/bizdemo/hertz_casbin/biz/router/register.go +++ b/bizdemo/hertz_casbin/biz/router/register.go @@ -20,7 +20,7 @@ package router import ( "github.com/cloudwego/hertz/pkg/app/server" - casbin "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/router/casbin" + casbin "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/router/casbin" ) // GeneratedRegister registers routers generated by IDL. diff --git a/bizdemo/hertz_casbin/go.mod b/bizdemo/hertz_casbin/go.mod index 4f16fd96..9d20fbad 100755 --- a/bizdemo/hertz_casbin/go.mod +++ b/bizdemo/hertz_casbin/go.mod @@ -1,4 +1,4 @@ -module github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin +module github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin go 1.19 diff --git a/bizdemo/hertz_casbin/main.go b/bizdemo/hertz_casbin/main.go index 21c23a76..5df10031 100755 --- a/bizdemo/hertz_casbin/main.go +++ b/bizdemo/hertz_casbin/main.go @@ -19,9 +19,9 @@ package main import ( + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/dal" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/mw" "github.com/cloudwego/hertz/pkg/app/server" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/dal" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/mw" ) func Init(h *server.Hertz) { diff --git a/bizdemo/hertz_casbin/pkg/consts/consts.go b/bizdemo/hertz_casbin/pkg/consts/consts.go index 235df664..94ca5ea0 100644 --- a/bizdemo/hertz_casbin/pkg/consts/consts.go +++ b/bizdemo/hertz_casbin/pkg/consts/consts.go @@ -17,7 +17,7 @@ package consts import ( - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" "github.com/golang-jwt/jwt/v4" ) diff --git a/bizdemo/hertz_casbin/pkg/utils/utils.go b/bizdemo/hertz_casbin/pkg/utils/utils.go index 20142c01..75fb5d65 100644 --- a/bizdemo/hertz_casbin/pkg/utils/utils.go +++ b/bizdemo/hertz_casbin/pkg/utils/utils.go @@ -22,15 +22,16 @@ import ( "encoding/json" "errors" "fmt" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" - "github.com/golang-jwt/jwt/v4" "io/ioutil" "net/http" - "strings" "time" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/golang-jwt/jwt/v4" ) +// MD5 use md5 to encrypt strings func Md5(s string) string { return fmt.Sprintf("%x", md5.Sum([]byte(s))) } @@ -42,14 +43,7 @@ func If(condition bool, trueValue, falseValue interface{}) interface{} { return falseValue } -// RFC3339ToNormalTime -func RFC3339ToNormalTime(rfc3339 string) string { - if len(rfc3339) < 19 || rfc3339 == "" || !strings.Contains(rfc3339, "T") { - return rfc3339 - } - return strings.Split(rfc3339, "T")[0] + " " + strings.Split(rfc3339, "T")[1][:8] -} - +// generate token if username and password is correct func GenerateToken(id uint, roles []casbin.Role, username string, second int) (string, error) { uc := consts.UserClaim{ @@ -69,6 +63,7 @@ func GenerateToken(id uint, roles []casbin.Role, username string, second int) (s return tokenString, nil } +// Verify the token func AnalyzeToken(token string) (*consts.UserClaim, error) { uc := new(consts.UserClaim) claims, err := jwt.ParseWithClaims(token, uc, func(token *jwt.Token) (interface{}, error) { @@ -85,7 +80,7 @@ func AnalyzeToken(token string) (*consts.UserClaim, error) { return uc, err } -// httpRequest . +// call httpRequest func httpRequest(url, method string, data, header []byte) ([]byte, error) { var err error reader := bytes.NewBuffer(data) @@ -126,18 +121,22 @@ func httpRequest(url, method string, data, header []byte) ([]byte, error) { return respBytes, nil } +// Request in "delete" mode func HttpDelete(url string, data []byte, header ...byte) ([]byte, error) { return httpRequest(url, "DELETE", data, header) } +// Request in "put" mode func HttpPut(url string, data []byte, header ...byte) ([]byte, error) { return httpRequest(url, "PUT", data, header) } +// Request in "post" mode func HttpPost(url string, data []byte, header ...byte) ([]byte, error) { return httpRequest(url, "POST", data, header) } +// Request in "get" mode func HttpGet(url string, header ...byte) ([]byte, error) { return httpRequest(url, "GET", []byte{}, header) } diff --git a/bizdemo/hertz_casbin/router.go b/bizdemo/hertz_casbin/router.go index 866e377a..c7405bb9 100755 --- a/bizdemo/hertz_casbin/router.go +++ b/bizdemo/hertz_casbin/router.go @@ -19,8 +19,8 @@ package main import ( + handler "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/handler" "github.com/cloudwego/hertz/pkg/app/server" - handler "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/handler" ) // customizeRegister registers customize routers. diff --git a/bizdemo/hertz_casbin/router_gen.go b/bizdemo/hertz_casbin/router_gen.go index c7f5196b..240df08b 100755 --- a/bizdemo/hertz_casbin/router_gen.go +++ b/bizdemo/hertz_casbin/router_gen.go @@ -20,7 +20,7 @@ package main import ( "github.com/cloudwego/hertz/pkg/app/server" - router "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/biz/router" + router "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/router" ) // register registers all routers. diff --git a/bizdemo/hertz_casbin/test/permission_test.go b/bizdemo/hertz_casbin/test/permission_test.go index 476878e7..27db88ab 100644 --- a/bizdemo/hertz_casbin/test/permission_test.go +++ b/bizdemo/hertz_casbin/test/permission_test.go @@ -19,11 +19,13 @@ package test import ( "encoding/json" "fmt" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" "testing" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/utils" ) +// Test add permission func TestPermissionAdd(t *testing.T) { header, _ = json.Marshal(rolem1) @@ -41,6 +43,7 @@ func TestPermissionAdd(t *testing.T) { fmt.Println(string(rep)) } +// Test bind permission func TestPermissionBind(t *testing.T) { m := consts.M{ "pid": "1", diff --git a/bizdemo/hertz_casbin/test/role_test.go b/bizdemo/hertz_casbin/test/role_test.go index 02da1f41..380e7cc3 100644 --- a/bizdemo/hertz_casbin/test/role_test.go +++ b/bizdemo/hertz_casbin/test/role_test.go @@ -19,11 +19,13 @@ package test import ( "encoding/json" "fmt" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" "testing" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/utils" ) +// Test add role func TestRoleAdd(t *testing.T) { header, _ = json.Marshal(rolem1) diff --git a/bizdemo/hertz_casbin/test/user_test.go b/bizdemo/hertz_casbin/test/user_test.go index b35aa4dd..2a9f88a3 100644 --- a/bizdemo/hertz_casbin/test/user_test.go +++ b/bizdemo/hertz_casbin/test/user_test.go @@ -19,11 +19,13 @@ package test import ( "encoding/json" "fmt" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/consts" - "github.com/darrenli6/hertz-examples/bizdemo/hertz_casbin/pkg/utils" "testing" + + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/consts" + "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/utils" ) +// Test the login of the admin user to get the token func TestUserLogin(t *testing.T) { m := consts.M{ "username": "admin", @@ -39,6 +41,7 @@ func TestUserLogin(t *testing.T) { fmt.Println(string(rep)) } +// Test the login of the role user to get the token func TestRoleUserLogin(t *testing.T) { m := consts.M{ "username": "role_user", @@ -54,6 +57,7 @@ func TestRoleUserLogin(t *testing.T) { fmt.Println(string(rep)) } +// Test the login of the permission user to get the token func TestPermissionUserLogin(t *testing.T) { m := consts.M{ "username": "permission_user", From 838cbbd1a33a310e14cb3721298704cbd94aa9aa Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 3 Feb 2023 18:01:16 +0800 Subject: [PATCH 08/10] modify --- bizdemo/hertz_casbin/biz/dal/mysql/permission.go | 2 +- bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go | 2 +- bizdemo/hertz_casbin/biz/dal/mysql/role_test.go | 2 +- .../hertz_casbin/biz/handler/casbin/permission_service.go | 2 +- bizdemo/hertz_casbin/test/common.go | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go index 9b4a556d..118820fb 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/permission.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission.go @@ -18,7 +18,7 @@ package mysql import "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" -func CreatePermisson(permission *casbin.Permission) error { +func CreatePermission(permission *casbin.Permission) error { return DB.Create(permission).Error } diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go index 3badb751..26ea45c2 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go @@ -44,7 +44,7 @@ func TestCreatePermission(t *testing.T) { fmt.Println("Permission already exists") return } - err = CreatePermisson(&permission) + err = CreatePermission(&permission) if err != nil { t.Fatal(err) } diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go index f90d8389..b59a3d72 100644 --- a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go +++ b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go @@ -27,7 +27,7 @@ func init() { Init() } -// craete role data +// create role data func TestCreateRole(t *testing.T) { role := casbin.Role{ diff --git a/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go index e31c597e..3132c535 100644 --- a/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go +++ b/bizdemo/hertz_casbin/biz/handler/casbin/permission_service.go @@ -63,7 +63,7 @@ func CreatePermission(ctx context.Context, c *app.RequestContext) { return } - err = mysql.CreatePermisson(&rpermission) + err = mysql.CreatePermission(&rpermission) if err != nil { resp.Code = 4 resp.Msg = "create failed" diff --git a/bizdemo/hertz_casbin/test/common.go b/bizdemo/hertz_casbin/test/common.go index 254b759c..05936c6f 100644 --- a/bizdemo/hertz_casbin/test/common.go +++ b/bizdemo/hertz_casbin/test/common.go @@ -19,14 +19,14 @@ package test const userServiceAddr = "http://127.0.0.1:8888" var m1 = map[string]string{ - "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcm5hbWUiOiJhZG1pbiIsInJpZHMiOlt7ImlkIjoxLCJuYW1lIjoiYWRtaW4ifSx7ImlkIjoyLCJuYW1lIjoicm9sZSJ9XSwiZXhwIjoxNjc3OTgzMTg5fQ.l9dJnbXyAIW-KqOXZ1jQzWwCWiyi84zLI8akWX2bfwM", + "token": "", } var rolem1 = map[string]string{ - "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NiwidXNlcm5hbWUiOiJyb2xlX3VzZXIiLCJyaWRzIjpbeyJpZCI6MiwibmFtZSI6InJvbGUifV0sImV4cCI6MTY3Nzk4NzQ2MH0.9CDKrUldcxg4dX2vqNWCBfuy44f3G7uwUqah6FhZb5c", + "token": "", } var permissionm1 = map[string]string{ - "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywidXNlcm5hbWUiOiJwZXJtaXNzaW9uX3VzZXIiLCJyaWRzIjpbeyJpZCI6MywibmFtZSI6InBlcm1pc3Npb24ifV0sImV4cCI6MTY3Nzk4ODQzN30.86z5EECrvRZuIiLDHYjwccbu81LoP6zxIuwjykA0fSk", + "token": "", } var header []byte From a88e0694afa2bed35bccf64af32eb4592f6eb68d Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 3 Feb 2023 18:04:53 +0800 Subject: [PATCH 09/10] remove mysql test --- .../biz/dal/mysql/permission_test.go | 105 ---------------- .../hertz_casbin/biz/dal/mysql/role_test.go | 112 ------------------ .../hertz_casbin/biz/dal/mysql/user_test.go | 74 ------------ 3 files changed, 291 deletions(-) delete mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go delete mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/role_test.go delete mode 100644 bizdemo/hertz_casbin/biz/dal/mysql/user_test.go diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go deleted file mode 100644 index 26ea45c2..00000000 --- a/bizdemo/hertz_casbin/biz/dal/mysql/permission_test.go +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package mysql - -import ( - "fmt" - "testing" - - "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" -) - -func init() { - Init() -} - -// create permission data -func TestCreatePermission(t *testing.T) { - - permission := casbin.Permission{ - V1: "/1", - V2: "/2", - } - - qRole, err := QueryPermissionByV(permission.V1, permission.V2) - if err != nil { - t.Fatal(err) - } - - if qRole.ID != 0 { - fmt.Println("Permission already exists") - return - } - err = CreatePermission(&permission) - if err != nil { - t.Fatal(err) - } - -} - -// query permission data -func TestQueryPermission(t *testing.T) { - qRole, err := QueryPermissionByV("/v1/role/create", "POST") - if err != nil { - t.Fatal(err) - } - - fmt.Println(qRole) - -} - -// bind permission and role -func TestBindPermission(t *testing.T) { - - permissionRole := casbin.PermissionRole{ - Pid: 1, - Rid: 1, - } - - rpermissionRole := QuerypermissionRoleByIds(int(permissionRole.Pid), int(permissionRole.Rid)) - - if len(rpermissionRole) > 0 { - t.Fatal("Data already exists") - } - - // 检查用户 - role, err := QueryRoleById(int(permissionRole.Rid)) - if err != nil { - t.Fatal(err) - } - - if role.ID == 0 { - t.Fatal("role data does not exist ") - } - - rPermission, err := QueryPermissionById(int(permissionRole.Pid)) - if err != nil { - t.Fatal(err) - } - - if rPermission.ID == 0 { - t.Fatal("Permission data does not exist") - } - - err = BindPermissionRole(&permissionRole) - if err != nil { - t.Fatal(err) - } - - fmt.Println(permissionRole) - -} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go deleted file mode 100644 index b59a3d72..00000000 --- a/bizdemo/hertz_casbin/biz/dal/mysql/role_test.go +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package mysql - -import ( - "fmt" - "testing" - - "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" -) - -func init() { - Init() -} - -// create role data -func TestCreateRole(t *testing.T) { - - role := casbin.Role{ - Name: "admin", - } - - qRole, err := QueryRoleByName(role.Name) - if err != nil { - t.Fatal(err) - } - - if qRole.ID != 0 { - fmt.Println("User already exists") - return - } - err = CreateRole(&role) - if err != nil { - t.Fatal(err) - } - -} - -// query role by the name of the role -func TestQueryRole(t *testing.T) { - qRole, err := QueryRoleByName("admin") - if err != nil { - t.Fatal(err) - } - - fmt.Println(qRole) - -} - -// query roles by the id of the user -func TestQueryRolesByUid(t *testing.T) { - qRoles := QueryRolesByUid(int(5)) - - fmt.Println(qRoles) - -} - -// bind role by the id of the role and id of the user -func TestBindUserRole(t *testing.T) { - - userRole := casbin.UserRole{ - UID: 5, - Rid: 1, - } - - userRoles1 := QueryUserRoleByIds(int(userRole.UID), int(userRole.Rid)) - - if len(userRoles1) > 0 { - t.Fatal("Data already exists") - } - - // check user - user, err := QueryUserById(int(userRole.UID)) - if err != nil { - t.Fatal(err) - } - - if user.ID == 0 { - t.Fatal("User data does not exist") - } - - crrole, err := QueryRoleById(int(userRole.Rid)) - if err != nil { - t.Fatal(err) - } - - if crrole.ID == 0 { - t.Fatal("Role data does not exist") - } - - err = BindRole(&userRole) - if err != nil { - t.Fatal(err) - } - - fmt.Println(userRole) - -} diff --git a/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go b/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go deleted file mode 100644 index 185323e8..00000000 --- a/bizdemo/hertz_casbin/biz/dal/mysql/user_test.go +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package mysql - -import ( - "fmt" - "testing" - - "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/biz/model/casbin" - "github.com/cloudwego/hertz-examples/bizdemo/hertz_casbin/pkg/utils" -) - -func init() { - Init() -} - -// create the user data -func TestCreateUser(t *testing.T) { - - user := casbin.User{ - Username: "admin", - Password: utils.Md5("123"), - } - - qUser, err := QueryUserByUsername(user.Username) - if err != nil { - t.Fatal(err) - } - - if qUser.ID != 0 { - fmt.Println("User already exists") - return - } - err = CreateUser(&user) - if err != nil { - t.Fatal(err) - } - - rUser, err := QueryUser(user.Username, user.Password) - if err != nil { - t.Fatal(err) - } - fmt.Println(rUser) - -} - -// query user by the username of user -func TestQueryUser(t *testing.T) { - qUser, err := QueryUserByUsername("admin") - if err != nil { - t.Fatal(err) - } - - if qUser.ID != 0 { - fmt.Println("User already exists") - } - - fmt.Println(qUser) - -} From 1e552ecab60d0876d8ce0810bf38213189e0f084 Mon Sep 17 00:00:00 2001 From: darren Date: Sat, 4 Feb 2023 09:54:36 +0800 Subject: [PATCH 10/10] pid --- go.mod | 1 + go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index d47d607a..bc33ec7f 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/alibaba/sentinel-golang v1.0.4 github.com/aliyun/alibaba-cloud-sdk-go v1.61.1764 // indirect github.com/apache/thrift v0.13.0 + github.com/choleraehyq/pid v0.0.16 // indirect github.com/cloudwego/hertz v0.4.2 github.com/cloudwego/kitex v0.3.1 github.com/go-errors/errors v1.4.2 // indirect diff --git a/go.sum b/go.sum index 558ccfdb..fa4aa46f 100644 --- a/go.sum +++ b/go.sum @@ -107,6 +107,8 @@ github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F github.com/choleraehyq/pid v0.0.12/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U= github.com/choleraehyq/pid v0.0.13 h1:Tc/jYjHC50SDCxSX+DWHfMmFqtwGR8EiQ08qJ/EK8zs= github.com/choleraehyq/pid v0.0.13/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U= +github.com/choleraehyq/pid v0.0.16 h1:1/714sMH9IBlE/aK6xM0acTagGKSzpiR0bDt7l0cG7o= +github.com/choleraehyq/pid v0.0.16/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=