diff --git a/controller/login.go b/controller/login.go index 5ac92a3..f935bee 100644 --- a/controller/login.go +++ b/controller/login.go @@ -9,10 +9,11 @@ import ( // @Summary 登陆验证接口 // @Produce json // @Accept multipart/form-data -// @Param username formData string true "username" -// @Param password formData string true "password" -// @Param type formData string true "type" -// @Success 200 {string} string "{"code":200,"result":{},"msg":"ok"}" +// @Param username formData string true "用户名" +// @Param password formData string true "密码" +// @Param type formData string true "类型" +// @Success 200 {object} controller.Response +// @Failure 200 {object} controller.Response // @Router /check [post] //验证接口 func LoginCheckPass(c *gin.Context) { diff --git a/controller/response.go b/controller/response.go new file mode 100644 index 0000000..7da8bba --- /dev/null +++ b/controller/response.go @@ -0,0 +1,6 @@ +package controller +type Response struct { + Code int `json:"code"` + Msg string `json:"msg"` + result interface{} `json:"result"` +} diff --git a/controller/visitor.go b/controller/visitor.go index 2671e00..5e7a844 100644 --- a/controller/visitor.go +++ b/controller/visitor.go @@ -16,6 +16,14 @@ func GetVisitor(c *gin.Context) { "result":vistor, }) } +// @Summary 获取访客列表接口 +// @Produce json +// @Accept multipart/form-data +// @Param page query string true "分页" +// @Param token header string true "认证token" +// @Success 200 {object} controller.Response +// @Failure 200 {object} controller.Response +// @Router /visitors [get] func GetVisitors(c *gin.Context) { page,_:=strconv.Atoi(c.Query("page")) kefuId,_:=c.Get("kefu_name") diff --git a/docs/docs.go b/docs/docs.go index c2cbbce..d61c065 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,20 +1,17 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2020-07-10 22:43:52.8548363 +0800 CST m=+0.306823701 +// 2020-07-13 15:09:32.8830515 +0800 CST m=+0.102005901 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}}", @@ -38,21 +35,21 @@ var doc = `{ "parameters": [ { "type": "string", - "description": "username", + "description": "用户名", "name": "username", "in": "formData", "required": true }, { "type": "string", - "description": "password", + "description": "密码", "name": "password", "in": "formData", "required": true }, { "type": "string", - "description": "type", + "description": "类型", "name": "type", "in": "formData", "required": true @@ -60,14 +57,67 @@ var doc = `{ ], "responses": { "200": { - "description": "{\"code\":200,\"result\":{},\"msg\":\"ok\"}", + "description": "OK", "schema": { - "type": "string" + "type": "object", + "$ref": "#/definitions/controller.Response" + } + } + } + } + }, + "/visitors": { + "get": { + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "summary": "获取访客列表接口", + "parameters": [ + { + "type": "string", + "description": "分页", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "认证token", + "name": "token", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "$ref": "#/definitions/controller.Response" } } } } } + }, + "definitions": { + "controller.Response": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "msg": { + "type": "string" + }, + "result": { + "type": "object" + } + } + } } }` @@ -75,39 +125,23 @@ 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{ - Version: "", - Host: "", - BasePath: "", - Schemes: []string{}, - Title: "", - Description: "", -} +var SwaggerInfo swaggerInfo type s struct{} func (s *s) ReadDoc() string { - 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) + t, err := template.New("swagger_info").Parse(doc) if err != nil { return doc } var tpl bytes.Buffer - if err := t.Execute(&tpl, sInfo); err != nil { + if err := t.Execute(&tpl, SwaggerInfo); err != nil { return doc } diff --git a/docs/swagger.json b/docs/swagger.json index 9c05645..0753c08 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,9 +1,14 @@ { "swagger": "2.0", "info": { + "description": "{{.Description}}", + "title": "{{.Title}}", "contact": {}, - "license": {} + "license": {}, + "version": "{{.Version}}" }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", "paths": { "/check": { "post": { @@ -17,21 +22,21 @@ "parameters": [ { "type": "string", - "description": "username", + "description": "用户名", "name": "username", "in": "formData", "required": true }, { "type": "string", - "description": "password", + "description": "密码", "name": "password", "in": "formData", "required": true }, { "type": "string", - "description": "type", + "description": "类型", "name": "type", "in": "formData", "required": true @@ -39,13 +44,66 @@ ], "responses": { "200": { - "description": "{\"code\":200,\"result\":{},\"msg\":\"ok\"}", + "description": "OK", "schema": { - "type": "string" + "type": "object", + "$ref": "#/definitions/controller.Response" } } } } + }, + "/visitors": { + "get": { + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "summary": "获取访客列表接口", + "parameters": [ + { + "type": "string", + "description": "分页", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "认证token", + "name": "token", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "$ref": "#/definitions/controller.Response" + } + } + } + } + } + }, + "definitions": { + "controller.Response": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "msg": { + "type": "string" + }, + "result": { + "type": "object" + } + } } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 91794c8..b3d3544 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,23 +1,38 @@ +basePath: '{{.BasePath}}' +definitions: + controller.Response: + properties: + code: + type: integer + msg: + type: string + result: + type: object + type: object +host: '{{.Host}}' info: contact: {} + description: '{{.Description}}' license: {} + title: '{{.Title}}' + version: '{{.Version}}' paths: /check: post: consumes: - multipart/form-data parameters: - - description: username + - description: 用户名 in: formData name: username required: true type: string - - description: password + - description: 密码 in: formData name: password required: true type: string - - description: type + - description: 类型 in: formData name: type required: true @@ -26,8 +41,33 @@ paths: - application/json responses: "200": - description: '{"code":200,"result":{},"msg":"ok"}' + description: OK schema: - type: string + $ref: '#/definitions/controller.Response' + type: object summary: 登陆验证接口 + /visitors: + get: + consumes: + - multipart/form-data + parameters: + - description: 分页 + in: query + name: page + required: true + type: string + - description: 认证token + in: header + name: token + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.Response' + type: object + summary: 获取访客列表接口 swagger: "2.0" diff --git a/main.go b/main.go index 7ce6f89..8635539 100644 --- a/main.go +++ b/main.go @@ -74,10 +74,10 @@ func main() { //文档服务 docs.SwaggerInfo.Title = "GO-FLY接口文档" docs.SwaggerInfo.Description = "go-fly即时通讯web客服管理系统" - docs.SwaggerInfo.Version = "0.0.5" + docs.SwaggerInfo.Version = "0.0.6" docs.SwaggerInfo.Host = "127.0.0.1:"+port docs.SwaggerInfo.BasePath = "/" - docs.SwaggerInfo.Schemes = []string{"http"} - engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + //docs.SwaggerInfo.Schemes = []string{"http"} + engine.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) engine.Run(baseServer) } diff --git a/static/html/nav.html b/static/html/nav.html index 0b4b4a2..b17e24f 100644 --- a/static/html/nav.html +++ b/static/html/nav.html @@ -2,7 +2,7 @@ - + 邮箱 聊天