micro/config/source/service/options.go
2020-03-11 22:31:24 +00:00

39 lines
808 B
Go

package service
import (
"context"
"github.com/micro/go-micro/v2/config/source"
)
type serviceNameKey struct{}
type namespaceKey struct{}
type pathKey struct{}
func ServiceName(name string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, serviceNameKey{}, name)
}
}
func Namespace(namespace string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, namespaceKey{}, namespace)
}
}
func Path(path string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, pathKey{}, path)
}
}