micro-register-etcd/options.go
Vasiliy Tolstov 4b14e4486f update to latest micro
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2022-01-26 00:51:00 +03:00

38 lines
793 B
Go

package etcd
import (
"context"
"go.uber.org/zap"
"go.unistack.org/micro/v3/register"
)
type authKey struct{}
type logConfigKey struct{}
type authCreds struct {
Username string
Password string
}
// Auth allows you to specify username/password
func Auth(username, password string) register.Option {
return func(o *register.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, authKey{}, &authCreds{Username: username, Password: password})
}
}
// LogConfig allows you to set etcd log config
func LogConfig(config *zap.Config) register.Option {
return func(o *register.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, logConfigKey{}, config)
}
}