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 = "127.0.0.1:"+port
docs.SwaggerInfo.Host = "gofly.sopans.com" docs.SwaggerInfo.Host = "gofly.sopans.com"
docs.SwaggerInfo.BasePath = "/" docs.SwaggerInfo.BasePath = "/"
//docs.SwaggerInfo.Schemes = []string{"http"} docs.SwaggerInfo.Schemes = []string{"https"}
engine.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) engine.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
//logFile, _ := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660) //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, "result": result,
}) })
} }
// @Summary 获取在线访客列表接口
// @Produce json
// @Success 200 {object} controller.Response
// @Failure 200 {object} controller.Response
// @Router /visitors_online [get]
func GetVisitorOnlines(c *gin.Context) { func GetVisitorOnlines(c *gin.Context) {
users := make([]map[string]string, 0) users := make([]map[string]string, 0)
for uid, visitor := range clientList { for uid, visitor := range clientList {

@ -1,17 +1,20 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at // 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 package docs
import ( import (
"bytes" "bytes"
"encoding/json"
"strings"
"github.com/alecthomas/template" "github.com/alecthomas/template"
"github.com/swaggo/swag" "github.com/swaggo/swag"
) )
var doc = `{ var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"description": "{{.Description}}", "description": "{{.Description}}",
@ -59,7 +62,6 @@ var doc = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"type": "object",
"$ref": "#/definitions/controller.Response" "$ref": "#/definitions/controller.Response"
} }
} }
@ -109,7 +111,6 @@ var doc = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"type": "object",
"$ref": "#/definitions/controller.Response" "$ref": "#/definitions/controller.Response"
} }
} }
@ -145,7 +146,6 @@ var doc = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"type": "object",
"$ref": "#/definitions/controller.Response" "$ref": "#/definitions/controller.Response"
} }
} }
@ -181,7 +181,22 @@ var doc = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"type": "object", "$ref": "#/definitions/controller.Response"
}
}
}
}
},
"/visitors_online": {
"get": {
"produces": [
"application/json"
],
"summary": "获取在线访客列表接口",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controller.Response" "$ref": "#/definitions/controller.Response"
} }
} }
@ -211,23 +226,39 @@ type swaggerInfo struct {
Version string Version string
Host string Host string
BasePath string BasePath string
Schemes []string
Title string Title string
Description string Description string
} }
// SwaggerInfo holds exported Swagger Info so clients can modify it // 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{} type s struct{}
func (s *s) ReadDoc() string { 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 { if err != nil {
return doc return doc
} }
var tpl bytes.Buffer var tpl bytes.Buffer
if err := t.Execute(&tpl, SwaggerInfo); err != nil { if err := t.Execute(&tpl, sInfo); err != nil {
return doc return doc
} }

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

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

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

Loading…
Cancel
Save