diff --git a/Makefile b/Makefile index 0766eaa..1ad25df 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: dev build multiarch-build run clean test test-cov test-ci dep lint container-start container-start-prod container-rebuild container-rebuild-prod container-restart container-restart-prod container-stop container-stop-prod container-destroy container-destroy-prod container-update container-update-prod container-dev container-ps container-ps-prod container-logs-all container-logs-all-prod container-logs container-logs-prod container-cli container-cli-prod +.PHONY: dev build multiarch-build run clean test test-cov test-ci dep lint container-start container-start-prod container-rebuild container-rebuild-prod container-restart container-restart-prod container-stop container-stop-prod container-destroy container-destroy-prod container-update container-update-prod container-dev container-ps container-ps-prod container-logs-all container-logs-all-prod container-logs container-logs-prod container-cli container-cli-prod container-push # .RECIPEPREFIX := $(.RECIPEPREFIX) BINARY_NAME=service-cli TESTCOVERAGE_THRESHOLD=0 @@ -115,3 +115,11 @@ container-cli: container-cli-prod: docker compose --file ./deployments/compose.production.yml exec go-service bash + +container-push: +ifdef VERSION + docker build --platform=linux/amd64 -t acikyazilim.registry.cpln.io/golang-service-template:v$(VERSION) . + docker push acikyazilim.registry.cpln.io/golang-service-template:v$(VERSION) +else + @echo "VERSION is not set" +endif diff --git a/pkg/bliss/httpfx/middlewares/resolve-address-middleware.go b/pkg/bliss/httpfx/middlewares/resolve-address-middleware.go index 7f9a8fe..8f2dbdb 100644 --- a/pkg/bliss/httpfx/middlewares/resolve-address-middleware.go +++ b/pkg/bliss/httpfx/middlewares/resolve-address-middleware.go @@ -2,6 +2,7 @@ package middlewares import ( "context" + "fmt" "net" "net/http" "strings" @@ -63,11 +64,19 @@ func ResolveAddressMiddleware() httpfx.Handler { } func DetectLocalNetwork(requestAddr string) (bool, error) { - requestAddrs := strings.SplitN(requestAddr, ",", 2) + var requestIp string - requestIp, _, err := net.SplitHostPort(requestAddrs[0]) - if err != nil { - return false, err + requestAddrs := strings.SplitN(requestAddr, ",", 2) //nolint:mnd + + if strings.ContainsRune(requestAddrs[0], ':') { + host, _, err := net.SplitHostPort(requestAddrs[0]) + if err != nil { + return false, fmt.Errorf("failed to split host and port: %w", err) + } + + requestIp = host + } else { + requestIp = requestAddrs[0] } addrs, err := net.InterfaceAddrs() @@ -113,5 +122,5 @@ func GetClientAddrs(req *http.Request) string { // split comma delimited list into a slice // (this happens when proxied via elastic load balancer then again through nginx) - return strings.Join(requester, ", ") + return strings.Join(requester, ",") }