-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9ac6a0
commit 7dbf778
Showing
13 changed files
with
379 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// 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": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html" | ||
}, | ||
"version": "{{.Version}}" | ||
}, | ||
"host": "{{.Host}}", | ||
"basePath": "{{.BasePath}}", | ||
"paths": { | ||
"/api/v1/tags/{id}": { | ||
"put": { | ||
"description": "修改文章标签", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"文章管理" | ||
], | ||
"summary": "修改文章标签", | ||
"parameters": [ | ||
{ | ||
"type": "integer", | ||
"description": "ID", | ||
"name": "id", | ||
"in": "path", | ||
"required": true | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "ID", | ||
"name": "name", | ||
"in": "query", | ||
"required": true | ||
}, | ||
{ | ||
"type": "integer", | ||
"description": "State", | ||
"name": "state", | ||
"in": "query" | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "ModifiedBy", | ||
"name": "modified_by", | ||
"in": "query", | ||
"required": true | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "{\"code\":200,\"data\":{},\"msg\":\"ok\"}", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"BasicAuth": { | ||
"type": "basic" | ||
} | ||
}, | ||
"externalDocs": { | ||
"description": "OpenAPI", | ||
"url": "https://swagger.io/resources/open-api/" | ||
} | ||
}` | ||
|
||
// SwaggerInfo holds exported Swagger Info so clients can modify it | ||
var SwaggerInfo = &swag.Spec{ | ||
Version: "1.0", | ||
Host: "localhost:8080", | ||
BasePath: "/api/v1", | ||
Schemes: []string{}, | ||
Title: "Swagger Example API", | ||
Description: "This is a sample server celler server.", | ||
InfoInstanceName: "swagger", | ||
SwaggerTemplate: docTemplate, | ||
LeftDelim: "{{", | ||
RightDelim: "}}", | ||
} | ||
|
||
func init() { | ||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "This is a sample server celler server.", | ||
"title": "Swagger Example API", | ||
"termsOfService": "http://swagger.io/terms/", | ||
"contact": { | ||
"name": "API Support", | ||
"url": "http://www.swagger.io/support", | ||
"email": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html" | ||
}, | ||
"version": "1.0" | ||
}, | ||
"host": "localhost:8080", | ||
"basePath": "/api/v1", | ||
"paths": { | ||
"/api/v1/tags/{id}": { | ||
"put": { | ||
"description": "修改文章标签", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"文章管理" | ||
], | ||
"summary": "修改文章标签", | ||
"parameters": [ | ||
{ | ||
"type": "integer", | ||
"description": "ID", | ||
"name": "id", | ||
"in": "path", | ||
"required": true | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "ID", | ||
"name": "name", | ||
"in": "query", | ||
"required": true | ||
}, | ||
{ | ||
"type": "integer", | ||
"description": "State", | ||
"name": "state", | ||
"in": "query" | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "ModifiedBy", | ||
"name": "modified_by", | ||
"in": "query", | ||
"required": true | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "{\"code\":200,\"data\":{},\"msg\":\"ok\"}", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"BasicAuth": { | ||
"type": "basic" | ||
} | ||
}, | ||
"externalDocs": { | ||
"description": "OpenAPI", | ||
"url": "https://swagger.io/resources/open-api/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
basePath: /api/v1 | ||
externalDocs: | ||
description: OpenAPI | ||
url: https://swagger.io/resources/open-api/ | ||
host: localhost:8080 | ||
info: | ||
contact: | ||
email: [email protected] | ||
name: API Support | ||
url: http://www.swagger.io/support | ||
description: This is a sample server celler server. | ||
license: | ||
name: Apache 2.0 | ||
url: http://www.apache.org/licenses/LICENSE-2.0.html | ||
termsOfService: http://swagger.io/terms/ | ||
title: Swagger Example API | ||
version: "1.0" | ||
paths: | ||
/api/v1/tags/{id}: | ||
put: | ||
description: 修改文章标签 | ||
parameters: | ||
- description: ID | ||
in: path | ||
name: id | ||
required: true | ||
type: integer | ||
- description: ID | ||
in: query | ||
name: name | ||
required: true | ||
type: string | ||
- description: State | ||
in: query | ||
name: state | ||
type: integer | ||
- description: ModifiedBy | ||
in: query | ||
name: modified_by | ||
required: true | ||
type: string | ||
produces: | ||
- application/json | ||
responses: | ||
"200": | ||
description: '{"code":200,"data":{},"msg":"ok"}' | ||
schema: | ||
type: string | ||
summary: 修改文章标签 | ||
tags: | ||
- 文章管理 | ||
securityDefinitions: | ||
BasicAuth: | ||
type: basic | ||
swagger: "2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,38 @@ import ( | |
"github.com/infraboard/mcube/v2/ioc" | ||
"github.com/infraboard/mcube/v2/ioc/server" | ||
|
||
// 非业务模块 | ||
// 引入生成好的API Doc代码 | ||
_ "github.com/infraboard/mcube/v2/examples/http_gin/docs" | ||
// 引入集成工程 | ||
_ "github.com/infraboard/mcube/v2/ioc/apps/apidoc/swaggo" | ||
|
||
// 开启Health健康检查 | ||
_ "github.com/infraboard/mcube/v2/ioc/apps/health/gin" | ||
// 开启Metric | ||
_ "github.com/infraboard/mcube/v2/ioc/apps/metric/gin" | ||
// 开启CORS, 允许资源跨域共享 | ||
_ "github.com/infraboard/mcube/v2/ioc/config/cors" | ||
) | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample server celler server. | ||
// @termsOfService http://swagger.io/terms/ | ||
|
||
// @contact.name API Support | ||
// @contact.url http://www.swagger.io/support | ||
// @contact.email [email protected] | ||
|
||
// @license.name Apache 2.0 | ||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html | ||
|
||
// @host localhost:8080 | ||
// @BasePath /api/v1 | ||
|
||
// @securityDefinitions.basic BasicAuth | ||
|
||
// @externalDocs.description OpenAPI | ||
// @externalDocs.url https://swagger.io/resources/open-api/ | ||
func main() { | ||
// 注册HTTP接口类 | ||
ioc.Api().Registry(&HelloServiceApiHandler{}) | ||
|
@@ -42,9 +68,21 @@ func (h *HelloServiceApiHandler) Version() string { | |
|
||
// API路由 | ||
func (h *HelloServiceApiHandler) Registry(r gin.IRouter) { | ||
r.GET("/", func(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{ | ||
"data": "hello mcube", | ||
}) | ||
r.GET("/", h.Hello) | ||
} | ||
|
||
// @Summary 修改文章标签 | ||
// @Description 修改文章标签 | ||
// @Tags 文章管理 | ||
// @Produce json | ||
// @Param id path int true "ID" | ||
// @Param name query string true "ID" | ||
// @Param state query int false "State" | ||
// @Param modified_by query string true "ModifiedBy" | ||
// @Success 200 {string} json "{"code":200,"data":{},"msg":"ok"}" | ||
// @Router /api/v1/tags/{id} [put] | ||
func (h *HelloServiceApiHandler) Hello(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{ | ||
"data": "hello mcube", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.