github.com/mailgun/holster/v4@v4.20.0/functional/functional_option.go (about)

     1  package functional
     2  
     3  import "io"
     4  
     5  type FunctionalOption interface {
     6  	Apply(t *T)
     7  }
     8  
     9  type withWriterOption struct {
    10  	writer io.Writer
    11  }
    12  
    13  func (o *withWriterOption) Apply(t *T) {
    14  	t.writer = o.writer
    15  	t.errWriter = o.writer
    16  }
    17  
    18  // WithWriter sets log output writer.
    19  func WithWriter(writer io.Writer) FunctionalOption {
    20  	return &withWriterOption{writer: writer}
    21  }
    22  
    23  type withArgs struct {
    24  	args []string
    25  }
    26  
    27  func (o *withArgs) Apply(t *T) {
    28  	t.args = o.args
    29  }
    30  
    31  func WithArgs(args ...string) FunctionalOption {
    32  	return &withArgs{args: args}
    33  }