github.com/proppy/fleet@v0.1.4/config/config.go (about)

     1  package config
     2  
     3  import (
     4  	"flag"
     5  	"strconv"
     6  	"strings"
     7  
     8  	"github.com/coreos/fleet/third_party/github.com/golang/glog"
     9  )
    10  
    11  type Config struct {
    12  	BootId      string
    13  	EtcdServers []string
    14  	PublicIP    string
    15  	Verbosity   int
    16  	RawMetadata string
    17  	UnitPrefix  string
    18  	AgentTTL    string
    19  }
    20  
    21  func NewConfig() *Config {
    22  	conf := Config{BootId: "", Verbosity: 0, PublicIP: ""}
    23  	return &conf
    24  }
    25  
    26  func (self *Config) Metadata() map[string]string {
    27  	meta := make(map[string]string, 0)
    28  
    29  	for _, pair := range strings.Split(self.RawMetadata, ",") {
    30  		parts := strings.SplitN(pair, "=", 2)
    31  		if len(parts) != 2 {
    32  			continue
    33  		}
    34  
    35  		key := strings.TrimSpace(parts[0])
    36  		val := strings.TrimSpace(parts[1])
    37  
    38  		meta[key] = val
    39  	}
    40  
    41  	return meta
    42  }
    43  
    44  func UpdateLoggingFlagsFromConfig(conf *Config) {
    45  	err := flag.Lookup("v").Value.Set(strconv.Itoa(conf.Verbosity))
    46  	if err != nil {
    47  		glog.Errorf("Failed to apply config.Verbosity to flag.v: %v", err)
    48  	}
    49  
    50  	err = flag.Lookup("logtostderr").Value.Set("true")
    51  	if err != nil {
    52  		glog.Errorf("Failed to set flag.logtostderr to true: %v", err)
    53  	}
    54  }