github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/registry/etcd/config.go (about)

     1  package etcd
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/volts-dev/volts/registry"
     7  	"go.uber.org/zap"
     8  )
     9  
    10  type authKey struct{}
    11  
    12  type logConfigKey struct{}
    13  
    14  type authCreds struct {
    15  	Username string
    16  	Password string
    17  }
    18  
    19  // Auth allows you to specify username/password
    20  func Auth(username, password string) registry.Option {
    21  	return func(cfg *registry.Config) {
    22  		if cfg.Context == nil {
    23  			cfg.Context = context.Background()
    24  		}
    25  		cfg.Context = context.WithValue(cfg.Context, authKey{}, &authCreds{Username: username, Password: password})
    26  	}
    27  }
    28  
    29  // LogConfig allows you to set etcd log config
    30  func LogConfig(config *zap.Config) registry.Option {
    31  	return func(cfg *registry.Config) {
    32  		if cfg.Context == nil {
    33  			cfg.Context = context.Background()
    34  		}
    35  		cfg.Context = context.WithValue(cfg.Context, logConfigKey{}, config)
    36  	}
    37  }