liuyuqi-cnb 2 months ago
parent
commit
67b6c8625e
4 changed files with 276 additions and 2 deletions
  1. 2 2
      back-go/cmd/filecloud.go
  2. 118 0
      back-go/docs/docs.go
  3. 94 0
      back-go/docs/swagger.json
  4. 62 0
      back-go/docs/swagger.yaml

+ 2 - 2
back-go/cmd/filecloud.go

@@ -10,7 +10,7 @@ import (
 	"filecloud/internal/database"
 	"filecloud/internal/database"
 	"filecloud/internal/handler"
 	"filecloud/internal/handler"
 	"filecloud/service"
 	"filecloud/service"
-	// _ "filecloud/docs"
+	_ "filecloud/docs"  // 取消注释,启用 Swagger 文档
 )
 )
 
 
 var (
 var (
@@ -35,7 +35,7 @@ func main() {
 
 
 	r := gin.Default()
 	r := gin.Default()
 
 
-	// 用本地静态文件服务替代 embed,改为 /static 路径
+	// 静态文件服务用 /static 前缀
 	r.Static("/static", "./public")
 	r.Static("/static", "./public")
 
 
 	// API routes
 	// API routes

+ 118 - 0
back-go/docs/docs.go

@@ -0,0 +1,118 @@
+// 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}}",
+        "contact": {},
+        "version": "{{.Version}}"
+    },
+    "host": "{{.Host}}",
+    "basePath": "{{.BasePath}}",
+    "paths": {
+        "/api/files": {
+            "get": {
+                "description": "Get a list of all files in the cloud storage",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "files"
+                ],
+                "summary": "List all files",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/model.File"
+                            }
+                        }
+                    }
+                }
+            },
+            "post": {
+                "description": "Upload a file to the cloud storage",
+                "consumes": [
+                    "multipart/form-data"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "files"
+                ],
+                "summary": "Upload a file",
+                "parameters": [
+                    {
+                        "type": "file",
+                        "description": "File to upload",
+                        "name": "file",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/model.File"
+                        }
+                    }
+                }
+            }
+        }
+    },
+    "definitions": {
+        "model.File": {
+            "type": "object",
+            "properties": {
+                "created_at": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "path": {
+                    "type": "string"
+                },
+                "size": {
+                    "type": "integer"
+                },
+                "type": {
+                    "type": "string"
+                },
+                "updated_at": {
+                    "type": "string"
+                }
+            }
+        }
+    }
+}`
+
+// SwaggerInfo holds exported Swagger Info so clients can modify it
+var SwaggerInfo = &swag.Spec{
+	Version:          "1.0",
+	Host:             "localhost:8080",
+	BasePath:         "/api",
+	Schemes:          []string{},
+	Title:            "FileCloud API",
+	Description:      "FileCloud API documentation",
+	InfoInstanceName: "swagger",
+	SwaggerTemplate:  docTemplate,
+	LeftDelim:        "{{",
+	RightDelim:       "}}",
+}
+
+func init() {
+	swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
+}

+ 94 - 0
back-go/docs/swagger.json

@@ -0,0 +1,94 @@
+{
+    "swagger": "2.0",
+    "info": {
+        "description": "FileCloud API documentation",
+        "title": "FileCloud API",
+        "contact": {},
+        "version": "1.0"
+    },
+    "host": "localhost:8080",
+    "basePath": "/api",
+    "paths": {
+        "/api/files": {
+            "get": {
+                "description": "Get a list of all files in the cloud storage",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "files"
+                ],
+                "summary": "List all files",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/model.File"
+                            }
+                        }
+                    }
+                }
+            },
+            "post": {
+                "description": "Upload a file to the cloud storage",
+                "consumes": [
+                    "multipart/form-data"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "files"
+                ],
+                "summary": "Upload a file",
+                "parameters": [
+                    {
+                        "type": "file",
+                        "description": "File to upload",
+                        "name": "file",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/model.File"
+                        }
+                    }
+                }
+            }
+        }
+    },
+    "definitions": {
+        "model.File": {
+            "type": "object",
+            "properties": {
+                "created_at": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "path": {
+                    "type": "string"
+                },
+                "size": {
+                    "type": "integer"
+                },
+                "type": {
+                    "type": "string"
+                },
+                "updated_at": {
+                    "type": "string"
+                }
+            }
+        }
+    }
+}

+ 62 - 0
back-go/docs/swagger.yaml

@@ -0,0 +1,62 @@
+basePath: /api
+definitions:
+  model.File:
+    properties:
+      created_at:
+        type: string
+      id:
+        type: integer
+      name:
+        type: string
+      path:
+        type: string
+      size:
+        type: integer
+      type:
+        type: string
+      updated_at:
+        type: string
+    type: object
+host: localhost:8080
+info:
+  contact: {}
+  description: FileCloud API documentation
+  title: FileCloud API
+  version: "1.0"
+paths:
+  /api/files:
+    get:
+      description: Get a list of all files in the cloud storage
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/model.File'
+            type: array
+      summary: List all files
+      tags:
+      - files
+    post:
+      consumes:
+      - multipart/form-data
+      description: Upload a file to the cloud storage
+      parameters:
+      - description: File to upload
+        in: formData
+        name: file
+        required: true
+        type: file
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/model.File'
+      summary: Upload a file
+      tags:
+      - files
+swagger: "2.0"