本文整理匯總了Golang中code/google/com/p/gcfg.ReadFileInto函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadFileInto函數的具體用法?Golang ReadFileInto怎麽用?Golang ReadFileInto使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ReadFileInto函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoadConfigs
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)
}
示例2: ParseConfig
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
}
示例3: ReadConfiguration
// 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
}
示例4: BootstrapConfig
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
}
示例5: init
func init() {
err := gcfg.ReadFileInto(&MasterConfig, "kirisurf.conf")
log.Debug("Read configuration successfully")
if err != nil {
panic(err.Error())
}
}
示例6: main
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
}
}
示例7: parseConfigFile
func parseConfigFile(filename string, cfg *Config) error {
// Just testing config structs
err := gcfg.ReadFileInto(cfg, configFile)
if err != nil {
panic(err)
}
}
示例8: ReadConfig
func ReadConfig(cfg *Config, path string) (ok bool) {
err := gcfg.ReadFileInto(cfg, path)
if err != nil {
return false
}
return true
}
示例9: getCfg
// 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
}
示例10: LoadConfig
func LoadConfig(filename string) (Config, error) {
var c Config
err := gcfg.ReadFileInto(&c, filename)
return c, err
}
示例11: init
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.")
}
示例12: main
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
}
示例13: readConfig
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
}
}
示例14: LoadConfig
// 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)
}
}
示例15: main
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)
}
}