go-micro.dev/v5@v5.12.0/config/source/file/options.go (about)

     1  package file
     2  
     3  import (
     4  	"context"
     5  	"io/fs"
     6  
     7  	"go-micro.dev/v5/config/source"
     8  )
     9  
    10  type filePathKey struct{}
    11  type fsKey struct{}
    12  
    13  // WithPath sets the path to file.
    14  func WithPath(p string) source.Option {
    15  	return func(o *source.Options) {
    16  		if o.Context == nil {
    17  			o.Context = context.Background()
    18  		}
    19  		o.Context = context.WithValue(o.Context, filePathKey{}, p)
    20  	}
    21  }
    22  
    23  // WithFS sets the underlying filesystem to lookup file from  (default os.FS).
    24  func WithFS(fs fs.FS) 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, fsKey{}, fs)
    30  	}
    31  }