diff --git a/.gitignore b/.gitignore index a780403..71f9472 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ rubbish-class logs/ *.log go.sum +swagger.yaml diff --git a/Makefile b/Makefile index f70f581..d7816a6 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,10 @@ build: go build -ldflags '-w' -i . dev: - go run . -d "root:root@tcp(i.myschools.me:6006)/rubbish?charset=utf8mb4&parseTime=True&loc=Local" \ No newline at end of file + 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 \ No newline at end of file diff --git a/admin/admin-handler.go b/admin/admin-handler.go index 497be1c..87c9136 100644 --- a/admin/admin-handler.go +++ b/admin/admin-handler.go @@ -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) diff --git a/public/public-handler.go b/public/public-handler.go index 4a473ed..6517995 100644 --- a/public/public-handler.go +++ b/public/public-handler.go @@ -9,6 +9,12 @@ import ( //CommunityListHandler 社区列表 func CommunityListHandler(c *gin.Context) { + // swagger:route GET /community/list commid + // + // 社区列表 + // + // Responses: + // 200: map service := community.NewService() data, err := service.Map() if err != nil { diff --git a/server.go b/server.go index 9783492..f378cfd 100644 --- a/server.go +++ b/server.go @@ -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 +// +// 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)) + }