handle addr when port is passed in host:port format in the StartServer func (#2747)

Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
This commit is contained in:
Nikhil Sharma
2023-03-23 16:38:17 +05:30
committed by GitHub
parent a8e8cfb72d
commit 1f138d03fa
+5 -1
View File
@@ -4,13 +4,17 @@ import (
"context"
"fmt"
"net/http"
"strings"
"go.uber.org/zap"
)
func StartServer(ctx context.Context, log *zap.Logger, svc string, port string, handler http.Handler) {
if !strings.Contains(port, ":") {
port = fmt.Sprintf(":%s", port)
}
server := http.Server{
Addr: fmt.Sprintf(":%s", port),
Addr: port,
Handler: handler,
}
l := log.With(zap.String("service", svc), zap.String("addr", server.Addr))