feat: complete contract-driven business development and MySQL integration
This commit is contained in:
22
httpx/metadata.go
Normal file
22
httpx/metadata.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package httpx
|
||||
|
||||
import "context"
|
||||
|
||||
// RequestMetadata is a value snapshot for Logic. It excludes credentials,
|
||||
// query strings, headers and bodies. ClientIP is resolved by App's proxy policy.
|
||||
type RequestMetadata struct{ ClientIP, Method, Route string }
|
||||
type metadataKey struct{}
|
||||
|
||||
func WithRequestMetadata(ctx context.Context, value RequestMetadata) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, metadataKey{}, value)
|
||||
}
|
||||
func Metadata(ctx context.Context) RequestMetadata {
|
||||
if ctx == nil {
|
||||
return RequestMetadata{}
|
||||
}
|
||||
value, _ := ctx.Value(metadataKey{}).(RequestMetadata)
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user