Skip to content

Commit

Permalink
Merge branch 'add-tests-for-common-metrics-and-httpserver' into 'main'
Browse files Browse the repository at this point in the history
feat: add tests for common, metrics and httpserver

See merge request BobyMCbobs/go-http-server!35
  • Loading branch information
BobyMCbobs committed Dec 20, 2023
2 parents e716996 + 8392865 commit 51ee22b
Show file tree
Hide file tree
Showing 7 changed files with 1,614 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ build-backend-smoketest:
- go build -o /dev/null .

build-container:
only:
- main
- tags
stage: build
image:
name: $IMAGE_GOLANG_ALPINE
Expand Down
8 changes: 5 additions & 3 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,19 @@ func GetRedirectRoutesPath() (output string) {

// GetHTTPAllowedOrigins ...
// returns a list of specified allowed origins for configuring CORS
func GetHTTPAllowedOrigins() (origins []string) {
func GetHTTPAllowedOrigins() (origins []string, err error) {
for _, o := range strings.Split(GetEnvOrDefault("APP_HTTP_ALLOWED_ORIGINS", "*"), ",") {
if o == "" {
continue
}
u, err := url.Parse(o)
if err != nil {
log.Panicf("error: failed to parse URL '%v' from allowed origins; %v", o, err)
log.Printf("error: failed to parse URL '%v' from allowed origins; %v\n", o, err)
return origins, err
}
origins = append(origins, u.String())
}
return origins
return origins, nil
}

// GetEnvOrDefault ...
Expand Down Expand Up @@ -247,6 +248,7 @@ func WriteHeadersToResponse(w http.ResponseWriter, headerMap map[string][]string
// GetRequestIP ...
// returns r.RemoteAddr unless RealIPHeader is set
func GetRequestIP(r *http.Request) (requestIP string) {
// TODO use from httpserver.WebServer
realIPHeader := GetAppRealIPHeader()
headerValue := r.Header.Get(realIPHeader)
if realIPHeader == "" || headerValue == "" {
Expand Down
Loading

0 comments on commit 51ee22b

Please sign in to comment.