github.com/annwntech/go-micro/v2@v2.9.5/config/source/service/options.go (about)

     1  package service
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/annwntech/go-micro/v2/config/source"
     7  )
     8  
     9  type serviceNameKey struct{}
    10  type namespaceKey struct{}
    11  type pathKey struct{}
    12  
    13  func ServiceName(name string) source.Option {
    14  	return func(o *source.Options) {
    15  		if o.Context == nil {
    16  			o.Context = context.Background()
    17  		}
    18  		o.Context = context.WithValue(o.Context, serviceNameKey{}, name)
    19  	}
    20  }
    21  
    22  func Namespace(namespace string) source.Option {
    23  	return func(o *source.Options) {
    24  		if o.Context == nil {
    25  			o.Context = context.Background()
    26  		}
    27  		o.Context = context.WithValue(o.Context, namespaceKey{}, namespace)
    28  	}
    29  }
    30  
    31  func Path(path string) source.Option {
    32  	return func(o *source.Options) {
    33  		if o.Context == nil {
    34  			o.Context = context.Background()
    35  		}
    36  		o.Context = context.WithValue(o.Context, pathKey{}, path)
    37  	}
    38  }