1. Set the GO environment

  • vim ~/.zshrc
    • export GOPATH=/home/hello/go
    • export GOBIN=/home/hello/go/bin
    • export PATH=$PATH:/home/hello/go/bin
  • source ~/.zshrc

2, install the swagger

  • go get github.com/go-swagger/go-swagger
  • cd /home/hello/go/src/github.com/go-swagger/go-swagger
  • go install ./cmd/swagger
  • Enter your own project directory for execution
    • swagger generate spec -o ./swagger.json
  • Start the Swagger HTTP service
    • swagger serve -F=swagger /home/hello/go/cyy/swagger.json

Go code comments

// Swagger :operation POST /user/addUser user addUser // -- // summary: new user information // description: used for new system user/ / parameters: // -name: username // in: body // description: username // type: string // required: true // -name: password // in: Body // description: password // type: string // required: true // responses: // 200: repoResp // 400: BadReq // swagger:operaion [POST: request mode (can be GET PUT DELETE...)] [url: Request address] [tag] [request for this endpoint] (you can think of the last two as id nodes, used to mark the address) // below this section is YAML format swagger specification. Make sure your indentation is consistent and correct // summary: title // description: description // parametres: The following is the parameter // -name: parameter name in: The position of [the header | body | query] parameters description: description of the type: the type of required: must be / / responses: responseCopy the code