Skip to content

Commit

Permalink
Add api.Config{App} option, to pass in Echo instance
Browse files Browse the repository at this point in the history
  • Loading branch information
rgalanakis committed May 6, 2022
1 parent 108a0ed commit f1bee74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
)

type Config struct {
// If not provided, create an echo.New.
App *echo.Echo
Logger *logrus.Entry
LoggingMiddlwareConfig LoggingMiddlwareConfig
// Origins for echo's CORS middleware.
Expand Down Expand Up @@ -82,7 +84,10 @@ func New(cfg Config) *echo.Echo {
if cfg.StatusPath == "" {
cfg.StatusPath = StatusPath
}
e := echo.New()
e := cfg.App
if e == nil {
e = echo.New()
}
e.Logger.SetOutput(os.Stdout)
e.HideBanner = true
e.HTTPErrorHandler = NewHTTPErrorHandler(e)
Expand Down
6 changes: 6 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ var _ = Describe("API", func() {
Expect(Serve(e, GetRequest("/statusz"))).To(HaveResponseCode(200))
})

It("can use the provided echo instance", func() {
e1 := echo.New()
e2 := api.New(api.Config{App: e1})
Expect(e2).To(BeIdenticalTo(e1))
})

Describe("tracing", func() {
It("uses the trace id in the Trace-Id header", func() {
req := GetRequest("/healthz")
Expand Down

0 comments on commit f1bee74

Please sign in to comment.