1. install and import swagger
参考https://www.soberkoder.com/swagger-go-api-swaggo/
step 1:
install swagger related tool:
go get -u github.com/swaggo/swag/cmd/swag
go get -u github.com/swaggo/http-swagger
go get -u github.com/alecthomas/template
step 2:
in main.go, import related package:
_ "xxx/docs" // this xxx name your real golang project package name, from "go mod init xxx" command
httpSwagger "github.com/swaggo/http-swagger"
"github.com/gorilla/mux"
"bytes"
"net/url"
"github.com/tidwall/gjson"
"encoding/base64"
"fmt"
"encoding/json"
2. golang code and swagger annotation
step 1, add following annotation before main() function or your related function. if before your non-main function, you need to add security related configuration in your doc.json file after "swag init" command
const (
TokenURL = "https://xxxxx.com/v1/user/token"
)
// @title appstatusviewer
// @version 1.0
// @description appstatusviewer swagger
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email xx@gmail.com
//