2020-01-17 23:53:33 +08:00
|
|
|
package service
|
2020-01-17 00:10:15 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/config/source"
|
2020-01-17 00:10:15 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type serviceNameKey struct{}
|
2020-03-11 22:31:24 +00:00
|
|
|
type namespaceKey struct{}
|
2020-01-20 18:31:18 +08:00
|
|
|
type pathKey struct{}
|
2020-01-17 00:10:15 +08:00
|
|
|
|
2020-01-20 18:31:18 +08:00
|
|
|
func ServiceName(name string) source.Option {
|
2020-01-17 00:10:15 +08:00
|
|
|
return func(o *source.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
2020-01-20 18:31:18 +08:00
|
|
|
o.Context = context.WithValue(o.Context, serviceNameKey{}, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 22:31:24 +00:00
|
|
|
func Namespace(namespace string) source.Option {
|
2020-01-20 18:31:18 +08:00
|
|
|
return func(o *source.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
2020-03-11 22:31:24 +00:00
|
|
|
o.Context = context.WithValue(o.Context, namespaceKey{}, namespace)
|
2020-01-20 18:31:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2020-01-17 00:10:15 +08:00
|
|
|
}
|
|
|
|
}
|