Skip to content

Commit

Permalink
Make server port configurable in pkg/util/httpserver/server
Browse files Browse the repository at this point in the history
Set default port to 8080 if not specified
  • Loading branch information
Andrey Kazakov committed Jul 15, 2024
1 parent 4187fc1 commit 75cd430
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/util/httpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ import (
//nolint:govet // ignore field alignment complaint, this is a singleton
type Server struct {
http.ServeMux
Port string

Logger *logrus.Entry
}

// Run runs an http server on port :8080.
func (s *Server) Run(ctx context.Context, _ int) error {
s.Logger.Info("Starting http server...")
if s.Port == "" {
s.Port = "8080"
}
srv := &http.Server{
Addr: ":8080",
Addr: ":" + s.Port,
Handler: s,
}
go func() {
Expand All @@ -51,7 +55,7 @@ func (s *Server) Run(ctx context.Context, _ int) error {
if err == http.ErrServerClosed {
s.Logger.WithError(err).Info("http server closed")
} else {
wrappedErr := errors.Wrap(err, "Could not listen on :8080")
wrappedErr := errors.Wrap(err, "Could not listen on :"+s.Port)
runtime.HandleError(s.Logger.WithError(wrappedErr), wrappedErr)
}
}
Expand Down

0 comments on commit 75cd430

Please sign in to comment.