forked from st3v/go-plugins
/
options.go
41 lines (34 loc) · 1013 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gocloud
import (
"context"
"github.com/go-alive/go-micro/broker"
"gocloud.dev/gcp"
)
type (
rabbitURLKey struct{}
gcpTokenSourceKey struct{}
gcpProjectIDKey struct{}
)
// RabbitURL is a broker Option that provides a URL for
// Go Cloud's RabbitMQ implementation.
func RabbitURL(url string) broker.Option {
return optfunc(rabbitURLKey{}, url)
}
// GCPTokenSource is a broker Option that provides a TokenSource
// for Go Cloud's Google Pub/Sub implementation.
func GCPTokenSource(ts gcp.TokenSource) broker.Option {
return optfunc(gcpTokenSourceKey{}, ts)
}
// GCPProjectID is a broker Option that provides a project ID
// for Go Cloud's Google Pub/Sub implementation.
func GCPProjectID(projID gcp.ProjectID) broker.Option {
return optfunc(gcpProjectIDKey{}, projID)
}
func optfunc(key, val interface{}) func(*broker.Options) {
return func(o *broker.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, key, val)
}
}