feat: 完善后端脚手架基础能力

This commit is contained in:
2026-08-09 01:06:21 +08:00
parent e311f416f2
commit f95311a107
61 changed files with 5630 additions and 521 deletions
+458
View File
@@ -0,0 +1,458 @@
// 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": {
"/auth/login": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "用户登录",
"parameters": [
{
"description": "登录信息",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.Credentials"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/middlewares.TokenPair"
}
}
}
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
},
"/auth/refresh": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "刷新并轮换 Token",
"parameters": [
{
"description": "Refresh Token",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.RefreshRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/middlewares.TokenPair"
}
}
}
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
},
"/auth/register": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "注册示例用户",
"parameters": [
{
"description": "注册信息",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.Credentials"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/auth.UserResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
},
"409": {
"description": "Conflict",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
},
"/example/hello": {
"get": {
"produces": [
"application/json"
],
"tags": [
"example"
],
"summary": "返回示例消息",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/example.HelloResponse"
}
}
}
]
}
}
}
}
},
"/health": {
"get": {
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "服务健康检查",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/rest.systemResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/rest.healthData"
}
}
}
]
}
},
"503": {
"description": "Service Unavailable",
"schema": {
"allOf": [
{
"$ref": "#/definitions/rest.systemResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/rest.healthData"
}
}
}
]
}
}
}
}
},
"/ping": {
"get": {
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "服务连通性检查",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/rest.systemResponse"
}
}
}
}
},
"/private/auth/logout": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "注销并撤销 Token",
"parameters": [
{
"description": "可选 Refresh Token",
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/auth.LogoutRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
}
},
"definitions": {
"auth.Credentials": {
"type": "object",
"required": [
"password",
"username"
],
"properties": {
"password": {
"type": "string",
"maxLength": 72,
"minLength": 8,
"example": "change-me-123"
},
"username": {
"type": "string",
"maxLength": 64,
"minLength": 3,
"example": "demo"
}
}
},
"auth.LogoutRequest": {
"type": "object",
"properties": {
"refresh_token": {
"type": "string"
}
}
},
"auth.RefreshRequest": {
"type": "object",
"required": [
"refresh_token"
],
"properties": {
"refresh_token": {
"type": "string"
}
}
},
"auth.UserResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"username": {
"type": "string"
}
}
},
"example.HelloResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
},
"middlewares.TokenPair": {
"type": "object",
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "integer",
"example": 900
},
"refresh_token": {
"type": "string"
},
"token_type": {
"type": "string",
"example": "Bearer"
}
}
},
"rest.healthData": {
"type": "object",
"properties": {
"database": {
"type": "string"
},
"redis": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"rest.systemResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 200
},
"data": {},
"message": {
"type": "string"
}
}
},
"utils.APIResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"data": {},
"message": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"BearerAuth": {
"description": "输入 Bearer {token}",
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "0.1.0",
Host: "",
BasePath: "/api",
Schemes: []string{},
Title: "Skeleton API",
Description: "Skeleton API documentation.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
+434
View File
@@ -0,0 +1,434 @@
{
"swagger": "2.0",
"info": {
"description": "Skeleton API documentation.",
"title": "Skeleton API",
"contact": {},
"version": "0.1.0"
},
"basePath": "/api",
"paths": {
"/auth/login": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "用户登录",
"parameters": [
{
"description": "登录信息",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.Credentials"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/middlewares.TokenPair"
}
}
}
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
},
"/auth/refresh": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "刷新并轮换 Token",
"parameters": [
{
"description": "Refresh Token",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.RefreshRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/middlewares.TokenPair"
}
}
}
]
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
},
"/auth/register": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "注册示例用户",
"parameters": [
{
"description": "注册信息",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.Credentials"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/auth.UserResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
},
"409": {
"description": "Conflict",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
},
"/example/hello": {
"get": {
"produces": [
"application/json"
],
"tags": [
"example"
],
"summary": "返回示例消息",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/example.HelloResponse"
}
}
}
]
}
}
}
}
},
"/health": {
"get": {
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "服务健康检查",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/rest.systemResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/rest.healthData"
}
}
}
]
}
},
"503": {
"description": "Service Unavailable",
"schema": {
"allOf": [
{
"$ref": "#/definitions/rest.systemResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/rest.healthData"
}
}
}
]
}
}
}
}
},
"/ping": {
"get": {
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "服务连通性检查",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/rest.systemResponse"
}
}
}
}
},
"/private/auth/logout": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "注销并撤销 Token",
"parameters": [
{
"description": "可选 Refresh Token",
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/auth.LogoutRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/utils.APIResponse"
}
}
}
}
}
},
"definitions": {
"auth.Credentials": {
"type": "object",
"required": [
"password",
"username"
],
"properties": {
"password": {
"type": "string",
"maxLength": 72,
"minLength": 8,
"example": "change-me-123"
},
"username": {
"type": "string",
"maxLength": 64,
"minLength": 3,
"example": "demo"
}
}
},
"auth.LogoutRequest": {
"type": "object",
"properties": {
"refresh_token": {
"type": "string"
}
}
},
"auth.RefreshRequest": {
"type": "object",
"required": [
"refresh_token"
],
"properties": {
"refresh_token": {
"type": "string"
}
}
},
"auth.UserResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"username": {
"type": "string"
}
}
},
"example.HelloResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
},
"middlewares.TokenPair": {
"type": "object",
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "integer",
"example": 900
},
"refresh_token": {
"type": "string"
},
"token_type": {
"type": "string",
"example": "Bearer"
}
}
},
"rest.healthData": {
"type": "object",
"properties": {
"database": {
"type": "string"
},
"redis": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"rest.systemResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 200
},
"data": {},
"message": {
"type": "string"
}
}
},
"utils.APIResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"data": {},
"message": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"BearerAuth": {
"description": "输入 Bearer {token}",
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}
+265
View File
@@ -0,0 +1,265 @@
basePath: /api
definitions:
auth.Credentials:
properties:
password:
example: change-me-123
maxLength: 72
minLength: 8
type: string
username:
example: demo
maxLength: 64
minLength: 3
type: string
required:
- password
- username
type: object
auth.LogoutRequest:
properties:
refresh_token:
type: string
type: object
auth.RefreshRequest:
properties:
refresh_token:
type: string
required:
- refresh_token
type: object
auth.UserResponse:
properties:
id:
type: integer
username:
type: string
type: object
example.HelloResponse:
properties:
message:
type: string
type: object
middlewares.TokenPair:
properties:
access_token:
type: string
expires_in:
example: 900
type: integer
refresh_token:
type: string
token_type:
example: Bearer
type: string
type: object
rest.healthData:
properties:
database:
type: string
redis:
type: string
status:
type: string
type: object
rest.systemResponse:
properties:
code:
example: 200
type: integer
data: {}
message:
type: string
type: object
utils.APIResponse:
properties:
code:
type: integer
data: {}
message:
type: string
type: object
info:
contact: {}
description: Skeleton API documentation.
title: Skeleton API
version: 0.1.0
paths:
/auth/login:
post:
consumes:
- application/json
parameters:
- description: 登录信息
in: body
name: body
required: true
schema:
$ref: '#/definitions/auth.Credentials'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/utils.APIResponse'
- properties:
data:
$ref: '#/definitions/middlewares.TokenPair'
type: object
"401":
description: Unauthorized
schema:
$ref: '#/definitions/utils.APIResponse'
summary: 用户登录
tags:
- auth
/auth/refresh:
post:
consumes:
- application/json
parameters:
- description: Refresh Token
in: body
name: body
required: true
schema:
$ref: '#/definitions/auth.RefreshRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/utils.APIResponse'
- properties:
data:
$ref: '#/definitions/middlewares.TokenPair'
type: object
"401":
description: Unauthorized
schema:
$ref: '#/definitions/utils.APIResponse'
summary: 刷新并轮换 Token
tags:
- auth
/auth/register:
post:
consumes:
- application/json
parameters:
- description: 注册信息
in: body
name: body
required: true
schema:
$ref: '#/definitions/auth.Credentials'
produces:
- application/json
responses:
"201":
description: Created
schema:
allOf:
- $ref: '#/definitions/utils.APIResponse'
- properties:
data:
$ref: '#/definitions/auth.UserResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/utils.APIResponse'
"409":
description: Conflict
schema:
$ref: '#/definitions/utils.APIResponse'
summary: 注册示例用户
tags:
- auth
/example/hello:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/utils.APIResponse'
- properties:
data:
$ref: '#/definitions/example.HelloResponse'
type: object
summary: 返回示例消息
tags:
- example
/health:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/rest.systemResponse'
- properties:
data:
$ref: '#/definitions/rest.healthData'
type: object
"503":
description: Service Unavailable
schema:
allOf:
- $ref: '#/definitions/rest.systemResponse'
- properties:
data:
$ref: '#/definitions/rest.healthData'
type: object
summary: 服务健康检查
tags:
- system
/ping:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/rest.systemResponse'
summary: 服务连通性检查
tags:
- system
/private/auth/logout:
post:
consumes:
- application/json
parameters:
- description: 可选 Refresh Token
in: body
name: body
schema:
$ref: '#/definitions/auth.LogoutRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/utils.APIResponse'
security:
- BearerAuth: []
summary: 注销并撤销 Token
tags:
- auth
securityDefinitions:
BearerAuth:
description: 输入 Bearer {token}
in: header
name: Authorization
type: apiKey
swagger: "2.0"