1. Install
go get -u github.com/swaggo/swag/cmd/swag
go get -u github.com/swaggo/http-swagger
go get -u github.com/alecthomas/template
2. Definition
// @title Orders API
// @version 1.0
// @description This is a sample serice for managing orders
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email soberkoder@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /
func main() {
router := mux.NewRouter()
...
log.Fatal(http.ListenAndServe(":8080", router))
}
주석 부분은 아래처럼 고쳐서 사용.
// @title API
// @version 1.0(수정해야함)
// @description API (Go version 1.20.7)
// @termsOfService https://mypage.test.com/terms/service
// @contact.url https://help.test.com/?utm_source=&utm_medium=help&utm_campaign=gnb
// @contact.email test@test.co.kr
// @BasePath /api/v1
// @in header
3. 각 api 가서 예시와 같이 주석처리하고 알맞게 고쳐준다.
// @Summary 필터 이름 중복 체크
// @Description 필터 이름 중복 체크 (true: 중복, false: 중복아님)
// @Tags webmail
// @Accept json
// @Produce json
// @Param domain path string true "도메인"
// @Param name path string true "이름"
// @Success 200 {object} WebmailHTTPResponse
// @Router /webmail/{domain}/name/{name} [get]
**항상 주석 처리하고 swag init 을 해야지만 Docs를 만들어 준다.

'Language > Go' 카테고리의 다른 글
| GO - sqlboiler (0) | 2023.10.26 |
|---|---|
| Go[sqlboiler] - 간단한 게시판 만들기(1.20.8-v) (0) | 2023.10.19 |
| Go 게시판 정리- 2 (0) | 2023.10.12 |
| Go[postgresql db] - 간단한 게시판 만들기 (0) | 2023.10.11 |
| Go 시작 (0) | 2023.09.17 |