引入swagger
This commit is contained in:
parent
fd03c6f398
commit
d9aa3f813a
|
|
@ -15,3 +15,4 @@ rubbish-class
|
|||
logs/
|
||||
*.log
|
||||
go.sum
|
||||
swagger.yaml
|
||||
|
|
|
|||
8
Makefile
8
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"
|
||||
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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
25
server.go
25
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<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))
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue