引入swagger

This commit is contained in:
suguo.yao 2020-04-12 10:41:11 +08:00
parent fd03c6f398
commit d9aa3f813a
5 changed files with 40 additions and 1 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ rubbish-class
logs/
*.log
go.sum
swagger.yaml

View File

@ -3,3 +3,9 @@ build:
dev:
go run . -d "root:root@tcp(i.myschools.me:6006)/rubbish?charset=utf8mb4&parseTime=True&loc=Local"
check_install:
which swagger || GO111MODULE=off go get -u -v github.com/go-swagger/go-swagger/cmd/swagger
swagger: check_install
GO111MODULE=off swagger generate spec -o ./swagger.yaml --scan-models

View File

@ -10,6 +10,7 @@ import (
//HTTP基本认证(Basic Authentication)
//"用户名+冒号+密码"用BASE64算法加密后的字符串放在http request 中的header的Authorization中发送给服务端
//最终格式Authorization: Basic BASE64("用户名+冒号+密码")
// @Router /user/person/login [post]
func HomeHandler(c *gin.Context) {
user := c.MustGet(gin.AuthUserKey).(string)
c.JSON(http.StatusOK, user)

View File

@ -9,6 +9,12 @@ import (
//CommunityListHandler 社区列表
func CommunityListHandler(c *gin.Context) {
// swagger:route GET /community/list commid
//
// 社区列表
//
// Responses:
// 200: map<string,int>
service := community.NewService()
data, err := service.Map()
if err != nil {

View File

@ -1,3 +1,18 @@
// Package main Rubbish-Class API
//
// Documentation for Rubbish-Class API
//
// Schemes: http
// BasePath: /rubbish/
// Version: 1.0.0
// Contact: Suguo.Yao<ysg@myschools.me>
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// swagger:meta
package main
import (
@ -94,5 +109,15 @@ func main() {
}
}
// go func() {
// log.Printf("Starting server on %s \r\n", *endpoint)
// err := r.Run(*endpoint)
// if err != nil {
// log.Printf("Error server: %s \n", err)
// os.Exit(1)
// }
// }()
log.Fatal(r.Run(*endpoint))
}