github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/util/cfg/data_test.go (about)

     1  package cfg
     2  
     3  import (
     4  	"flag"
     5  	"time"
     6  
     7  	"github.com/grafana/dskit/flagext"
     8  )
     9  
    10  // Data is a test Data structure
    11  type Data struct {
    12  	Verbose bool   `yaml:"verbose"`
    13  	Server  Server `yaml:"server"`
    14  	TLS     TLS    `yaml:"tls"`
    15  }
    16  
    17  // Clone takes advantage of pass-by-value semantics to return a distinct *Data.
    18  // This is primarily used to parse a different flag set without mutating the original *Data.
    19  func (d *Data) Clone() flagext.Registerer {
    20  	return func(d Data) *Data {
    21  		return &d
    22  	}(*d)
    23  }
    24  
    25  type Server struct {
    26  	Port    int           `yaml:"port"`
    27  	Timeout time.Duration `yaml:"timeout"`
    28  }
    29  
    30  type TLS struct {
    31  	Cert string `yaml:"cert"`
    32  	Key  string `yaml:"key"`
    33  }
    34  
    35  // RegisterFlags makes Data implement flagext.Registerer for using flags
    36  func (d *Data) RegisterFlags(fs *flag.FlagSet) {
    37  	fs.BoolVar(&d.Verbose, "verbose", false, "")
    38  	fs.IntVar(&d.Server.Port, "server.port", 80, "")
    39  	fs.DurationVar(&d.Server.Timeout, "server.timeout", 60*time.Second, "")
    40  
    41  	fs.StringVar(&d.TLS.Cert, "tls.cert", "DEFAULTCERT", "")
    42  	fs.StringVar(&d.TLS.Key, "tls.key", "DEFAULTKEY", "")
    43  }