func LoadConfigs() { defer setDefaults(&cfg) // Load the defaults at the end of the function call cfg = Config{} gcfg.ReadFileInto(&cfg, globalFile) gcfg.ReadFileInto(&cfg, configFile) gcfg.ReadFileInto(&cfg, overrideFile) }
func ParseConfig(inputFile string) (subnets []*scanner.Subnet, params Params, e error) { type Config struct { Parameters Params Subnet map[string]*struct { Network string } } config := Config{} e = gcfg.ReadFileInto(&config, inputFile) if e != nil { return nil, Params{}, e } params = config.Parameters for subnetName, network := range config.Subnet { log.Printf("Adding subnet %s %s", subnetName, network.Network) _, ipNet, e := net.ParseCIDR(network.Network) if e != nil { return nil, Params{}, e } sub := scanner.NewSubnet(subnetName, ipNet.String()) generateAllInSubnet(ipNet, sub) subnets = append(subnets, sub) } return }
// ReadConfiguration loads a client configuration from a local configuration file // and verifies that GnuPG's secring is available func ReadConfiguration(file string) (conf Configuration, err error) { defer func() { if e := recover(); e != nil { err = fmt.Errorf("ReadConfiguration() -> %v", e) } }() _, err = os.Stat(file) if err != nil { fmt.Fprintf(os.Stderr, "no configuration file found at %s\n", file) err = MakeConfiguration(file) if err != nil { panic(err) } } err = gcfg.ReadFileInto(&conf, file) if conf.GPG.Home == "" { gnupgdir := os.Getenv("GNUPGHOME") if gnupgdir == "" { gnupgdir = "/.gnupg" } conf.GPG.Home = FindHomedir() + gnupgdir } _, err = os.Stat(conf.GPG.Home + "/secring.gpg") if err != nil { panic("secring.gpg not found") } // if trailing slash is missing from API url, add it if conf.API.URL[len(conf.API.URL)-1] != '/' { conf.API.URL += "/" } return }
func BootstrapConfig() (*Config, error) { home := os.Getenv("STF_HOME") if home == "" { var err error home, err = os.Getwd() if err != nil { log.Fatalf("Failed to get home from env and Getwd: %s", err) } } cfg := Config{} file := os.Getenv("STF_CONFIG") if file == "" { file = path.Join("etc", "config.gcfg") } if !filepath.IsAbs(file) { file = path.Join(home, file) } err := gcfg.ReadFileInto(&cfg, file) if err != nil { return nil, errors.New( fmt.Sprintf( "Failed to load config file '%s': %s", file, err, ), ) } cfg.FileName = file cfg.Prepare() return &cfg, nil }
func init() { err := gcfg.ReadFileInto(&MasterConfig, "kirisurf.conf") log.Debug("Read configuration successfully") if err != nil { panic(err.Error()) } }
func main() { configFilePath := flag.String("config", "./etc/goahead.ini", "Configuration file path") help := flag.Bool("help", false, "Show me the help!") run := flag.Bool("run", false, "Run server") build := flag.Bool("build", false, "Create the scaffold") flag.Parse() if *help || (!(*run) && !(*build)) { showHelp() return } err := gcfg.ReadFileInto(&_cfg, *configFilePath) if err != nil { log.Fatal(err) } db := database.Create(&(_cfg.Database)) err = db.IsValid() if err != nil { log.Fatal(err) } if *build { buildScaffold(db) return } if *run { runServer(db) return } }
func parseConfigFile(filename string, cfg *Config) error { // Just testing config structs err := gcfg.ReadFileInto(cfg, configFile) if err != nil { panic(err) } }
func ReadConfig(cfg *Config, path string) (ok bool) { err := gcfg.ReadFileInto(cfg, path) if err != nil { return false } return true }
// Read configuration. func getCfg() *cfgType { var c cfgType var errorSeen bool // set up some sane default configuration settings: c.Main.Zpoolstatusrefresh = 10 c.Main.Zpoolstatuscmd = "zpool status" c.Main.Zfslistrefresh = 60 c.Main.Zfslistcmd = "zfs list -H -o name,avail,used,usedsnap,usedds,usedrefreserv,usedchild,refer,mountpoint -d 0" c.Main.Zfslistusagecmd = "zfs list -H -o name,avail,used,usedsnap,usedds,usedrefreserv,usedchild,refer,mountpoint -r -t all" c.Leds.Ledctlcmd = "ledctl" c.Severity.Pooladded = notifier.INFO c.Severity.Poolremoved = notifier.INFO c.Severity.Poolstatuschanged = notifier.INFO c.Severity.Poolstatuscleared = notifier.INFO c.Severity.Poolerrorschanged = notifier.INFO c.Severity.Devadded = notifier.INFO c.Severity.Devremoved = notifier.INFO c.Severity.Devreaderrorsincreased = notifier.INFO c.Severity.Devwriteerrorsincreased = notifier.INFO c.Severity.Devcksumerrorsincreased = notifier.INFO c.Severity.Devadditionalinfochanged = notifier.INFO c.Severity.Devadditionalinfocleared = notifier.INFO // read configuration settings: err := gcfg.ReadFileInto(&c, cfgFile) checkCfgErr(cfgFile, "", "", "", err, &errorSeen) if errorSeen { return nil } return &c }
func LoadConfig(filename string) (Config, error) { var c Config err := gcfg.ReadFileInto(&c, filename) return c, err }
func init() { flag.Parse() err := gcfg.ReadFileInto(&cfg, *configFile) if err != nil { log.Fatal(err) } session, err = r.Connect(r.ConnectOpts{ Address: cfg.Database.Host + ":" + cfg.Database.Port, //localhost:28015 Database: cfg.Database.DB, //DB: cats }) if err != nil { log.Fatal("Could not connect") } res, err := r.DBCreate(cfg.Database.DB).RunWrite(session) if err != nil { log.Println(err.Error()) } fmt.Printf("%d DB created\n", res.DBsCreated) r.DB(cfg.Database.DB).TableCreate("instacat").Run(session) log.Println("Create table instacat.") r.Table("instacat").IndexCreate("time").Run(session) log.Println("Create index time.") r.Table("instacat").IndexCreate("place", r.IndexCreateOpts{Geo: true}).Run(session) log.Println("Create index place.") }
func main() { var ( err error conf Config ) flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s - a worker verifying agents that fail to authenticate\n", os.Args[0]) flag.PrintDefaults() } var configPath = flag.String("c", "/etc/mig/agent_verif_worker.cfg", "Load configuration from file") flag.Parse() err = gcfg.ReadFileInto(&conf, *configPath) if err != nil { panic(err) } // set a binding to route events from event.Q_Agt_Auth_Fail into the queue named after the worker // and return a channel that consumes the queue workerQueue := "migevent.worker." + workerName consumerChan, err := workers.InitMqWithConsumer(conf.Mq, workerQueue, event.Q_Agt_Auth_Fail) if err != nil { panic(err) } fmt.Println("started worker", workerName, "consuming queue", workerQueue, "from key", event.Q_Agt_Auth_Fail) for event := range consumerChan { fmt.Printf("%s\n", event.Body) } return }
func readConfig() { err := gcfg.ReadFileInto(&IcerayCfg, *ConfigPath) if err != nil { log.Fatal("Error opening config file: " + err.Error()) } if *Hostname == DEFAULT_HOSTNAME && IcerayCfg.Server.Hostname != "" { *Hostname = IcerayCfg.Server.Hostname } if *Port == DEFAULT_PORT && IcerayCfg.Server.Port != 0 { *Port = IcerayCfg.Server.Port } mountpoint := IcerayCfg.Server.Mount if mountpoint[0] != '/' { mountpoint = "/" + mountpoint } if *Mount == DEFAULT_MOUNTPOINT && IcerayCfg.Server.Mount != "" { *Mount = IcerayCfg.Server.Mount } if *Username == DEFAULT_USERNAME && IcerayCfg.Server.User != "" { *Username = IcerayCfg.Server.User } if *Password == DEFAULT_PASSWORD && IcerayCfg.Server.Password != "" { *Password = IcerayCfg.Server.Password } }
// LoadConfig loads the configuration from given file path func LoadConfig(filename string) { err := gcfg.ReadFileInto(&Config, filename) if err != nil { logger.Logger.Print("Config: ", err) log.Fatal("Config: ", err) } }
func main() { var ( confPath string ) flag.StringVar(&confPath, "f", "./ipcapcom.conf", "path to config file") flag.Parse() err := gcfg.ReadFileInto(&cfg, confPath) if err != nil { fmt.Fprintf(os.Stderr, "error reading config file: %v\n", err) os.Exit(1) } r := mux.NewRouter() r.HandleFunc("/ping", handlePing).Methods("GET") r.HandleFunc("/apply", handleApply).Methods("POST") r.HandleFunc("/purge", handlePurge).Methods("GET") r.PathPrefix("/").Handler(http.FileServer(http.Dir(cfg.General.StaticDir))) http.Handle("/", context.ClearHandler(r)) go reaper() err = http.ListenAndServe(":"+cfg.General.ListenPort, nil) if err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(1) } }
func main() { flag.Parse() if *ticket_number == 0 { log.Fatal("You must specify a ticket number. View usage for details.") } if *link_with == 0 { log.Print("No linking ticket specified. Will create Sprint.ly ticket.") } config := ConfigFile{} err := gcfg.ReadFileInto(&config, os.ExpandEnv(*config_location)) if err != nil { log.Fatal(err) } err = config.validate() if err != nil { log.Fatalf("Invalid config file: %s", err) } uv_client := uservoice.NewUservoiceClient(config.Uservoice) // get ticket from uservoice ticket, err := uv_client.GetTicketByNumber(*ticket_number) if err != nil { log.Fatalf("Error fetching ticket by number: %s\n", err) } s_client := sprintly.NewSprintlyClient( config.Sprintly.Email, config.Sprintly.ApiKey, config.Sprintly.ProductId, ) var url string if *link_with == 0 { // post to sprint.ly if len(ticket.Messages) > 0 { message := fmt.Sprintf("%s\n\n(Link to Uservoice)[%s]", ticket.Messages[len(ticket.Messages)-1].PlaintextBody, uv_client.UrlForTicket(ticket.Number)) url, err = s_client.CreateDefect(ticket.Subject, message) if err != nil { log.Fatalf("Couldn't create Sprint.ly defect: %s\n", err) } } else { log.Fatal("There were no messages in the provided ticket.") } } else { url = s_client.ItemLink(*link_with) s_client.AddAnnotation(*link_with, "uservoice", "received a message from a customer", fmt.Sprintf("[%d](%s)", ticket.Number, uv_client.UrlForTicket(ticket.Number))) } // post url of sprintly ticket as note to uservoice uv_client.PostNote(ticket.Id, url) fmt.Printf("Ticket ( %s ) posted from Uservoice #%v\n", url, *ticket_number) }
func LoadConfig() error { err := gcfg.ReadFileInto(&config, "/etc/disco/disco.conf") if err != nil { return err } return nil }
func main() { var err error flag.Parse() // Read config c := dalga.NewConfig() if *configPath != "" { err = gcfg.ReadFileInto(c, *configPath) if err != nil { log.Fatalln(err) } fmt.Println("Read config: ", c) } // Initialize Dalga object d := dalga.NewDalga(c) // Create jobs table if *createTable { err = d.CreateTable() if err != nil { log.Fatalln(err) } fmt.Println("Table created successfully") return } // Run Dalga err = d.Run() if err != nil { log.Fatalln(err) } }
func readConfig() *FactomdConfig { cfg := new(FactomdConfig) filename := getHomeDir() + "/.factom/factomd.conf" log.Println("read factom config file: ", filename) // This makes factom config file located at // POSIX (Linux/BSD): ~/.factom/factom.conf // Mac OS: $HOME/Library/Application Support/Factom/factom.conf // Windows: %LOCALAPPDATA%\Factom\factom.conf // Plan 9: $home/factom/factom.conf //factomHomeDir := btcutil.AppDataDir("factom", false) //defaultConfigFile := filepath.Join(factomHomeDir, "factomd.conf") // // eventually we need to make data dir as following //defaultDataDir = filepath.Join(factomHomeDir, "data") //LdbPath = filepath.Join(defaultDataDir, "ldb9") //DataStorePath = filepath.Join(defaultDataDir, "store/seed/") err := gcfg.ReadFileInto(cfg, filename) if err != nil { log.Println("Server starting with default settings...") gcfg.ReadStringInto(cfg, defaultConfig) } return cfg }
// Loads config.gcfg into jew.conf, a variable type of JewConfig func loadConfiguration() error { if gcfg.ReadFileInto(&jew.conf, fmt.Sprintf("%s/jewvis/config.gcfg", jew.homeDir)) == nil { return nil } fmt.Printf("%s/jewvis/config.gcfg\n", jew.homeDir) return errors.New("Configuration load failed.") }
func main() { flag.Parse() // Test cfgfile exists res := testcfgfile() if res != nil { fmt.Println("Configuration file error: " + res.Error()) os.Exit(1) } // Parse in config file err := gcfg.ReadFileInto(&config, cfgfile) if err != nil { fmt.Println("Configuration file error: " + err.Error()) os.Exit(1) } if chkping && pcount == 0 { pcount = config.Ping.Packets } if chkdns { dns.TestHosts(config.Dns.Host, debug) } if chkping { ping.PingHosts(config.Ping.Host, pcount, debug) } }
func loadConfigurations() { cfg := struct { Wallet struct { WalletStorePath string } }{} var sf = "wallet.conf" wd, err := os.Getwd() if err != nil { log.Println(err) } else { sf = wd + "/" + sf } err = gcfg.ReadFileInto(&cfg, sf) if err != nil { log.Println(err) log.Println("Wallet using default settings...") } else { log.Println("Walet using settings from: " + sf) log.Println(cfg) walletStorePath = cfg.Wallet.WalletStorePath } }
func LoadConfig(cfgPath string) *Config { var cfg Config err := gcfg.ReadFileInto(&cfg, cfgPath) if err != nil { log.Printf("Error while reading configuration: %s", err.Error()) panic(err) } // do some basic checking if len(cfg.Billing.Currency) != 3 { log.Printf("Warning: currency is set to [%s], but currency codes should be three characters", cfg.Billing.Currency) } if cfg.Billing.BandwidthOverageFee == 0 { log.Printf("Warning: bandwidth overage fee not set") } if cfg.Billing.StorageFee == 0 { log.Printf("Warning: storage fee not set") } if cfg.Billing.BillingInterval == 0 { log.Printf("Warning: billing interval not set, defaulting to 60 minutes") cfg.Billing.BillingInterval = 60 } if cfg.Billing.BillingVmMinimum < 1 { log.Printf("Warning: minimum VM billing intervals less than 1, setting to 1") cfg.Billing.BillingVmMinimum = 1 } return &cfg }
func main() { // Parse command line arguments var ( config_file = flag.String("config", "", "Path to configuration file") ) flag.Parse() // Load configuration into package variable Config config_error := gcfg.ReadFileInto(&Config, *config_file) if config_error != nil { log.Fatal("Could not load config file: " + config_error.Error()) } // Instantiate StatsD connection if Config.Statsd.Host == "" { StatsD = g2s.Noop() } else { StatsD, _ = g2s.Dial(Config.Statsd.Protocol, Config.Statsd.Host+":"+Config.Statsd.Port) } // Log startup log.Println("go-airbrake-proxy started") // Fire up an HTTP server and handle it http.HandleFunc("/", httpHandler) http.ListenAndServe(Config.Listen.Host+":"+Config.Listen.Port, nil) }
func NewEntityFactory(cfgFile string) (EntityFactory, error) { ef := &entityFactoryStruct{ Unit: make(map[string]*unit.UnitType), Tower: make(map[string]*tower.TowerType), } err := gcfg.ReadFileInto(ef, cfgFile) if err != nil { return nil, err } for name, u := range ef.Unit { if name != u.Name { return nil, fmt.Errorf("Unit is listed as '%s' but name = '%s'", name, u.Name) } } for name, t := range ef.Tower { if name != t.Name { return nil, fmt.Errorf("Tower is listed as '%s' but name = '%s'", name, t.Name) } } return ef, nil }
func (c *Config) getConfig() error { flag.Parse() if c.General.Configs != "" { configs := filepath.SplitList(c.General.Configs) for _, config := range configs { err := gcfg.ReadFileInto(c, config) if err != nil { fmt.Fprintf(os.Stderr, "Error loading config: %s\n\n%s\n", config, err.Error()) os.Exit(2) } } } if c.General.Path == "" { fmt.Fprintf(os.Stderr, "Missing path\n") flag.Usage() os.Exit(2) } if c.General.Mountpoint == "" { fmt.Fprintf(os.Stderr, "Missing mount point\n") flag.Usage() os.Exit(2) } return nil }
func LoadConfig(home string) (*Config, error) { cfg := &Config{} file := os.Getenv("STF_CONFIG") if file == "" { file = path.Join("etc", "config.gcfg") } if !filepath.IsAbs(file) { file = path.Join(home, file) } log.Printf("Loading config file %s", file) err := gcfg.ReadFileInto(cfg, file) if err != nil { return nil, errors.New( fmt.Sprintf( "Failed to load config file '%s': %s", file, err, ), ) } cfg.FileName = file cfg.Prepare() return cfg, nil }
func configReader(fileName string) error { stat, err := os.Stat(fileName) if err != nil { log.Printf("Failed to find config file: %s\n", err) return err } if !stat.ModTime().After(lastReadConfig) { return err } lastReadConfig = time.Now() log.Printf("Loading config: %s\n", fileName) cfg := new(AppConfig) err = gcfg.ReadFileInto(cfg, fileName) if err != nil { log.Printf("Failed to parse config data: %s\n", err) return err } cfg.Flags.HasStatHat = len(cfg.StatHat.ApiKey) > 0 // log.Println("STATHAT APIKEY:", cfg.StatHat.ApiKey) // log.Println("STATHAT FLAG :", cfg.Flags.HasStatHat) Config = cfg return nil }
// Loads mumbledj.gcfg into dj.conf, a variable of type DjConfig. func loadConfiguration() error { if gcfg.ReadFileInto(&dj.conf, fmt.Sprintf("%s/.mumbledj/config/mumbledj.gcfg", dj.homeDir)) == nil { return nil } fmt.Printf("%s/.mumbledj/config/mumbledj.gcfg\n", dj.homeDir) return errors.New("Configuration load failed.") }
func loadConfig() error { err := gcfg.ReadFileInto(&cfg, configFile) if err != nil { return err } return nil }