2025-05-15 13:47:35 -04:00
|
|
|
package etcd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-06-18 11:55:35 +01:00
|
|
|
"go-micro.dev/v6/registry"
|
2025-05-15 13:47:35 -04:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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) 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})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
}
|
|
|
|
|
o.Context = context.WithValue(o.Context, logConfigKey{}, config)
|
|
|
|
|
}
|
|
|
|
|
}
|