Merge pull request #185 from unistack-org/server

server: add server.SetHandlerOption helper
This commit is contained in:
Василий Толстов 2023-02-13 23:33:57 +03:00 committed by GitHub
commit 75fd1e43b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -42,3 +42,13 @@ func SetSubscriberOption(k, v interface{}) SubscriberOption {
o.Context = context.WithValue(o.Context, k, v)
}
}
// SetHandlerOption returns a function to setup a context with given value
func SetHandlerOption(k, v interface{}) HandlerOption {
return func(o *HandlerOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, k, v)
}
}

View File

@ -322,7 +322,7 @@ type HandlerOption func(*HandlerOptions)
type HandlerOptions struct {
// Context holds external options
Context context.Context
// Metadata for hondler
// Metadata for handler
Metadata map[string]metadata.Metadata
}