Skip to content

Commit

Permalink
Merge pull request #567 from traPtitech/fix/563
Browse files Browse the repository at this point in the history
✨ add EnableLogger option
  • Loading branch information
ras0q authored Sep 22, 2023
2 parents af54b1f + 0cf6836 commit ed7b918
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions interfaces/handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import (
"github.com/traPtitech/traPortfolio/usecases/repository"
)

func Setup(e *echo.Echo, api API) error {
type Option func(*echo.Echo) error

func Setup(e *echo.Echo, api API, opts ...Option) error {
e.HTTPErrorHandler = newHTTPErrorHandler(e)
e.Binder = &binderWithValidation{}

e.Use(middleware.Logger())
for _, opt := range opts {
if err := opt(e); err != nil {
return fmt.Errorf("apply option: %w", err)
}
}

e.Use(middleware.Recover())

apiGroup := e.Group("/api")
Expand Down Expand Up @@ -94,3 +101,10 @@ func (b *binderWithValidation) Bind(i interface{}, c echo.Context) error {

return nil
}

func WithRequestLogger() Option {
return func(e *echo.Echo) error {
e.Use(middleware.Logger())
return nil
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
}

e := echo.New()
if err := handler.Setup(e, api); err != nil {
if err := handler.Setup(e, api, handler.WithRequestLogger()); err != nil {
log.Fatal(err)
}

Expand Down

0 comments on commit ed7b918

Please sign in to comment.