2019-10-02 18:56:53 +01:00
|
|
|
package etcd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/registry"
|
2019-12-13 11:22:05 +08:00
|
|
|
"go.uber.org/zap"
|
2019-10-02 18:56:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type authKey struct{}
|
|
|
|
|
2019-12-13 11:22:05 +08:00
|
|
|
type logConfigKey struct{}
|
|
|
|
|
2019-10-02 18:56:53 +01:00
|
|
|
type authCreds struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auth allows you to specify username/password
|
|
|
|
func Auth(username, password string) registry.Option {
|
|
|
|
return func(o *registry.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, authKey{}, &authCreds{Username: username, Password: password})
|
|
|
|
}
|
|
|
|
}
|
2019-12-13 11:22:05 +08:00
|
|
|
|
|
|
|
// LogConfig allows you to set etcd log config
|
|
|
|
func LogConfig(config *zap.Config) registry.Option {
|
|
|
|
return func(o *registry.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
2019-12-23 15:29:13 +08:00
|
|
|
o.Context = context.WithValue(o.Context, logConfigKey{}, config)
|
2019-12-13 11:22:05 +08:00
|
|
|
}
|
|
|
|
}
|