What I do
Create HTTP handlers with Echo framework and Swagger documentation.
When to use me
Adding new API endpoints.
Pattern
go
type (
xxxInput struct {
Field string `json:"field"`
}
XxxHandler struct { xxx todo.Xxx }
)
func NewXxxHandler(xxx todo.Xxx) *XxxHandler { ... }
// @Summary ...
// @Description ...
// @Tags todos
// @Accept json
// @Produce json
// @Param ...
// @Success ...
// @Failure ...
// @Router /todos [method]
func (h *XxxHandler) Handle(c echo.Context) error { ... }
func (h *XxxHandler) Path() string { return "/todos" }
func (h *XxxHandler) Method() string { return http.MethodXxx }
Rules
- •Input struct uses snake_case JSON tags
- •Delegate to usecase, handle only HTTP
- •Return usecase.Error or JSON response
- •Add Swagger annotations