func main() { var opts tunnelproxy.ServerOptions mc := multiconfig.New() mc.Loader = multiconfig.MultiLoader( &multiconfig.TagLoader{}, &multiconfig.EnvironmentLoader{}, &multiconfig.EnvironmentLoader{Prefix: "KONFIG_TUNNELSERVER"}, &multiconfig.FlagLoader{}, ) mc.MustLoad(&opts) server, err := tunnelproxy.NewServer(&opts) if err != nil { die(err) } k, err := tunnelproxy.NewServerKite(server, Name, Version) if err != nil { die(err) } k.Run() }
// Perform some basic test setup, like configuration parsing func SetupTest(t *testing.T) *StringMetadata { // Create a new DefaultLoader m := multiconfig.New() // Create an empty struct for my configuration stringMetadata := new(StringMetadata) // Load the configuration data m.MustLoad(stringMetadata) return stringMetadata }
func main() { conf := &terraformer.Config{} mc := multiconfig.New() mc.Loader = multiconfig.MultiLoader( &multiconfig.TagLoader{}, &multiconfig.EnvironmentLoader{}, &multiconfig.EnvironmentLoader{Prefix: "KONFIG_TERRAFORMER"}, &multiconfig.FlagLoader{}, ) mc.MustLoad(conf) if !conf.TerraformDebug { // hashicorp.terraform outputs many logs, discard them log.SetOutput(ioutil.Discard) } log := logging.NewCustom(terraformer.Name, conf.Debug) // init terraformer t, err := terraformer.New(conf, log) if err != nil { log.Fatal(err.Error()) } k, err := terraformer.NewKite(t, conf) if err != nil { log.Fatal(err.Error()) } if err := k.RegisterForever(k.RegisterURL(true)); err != nil { log.Fatal(err.Error()) } go k.Run() <-k.ServerReadyNotify() log.Debug("Kite Started Listening") // terraformer can only be closed with signals, wait for any signal if err := t.Wait(); err != nil { log.Error("Err after waiting terraformer %s", err) } k.Close() }
// ParseFlags uses multiconfig to fill the given v with matching // flag values read from tags, environment and command line. func ParseFlags(v interface{}) error { type parentFlags interface { Underlying() *Flags } envPrefix := "keygen" // Try to read the EnvPrefix from the v, so it is possible // to set different flags for different tests when // run at once e.g. with: // // go test ./... // switch f := v.(type) { case *Flags: if f.EnvPrefix != "" { envPrefix = f.EnvPrefix } case parentFlags: if f := f.Underlying(); f.EnvPrefix != "" { envPrefix = f.EnvPrefix } } args := make([]string, 0) // non-nil to force FlagLoader to not read test flags for i, arg := range os.Args { if arg == "--" { args = os.Args[i+1:] break } } mc := multiconfig.New() mc.Loader = multiconfig.MultiLoader( &multiconfig.TagLoader{}, &multiconfig.EnvironmentLoader{ Prefix: strings.ToUpper(envPrefix), }, &multiconfig.FlagLoader{ Args: args, }, ) return mc.Load(v) }
func main() { c := &Conf{} mc := multiconfig.New() mc.Loader = multiconfig.MultiLoader( &multiconfig.TagLoader{}, &multiconfig.EnvironmentLoader{}, &multiconfig.EnvironmentLoader{Prefix: "ASGD"}, &multiconfig.FlagLoader{}, ) mc.MustLoad(c) conf := &asgd.Config{ Name: c.Name, AccessKeyID: c.AccessKeyID, SecretAccessKey: c.SecretAccessKey, Region: c.Region, AutoScalingName: c.AutoScalingName, Debug: c.Debug, } session, err := asgd.Configure(conf) if err != nil { log.Fatal("Reading config failed: ", err.Error()) } log := logging.NewCustom("asgd", conf.Debug) // remove formatting from call stack and output correct line log.SetCallDepth(1) // create lifecycle l := asgd.NewLifeCycle(session, log, conf.AutoScalingName) // configure lifecycle with system name if err := l.Configure(conf.Name); err != nil { log.Fatal(err.Error()) } done := registerSignalHandler(l, log) // listen to lifecycle events if err := l.Listen(process(c.Execute)); err != nil { log.Fatal(err.Error()) } <-done }
func configure() (*tunnelproxymanager.Config, error) { c := &tunnelproxymanager.Config{} mc := multiconfig.New() mc.Loader = multiconfig.MultiLoader( &multiconfig.TagLoader{}, &multiconfig.EnvironmentLoader{}, &multiconfig.EnvironmentLoader{Prefix: "KONFIG_TUNNELPROXYMANAGER"}, &multiconfig.FlagLoader{}, ) mc.MustLoad(c) // decide on eb env name ebEnvName, err := getEBEnvName(c) if err != nil { return nil, err } c.EBEnvName = ebEnvName return c, nil }
func main() { m := multiconfig.New() conf := new(Config) m.MustLoad(conf) log := logging.NewLogger("webhook") conf.PublicURL = fmt.Sprintf("%s%s", conf.PublicURL, proxyURL) sf := services.NewServices() RegisterServices(sf, conf) h := integration.NewHandler(log, sf) mux := http.NewServeMux() mux.Handle("/{name}/{token}", h) mux.HandleFunc("/configure/{name}", h.Configure) log.Info("Integration server started") if err := http.ListenAndServe(conf.Addr, mux); err != nil { log.Fatal("Could not initialize server: %s", err) } }
func main() { mc := multiconfig.New() conf := new(Config) mc.MustLoad(conf) prometheus.MustRegister(masterBin) prometheus.MustRegister(masterPos) prometheus.MustRegister(riverBin) prometheus.MustRegister(riverPos) prometheus.MustRegister(inserts) prometheus.MustRegister(updates) prometheus.MustRegister(deletes) handler := proxyHandler(prometheus.Handler(), func() { readCounts(conf.River) }) http.Handle("/metrics", handler) err := http.ListenAndServe(fmt.Sprintf("%s:%d", conf.Host, conf.Port), nil) if err != nil { panic(err) } }
func withKite(t *testing.T, f func(k *kite.Kite) error) { conf := &Config{} // Load the config, reads environment variables or from flags multiconfig.New().MustLoad(conf) // enable test mode conf.Test = true if !conf.Debug { // hashicorp.terraform outputs many logs, discard them log.SetOutput(ioutil.Discard) } log := logging.NewCustom(Name, conf.Debug) // init terraformer tr, err := New(conf, log) if err != nil { t.Errorf("err while creating terraformer %s", err.Error()) } // init terraformer's kite k, err := NewKite(tr, conf) if err != nil { t.Errorf(err.Error()) } k.Config.DisableAuthentication = true go k.Run() <-k.ServerReadyNotify() err = f(k) tr.Close() tr.Wait() k.Close() if err != nil { t.Errorf("failed with %s", err.Error()) } }
func main() { conf := new(Kontrol) multiconfig.New().MustLoad(conf) publicKey, err := ioutil.ReadFile(conf.PublicKeyFile) if err != nil { log.Fatalf("cannot read public key file: %s", err.Error()) } privateKey, err := ioutil.ReadFile(conf.PrivateKeyFile) if err != nil { log.Fatalf("cannot read private key file: %s", err.Error()) } if conf.Initial { initialKey(conf, publicKey, privateKey) os.Exit(0) } kiteConf := config.MustGet() kiteConf.IP = conf.Ip kiteConf.Port = conf.Port k := kontrol.New(kiteConf, conf.Version) if conf.TLSCertFile != "" || conf.TLSKeyFile != "" { cert, err := tls.LoadX509KeyPair(conf.TLSCertFile, conf.TLSKeyFile) if err != nil { log.Fatalf("cannot load TLS certificate: %s", err.Error()) } k.Kite.TLSConfig = &tls.Config{Certificates: []tls.Certificate{cert}} } if conf.RegisterUrl != "" { k.RegisterURL = conf.RegisterUrl } switch os.Getenv("KONTROL_STORAGE") { case "etcd": k.SetStorage(kontrol.NewEtcd(conf.Machines, k.Kite.Log)) case "postgres": postgresConf := &kontrol.PostgresConfig{ Host: conf.Postgres.Host, Port: conf.Postgres.Port, Username: conf.Postgres.Username, Password: conf.Postgres.Password, DBName: conf.Postgres.DBName, } p := kontrol.NewPostgres(postgresConf, k.Kite.Log) k.SetStorage(p) k.SetKeyPairStorage(p) default: k.SetStorage(kontrol.NewEtcd(conf.Machines, k.Kite.Log)) } k.AddKeyPair("", string(publicKey), string(privateKey)) k.Kite.SetLogLevel(kite.DEBUG) k.Run() }
package main import ( "fmt" "log" "net/http" "os" konfig "koding/kites/config" "koding/kites/kloud/kloud" "koding/kites/kloud/stack" "github.com/koding/multiconfig" ) var config = multiconfig.New() func init() { config.Loader = multiconfig.MultiLoader( &multiconfig.TagLoader{}, &multiconfig.EnvironmentLoader{}, &multiconfig.EnvironmentLoader{Prefix: "KONFIG_KLOUD"}, &multiconfig.FlagLoader{}, ) log.SetFlags(log.LstdFlags | log.Lshortfile) } func main() { var cfg kloud.Config