S SmartDocs
Chuỗi bài: Go go 422 dòng · Cập nhật 2026-04-18

docs.go

Go/Baasid/docs/docs.go

// 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": "https://github.com/example/baasid",
            "email": "support@example.com"
        },
        "license": {
            "name": "MIT",
            "url": "https://opensource.org/licenses/MIT"
        },
        "version": "{{.Version}}"
    },
    "host": "{{.Host}}",
    "basePath": "{{.BasePath}}",
    "paths": {
        "/auth/login": {
            "post": {
                "description": "驗證帳號密碼後簽發 JWT。成功時於 **Response Header** 的 ` + "`" + `Authorization` + "`" + ` 欄位回傳 Bearer Token,Body 回傳帳號與姓名。",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "auth"
                ],
                "summary": "用戶登入",
                "parameters": [
                    {
                        "description": "登入帳號與密碼",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.LoginRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功;並於 Header ` + "`" + `Authorization` + "`" + ` 帶入 JWT",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.LoginResponse"
                        }
                    },
                    "401": {
                        "description": "帳號密碼錯誤",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "500": {
                        "description": "系統錯誤",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    }
                }
            }
        },
        "/goods": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "回傳陣列,每個元素為 ` + "`" + `_id` + "`" + ` 與 ` + "`" + `goods_name` + "`" + `。",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "goods"
                ],
                "summary": "取得所有商品",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/baasid_internal_dto.GoodsResponse"
                            }
                        }
                    },
                    "403": {
                        "description": "權限不足",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "500": {
                        "description": "系統錯誤",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    }
                }
            }
        },
        "/goods/add": {
            "post": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "建立一筆商品;需帶入有效 JWT。成功回傳新商品的 ` + "`" + `_id` + "`" + ` 與 ` + "`" + `goods_name` + "`" + `。",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "goods"
                ],
                "summary": "新增商品",
                "parameters": [
                    {
                        "description": "商品名稱 goods_name",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.GoodsCreateRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.GoodsResponse"
                        }
                    },
                    "403": {
                        "description": "權限不足(未帶 Token 或 Token 無效)",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "500": {
                        "description": "系統錯誤",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    }
                }
            }
        },
        "/goods/{id}": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "路徑參數 ` + "`" + `id` + "`" + ` 為商品 UUID(字串格式)。",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "goods"
                ],
                "summary": "取得指定商品",
                "parameters": [
                    {
                        "type": "string",
                        "description": "商品代號 (UUID)",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.GoodsResponse"
                        }
                    },
                    "403": {
                        "description": "權限不足",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "404": {
                        "description": "找不到商品",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "500": {
                        "description": "系統錯誤",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    }
                }
            },
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "依 ` + "`" + `id` + "`" + ` 更新商品名稱;` + "`" + `up_user` + "`" + ` / ` + "`" + `up_datetime` + "`" + ` 由後端寫入。",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "goods"
                ],
                "summary": "更新商品",
                "parameters": [
                    {
                        "type": "string",
                        "description": "商品代號 (UUID)",
                        "name": "id",
                        "in": "path",
                        "required": true
                    },
                    {
                        "description": "新商品名稱",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.GoodsUpdateRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.GoodsResponse"
                        }
                    },
                    "403": {
                        "description": "權限不足",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "404": {
                        "description": "找不到商品",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "500": {
                        "description": "系統錯誤",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    }
                }
            },
            "delete": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "依 ` + "`" + `id` + "`" + ` 刪除商品;成功僅回 HTTP 200(無 Body 亦可,此處回空 JSON 物件方便客戶端解析)。",
                "tags": [
                    "goods"
                ],
                "summary": "刪除商品",
                "parameters": [
                    {
                        "type": "string",
                        "description": "商品代號 (UUID)",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功,例如 {\\\"status\\\":\\\"ok\\\"}",
                        "schema": {
                            "type": "object",
                            "additionalProperties": {
                                "type": "string"
                            }
                        }
                    },
                    "403": {
                        "description": "權限不足",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "404": {
                        "description": "找不到商品",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    },
                    "500": {
                        "description": "系統錯誤",
                        "schema": {
                            "$ref": "#/definitions/baasid_internal_dto.ErrorMessage"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "baasid_internal_dto.ErrorMessage": {
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                }
            }
        },
        "baasid_internal_dto.GoodsCreateRequest": {
            "type": "object",
            "properties": {
                "goods_name": {
                    "type": "string",
                    "example": "Sample Product"
                }
            }
        },
        "baasid_internal_dto.GoodsResponse": {
            "type": "object",
            "properties": {
                "_id": {
                    "type": "string",
                    "example": "550e8400-e29b-41d4-a716-446655440000"
                },
                "goods_name": {
                    "type": "string",
                    "example": "Sample Product"
                }
            }
        },
        "baasid_internal_dto.GoodsUpdateRequest": {
            "type": "object",
            "properties": {
                "goods_name": {
                    "type": "string",
                    "example": "Updated name"
                }
            }
        },
        "baasid_internal_dto.LoginRequest": {
            "type": "object",
            "properties": {
                "account": {
                    "type": "string",
                    "example": "admin"
                },
                "password": {
                    "type": "string",
                    "example": "password123"
                }
            }
        },
        "baasid_internal_dto.LoginResponse": {
            "type": "object",
            "properties": {
                "account": {
                    "type": "string",
                    "example": "admin"
                },
                "name": {
                    "type": "string",
                    "example": "系統管理員"
                }
            }
        }
    },
    "securityDefinitions": {
        "BearerAuth": {
            "description": "填入 ` + "`" + `Bearer ` + "`" + ` 後接 JWT,例如:` + "`" + `Bearer eyJhbGciOiJIUzI1NiIs...` + "`" + `",
            "type": "apiKey",
            "name": "Authorization",
            "in": "header"
        }
    }
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
	Version:          "1.1",
	Host:             "localhost:8080",
	BasePath:         "/",
	Schemes:          []string{},
	Title:            "Baasid Backend API",
	Description:      "用戶登入成功後,Server 產生 JWT;之後商品 CRUD 請求皆須於 **Header** 帶入 `Authorization: Bearer <token>`。",
	InfoInstanceName: "swagger",
	SwaggerTemplate:  docTemplate,
	LeftDelim:        "{{",
	RightDelim:       "}}",
}

func init() {
	swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}

Bài viết liên quan