mirror of
https://github.com/go-micro/go-micro.git
synced 2025-01-29 18:04:17 +02:00
42 lines
1012 B
Go
42 lines
1012 B
Go
package gocloud
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/asim/go-micro/v3/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)
|
|
}
|
|
}
|