-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package domain | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
|
||
"github.com/labstack/echo" | ||
) | ||
|
||
// RequestPathKeyType is a custom type for request path key. | ||
type RequestPathKeyType string | ||
|
||
const ( | ||
// RequestPathCtxKey is the key used to store the request path in the request context | ||
RequestPathCtxKey RequestPathKeyType = "request_path" | ||
) | ||
|
||
// ParseURLPath parses the URL path from the echo context | ||
func ParseURLPath(c echo.Context) (string, error) { | ||
parsedURL, err := url.Parse(c.Request().RequestURI) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return parsedURL.Path, nil | ||
} | ||
|
||
// GetURLPathFromContext returns the request path from the context | ||
func GetURLPathFromContext(ctx context.Context) (string, error) { | ||
// Get request path for metrics | ||
requestPath, ok := ctx.Value(RequestPathCtxKey).(string) | ||
if !ok || (ok && len(requestPath) == 0) { | ||
requestPath = "unknown" | ||
} | ||
return requestPath, nil | ||
} |
This file contains 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
This file contains 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