github.com/micro/go-micro/v2@v2.9.1/registry/etcd/options.go (about)

     1  package etcd
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/micro/go-micro/v2/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(o *registry.Options) {
    22  		if o.Context == nil {
    23  			o.Context = context.Background()
    24  		}
    25  		o.Context = context.WithValue(o.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(o *registry.Options) {
    32  		if o.Context == nil {
    33  			o.Context = context.Background()
    34  		}
    35  		o.Context = context.WithValue(o.Context, logConfigKey{}, config)
    36  	}
    37  }