Skip to content

Commit

Permalink
Merge pull request #12 from alexandreh2ag/update_http_server_panic
Browse files Browse the repository at this point in the history
Prevent panic when http server stop
  • Loading branch information
alexandreh2ag authored Jan 25, 2025
2 parents e3379ca + 049074d commit 67f97b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion apps/agent/http/server.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package http

import (
"fmt"
"github.com/alexandreh2ag/lets-go-tls/apps/agent/context"
"github.com/alexandreh2ag/lets-go-tls/apps/agent/http/controller"
"github.com/alexandreh2ag/lets-go-tls/apps/agent/http/middleware"
"github.com/alexandreh2ag/lets-go-tls/http"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
buildinHttp "net/http"
)

func CreateServerHTTP(ctx *context.AgentContext) (*echo.Echo, error) {
Expand All @@ -25,7 +27,9 @@ func CreateServerHTTP(ctx *context.AgentContext) (*echo.Echo, error) {

go func() {
err := e.Start(ctx.Config.HTTP.Listen)
ctx.Logger.Error(err.Error())
if err != nil && err != buildinHttp.ErrServerClosed {
panic(fmt.Errorf("fail to start http server with %v", err))
}

}()
return e, nil
Expand Down
3 changes: 2 additions & 1 deletion apps/server/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/labstack/echo-contrib/echoprometheus"
echojwt "github.com/labstack/echo-jwt/v4"
"github.com/labstack/echo/v4"
buildinHttp "net/http"
)

const (
Expand Down Expand Up @@ -47,7 +48,7 @@ func CreateServerHTTP(ctx *context.ServerContext, httpProvider *acmeHttp.Challen
} else {
err = e.Start(ctx.Config.HTTP.Listen)
}
if err != nil {
if err != nil && err != buildinHttp.ErrServerClosed {
panic(fmt.Errorf("fail to start http server with %v", err))
}
}()
Expand Down

0 comments on commit 67f97b2

Please sign in to comment.