@rivascva/dt-idl 1.1.93 → 1.1.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/go/log/utils.go
CHANGED
|
@@ -59,6 +59,11 @@ func toJson(ctx context.Context, m any, kvs map[string]any, lvl string) string {
|
|
|
59
59
|
out["requestPath"] = requestPath
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// add the request method
|
|
63
|
+
if requestMethod, err := utils.GetRequestMethodFromContext(ctx); err == nil {
|
|
64
|
+
out["requestMethod"] = requestMethod
|
|
65
|
+
}
|
|
66
|
+
|
|
62
67
|
// add the request id
|
|
63
68
|
if requestId, err := utils.GetRequestIdFromContext(ctx); err == nil {
|
|
64
69
|
out["requestId"] = requestId
|
|
@@ -22,7 +22,7 @@ func GetAuthMiddleware(secret string) func(http.Handler) http.Handler {
|
|
|
22
22
|
return func(next http.Handler) http.Handler {
|
|
23
23
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
24
24
|
// check if the request path is a login endpoint
|
|
25
|
-
if slices.Contains([]string{"/v1/login", "/v1/login/provider"}, r.URL.Path) {
|
|
25
|
+
if slices.Contains([]string{"/v1/login", "/v1/login/by-provider"}, r.URL.Path) {
|
|
26
26
|
next.ServeHTTP(w, r)
|
|
27
27
|
return
|
|
28
28
|
}
|
|
@@ -67,6 +67,9 @@ func CommonContext(next http.Handler) http.Handler {
|
|
|
67
67
|
// set the request path in the request context
|
|
68
68
|
ctx = context.WithValue(ctx, models.RequestPathKey, r.URL.Path)
|
|
69
69
|
|
|
70
|
+
// set the request method in the request context
|
|
71
|
+
ctx = context.WithValue(ctx, models.RequestMethodKey, r.Method)
|
|
72
|
+
|
|
70
73
|
r = r.WithContext(ctx)
|
|
71
74
|
next.ServeHTTP(w, r)
|
|
72
75
|
})
|
package/go/models/constants.go
CHANGED
|
@@ -8,6 +8,8 @@ const (
|
|
|
8
8
|
TokenKey = ContextKey("token")
|
|
9
9
|
// RequestPathKey is the key used to set/get the request path in the request context.
|
|
10
10
|
RequestPathKey = ContextKey("requestPath")
|
|
11
|
+
// RequestMethodKey is the key used to set/get the request method in the request context.
|
|
12
|
+
RequestMethodKey = ContextKey("requestMethod")
|
|
11
13
|
// RequestIdKey is the key used to set/get the request id in the request context.
|
|
12
14
|
RequestIdKey = ContextKey("requestId")
|
|
13
15
|
)
|
package/go/utils/context.go
CHANGED
|
@@ -66,6 +66,15 @@ func GetRequestPathFromContext(ctx context.Context) (string, error) {
|
|
|
66
66
|
return requestPath, nil
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// GetRequestMethodFromContext retrieves the request method from the given context.
|
|
70
|
+
func GetRequestMethodFromContext(ctx context.Context) (string, error) {
|
|
71
|
+
requestMethod, ok := ctx.Value(models.RequestMethodKey).(string)
|
|
72
|
+
if !ok {
|
|
73
|
+
return "", errors.New("request method not found in the context")
|
|
74
|
+
}
|
|
75
|
+
return requestMethod, nil
|
|
76
|
+
}
|
|
77
|
+
|
|
69
78
|
// GetRequestIdFromContext retrieves the request id from the given context.
|
|
70
79
|
func GetRequestIdFromContext(ctx context.Context) (string, error) {
|
|
71
80
|
requestId, ok := ctx.Value(models.RequestIdKey).(string)
|