| 12345678910111213141516171819202122232425262728293031323334353637 |
- package audit
- import (
- "context"
- )
- // RequestMeta carries per-request caller identity parsed from HTTP headers.
- // udeServer has no auth layer yet, so the fields stay empty unless a future
- // middleware fills them in.
- type RequestMeta struct {
- UserId string
- UserName string
- UserToken string
- ApiKey string
- ApiSecret string
- ApiHmac string
- }
- type ctxKeyRequestMeta struct{}
- // RequestMetaKey is the context key of RequestMeta.
- var RequestMetaKey = ctxKeyRequestMeta{}
- // WithRequestMeta stores RequestMeta in ctx.
- func WithRequestMeta(ctx context.Context, m RequestMeta) context.Context {
- return context.WithValue(ctx, RequestMetaKey, m)
- }
- // GetRequestMeta returns the RequestMeta carried by ctx, or the zero value.
- func GetRequestMeta(ctx context.Context) RequestMeta {
- if v := ctx.Value(RequestMetaKey); v != nil {
- if m, ok := v.(RequestMeta); ok {
- return m
- }
- }
- return RequestMeta{}
- }
|