feat: Add swagger support

This commit is contained in:
chris
2023-09-03 20:44:31 +08:00
parent 963247b6d0
commit aa00079f15
14 changed files with 865 additions and 1434 deletions

200
docs/docs.go Normal file
View File

@@ -0,0 +1,200 @@
// Package docs 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}}",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/login": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户模块"
],
"summary": "账号登录",
"parameters": [
{
"description": "params",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_internal_pkg_request.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_internal_pkg_response.Response"
}
}
}
}
},
"/register": {
"post": {
"description": "目前只支持邮箱登录",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户模块"
],
"summary": "用户注册",
"parameters": [
{
"description": "params",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_internal_pkg_request.RegisterRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_internal_pkg_response.Response"
}
}
}
}
},
"/user": {
"get": {
"security": [
{
"Bearer": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户模块"
],
"summary": "获取用户信息",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/github_com_go-nunu_nunu-layout-advanced_internal_pkg_response.Response"
}
}
}
}
}
},
"definitions": {
"github_com_go-nunu_nunu-layout-advanced_internal_pkg_request.LoginRequest": {
"type": "object",
"required": [
"password",
"username"
],
"properties": {
"password": {
"type": "string",
"example": "123456"
},
"username": {
"type": "string",
"example": "alan"
}
}
},
"github_com_go-nunu_nunu-layout-advanced_internal_pkg_request.RegisterRequest": {
"type": "object",
"required": [
"email",
"password",
"username"
],
"properties": {
"email": {
"type": "string",
"example": "1234@gmail.com"
},
"password": {
"type": "string",
"example": "123456"
},
"username": {
"type": "string",
"example": "alan"
}
}
},
"github_com_go-nunu_nunu-layout-advanced_internal_pkg_response.Response": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"data": {},
"message": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0.0",
Host: "localhost:8000",
BasePath: "/",
Schemes: []string{},
Title: "Nunu Example API",
Description: "This is a sample server celler server.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}