Browse Source

代码更新

huangyan 1 year ago
parent
commit
c025208deb
4 changed files with 859 additions and 0 deletions
  1. 24 0
      app/middlewares/cors.go
  2. 322 0
      docs/docs.go
  3. 300 0
      docs/swagger.json
  4. 213 0
      docs/swagger.yaml

+ 24 - 0
app/middlewares/cors.go

@@ -0,0 +1,24 @@
+package middleware
+
+import (
+	"github.com/gin-gonic/gin"
+	"net/http"
+)
+
+func Cors() gin.HandlerFunc {
+	return func(c *gin.Context) {
+		method := c.Request.Method
+		origin := c.Request.Header.Get("Origin")
+		if origin != "" {
+			c.Header("Access-Control-Allow-Origin", "*") // 可将将 * 替换为指定的域名
+			c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
+			c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
+			c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
+			c.Header("Access-Control-Allow-Credentials", "true")
+		}
+		if method == "OPTIONS" {
+			c.AbortWithStatus(http.StatusNoContent)
+		}
+		c.Next()
+	}
+}

+ 322 - 0
docs/docs.go

@@ -0,0 +1,322 @@
+// Code generated by swaggo/swag. DO NOT EDIT
+package docs
+
+import "github.com/swaggo/swag"
+
+const docTemplate = `{
+    "schemes": {{ marshal .Schemes }},
+    "swagger": "2.0",
+    "info": {
+        "description": "{{escape .Description}}",
+        "title": "{{.Title}}",
+        "contact": {},
+        "version": "{{.Version}}"
+    },
+    "host": "{{.Host}}",
+    "basePath": "{{.BasePath}}",
+    "paths": {
+        "/admin/getalluser": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "获取所有用户",
+                "parameters": [
+                    {
+                        "description": "分页信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/page.PageParams"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/admin/user": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "获取所有用户",
+                "parameters": [
+                    {
+                        "description": "分页信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/page.PageParams"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            },
+            "delete": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "删除用户",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/codelogin": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "验证码登录",
+                "parameters": [
+                    {
+                        "description": "账号信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.UserRegist"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/sendcode": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "发送验证码",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "手机号",
+                        "name": "phone",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/user": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "账号密码登录",
+                "parameters": [
+                    {
+                        "description": "账号信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.UserRegist"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        }
+    },
+    "definitions": {
+        "e.R": {
+            "type": "object",
+            "properties": {
+                "code": {
+                    "$ref": "#/definitions/e.Rescode"
+                },
+                "data": {},
+                "message": {}
+            }
+        },
+        "e.Rescode": {
+            "type": "integer",
+            "enum": [
+                200,
+                201,
+                1001,
+                1002,
+                1003,
+                1004,
+                1005,
+                1006,
+                1007,
+                1008,
+                1009,
+                1010,
+                1011,
+                1012,
+                1013,
+                1014,
+                1015,
+                1016,
+                1017
+            ],
+            "x-enum-varnames": [
+                "SUCCESS",
+                "ERROR",
+                "TokenIsInvalid",
+                "TokenIsExpired",
+                "DELETEFAIL",
+                "UPDATEFAIL",
+                "PaginationFailed",
+                "JSONParsingFailed",
+                "TheUserAlreadyExists",
+                "AlreadyExists",
+                "TheSystemIsAbnormal",
+                "CodeIsError",
+                "Theuseralreadyexists",
+                "ThePhoneNumberIsWrong",
+                "AnExceptionOccursWhenSendingAnSMSVerificationCode",
+                "TokenIsFaild",
+                "ThePasswordIsWrongOrThePhoneNumberIsIncorrect",
+                "HasSend",
+                "TheUserIsEmpty"
+            ]
+        },
+        "models.UserRegist": {
+            "type": "object",
+            "required": [
+                "account",
+                "code",
+                "password",
+                "phone",
+                "username"
+            ],
+            "properties": {
+                "account": {
+                    "description": "账号",
+                    "type": "string",
+                    "maxLength": 20,
+                    "minLength": 6
+                },
+                "code": {
+                    "description": "验证码",
+                    "type": "string",
+                    "maxLength": 6,
+                    "minLength": 6
+                },
+                "password": {
+                    "description": "密码",
+                    "type": "string",
+                    "maxLength": 20,
+                    "minLength": 6
+                },
+                "phone": {
+                    "description": "手机号",
+                    "type": "string",
+                    "maxLength": 11,
+                    "minLength": 11
+                },
+                "username": {
+                    "description": "用户名",
+                    "type": "string",
+                    "maxLength": 20,
+                    "minLength": 2
+                }
+            }
+        },
+        "page.PageParams": {
+            "type": "object",
+            "properties": {
+                "desc": {
+                    "type": "string"
+                },
+                "page": {
+                    "type": "integer"
+                },
+                "size": {
+                    "type": "integer"
+                }
+            }
+        }
+    }
+}`
+
+// SwaggerInfo holds exported Swagger Info so clients can modify it
+var SwaggerInfo = &swag.Spec{
+	Version:          "1.0",
+	Host:             "127.0.0.1:8080",
+	BasePath:         "/api",
+	Schemes:          []string{},
+	Title:            "统一登录平台",
+	Description:      "统一登录平台",
+	InfoInstanceName: "swagger",
+	SwaggerTemplate:  docTemplate,
+}
+
+func init() {
+	swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
+}

+ 300 - 0
docs/swagger.json

@@ -0,0 +1,300 @@
+{
+    "swagger": "2.0",
+    "info": {
+        "description": "统一登录平台",
+        "title": "统一登录平台",
+        "contact": {},
+        "version": "1.0"
+    },
+    "host": "127.0.0.1:8080",
+    "basePath": "/api",
+    "paths": {
+        "/admin/getalluser": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "获取所有用户",
+                "parameters": [
+                    {
+                        "description": "分页信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/page.PageParams"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/admin/user": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "获取所有用户",
+                "parameters": [
+                    {
+                        "description": "分页信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/page.PageParams"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            },
+            "delete": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "删除用户",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "id",
+                        "name": "id",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/codelogin": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "验证码登录",
+                "parameters": [
+                    {
+                        "description": "账号信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.UserRegist"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/sendcode": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "发送验证码",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "手机号",
+                        "name": "phone",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        },
+        "/user": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户管理"
+                ],
+                "summary": "账号密码登录",
+                "parameters": [
+                    {
+                        "description": "账号信息",
+                        "name": "req",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.UserRegist"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/e.R"
+                        }
+                    }
+                }
+            }
+        }
+    },
+    "definitions": {
+        "e.R": {
+            "type": "object",
+            "properties": {
+                "code": {
+                    "$ref": "#/definitions/e.Rescode"
+                },
+                "data": {},
+                "message": {}
+            }
+        },
+        "e.Rescode": {
+            "type": "integer",
+            "enum": [
+                200,
+                201,
+                1001,
+                1002,
+                1003,
+                1004,
+                1005,
+                1006,
+                1007,
+                1008,
+                1009,
+                1010,
+                1011,
+                1012,
+                1013,
+                1014,
+                1015,
+                1016,
+                1017
+            ],
+            "x-enum-varnames": [
+                "SUCCESS",
+                "ERROR",
+                "TokenIsInvalid",
+                "TokenIsExpired",
+                "DELETEFAIL",
+                "UPDATEFAIL",
+                "PaginationFailed",
+                "JSONParsingFailed",
+                "TheUserAlreadyExists",
+                "AlreadyExists",
+                "TheSystemIsAbnormal",
+                "CodeIsError",
+                "Theuseralreadyexists",
+                "ThePhoneNumberIsWrong",
+                "AnExceptionOccursWhenSendingAnSMSVerificationCode",
+                "TokenIsFaild",
+                "ThePasswordIsWrongOrThePhoneNumberIsIncorrect",
+                "HasSend",
+                "TheUserIsEmpty"
+            ]
+        },
+        "models.UserRegist": {
+            "type": "object",
+            "required": [
+                "account",
+                "code",
+                "password",
+                "phone",
+                "username"
+            ],
+            "properties": {
+                "account": {
+                    "description": "账号",
+                    "type": "string",
+                    "maxLength": 20,
+                    "minLength": 6
+                },
+                "code": {
+                    "description": "验证码",
+                    "type": "string",
+                    "maxLength": 6,
+                    "minLength": 6
+                },
+                "password": {
+                    "description": "密码",
+                    "type": "string",
+                    "maxLength": 20,
+                    "minLength": 6
+                },
+                "phone": {
+                    "description": "手机号",
+                    "type": "string",
+                    "maxLength": 11,
+                    "minLength": 11
+                },
+                "username": {
+                    "description": "用户名",
+                    "type": "string",
+                    "maxLength": 20,
+                    "minLength": 2
+                }
+            }
+        },
+        "page.PageParams": {
+            "type": "object",
+            "properties": {
+                "desc": {
+                    "type": "string"
+                },
+                "page": {
+                    "type": "integer"
+                },
+                "size": {
+                    "type": "integer"
+                }
+            }
+        }
+    }
+}

+ 213 - 0
docs/swagger.yaml

@@ -0,0 +1,213 @@
+basePath: /api
+definitions:
+  e.R:
+    properties:
+      code:
+        $ref: '#/definitions/e.Rescode'
+      data: {}
+      message: {}
+    type: object
+  e.Rescode:
+    enum:
+    - 200
+    - 201
+    - 1001
+    - 1002
+    - 1003
+    - 1004
+    - 1005
+    - 1006
+    - 1007
+    - 1008
+    - 1009
+    - 1010
+    - 1011
+    - 1012
+    - 1013
+    - 1014
+    - 1015
+    - 1016
+    - 1017
+    type: integer
+    x-enum-varnames:
+    - SUCCESS
+    - ERROR
+    - TokenIsInvalid
+    - TokenIsExpired
+    - DELETEFAIL
+    - UPDATEFAIL
+    - PaginationFailed
+    - JSONParsingFailed
+    - TheUserAlreadyExists
+    - AlreadyExists
+    - TheSystemIsAbnormal
+    - CodeIsError
+    - Theuseralreadyexists
+    - ThePhoneNumberIsWrong
+    - AnExceptionOccursWhenSendingAnSMSVerificationCode
+    - TokenIsFaild
+    - ThePasswordIsWrongOrThePhoneNumberIsIncorrect
+    - HasSend
+    - TheUserIsEmpty
+  models.UserRegist:
+    properties:
+      account:
+        description: 账号
+        maxLength: 20
+        minLength: 6
+        type: string
+      code:
+        description: 验证码
+        maxLength: 6
+        minLength: 6
+        type: string
+      password:
+        description: 密码
+        maxLength: 20
+        minLength: 6
+        type: string
+      phone:
+        description: 手机号
+        maxLength: 11
+        minLength: 11
+        type: string
+      username:
+        description: 用户名
+        maxLength: 20
+        minLength: 2
+        type: string
+    required:
+    - account
+    - code
+    - password
+    - phone
+    - username
+    type: object
+  page.PageParams:
+    properties:
+      desc:
+        type: string
+      page:
+        type: integer
+      size:
+        type: integer
+    type: object
+host: 127.0.0.1:8080
+info:
+  contact: {}
+  description: 统一登录平台
+  title: 统一登录平台
+  version: "1.0"
+paths:
+  /admin/getalluser:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 分页信息
+        in: body
+        name: req
+        required: true
+        schema:
+          $ref: '#/definitions/page.PageParams'
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/e.R'
+      summary: 获取所有用户
+      tags:
+      - 用户管理
+  /admin/user:
+    delete:
+      consumes:
+      - application/json
+      parameters:
+      - description: id
+        in: query
+        name: id
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/e.R'
+      summary: 删除用户
+      tags:
+      - 用户管理
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 分页信息
+        in: body
+        name: req
+        required: true
+        schema:
+          $ref: '#/definitions/page.PageParams'
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/e.R'
+      summary: 获取所有用户
+      tags:
+      - 用户管理
+  /codelogin:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 账号信息
+        in: body
+        name: req
+        required: true
+        schema:
+          $ref: '#/definitions/models.UserRegist'
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/e.R'
+      summary: 验证码登录
+      tags:
+      - 用户管理
+  /sendcode:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 手机号
+        in: query
+        name: phone
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/e.R'
+      summary: 发送验证码
+      tags:
+      - 用户管理
+  /user:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 账号信息
+        in: body
+        name: req
+        required: true
+        schema:
+          $ref: '#/definitions/models.UserRegist'
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/e.R'
+      summary: 账号密码登录
+      tags:
+      - 用户管理
+swagger: "2.0"