API文档增加

pull/23/head
陶士涵 4 years ago
parent 2065c1eaf1
commit d0a274096c

@ -66,7 +66,7 @@ func run() {
//docs.SwaggerInfo.Host = "127.0.0.1:"+port
docs.SwaggerInfo.Host = "gofly.sopans.com"
docs.SwaggerInfo.BasePath = "/"
//docs.SwaggerInfo.Schemes = []string{"http"}
docs.SwaggerInfo.Schemes = []string{"https"}
engine.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
//logFile, _ := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660)

@ -175,6 +175,12 @@ func GetVisitorMessage(c *gin.Context) {
"result": result,
})
}
// @Summary 获取在线访客列表接口
// @Produce json
// @Success 200 {object} controller.Response
// @Failure 200 {object} controller.Response
// @Router /visitors_online [get]
func GetVisitorOnlines(c *gin.Context) {
users := make([]map[string]string, 0)
for uid, visitor := range clientList {

@ -1,17 +1,20 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2020-07-23 16:30:50.1490506 +0800 CST m=+0.137007801
// 2020-10-19 23:32:55.3852666 +0800 CST m=+0.208956401
package docs
import (
"bytes"
"encoding/json"
"strings"
"github.com/alecthomas/template"
"github.com/swaggo/swag"
)
var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
@ -59,7 +62,6 @@ var doc = `{
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
@ -109,7 +111,6 @@ var doc = `{
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
@ -145,7 +146,6 @@ var doc = `{
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
@ -181,7 +181,22 @@ var doc = `{
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
}
}
},
"/visitors_online": {
"get": {
"produces": [
"application/json"
],
"summary": "获取在线访客列表接口",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controller.Response"
}
}
@ -211,23 +226,39 @@ type swaggerInfo struct {
Version string
Host string
BasePath string
Schemes []string
Title string
Description string
}
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo swaggerInfo
var SwaggerInfo = swaggerInfo{
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
}
type s struct{}
func (s *s) ReadDoc() string {
t, err := template.New("swagger_info").Parse(doc)
sInfo := SwaggerInfo
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
t, err := template.New("swagger_info").Funcs(template.FuncMap{
"marshal": func(v interface{}) string {
a, _ := json.Marshal(v)
return string(a)
},
}).Parse(doc)
if err != nil {
return doc
}
var tpl bytes.Buffer
if err := t.Execute(&tpl, SwaggerInfo); err != nil {
if err := t.Execute(&tpl, sInfo); err != nil {
return doc
}

@ -1,14 +1,9 @@
{
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
"title": "{{.Title}}",
"contact": {},
"license": {},
"version": "{{.Version}}"
"license": {}
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/check": {
"post": {
@ -46,7 +41,6 @@
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
@ -96,7 +90,6 @@
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
@ -132,7 +125,6 @@
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
@ -168,7 +160,22 @@
"200": {
"description": "OK",
"schema": {
"type": "object",
"$ref": "#/definitions/controller.Response"
}
}
}
}
},
"/visitors_online": {
"get": {
"produces": [
"application/json"
],
"summary": "获取在线访客列表接口",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controller.Response"
}
}

@ -1,4 +1,3 @@
basePath: '{{.BasePath}}'
definitions:
controller.Response:
properties:
@ -9,13 +8,9 @@ definitions:
result:
type: object
type: object
host: '{{.Host}}'
info:
contact: {}
description: '{{.Description}}'
license: {}
title: '{{.Title}}'
version: '{{.Version}}'
paths:
/check:
post:
@ -44,7 +39,6 @@ paths:
description: OK
schema:
$ref: '#/definitions/controller.Response'
type: object
summary: 登陆验证接口
/message:
post:
@ -78,7 +72,6 @@ paths:
description: OK
schema:
$ref: '#/definitions/controller.Response'
type: object
summary: 发送消息接口
/messages:
get:
@ -102,7 +95,6 @@ paths:
description: OK
schema:
$ref: '#/definitions/controller.Response'
type: object
summary: 获取访客聊天信息接口
/visitors:
get:
@ -126,6 +118,15 @@ paths:
description: OK
schema:
$ref: '#/definitions/controller.Response'
type: object
summary: 获取访客列表接口
/visitors_online:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controller.Response'
summary: 获取在线访客列表接口
swagger: "2.0"

@ -123,4 +123,4 @@ server{
### 生成文档
1. 需要先安装swag
2. 在根目录swag init
2. 在根目录swag init -g go-fly.go

Loading…
Cancel
Save