//go:generate swag init | |
package main | |
import ( | |
"net/http" | |
httpSwagger "github.com/swaggo/http-swagger" | |
) | |
func init() { | |
http.HandleFunc("/api/v1/example", Example) | |
http.Handle("/swagger/", http.StripPrefix("/swagger", http.FileServer(http.Dir("docs")))) | |
http.HandleFunc("/api/docs/", httpSwagger.Handler( | |
httpSwagger.URL("/swagger/swagger.json"), //The url pointing to API definition" | |
)) | |
} | |
func main() { | |
http.ListenAndServe(":8080", nil) | |
} | |
// Example godoc | |
// @Summary example api summary | |
// @Tags example | |
// example[, TAG_NAME] | |
// @Accept json | |
// @Product json | |
// @Param QueryArgc query int true "query args count" | |
// @Param QueryArgv query list true "query args vector" | |
// @Param PathArgc path int true "Path args" | |
// @Param BodyArgc body main.Message true "Path args" | |
// @Success 200 {object} main.Response | |
// @Success 201 {array} main.Message | |
// @Failure 500 {object} main.Message | |
// @Router /api/v1/example/{PathArgc} [post] | |
func Example(w http.ResponseWriter, r *http.Request) { | |
} | |
// Response struct | |
type Response struct { | |
Code int `json:"code"` | |
Msg Message `json:"message"` | |
} | |
// Message struct | |
type Message struct { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment