add: user api doc and grpc api
This commit is contained in:
parent
6e59e3d3d4
commit
efe7dd6d8a
|
@ -73,6 +73,8 @@ cp config.yaml.example config.yaml
|
|||
| | run_mode | 运行模式,可选debug、release、test |
|
||||
| | default_context_timeout | 上下文超时时长 |
|
||||
| | page_size | 默认分页数量 |
|
||||
| | jwt_secret | jwt加密参数 |
|
||||
| | jwt_expire | jwt过期时间 |
|
||||
| server | http_port | http服务端口号 |
|
||||
| | grpc_port | grpc服务端口号 |
|
||||
| | read_timeout | 读数据超时时长 |
|
||||
|
|
|
@ -5,6 +5,8 @@ app:
|
|||
run_mode: 'debug'
|
||||
default_context_timeout: 60
|
||||
page_size: 10
|
||||
jwt_secret: 'account-server'
|
||||
jwt_expire: 7200
|
||||
server:
|
||||
http_port: 8021
|
||||
grpc_port: 8022
|
||||
|
|
214
docs/docs.go
214
docs/docs.go
|
@ -1,22 +1,14 @@
|
|||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag
|
||||
|
||||
package docs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
import "github.com/swaggo/swag"
|
||||
|
||||
"github.com/alecthomas/template"
|
||||
"github.com/swaggo/swag"
|
||||
)
|
||||
|
||||
var doc = `{
|
||||
const docTemplate_swagger = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{.Description}}",
|
||||
"description": "{{escape .Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"contact": {},
|
||||
"version": "{{.Version}}"
|
||||
|
@ -100,9 +92,13 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/templates": {
|
||||
"/users": {
|
||||
"get": {
|
||||
"description": "一段描述",
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -110,9 +106,9 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "数据列表",
|
||||
"summary": "用户列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
|
@ -127,16 +123,17 @@ var doc = `{
|
|||
"in": "query"
|
||||
},
|
||||
{
|
||||
"maxLength": 100,
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "名称搜索",
|
||||
"name": "name",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "uuid搜索",
|
||||
"name": "uuid",
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "昵称",
|
||||
"name": "nickname",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
|
@ -144,12 +141,17 @@ var doc = `{
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
|
@ -157,23 +159,33 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "新增一条模板数据",
|
||||
"summary": "新增用户",
|
||||
"parameters": [
|
||||
{
|
||||
"maxLength": 100,
|
||||
"maxLength": 30,
|
||||
"minLength": 1,
|
||||
"type": "string",
|
||||
"description": "名称",
|
||||
"name": "name",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "uuid",
|
||||
"name": "uuid",
|
||||
"maxLength": 18,
|
||||
"minLength": 1,
|
||||
"type": "string",
|
||||
"description": "密码",
|
||||
"name": "password",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "昵称",
|
||||
"name": "nickname",
|
||||
"in": "formData"
|
||||
}
|
||||
],
|
||||
|
@ -181,15 +193,19 @@ var doc = `{
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/templates/{id}": {
|
||||
"/users/{id}": {
|
||||
"get": {
|
||||
"description": "这是一段描述",
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -197,13 +213,13 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "获取单个模板",
|
||||
"summary": "用户",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"description": "用户 ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
|
@ -213,12 +229,17 @@ var doc = `{
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -226,13 +247,13 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "删除一条数据",
|
||||
"summary": "删除用户",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"description": "用户ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
|
@ -242,12 +263,17 @@ var doc = `{
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
|
@ -255,29 +281,36 @@ var doc = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "修改模板数据",
|
||||
"summary": "更新用户",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"description": "用户ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"maxLength": 100,
|
||||
"minLength": 1,
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "名称",
|
||||
"name": "name",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "uuid",
|
||||
"name": "uuid",
|
||||
"maxLength": 18,
|
||||
"type": "string",
|
||||
"description": "密码",
|
||||
"name": "password",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "昵称",
|
||||
"name": "nickname",
|
||||
"in": "formData"
|
||||
}
|
||||
],
|
||||
|
@ -285,7 +318,7 @@ var doc = `{
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -299,15 +332,13 @@ var doc = `{
|
|||
"code": {
|
||||
"type": "integer"
|
||||
},
|
||||
"data": {
|
||||
"type": "object"
|
||||
},
|
||||
"data": {},
|
||||
"msg": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"model.Template": {
|
||||
"model.User": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created_at": {
|
||||
|
@ -316,63 +347,42 @@ var doc = `{
|
|||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"is_admin": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"nickname": {
|
||||
"type": "string"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"uuid": {
|
||||
"type": "integer"
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"ApiKeyAuth": {
|
||||
"type": "apiKey",
|
||||
"name": "Authorization",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
type swaggerInfo struct {
|
||||
Version string
|
||||
Host string
|
||||
BasePath string
|
||||
Schemes []string
|
||||
Title string
|
||||
Description string
|
||||
}
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = swaggerInfo{
|
||||
Version: "1.0",
|
||||
Host: "",
|
||||
BasePath: "/api",
|
||||
Schemes: []string{},
|
||||
Title: "AccountServer Api",
|
||||
Description: "账号服务",
|
||||
}
|
||||
|
||||
type s struct{}
|
||||
|
||||
func (s *s) ReadDoc() string {
|
||||
sInfo := SwaggerInfo
|
||||
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
|
||||
|
||||
t, err := template.New("swagger_info").Funcs(template.FuncMap{
|
||||
"marshal": func(v interface{}) string {
|
||||
a, _ := json.Marshal(v)
|
||||
return string(a)
|
||||
},
|
||||
}).Parse(doc)
|
||||
if err != nil {
|
||||
return doc
|
||||
}
|
||||
|
||||
var tpl bytes.Buffer
|
||||
if err := t.Execute(&tpl, sInfo); err != nil {
|
||||
return doc
|
||||
}
|
||||
|
||||
return tpl.String()
|
||||
// SwaggerInfo_swagger holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo_swagger = &swag.Spec{
|
||||
Version: "1.0",
|
||||
Host: "",
|
||||
BasePath: "/api",
|
||||
Schemes: []string{},
|
||||
Title: "AccountServer Api",
|
||||
Description: "账号服务",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate_swagger,
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(swag.Name, &s{})
|
||||
swag.Register(SwaggerInfo_swagger.InstanceName(), SwaggerInfo_swagger)
|
||||
}
|
||||
|
|
|
@ -84,9 +84,13 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/templates": {
|
||||
"/users": {
|
||||
"get": {
|
||||
"description": "一段描述",
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -94,9 +98,9 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "数据列表",
|
||||
"summary": "用户列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
|
@ -111,16 +115,17 @@
|
|||
"in": "query"
|
||||
},
|
||||
{
|
||||
"maxLength": 100,
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "名称搜索",
|
||||
"name": "name",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "uuid搜索",
|
||||
"name": "uuid",
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "昵称",
|
||||
"name": "nickname",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
|
@ -128,12 +133,17 @@
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
|
@ -141,23 +151,33 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "新增一条模板数据",
|
||||
"summary": "新增用户",
|
||||
"parameters": [
|
||||
{
|
||||
"maxLength": 100,
|
||||
"maxLength": 30,
|
||||
"minLength": 1,
|
||||
"type": "string",
|
||||
"description": "名称",
|
||||
"name": "name",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "uuid",
|
||||
"name": "uuid",
|
||||
"maxLength": 18,
|
||||
"minLength": 1,
|
||||
"type": "string",
|
||||
"description": "密码",
|
||||
"name": "password",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "昵称",
|
||||
"name": "nickname",
|
||||
"in": "formData"
|
||||
}
|
||||
],
|
||||
|
@ -165,15 +185,19 @@
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/templates/{id}": {
|
||||
"/users/{id}": {
|
||||
"get": {
|
||||
"description": "这是一段描述",
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -181,13 +205,13 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "获取单个模板",
|
||||
"summary": "用户",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"description": "用户 ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
|
@ -197,12 +221,17 @@
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -210,13 +239,13 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "删除一条数据",
|
||||
"summary": "删除用户",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"description": "用户ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
|
@ -226,12 +255,17 @@
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
|
@ -239,29 +273,36 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"templates"
|
||||
"users"
|
||||
],
|
||||
"summary": "修改模板数据",
|
||||
"summary": "更新用户",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"description": "用户ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"maxLength": 100,
|
||||
"minLength": 1,
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "名称",
|
||||
"name": "name",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "uuid",
|
||||
"name": "uuid",
|
||||
"maxLength": 18,
|
||||
"type": "string",
|
||||
"description": "密码",
|
||||
"name": "password",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"maxLength": 30,
|
||||
"type": "string",
|
||||
"description": "昵称",
|
||||
"name": "nickname",
|
||||
"in": "formData"
|
||||
}
|
||||
],
|
||||
|
@ -269,7 +310,7 @@
|
|||
"200": {
|
||||
"description": "请求成功",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.Template"
|
||||
"$ref": "#/definitions/model.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,15 +324,13 @@
|
|||
"code": {
|
||||
"type": "integer"
|
||||
},
|
||||
"data": {
|
||||
"type": "object"
|
||||
},
|
||||
"data": {},
|
||||
"msg": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"model.Template": {
|
||||
"model.User": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created_at": {
|
||||
|
@ -300,16 +339,26 @@
|
|||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"is_admin": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"nickname": {
|
||||
"type": "string"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"uuid": {
|
||||
"type": "integer"
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"ApiKeyAuth": {
|
||||
"type": "apiKey",
|
||||
"name": "Authorization",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,23 +4,24 @@ definitions:
|
|||
properties:
|
||||
code:
|
||||
type: integer
|
||||
data:
|
||||
type: object
|
||||
data: {}
|
||||
msg:
|
||||
type: string
|
||||
type: object
|
||||
model.Template:
|
||||
model.User:
|
||||
properties:
|
||||
created_at:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
is_admin:
|
||||
type: boolean
|
||||
nickname:
|
||||
type: string
|
||||
updated_at:
|
||||
type: string
|
||||
uuid:
|
||||
type: integer
|
||||
username:
|
||||
type: string
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
|
@ -78,11 +79,10 @@ paths:
|
|||
schema:
|
||||
$ref: '#/definitions/errcode.Error'
|
||||
summary: 用户注册
|
||||
/templates:
|
||||
/users:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 一段描述
|
||||
parameters:
|
||||
- description: 页码
|
||||
in: query
|
||||
|
@ -92,56 +92,69 @@ paths:
|
|||
in: query
|
||||
name: page_size
|
||||
type: integer
|
||||
- description: 名称搜索
|
||||
- description: 用户名
|
||||
in: query
|
||||
maxLength: 100
|
||||
name: name
|
||||
maxLength: 30
|
||||
name: username
|
||||
type: string
|
||||
- description: uuid搜索
|
||||
- description: 昵称
|
||||
in: query
|
||||
name: uuid
|
||||
type: integer
|
||||
maxLength: 30
|
||||
name: nickname
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: 请求成功
|
||||
schema:
|
||||
$ref: '#/definitions/model.Template'
|
||||
summary: 数据列表
|
||||
$ref: '#/definitions/model.User'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 用户列表
|
||||
tags:
|
||||
- templates
|
||||
- users
|
||||
post:
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
parameters:
|
||||
- description: 名称
|
||||
- description: 用户名
|
||||
in: formData
|
||||
maxLength: 100
|
||||
maxLength: 30
|
||||
minLength: 1
|
||||
name: name
|
||||
name: username
|
||||
required: true
|
||||
type: string
|
||||
- description: uuid
|
||||
- description: 密码
|
||||
in: formData
|
||||
name: uuid
|
||||
type: integer
|
||||
maxLength: 18
|
||||
minLength: 1
|
||||
name: password
|
||||
required: true
|
||||
type: string
|
||||
- description: 昵称
|
||||
in: formData
|
||||
maxLength: 30
|
||||
name: nickname
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: 请求成功
|
||||
schema:
|
||||
$ref: '#/definitions/model.Template'
|
||||
summary: 新增一条模板数据
|
||||
$ref: '#/definitions/model.User'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 新增用户
|
||||
tags:
|
||||
- templates
|
||||
/templates/{id}:
|
||||
- users
|
||||
/users/{id}:
|
||||
delete:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: ID
|
||||
- description: 用户ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
|
@ -152,16 +165,17 @@ paths:
|
|||
"200":
|
||||
description: 请求成功
|
||||
schema:
|
||||
$ref: '#/definitions/model.Template'
|
||||
summary: 删除一条数据
|
||||
$ref: '#/definitions/model.User'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 删除用户
|
||||
tags:
|
||||
- templates
|
||||
- users
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 这是一段描述
|
||||
parameters:
|
||||
- description: ID
|
||||
- description: 用户 ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
|
@ -172,37 +186,51 @@ paths:
|
|||
"200":
|
||||
description: 请求成功
|
||||
schema:
|
||||
$ref: '#/definitions/model.Template'
|
||||
summary: 获取单个模板
|
||||
$ref: '#/definitions/model.User'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 用户
|
||||
tags:
|
||||
- templates
|
||||
- users
|
||||
patch:
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
parameters:
|
||||
- description: ID
|
||||
- description: 用户ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
- description: 名称
|
||||
- description: 用户名
|
||||
in: formData
|
||||
maxLength: 100
|
||||
minLength: 1
|
||||
name: name
|
||||
maxLength: 30
|
||||
name: username
|
||||
type: string
|
||||
- description: uuid
|
||||
- description: 密码
|
||||
in: formData
|
||||
name: uuid
|
||||
type: integer
|
||||
maxLength: 18
|
||||
name: password
|
||||
type: string
|
||||
- description: 昵称
|
||||
in: formData
|
||||
maxLength: 30
|
||||
name: nickname
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: 请求成功
|
||||
schema:
|
||||
$ref: '#/definitions/model.Template'
|
||||
summary: 修改模板数据
|
||||
$ref: '#/definitions/model.User'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 更新用户
|
||||
tags:
|
||||
- templates
|
||||
- users
|
||||
securityDefinitions:
|
||||
ApiKeyAuth:
|
||||
in: header
|
||||
name: Authorization
|
||||
type: apiKey
|
||||
swagger: "2.0"
|
||||
|
|
25
go.mod
25
go.mod
|
@ -3,22 +3,22 @@ module gitlink.org.cn/Gitlink/account-server
|
|||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
||||
github.com/fsnotify/fsnotify v1.4.9
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/go-playground/locales v0.13.0
|
||||
github.com/go-playground/universal-translator v0.17.0
|
||||
github.com/go-playground/validator/v10 v10.6.1
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-playground/locales v0.14.0
|
||||
github.com/go-playground/universal-translator v0.18.0
|
||||
github.com/go-playground/validator/v10 v10.10.0
|
||||
github.com/go-redis/redis v6.15.9+incompatible
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/google/go-cmp v0.5.6 // indirect
|
||||
github.com/jackc/pgx/v4 v4.15.0 // indirect
|
||||
github.com/json-iterator/go v1.1.10 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||
github.com/lestrrat-go/strftime v1.0.4 // indirect
|
||||
github.com/mailru/easyjson v0.7.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/onsi/ginkgo v1.16.4 // indirect
|
||||
github.com/onsi/gomega v1.13.0 // indirect
|
||||
github.com/pelletier/go-toml v1.8.1 // indirect
|
||||
|
@ -27,20 +27,21 @@ require (
|
|||
github.com/spf13/afero v1.2.2 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.7.1
|
||||
github.com/swaggo/gin-swagger v1.3.0
|
||||
github.com/swaggo/swag v1.7.0
|
||||
github.com/swaggo/gin-swagger v1.4.1
|
||||
github.com/swaggo/swag v1.7.9
|
||||
github.com/ugorji/go v1.2.6 // indirect
|
||||
github.com/viletyy/yolk v1.0.1
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.7.0 // indirect
|
||||
go.uber.org/zap v1.21.0
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
|
||||
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect
|
||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
|
||||
golang.org/x/tools v0.1.9 // indirect
|
||||
google.golang.org/genproto v0.0.0-20211013025323-ce878158c4d4 // indirect
|
||||
google.golang.org/grpc v1.41.0
|
||||
google.golang.org/protobuf v1.27.1
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gorm.io/driver/mysql v1.2.3
|
||||
gorm.io/driver/postgres v1.2.3
|
||||
gorm.io/gorm v1.22.5
|
||||
moul.io/zapgorm2 v1.1.2
|
||||
)
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
func RunGrpcServer(port string) error {
|
||||
server := grpc.NewServer()
|
||||
pb.RegisterTemplateServiceServer(server, grpc_server.NewTemplateServer())
|
||||
pb.RegisterUserServiceServer(server, grpc_server.NewUserServer())
|
||||
|
||||
reflection.Register(server)
|
||||
|
||||
|
|
|
@ -1,199 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/viletyy/yolk/convert"
|
||||
"gitlink.org.cn/Gitlink/account-server/global"
|
||||
"gitlink.org.cn/Gitlink/account-server/internal/service"
|
||||
"gitlink.org.cn/Gitlink/account-server/pkg/app"
|
||||
"gitlink.org.cn/Gitlink/account-server/pkg/errcode"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Template struct{}
|
||||
|
||||
func NewTemplate() Template {
|
||||
return Template{}
|
||||
}
|
||||
|
||||
// @Summary 数据列表
|
||||
// @Tags templates
|
||||
// @Description 一段描述
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query int false "页码"
|
||||
// @Param page_size query int false "每页数量"
|
||||
// @Param name query string false "名称搜索" maxlength(100)
|
||||
// @Param uuid query int false "uuid搜索"
|
||||
// @Success 200 {object} model.Template "请求成功"
|
||||
// @Router /templates [get]
|
||||
func (template Template) List(c *gin.Context) {
|
||||
param := service.TemplateListRequest{}
|
||||
response := app.NewResponse(c)
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs.Errors())
|
||||
return
|
||||
}
|
||||
|
||||
svc := service.New(c.Request.Context())
|
||||
paper := app.Pager{Page: app.GetPage(c), PageSize: app.GetPageSize(c)}
|
||||
total, err := svc.CountTemplate(&service.CountTemplateRequest{Name: param.Name, Uuid: param.Uuid})
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.CountTemplate err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorCountFail)
|
||||
return
|
||||
}
|
||||
templates, err := svc.GetTemplateList(¶m, &paper)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.GetTemplateList err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetListFail)
|
||||
return
|
||||
}
|
||||
|
||||
response.ToResponseList(templates, total)
|
||||
}
|
||||
|
||||
// @Summary 获取单个模板
|
||||
// @Tags templates
|
||||
// @Description 这是一段描述
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "ID"
|
||||
// @Success 200 {object} model.Template "请求成功"
|
||||
// @Router /templates/{id} [get]
|
||||
func (template Template) Get(c *gin.Context) {
|
||||
templateID, err := convert.StrTo(c.Param("id")).Int64()
|
||||
response := app.NewResponse(c)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("convert.StrTo err: %v", err)
|
||||
response.ToErrorResponse(errcode.InvalidParams)
|
||||
return
|
||||
}
|
||||
param := service.TemplateRequest{ID: templateID}
|
||||
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs.Errors())
|
||||
return
|
||||
}
|
||||
|
||||
svc := service.New(c.Request.Context())
|
||||
dbTemplate, err := svc.GetTemplate(¶m)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.GetTemplate err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetFail)
|
||||
return
|
||||
}
|
||||
|
||||
response.ToResponse(dbTemplate)
|
||||
}
|
||||
|
||||
// @Summary 新增一条模板数据
|
||||
// @Tags templates
|
||||
// @Description
|
||||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param name formData string true "名称" minlength(1) maxlength(100)
|
||||
// @Param uuid formData int false "uuid"
|
||||
// @Success 200 {object} model.Template "请求成功"
|
||||
// @Router /templates [post]
|
||||
func (template Template) Create(c *gin.Context) {
|
||||
param := service.CreateTemplateRequest{}
|
||||
response := app.NewResponse(c)
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs.Errors())
|
||||
return
|
||||
}
|
||||
|
||||
svc := service.New(c.Request.Context())
|
||||
dbTemplate, err := svc.CreateTemplate(¶m)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.CreateTemplate err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorCreateFail)
|
||||
return
|
||||
}
|
||||
|
||||
response.ToResponse(dbTemplate)
|
||||
}
|
||||
|
||||
// @Summary 修改模板数据
|
||||
// @Tags templates
|
||||
// @Description
|
||||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param id path int true "ID"
|
||||
// @Param name formData string false "名称" minlength(1) maxlength(100)
|
||||
// @Param uuid formData int false "uuid"
|
||||
// @Success 200 {object} model.Template "请求成功"
|
||||
// @Router /templates/{id} [patch]
|
||||
func (template Template) Update(c *gin.Context) {
|
||||
templateID, err := convert.StrTo(c.Param("id")).Int64()
|
||||
response := app.NewResponse(c)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("convert.StrTo err: %v", err)
|
||||
response.ToErrorResponse(errcode.InvalidParams)
|
||||
return
|
||||
}
|
||||
param := service.UpdateTemplateRequest{ID: templateID}
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs)
|
||||
return
|
||||
}
|
||||
svc := service.New(c.Request.Context())
|
||||
dbTemplate, err := svc.UpdateTemplate(¶m)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
global.GO_LOG.Sugar().Errorf("svc.UpdateTemplate err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetFail)
|
||||
return
|
||||
} else {
|
||||
global.GO_LOG.Sugar().Errorf("svc.UpdateTemplate err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorUpdateFail)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
response.ToResponse(dbTemplate)
|
||||
}
|
||||
|
||||
// @Summary 删除一条数据
|
||||
// @Tags templates
|
||||
// @Description
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "ID"
|
||||
// @Success 200 {object} model.Template "请求成功"
|
||||
// @Router /templates/{id} [delete]
|
||||
func (template Template) Delete(c *gin.Context) {
|
||||
templateId, err := convert.StrTo(c.Param("id")).Int64()
|
||||
response := app.NewResponse(c)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("convert.StrTo err: %v", err)
|
||||
response.ToErrorResponse(errcode.InvalidParams)
|
||||
return
|
||||
}
|
||||
param := service.DeleteTemplateRequest{ID: templateId}
|
||||
svc := service.New(c.Request.Context())
|
||||
dbTemplate, err := svc.DeleteTemplate(¶m)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
global.GO_LOG.Sugar().Errorf("svc.DeleteTemplate err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetFail)
|
||||
return
|
||||
} else {
|
||||
global.GO_LOG.Sugar().Errorf("svc.DeleteTemplate err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorDeleteFail)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
errcode.Success.Data = dbTemplate
|
||||
response.ToErrorResponse(errcode.Success)
|
||||
}
|
|
@ -2,10 +2,12 @@ package api
|
|||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/viletyy/yolk/convert"
|
||||
"gitlink.org.cn/Gitlink/account-server/global"
|
||||
"gitlink.org.cn/Gitlink/account-server/internal/service"
|
||||
"gitlink.org.cn/Gitlink/account-server/pkg/app"
|
||||
"gitlink.org.cn/Gitlink/account-server/pkg/errcode"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// @Summary 用户注册
|
||||
|
@ -76,3 +78,200 @@ func Login(c *gin.Context) {
|
|||
"token": token,
|
||||
})
|
||||
}
|
||||
|
||||
type User struct{}
|
||||
|
||||
func NewUser() User {
|
||||
return User{}
|
||||
}
|
||||
|
||||
// @Summary 用户列表
|
||||
// @Tags users
|
||||
// @Description
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query int false "页码"
|
||||
// @Param page_size query int false "每页数量"
|
||||
// @Param username query string false "用户名" maxlength(30)
|
||||
// @Param nickname query string false "昵称" maxlength(30)
|
||||
// @Success 200 {object} model.User "请求成功"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /users [get]
|
||||
func (user User) List(c *gin.Context) {
|
||||
param := service.UserListRequest{}
|
||||
response := app.NewResponse(c)
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs.Errors())
|
||||
return
|
||||
}
|
||||
|
||||
svc := service.New(c.Request.Context())
|
||||
paper := app.Pager{Page: app.GetPage(c), PageSize: app.GetPageSize(c)}
|
||||
total, err := svc.CountUser(&service.CountUserRequest{Username: param.Username, Nickname: param.Nickname})
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.CountUser err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorCountFail)
|
||||
return
|
||||
}
|
||||
|
||||
users, err := svc.GetUserList(¶m, &paper)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.GetUserList err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetListFail)
|
||||
return
|
||||
}
|
||||
|
||||
response.ToResponseList(users, total)
|
||||
}
|
||||
|
||||
// @Summary 用户
|
||||
// @Tags users
|
||||
// @Description
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "用户 ID"
|
||||
// @Success 200 {object} model.User "请求成功"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /users/{id} [get]
|
||||
func (user User) Get(c *gin.Context) {
|
||||
userID, err := convert.StrTo(c.Param("id")).Int64()
|
||||
response := app.NewResponse(c)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("convert.StrTo err: %v", err)
|
||||
response.ToErrorResponse(errcode.InvalidParams)
|
||||
return
|
||||
}
|
||||
param := service.UserRequest{ID: userID}
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs.Errors())
|
||||
return
|
||||
}
|
||||
|
||||
svc := service.New(c.Request.Context())
|
||||
dbUser, err := svc.GetUser(¶m)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.GetUser err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetFail)
|
||||
return
|
||||
}
|
||||
|
||||
response.ToResponse(dbUser)
|
||||
}
|
||||
|
||||
// @Summary 新增用户
|
||||
// @Tags users
|
||||
// @Description
|
||||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param username formData string true "用户名" minlength(1) maxlength(30)
|
||||
// @Param password formData string true "密码" minlength(1) maxlength(18)
|
||||
// @param nickname formData string false "昵称" maxlength(30)
|
||||
// @Success 200 {object} model.User "请求成功"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /users [post]
|
||||
func (user User) Create(c *gin.Context) {
|
||||
param := service.CreateUserRequest{}
|
||||
response := app.NewResponse(c)
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs.Errors())
|
||||
return
|
||||
}
|
||||
|
||||
svc := service.New(c.Request.Context())
|
||||
dbUser, err := svc.CreateUser(¶m)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("svc.CreateUser err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorCreateFail)
|
||||
return
|
||||
}
|
||||
|
||||
response.ToResponse(dbUser)
|
||||
}
|
||||
|
||||
// @Summary 更新用户
|
||||
// @Tags users
|
||||
// @Description
|
||||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param id path int true "用户ID"
|
||||
// @Param username formData string false "用户名" maxlength(30)
|
||||
// @Param password formData string false "密码" maxlength(18)
|
||||
// @param nickname formData string false "昵称" maxlength(30)
|
||||
// @Success 200 {object} model.User "请求成功"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /users/{id} [patch]
|
||||
func (user User) Update(c *gin.Context) {
|
||||
userID, err := convert.StrTo(c.Param("id")).Int64()
|
||||
response := app.NewResponse(c)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("convert.StrTo err: %v", err)
|
||||
response.ToErrorResponse(errcode.InvalidParams)
|
||||
return
|
||||
}
|
||||
|
||||
param := service.UpdateUserRequest{ID: userID}
|
||||
valid, errs := app.BindAndValid(c, ¶m)
|
||||
if !valid {
|
||||
global.GO_LOG.Sugar().Errorf("app.BindAndValid errs: %v", errs)
|
||||
response.ToResponseErrors(errs)
|
||||
return
|
||||
}
|
||||
svc := service.New(c.Request.Context())
|
||||
dbUser, err := svc.UpdateUser(¶m)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
global.GO_LOG.Sugar().Errorf("svc.UpdateUser err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetFail)
|
||||
return
|
||||
} else {
|
||||
global.GO_LOG.Sugar().Errorf("svc.UpdateUser err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorUpdateFail)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
response.ToResponse(dbUser)
|
||||
}
|
||||
|
||||
// @Summary 删除用户
|
||||
// @Tags users
|
||||
// @Description
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "用户ID"
|
||||
// @Success 200 {object} model.User "请求成功"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /users/{id} [delete]
|
||||
func (user User) Delete(c *gin.Context) {
|
||||
userID, err := convert.StrTo(c.Param("id")).Int64()
|
||||
response := app.NewResponse(c)
|
||||
if err != nil {
|
||||
global.GO_LOG.Sugar().Errorf("convert.StrTo err: %v", err)
|
||||
response.ToErrorResponse(errcode.InvalidParams)
|
||||
return
|
||||
}
|
||||
|
||||
param := service.DeleteUserRequest{ID: userID}
|
||||
svc := service.New(c.Request.Context())
|
||||
dbUser, err := svc.DeleteUser(¶m)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
global.GO_LOG.Sugar().Errorf("svc.DeleteUser err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorGetFail)
|
||||
return
|
||||
} else {
|
||||
global.GO_LOG.Sugar().Errorf("svc.DeleteUser err: %v", err)
|
||||
response.ToErrorResponse(errcode.ErrorDeleteFail)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
errcode.Success.Data = dbUser
|
||||
response.ToErrorResponse(errcode.Success)
|
||||
}
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/Gitlink/account-server/internal/model"
|
||||
"gitlink.org.cn/Gitlink/account-server/pkg/app"
|
||||
)
|
||||
|
||||
func (d *Dao) CountTemplate(name string, uuid int) (int64, error) {
|
||||
template := model.Template{Name: name, Uuid: uuid}
|
||||
return template.Count(d.Engine)
|
||||
}
|
||||
|
||||
func (d *Dao) GetTemplateList(name string, uuid int, page, pageSize int) ([]model.Template, error) {
|
||||
template := model.Template{Name: name, Uuid: uuid}
|
||||
pageOffset := app.GetPageOffset(page, pageSize)
|
||||
return template.List(d.Engine, pageOffset, pageSize)
|
||||
}
|
||||
|
||||
func (d *Dao) GetTemplate(id int64) (model.Template, error) {
|
||||
template := model.Template{
|
||||
Model: &model.Model{ID: id},
|
||||
}
|
||||
|
||||
return template.Get(d.Engine)
|
||||
}
|
||||
|
||||
func (d *Dao) CreateTemplate(name string, uuid int) (model.Template, error) {
|
||||
template := model.Template{
|
||||
Name: name,
|
||||
Uuid: uuid,
|
||||
}
|
||||
|
||||
return template, template.Create(d.Engine)
|
||||
}
|
||||
|
||||
func (d *Dao) UpdateTemplate(id int64, name string, uuid int) (model.Template, error) {
|
||||
template := model.Template{
|
||||
Name: name,
|
||||
Uuid: uuid,
|
||||
Model: &model.Model{ID: id},
|
||||
}
|
||||
|
||||
dbTemplate, err := template.Get(d.Engine)
|
||||
|
||||
if err != nil {
|
||||
return template, err
|
||||
}
|
||||
|
||||
return dbTemplate, dbTemplate.Update(d.Engine)
|
||||
}
|
||||
|
||||
func (d *Dao) DeleteTemplate(id int64) (model.Template, error) {
|
||||
template := model.Template{
|
||||
Model: &model.Model{ID: id},
|
||||
}
|
||||
|
||||
dbTemplate, err := template.Get(d.Engine)
|
||||
|
||||
if err != nil {
|
||||
return template, err
|
||||
}
|
||||
|
||||
return dbTemplate, dbTemplate.Delete(d.Engine)
|
||||
}
|
|
@ -19,13 +19,13 @@ func JWT() gin.HandlerFunc {
|
|||
token string
|
||||
ecode = errcode.Success
|
||||
)
|
||||
if s, exist := c.GetQuery("token"); exist {
|
||||
if s, exist := c.GetQuery("Authorization"); exist {
|
||||
token = s
|
||||
} else {
|
||||
token = c.GetHeader("token")
|
||||
token = c.GetHeader("Authorization")
|
||||
}
|
||||
if token == "" {
|
||||
ecode = errcode.InvalidParams
|
||||
ecode = errcode.UnauthorizedTokenError
|
||||
} else {
|
||||
_, err := app.ParseToken(token)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* @Date: 2021-03-21 19:54:57
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-11 11:01:28
|
||||
* @FilePath: /potato/internal/model/basic/vendor.go
|
||||
*/
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Template struct {
|
||||
*Model
|
||||
|
||||
Name string `json:"name"`
|
||||
Uuid int `json:"uuid"`
|
||||
}
|
||||
|
||||
func (v Template) Count(db *gorm.DB) (int64, error) {
|
||||
var count int64
|
||||
if v.Name != "" {
|
||||
db = db.Where("name = ?", v.Name)
|
||||
}
|
||||
if v.Uuid != 0 {
|
||||
db = db.Where("uuid = ?", v.Uuid)
|
||||
}
|
||||
if err := db.Model(&v).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (v Template) List(db *gorm.DB, pageOffset, pageSize int) (vendors []Template, err error) {
|
||||
if pageOffset >= 0 && pageSize > 0 {
|
||||
db = db.Offset(pageOffset).Limit(pageSize)
|
||||
}
|
||||
if v.Name != "" {
|
||||
db = db.Where("name = ?", v.Name)
|
||||
}
|
||||
if v.Uuid != 0 {
|
||||
db = db.Where("uuid = ?", v.Uuid)
|
||||
}
|
||||
if err = db.Find(&vendors).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (v Template) Get(db *gorm.DB) (vendor Template, err error) {
|
||||
if err = db.Where("id = ?", v.ID).First(&vendor).Error; err != nil {
|
||||
return v, err
|
||||
}
|
||||
|
||||
return vendor, nil
|
||||
}
|
||||
|
||||
func (v *Template) Create(db *gorm.DB) error {
|
||||
return db.Create(v).Error
|
||||
}
|
||||
|
||||
func (v *Template) Update(db *gorm.DB) error {
|
||||
err := db.Save(v).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func (v *Template) Delete(db *gorm.DB) error {
|
||||
return db.Where("id = ?", v.ID).Delete(v).Error
|
||||
}
|
|
@ -10,10 +10,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/swaggo/gin-swagger"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
_ "github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
_ "gitlink.org.cn/Gitlink/account-server/docs"
|
||||
"gitlink.org.cn/Gitlink/account-server/global"
|
||||
"gitlink.org.cn/Gitlink/account-server/internal/controller/api"
|
||||
|
@ -43,15 +41,14 @@ func InitRouter() *gin.Engine {
|
|||
Engine.POST("/api/login", api.Login)
|
||||
apiRouterGroup := Engine.Group("../api")
|
||||
apiRouterGroup.Use(middleware.JWT())
|
||||
|
||||
templates := apiRouterGroup.Group("/templates")
|
||||
template := api.NewTemplate()
|
||||
users := apiRouterGroup.Group("/users")
|
||||
user := api.NewUser()
|
||||
{
|
||||
templates.GET("", template.List)
|
||||
templates.POST("", template.Create)
|
||||
templates.GET("/:id", template.Get)
|
||||
templates.PATCH("/:id", template.Update)
|
||||
templates.DELETE("/:id", template.Delete)
|
||||
users.GET("", user.List)
|
||||
users.POST("", user.Create)
|
||||
users.GET("/:id", user.Get)
|
||||
users.PATCH("/:id", user.Update)
|
||||
users.DELETE("/:id", user.Delete)
|
||||
}
|
||||
|
||||
return Engine
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/Gitlink/account-server/internal/model"
|
||||
"gitlink.org.cn/Gitlink/account-server/pkg/app"
|
||||
)
|
||||
|
||||
type CountTemplateRequest struct {
|
||||
Name string `form:"name" json:"name" validate:"max=100"`
|
||||
Uuid int `form:"uuid" json:"uuid"`
|
||||
}
|
||||
|
||||
type TemplateListRequest struct {
|
||||
Name string `form:"name" json:"name" validate:"max=100"`
|
||||
Uuid int `form:"uuid" json:"uuid"`
|
||||
}
|
||||
|
||||
type TemplateRequest struct {
|
||||
ID int64 `form:"id" json:"id" validate:"required,gte=1"`
|
||||
}
|
||||
|
||||
type CreateTemplateRequest struct {
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Uuid int `form:"uuid" json:"uuid"`
|
||||
}
|
||||
|
||||
type UpdateTemplateRequest struct {
|
||||
ID int64 `form:"id" json:"id" validate:"required,gte=1"`
|
||||
Name string `form:"name" json:"name"`
|
||||
Uuid int `form:"uuid" json:"uuid"`
|
||||
}
|
||||
|
||||
type DeleteTemplateRequest struct {
|
||||
ID int64 `json:"id" validate:"required,gte=1"`
|
||||
}
|
||||
|
||||
func (svc *Service) CountTemplate(param *CountTemplateRequest) (int64, error) {
|
||||
return svc.Dao.CountTemplate(param.Name, param.Uuid)
|
||||
}
|
||||
|
||||
func (svc *Service) GetTemplateList(param *TemplateListRequest, paper *app.Pager) ([]model.Template, error) {
|
||||
return svc.Dao.GetTemplateList(param.Name, param.Uuid, paper.Page, paper.PageSize)
|
||||
}
|
||||
|
||||
func (svc *Service) GetTemplate(param *TemplateRequest) (model.Template, error) {
|
||||
return svc.Dao.GetTemplate(param.ID)
|
||||
}
|
||||
|
||||
func (svc *Service) CreateTemplate(param *CreateTemplateRequest) (model.Template, error) {
|
||||
return svc.Dao.CreateTemplate(param.Name, param.Uuid)
|
||||
}
|
||||
|
||||
func (svc *Service) UpdateTemplate(param *UpdateTemplateRequest) (model.Template, error) {
|
||||
return svc.Dao.UpdateTemplate(param.ID, param.Name, param.Uuid)
|
||||
}
|
||||
|
||||
func (svc *Service) DeleteTemplate(param *DeleteTemplateRequest) (model.Template, error) {
|
||||
return svc.Dao.DeleteTemplate(param.ID)
|
||||
}
|
12
main.go
12
main.go
|
@ -9,10 +9,14 @@ import (
|
|||
"gitlink.org.cn/Gitlink/account-server/migrations"
|
||||
)
|
||||
|
||||
// @title AccountServer Api
|
||||
// @version 1.0
|
||||
// @description 账号服务
|
||||
// @BasePath /api
|
||||
// @title AccountServer Api
|
||||
// @version 1.0
|
||||
// @description 账号服务
|
||||
// @BasePath /api
|
||||
|
||||
// @securityDefinitions.apikey ApiKeyAuth
|
||||
// @in header
|
||||
// @name Authorization
|
||||
var grpcPort string
|
||||
var httpPort string
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
package rpc
|
||||
|
||||
var (
|
||||
RpcErrorGetTemplateListFail = NewRpcError(20101, "获取列表失败")
|
||||
RpcErrorGetTemplateFail = NewRpcError(20102, "获取失败")
|
||||
RpcErrorCreateTemplateFail = NewRpcError(20103, "创建失败")
|
||||
RpcErrorUpdateTemplateFail = NewRpcError(20104, "更新失败")
|
||||
RpcErrorDeleteTemplateFail = NewRpcError(20105, "删除失败")
|
||||
RpcErrorCountTemplateFail = NewRpcError(20106, "统计失败")
|
||||
RpcErrorGetListFail = NewRpcError(20101, "获取列表失败")
|
||||
RpcErrorGetFail = NewRpcError(20102, "获取失败")
|
||||
RpcErrorCreateFail = NewRpcError(20103, "创建失败")
|
||||
RpcErrorUpdateFail = NewRpcError(20104, "更新失败")
|
||||
RpcErrorDeleteFail = NewRpcError(20105, "删除失败")
|
||||
RpcErrorCountFail = NewRpcError(20106, "统计失败")
|
||||
)
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: proto/template.proto
|
||||
|
||||
package proto
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type GetTemplateListRequest struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Uuid int64 `protobuf:"varint,2,opt,name=uuid,proto3" json:"uuid,omitempty"`
|
||||
Page int64 `protobuf:"varint,3,opt,name=page,proto3" json:"page,omitempty"`
|
||||
PageSize int64 `protobuf:"varint,4,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *GetTemplateListRequest) Reset() { *m = GetTemplateListRequest{} }
|
||||
func (m *GetTemplateListRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*GetTemplateListRequest) ProtoMessage() {}
|
||||
func (*GetTemplateListRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_dc851a26de071022, []int{0}
|
||||
}
|
||||
|
||||
func (m *GetTemplateListRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_GetTemplateListRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *GetTemplateListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_GetTemplateListRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *GetTemplateListRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GetTemplateListRequest.Merge(m, src)
|
||||
}
|
||||
func (m *GetTemplateListRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_GetTemplateListRequest.Size(m)
|
||||
}
|
||||
func (m *GetTemplateListRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GetTemplateListRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GetTemplateListRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *GetTemplateListRequest) GetName() string {
|
||||
if m != nil {
|
||||
return m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *GetTemplateListRequest) GetUuid() int64 {
|
||||
if m != nil {
|
||||
return m.Uuid
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *GetTemplateListRequest) GetPage() int64 {
|
||||
if m != nil {
|
||||
return m.Page
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *GetTemplateListRequest) GetPageSize() int64 {
|
||||
if m != nil {
|
||||
return m.PageSize
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type Template struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Uuid int64 `protobuf:"varint,3,opt,name=uuid,proto3" json:"uuid,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Template) Reset() { *m = Template{} }
|
||||
func (m *Template) String() string { return proto.CompactTextString(m) }
|
||||
func (*Template) ProtoMessage() {}
|
||||
func (*Template) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_dc851a26de071022, []int{1}
|
||||
}
|
||||
|
||||
func (m *Template) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Template.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Template) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Template.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Template) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Template.Merge(m, src)
|
||||
}
|
||||
func (m *Template) XXX_Size() int {
|
||||
return xxx_messageInfo_Template.Size(m)
|
||||
}
|
||||
func (m *Template) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Template.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Template proto.InternalMessageInfo
|
||||
|
||||
func (m *Template) GetId() int64 {
|
||||
if m != nil {
|
||||
return m.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Template) GetName() string {
|
||||
if m != nil {
|
||||
return m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Template) GetUuid() int64 {
|
||||
if m != nil {
|
||||
return m.Uuid
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetTemplateListReply struct {
|
||||
List []*Template `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"`
|
||||
Pager *Pager `protobuf:"bytes,2,opt,name=pager,proto3" json:"pager,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *GetTemplateListReply) Reset() { *m = GetTemplateListReply{} }
|
||||
func (m *GetTemplateListReply) String() string { return proto.CompactTextString(m) }
|
||||
func (*GetTemplateListReply) ProtoMessage() {}
|
||||
func (*GetTemplateListReply) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_dc851a26de071022, []int{2}
|
||||
}
|
||||
|
||||
func (m *GetTemplateListReply) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_GetTemplateListReply.Unmarshal(m, b)
|
||||
}
|
||||
func (m *GetTemplateListReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_GetTemplateListReply.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *GetTemplateListReply) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GetTemplateListReply.Merge(m, src)
|
||||
}
|
||||
func (m *GetTemplateListReply) XXX_Size() int {
|
||||
return xxx_messageInfo_GetTemplateListReply.Size(m)
|
||||
}
|
||||
func (m *GetTemplateListReply) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GetTemplateListReply.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GetTemplateListReply proto.InternalMessageInfo
|
||||
|
||||
func (m *GetTemplateListReply) GetList() []*Template {
|
||||
if m != nil {
|
||||
return m.List
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GetTemplateListReply) GetPager() *Pager {
|
||||
if m != nil {
|
||||
return m.Pager
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*GetTemplateListRequest)(nil), "GetTemplateListRequest")
|
||||
proto.RegisterType((*Template)(nil), "Template")
|
||||
proto.RegisterType((*GetTemplateListReply)(nil), "GetTemplateListReply")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("proto/template.proto", fileDescriptor_dc851a26de071022) }
|
||||
|
||||
var fileDescriptor_dc851a26de071022 = []byte{
|
||||
// 286 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xcf, 0x4b, 0xc3, 0x30,
|
||||
0x14, 0xc7, 0xed, 0x0f, 0xc7, 0x9a, 0x81, 0x83, 0x30, 0xb5, 0x4c, 0x85, 0xd2, 0x53, 0x2f, 0x4b,
|
||||
0xa5, 0xfe, 0x07, 0xf3, 0xb0, 0x8b, 0x07, 0x49, 0xc5, 0x83, 0x17, 0xa9, 0xdd, 0xa3, 0x04, 0x9b,
|
||||
0xa6, 0x4b, 0xd2, 0x81, 0xfb, 0xeb, 0x25, 0x89, 0x45, 0xd0, 0x9e, 0xde, 0x7b, 0x9f, 0x3e, 0xde,
|
||||
0xe7, 0x4b, 0x83, 0x56, 0xbd, 0x14, 0x5a, 0xe4, 0x1a, 0x78, 0xdf, 0x56, 0x1a, 0x88, 0x1d, 0xd7,
|
||||
0xd8, 0xd1, 0x5a, 0x70, 0x2e, 0x3a, 0xc7, 0xd2, 0x03, 0xba, 0xda, 0x81, 0x7e, 0xf9, 0x59, 0x7c,
|
||||
0x62, 0x4a, 0x53, 0x38, 0x0c, 0xa0, 0x34, 0xc6, 0x28, 0xec, 0x2a, 0x0e, 0xb1, 0x97, 0x78, 0x59,
|
||||
0x44, 0x6d, 0x6f, 0xd8, 0x30, 0xb0, 0x7d, 0xec, 0x27, 0x5e, 0x16, 0x50, 0xdb, 0x1b, 0xd6, 0x57,
|
||||
0x0d, 0xc4, 0x81, 0x63, 0xa6, 0xc7, 0x37, 0x28, 0x32, 0xf5, 0x5d, 0xb1, 0x13, 0xc4, 0xa1, 0xfd,
|
||||
0x30, 0x37, 0xa0, 0x64, 0x27, 0x48, 0xb7, 0x68, 0x3e, 0xfa, 0xf0, 0x05, 0xf2, 0xd9, 0xde, 0x2a,
|
||||
0x02, 0xea, 0xbb, 0x63, 0x56, 0xea, 0x4f, 0x48, 0x83, 0x5f, 0x69, 0x5a, 0xa2, 0xd5, 0xbf, 0xd8,
|
||||
0x7d, 0xfb, 0x85, 0xef, 0x50, 0xd8, 0x32, 0xa5, 0x63, 0x2f, 0x09, 0xb2, 0x45, 0x11, 0x91, 0x71,
|
||||
0x83, 0x5a, 0x8c, 0x6f, 0xd1, 0xb9, 0x89, 0x21, 0xed, 0xfd, 0x45, 0x31, 0x23, 0xcf, 0x66, 0xa2,
|
||||
0x0e, 0x16, 0xaf, 0x68, 0x39, 0xee, 0x97, 0x20, 0x8f, 0xac, 0x06, 0xfc, 0x88, 0x96, 0x7f, 0x3c,
|
||||
0xf8, 0x9a, 0x4c, 0xff, 0xb0, 0xf5, 0x25, 0x99, 0x8a, 0x94, 0x9e, 0x6d, 0x8b, 0xb7, 0xfb, 0x86,
|
||||
0xe9, 0x96, 0x75, 0x9f, 0x44, 0xc8, 0x86, 0xd4, 0x5d, 0xbe, 0x73, 0x63, 0xce, 0x59, 0x2d, 0xc5,
|
||||
0x46, 0x81, 0x3c, 0x82, 0xdc, 0x28, 0xc6, 0xfb, 0x16, 0x72, 0xfb, 0x2e, 0x1f, 0x33, 0x5b, 0x1e,
|
||||
0xbe, 0x03, 0x00, 0x00, 0xff, 0xff, 0xa4, 0xb3, 0x98, 0xcb, 0xca, 0x01, 0x00, 0x00,
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
syntax = "proto3";
|
||||
|
||||
option go_package= "gitlink.org.cn/Gitlink/account-server/proto";
|
||||
|
||||
import "proto/common.proto";
|
||||
|
||||
service TemplateService {
|
||||
rpc GetTemplateList(GetTemplateListRequest) returns (GetTemplateListReply) {}
|
||||
}
|
||||
|
||||
message GetTemplateListRequest {
|
||||
string name = 1;
|
||||
int64 uuid = 2;
|
||||
int64 page = 3;
|
||||
int64 page_size = 4;
|
||||
}
|
||||
|
||||
message Template {
|
||||
int64 id = 1;
|
||||
string name = 2;
|
||||
int64 uuid = 3;
|
||||
}
|
||||
|
||||
message GetTemplateListReply {
|
||||
repeated Template list = 1;
|
||||
Pager pager = 2;
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package proto
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// TemplateServiceClient is the client API for TemplateService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type TemplateServiceClient interface {
|
||||
GetTemplateList(ctx context.Context, in *GetTemplateListRequest, opts ...grpc.CallOption) (*GetTemplateListReply, error)
|
||||
}
|
||||
|
||||
type templateServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewTemplateServiceClient(cc grpc.ClientConnInterface) TemplateServiceClient {
|
||||
return &templateServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *templateServiceClient) GetTemplateList(ctx context.Context, in *GetTemplateListRequest, opts ...grpc.CallOption) (*GetTemplateListReply, error) {
|
||||
out := new(GetTemplateListReply)
|
||||
err := c.cc.Invoke(ctx, "/TemplateService/GetTemplateList", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TemplateServiceServer is the server API for TemplateService service.
|
||||
// All implementations must embed UnimplementedTemplateServiceServer
|
||||
// for forward compatibility
|
||||
type TemplateServiceServer interface {
|
||||
GetTemplateList(context.Context, *GetTemplateListRequest) (*GetTemplateListReply, error)
|
||||
mustEmbedUnimplementedTemplateServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedTemplateServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedTemplateServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedTemplateServiceServer) GetTemplateList(context.Context, *GetTemplateListRequest) (*GetTemplateListReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetTemplateList not implemented")
|
||||
}
|
||||
func (UnimplementedTemplateServiceServer) mustEmbedUnimplementedTemplateServiceServer() {}
|
||||
|
||||
// UnsafeTemplateServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to TemplateServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeTemplateServiceServer interface {
|
||||
mustEmbedUnimplementedTemplateServiceServer()
|
||||
}
|
||||
|
||||
func RegisterTemplateServiceServer(s grpc.ServiceRegistrar, srv TemplateServiceServer) {
|
||||
s.RegisterService(&TemplateService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _TemplateService_GetTemplateList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetTemplateListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TemplateServiceServer).GetTemplateList(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/TemplateService/GetTemplateList",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TemplateServiceServer).GetTemplateList(ctx, req.(*GetTemplateListRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// TemplateService_ServiceDesc is the grpc.ServiceDesc for TemplateService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var TemplateService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "TemplateService",
|
||||
HandlerType: (*TemplateServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetTemplateList",
|
||||
Handler: _TemplateService_GetTemplateList_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "proto/template.proto",
|
||||
}
|
|
@ -0,0 +1,225 @@
|
|||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: proto/user.proto
|
||||
|
||||
package proto
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type GetUserListRequest struct {
|
||||
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
|
||||
Nickname string `protobuf:"bytes,2,opt,name=nickname,proto3" json:"nickname,omitempty"`
|
||||
Page int64 `protobuf:"varint,3,opt,name=page,proto3" json:"page,omitempty"`
|
||||
PageSize int64 `protobuf:"varint,4,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *GetUserListRequest) Reset() { *m = GetUserListRequest{} }
|
||||
func (m *GetUserListRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*GetUserListRequest) ProtoMessage() {}
|
||||
func (*GetUserListRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_d570e3e37e5899c5, []int{0}
|
||||
}
|
||||
|
||||
func (m *GetUserListRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_GetUserListRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *GetUserListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_GetUserListRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *GetUserListRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GetUserListRequest.Merge(m, src)
|
||||
}
|
||||
func (m *GetUserListRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_GetUserListRequest.Size(m)
|
||||
}
|
||||
func (m *GetUserListRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GetUserListRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GetUserListRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *GetUserListRequest) GetUsername() string {
|
||||
if m != nil {
|
||||
return m.Username
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *GetUserListRequest) GetNickname() string {
|
||||
if m != nil {
|
||||
return m.Nickname
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *GetUserListRequest) GetPage() int64 {
|
||||
if m != nil {
|
||||
return m.Page
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *GetUserListRequest) GetPageSize() int64 {
|
||||
if m != nil {
|
||||
return m.PageSize
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
||||
Nickname string `protobuf:"bytes,3,opt,name=nickname,proto3" json:"nickname,omitempty"`
|
||||
IsAdmin bool `protobuf:"varint,4,opt,name=is_admin,json=isAdmin,proto3" json:"is_admin,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *User) Reset() { *m = User{} }
|
||||
func (m *User) String() string { return proto.CompactTextString(m) }
|
||||
func (*User) ProtoMessage() {}
|
||||
func (*User) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_d570e3e37e5899c5, []int{1}
|
||||
}
|
||||
|
||||
func (m *User) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_User.Unmarshal(m, b)
|
||||
}
|
||||
func (m *User) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_User.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *User) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_User.Merge(m, src)
|
||||
}
|
||||
func (m *User) XXX_Size() int {
|
||||
return xxx_messageInfo_User.Size(m)
|
||||
}
|
||||
func (m *User) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_User.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_User proto.InternalMessageInfo
|
||||
|
||||
func (m *User) GetId() int64 {
|
||||
if m != nil {
|
||||
return m.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *User) GetUsername() string {
|
||||
if m != nil {
|
||||
return m.Username
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *User) GetNickname() string {
|
||||
if m != nil {
|
||||
return m.Nickname
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *User) GetIsAdmin() bool {
|
||||
if m != nil {
|
||||
return m.IsAdmin
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type GetUserListReply struct {
|
||||
List []*User `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"`
|
||||
Pager *Pager `protobuf:"bytes,2,opt,name=pager,proto3" json:"pager,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *GetUserListReply) Reset() { *m = GetUserListReply{} }
|
||||
func (m *GetUserListReply) String() string { return proto.CompactTextString(m) }
|
||||
func (*GetUserListReply) ProtoMessage() {}
|
||||
func (*GetUserListReply) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_d570e3e37e5899c5, []int{2}
|
||||
}
|
||||
|
||||
func (m *GetUserListReply) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_GetUserListReply.Unmarshal(m, b)
|
||||
}
|
||||
func (m *GetUserListReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_GetUserListReply.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *GetUserListReply) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GetUserListReply.Merge(m, src)
|
||||
}
|
||||
func (m *GetUserListReply) XXX_Size() int {
|
||||
return xxx_messageInfo_GetUserListReply.Size(m)
|
||||
}
|
||||
func (m *GetUserListReply) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GetUserListReply.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GetUserListReply proto.InternalMessageInfo
|
||||
|
||||
func (m *GetUserListReply) GetList() []*User {
|
||||
if m != nil {
|
||||
return m.List
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GetUserListReply) GetPager() *Pager {
|
||||
if m != nil {
|
||||
return m.Pager
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*GetUserListRequest)(nil), "GetUserListRequest")
|
||||
proto.RegisterType((*User)(nil), "User")
|
||||
proto.RegisterType((*GetUserListReply)(nil), "GetUserListReply")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("proto/user.proto", fileDescriptor_d570e3e37e5899c5) }
|
||||
|
||||
var fileDescriptor_d570e3e37e5899c5 = []byte{
|
||||
// 300 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0xbf, 0x4b, 0x03, 0x31,
|
||||
0x14, 0xf6, 0x7e, 0xb4, 0x5e, 0xdf, 0x81, 0xd4, 0xb8, 0x5c, 0xab, 0x43, 0xb9, 0xa9, 0x20, 0xcd,
|
||||
0x41, 0x1d, 0x9c, 0x75, 0xb0, 0x83, 0x0e, 0x92, 0xe2, 0xe2, 0x52, 0xce, 0xeb, 0xa3, 0x3c, 0xda,
|
||||
0x4b, 0x6a, 0x92, 0x2b, 0x58, 0xf0, 0x7f, 0x97, 0xe4, 0x50, 0x6c, 0x05, 0xa7, 0xf7, 0xfd, 0x48,
|
||||
0xf2, 0x7d, 0x49, 0xa0, 0xbf, 0xd5, 0xca, 0xaa, 0xa2, 0x31, 0xa8, 0xb9, 0x87, 0x43, 0xd6, 0x2a,
|
||||
0x95, 0xaa, 0x6b, 0x25, 0x5b, 0x2d, 0xff, 0x04, 0x36, 0x43, 0xfb, 0x62, 0x50, 0x3f, 0x91, 0xb1,
|
||||
0x02, 0xdf, 0x1b, 0x34, 0x96, 0x0d, 0x21, 0x71, 0xfb, 0x64, 0x59, 0x63, 0x16, 0x8c, 0x82, 0x71,
|
||||
0x4f, 0xfc, 0x70, 0xe7, 0x49, 0xaa, 0xd6, 0xde, 0x0b, 0x5b, 0xef, 0x9b, 0x33, 0x06, 0xf1, 0xb6,
|
||||
0x5c, 0x61, 0x16, 0x8d, 0x82, 0x71, 0x24, 0x3c, 0x66, 0x97, 0xd0, 0x73, 0x73, 0x61, 0x68, 0x8f,
|
||||
0x59, 0xec, 0x8d, 0xc4, 0x09, 0x73, 0xda, 0x63, 0x4e, 0x10, 0xbb, 0x6c, 0x76, 0x06, 0x21, 0x2d,
|
||||
0x7d, 0x54, 0x24, 0x42, 0x5a, 0x1e, 0x14, 0x08, 0xff, 0x29, 0x10, 0x1d, 0x15, 0x18, 0x40, 0x42,
|
||||
0x66, 0x51, 0x2e, 0x6b, 0x92, 0x3e, 0x2b, 0x11, 0xa7, 0x64, 0xee, 0x1c, 0xcd, 0x1f, 0xa1, 0x7f,
|
||||
0x70, 0xd3, 0xed, 0xe6, 0x83, 0x0d, 0x20, 0xde, 0x90, 0xb1, 0x59, 0x30, 0x8a, 0xc6, 0xe9, 0xb4,
|
||||
0xc3, 0x9d, 0x2b, 0xbc, 0xc4, 0xae, 0xa0, 0xe3, 0x5a, 0x6a, 0x1f, 0x9f, 0x4e, 0xbb, 0xfc, 0xd9,
|
||||
0x31, 0xd1, 0x8a, 0xd3, 0x07, 0x48, 0xdd, 0xda, 0x39, 0xea, 0x1d, 0x55, 0xc8, 0x6e, 0x21, 0xfd,
|
||||
0x75, 0x36, 0xbb, 0xe0, 0x7f, 0xdf, 0x74, 0x78, 0xce, 0x8f, 0xe3, 0xf3, 0x93, 0xfb, 0xc9, 0xeb,
|
||||
0xf5, 0x8a, 0xec, 0x86, 0xe4, 0x9a, 0x2b, 0xbd, 0xe2, 0x95, 0x2c, 0x66, 0x2d, 0x2d, 0xca, 0xaa,
|
||||
0x52, 0x8d, 0xb4, 0x13, 0x83, 0x7a, 0x87, 0xba, 0xf0, 0xbf, 0xf5, 0xd6, 0xf5, 0xe3, 0xe6, 0x2b,
|
||||
0x00, 0x00, 0xff, 0xff, 0xc0, 0x21, 0xcf, 0x3d, 0xdc, 0x01, 0x00, 0x00,
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
syntax = "proto3";
|
||||
|
||||
option go_package= "gitlink.org.cn/Gitlink/account-server/proto";
|
||||
|
||||
import "proto/common.proto";
|
||||
|
||||
service UserService {
|
||||
rpc GetUserList(GetUserListRequest) returns (GetUserListReply) {}
|
||||
}
|
||||
|
||||
message GetUserListRequest {
|
||||
string username = 1;
|
||||
string nickname = 2;
|
||||
int64 page = 3;
|
||||
int64 page_size = 4;
|
||||
}
|
||||
|
||||
message User {
|
||||
int64 id = 1;
|
||||
string username = 2;
|
||||
string nickname = 3;
|
||||
bool is_admin = 4;
|
||||
}
|
||||
|
||||
message GetUserListReply {
|
||||
repeated User list = 1;
|
||||
Pager pager = 2;
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package proto
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// UserServiceClient is the client API for UserService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type UserServiceClient interface {
|
||||
GetUserList(ctx context.Context, in *GetUserListRequest, opts ...grpc.CallOption) (*GetUserListReply, error)
|
||||
}
|
||||
|
||||
type userServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient {
|
||||
return &userServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *userServiceClient) GetUserList(ctx context.Context, in *GetUserListRequest, opts ...grpc.CallOption) (*GetUserListReply, error) {
|
||||
out := new(GetUserListReply)
|
||||
err := c.cc.Invoke(ctx, "/UserService/GetUserList", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserServiceServer is the server API for UserService service.
|
||||
// All implementations must embed UnimplementedUserServiceServer
|
||||
// for forward compatibility
|
||||
type UserServiceServer interface {
|
||||
GetUserList(context.Context, *GetUserListRequest) (*GetUserListReply, error)
|
||||
mustEmbedUnimplementedUserServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedUserServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedUserServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedUserServiceServer) GetUserList(context.Context, *GetUserListRequest) (*GetUserListReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetUserList not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {}
|
||||
|
||||
// UnsafeUserServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to UserServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeUserServiceServer interface {
|
||||
mustEmbedUnimplementedUserServiceServer()
|
||||
}
|
||||
|
||||
func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) {
|
||||
s.RegisterService(&UserService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _UserService_GetUserList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUserListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).GetUserList(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/UserService/GetUserList",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).GetUserList(ctx, req.(*GetUserListRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// UserService_ServiceDesc is the grpc.ServiceDesc for UserService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var UserService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "UserService",
|
||||
HandlerType: (*UserServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetUserList",
|
||||
Handler: _UserService_GetUserList_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "proto/user.proto",
|
||||
}
|
|
@ -10,26 +10,26 @@ import (
|
|||
pb "gitlink.org.cn/Gitlink/account-server/proto"
|
||||
)
|
||||
|
||||
type TemplateServer struct {
|
||||
pb.UnimplementedTemplateServiceServer
|
||||
type UserServer struct {
|
||||
pb.UnimplementedUserServiceServer
|
||||
}
|
||||
|
||||
func NewTemplateServer() *TemplateServer {
|
||||
return &TemplateServer{}
|
||||
func NewUserServer() *UserServer {
|
||||
return &UserServer{}
|
||||
}
|
||||
|
||||
func (t *TemplateServer) GetTemplateList(ctx context.Context, r *pb.GetTemplateListRequest) (*pb.GetTemplateListReply, error) {
|
||||
func (t *UserServer) GetUserList(ctx context.Context, r *pb.GetUserListRequest) (*pb.GetUserListReply, error) {
|
||||
svc := service.New(ctx)
|
||||
dbTemplateList, err := svc.Dao.GetTemplateList(r.GetName(), int(r.GetUuid()), int(r.GetPage()), int(r.GetPageSize()))
|
||||
dbUserList, err := svc.Dao.GetUserList(r.GetUsername(), r.GetNickname(), int(r.GetPage()), int(r.GetPageSize()))
|
||||
if err != nil {
|
||||
return nil, rpc.ToRpcError(rpc.RpcErrorGetTemplateListFail)
|
||||
return nil, rpc.ToRpcError(rpc.RpcErrorGetListFail)
|
||||
}
|
||||
total, err := svc.Dao.CountTemplate(r.GetName(), int(r.GetUuid()))
|
||||
total, err := svc.Dao.CountUser(r.GetUsername(), r.GetNickname())
|
||||
if err != nil {
|
||||
return nil, rpc.ToRpcError(rpc.RpcErrorCountTemplateFail)
|
||||
return nil, rpc.ToRpcError(rpc.RpcErrorCountFail)
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"list": dbTemplateList,
|
||||
"list": dbUserList,
|
||||
"pager": app.Pager{
|
||||
Page: int(r.GetPage()),
|
||||
PageSize: int(r.GetPageSize()),
|
||||
|
@ -40,7 +40,7 @@ func (t *TemplateServer) GetTemplateList(ctx context.Context, r *pb.GetTemplateL
|
|||
if err != nil {
|
||||
return nil, rpc.ToRpcError(rpc.RpcInvalidParams)
|
||||
}
|
||||
userList := pb.GetTemplateListReply{}
|
||||
userList := pb.GetUserListReply{}
|
||||
err = json.Unmarshal(byteData, &userList)
|
||||
if err != nil {
|
||||
return nil, rpc.ToRpcError(rpc.RpcInvalidParams)
|
||||
|
|
Loading…
Reference in New Issue