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

     1  package memory
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/annwntech/go-micro/v2/config/source"
     7  )
     8  
     9  type changeSetKey struct{}
    10  
    11  func withData(d []byte, f string) source.Option {
    12  	return func(o *source.Options) {
    13  		if o.Context == nil {
    14  			o.Context = context.Background()
    15  		}
    16  		o.Context = context.WithValue(o.Context, changeSetKey{}, &source.ChangeSet{
    17  			Data:   d,
    18  			Format: f,
    19  		})
    20  	}
    21  }
    22  
    23  // WithChangeSet allows a changeset to be set
    24  func WithChangeSet(cs *source.ChangeSet) source.Option {
    25  	return func(o *source.Options) {
    26  		if o.Context == nil {
    27  			o.Context = context.Background()
    28  		}
    29  		o.Context = context.WithValue(o.Context, changeSetKey{}, cs)
    30  	}
    31  }
    32  
    33  // WithJSON allows the source data to be set to json
    34  func WithJSON(d []byte) source.Option {
    35  	return withData(d, "json")
    36  }
    37  
    38  // WithYAML allows the source data to be set to yaml
    39  func WithYAML(d []byte) source.Option {
    40  	return withData(d, "yaml")
    41  }