2020-01-17 18:53:33 +03:00
|
|
|
package service
|
2020-01-16 19:10:15 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/micro/go-micro/config/source"
|
|
|
|
)
|
|
|
|
|
|
|
|
type serviceNameKey struct{}
|
2020-01-20 13:31:18 +03:00
|
|
|
type keyKey struct{}
|
|
|
|
type pathKey struct{}
|
2020-01-16 19:10:15 +03:00
|
|
|
|
2020-01-20 13:31:18 +03:00
|
|
|
func ServiceName(name string) source.Option {
|
2020-01-16 19:10:15 +03:00
|
|
|
return func(o *source.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
2020-01-20 13:31:18 +03:00
|
|
|
o.Context = context.WithValue(o.Context, serviceNameKey{}, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Key(key string) source.Option {
|
|
|
|
return func(o *source.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, keyKey{}, key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-16 19:10:15 +03:00
|
|
|
}
|
|
|
|
}
|