Created
September 25, 2022 20:42
-
-
Save karl-gustav/001e05e70527986f8b6d11f675ed610c to your computer and use it in GitHub Desktop.
Get full URL from http request in go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fullURL(r *http.Request, overridePath ...string) string { | |
scheme := "http" | |
if r.TLS != nil { | |
scheme = "https" | |
} | |
if len(overridePath) != 0 { | |
return fmt.Sprintf("%s://%s%s", scheme, r.Host, overridePath[0]) | |
} | |
return fmt.Sprintf("%s://%s%s?%s#%s", scheme, r.Host, r.URL.Path, r.URL.RawQuery, r.URL.Fragment) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there already a package which provides that?