Skip to content

Commit

Permalink
Merge pull request #185 from unistack-org/server
Browse files Browse the repository at this point in the history
server: add server.SetHandlerOption helper
  • Loading branch information
vtolstov authored Feb 13, 2023
2 parents 3ba8cb7 + 395a3ee commit 75fd1e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions server/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 75fd1e4

Please sign in to comment.