本文整理匯總了Golang中code/google/com/p/gcfg.ReadStringInto函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadStringInto函數的具體用法?Golang ReadStringInto怎麽用?Golang ReadStringInto使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ReadStringInto函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewConfig
func NewConfig(cfgfile string) *Config {
var cfg Config
gcfg.ReadStringInto(&cfg, defaultConfig)
content, err := ioutil.ReadFile(cfgfile)
if err != nil {
log.Fatal(err)
}
err = gcfg.ReadStringInto(&cfg, string(content))
if err != nil {
log.Fatal("Failed to parse "+cfgfile+":", err)
}
return &cfg
}
示例2: readConfig
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
}
示例3: initConfigurationTo
//initConfigurationTo prepara um arquivo de configuração inicial para o diretório informado,
//retornando sua representação em memória
func initConfigurationTo(dir string) localStorageConfig {
file, err := os.Create(filepath.Join(dir, DIR_CONFIG_FILENAME))
defer func() {
file.Close()
}()
if err != nil {
log.Fatal(err.Error())
}
configSample := `
[Global]
locked=false
[Filters]
allow="text/plain"
allow="application/xml"
allow="text/xml"
allow="image/jpeg"
allow="image/png"
allow="image/bmp"
`
file.WriteString(configSample)
var config localStorageConfig
gcfg.ReadStringInto(&config, configSample)
return config
}
示例4: ReadConfig
func ReadConfig(configString string, cfg Configurer) error {
err := gcfg.ReadStringInto(cfg, configString)
if err != nil {
log.Println("Error Loading configuration", err)
}
return err
}
示例5: ReadConfig
func ReadConfig() *CliConf {
cfg := new(CliConf)
filename := os.Getenv("HOME") + "/.factom/factom-cli.conf"
if err := gcfg.ReadFileInto(cfg, filename); err != nil {
gcfg.ReadStringInto(cfg, defaultConf)
}
return cfg
}
示例6: TryMe
func TryMe(data string) error {
cfg := struct {
Section struct {
Name string
}
}{}
return gcfg.ReadStringInto(&cfg, data)
}
示例7: ReadConfig
// ReadConfig reads the default factomexplorer.conf file and returns the
// ExplorerConfig object corresponding to the state of the conf file.
func ReadConfig() *ExplorerConfig {
cfg := new(ExplorerConfig)
filename := os.Getenv("HOME") + "/.factom/factomexplorer.conf"
err := gcfg.ReadFileInto(cfg, filename)
if err != nil {
gcfg.ReadStringInto(cfg, defaultConfig)
}
return cfg
}
示例8: ReadConfig
/**
* ReadConfig reads config from a string
* @param string The configuration definition
* @return Config A Config struct, or nil if something went wrong
* @return error Returns error if something went wrong. Config will be nil in this case.
*/
func ReadConfig(configDef string) (*Config, error) {
cfg := Config{}
if err := gcfg.ReadStringInto(&cfg, configDef); err != nil {
return nil, err
}
if cfg.Threads.Hash < 1 {
return nil, fmt.Errorf("Need at least one hash thread")
}
if cfg.Threads.Upload < 1 {
return nil, fmt.Errorf("Need at least one upload thread")
}
if len(cfg.Backup) == 0 {
return nil, errors.New("No configurations given")
}
for key, backup := range cfg.Backup {
if backup.Region.Region == nil {
return nil, fmt.Errorf("No region supplied for config `%s`", key)
}
if backup.Path == "" {
return nil, fmt.Errorf("No path supplied for config `%s`", key)
}
if backup.Db == "" {
return nil, fmt.Errorf("No db supplied for config `%s`", key)
}
if backup.Vault == "" {
return nil, fmt.Errorf("No vault supplied for config `%s`", key)
}
if backup.AwsAccess != "" && backup.AwsSecret == "" {
return nil, fmt.Errorf("AWS Access code suplied, but no AWS Secret for config `%s`", key)
}
if backup.AwsAccess == "" && backup.AwsSecret != "" {
return nil, fmt.Errorf("AWS Secret suplied, but no AWS Access code for config `%s`", key)
}
if backup.AwsAccess == "" && backup.AwsSecret == "" {
if cfg.Aws.Access != "" && cfg.Aws.Secret != "" {
backup.AwsAccess = cfg.Aws.Access
backup.AwsSecret = cfg.Aws.Secret
} else {
return nil, fmt.Errorf("No AWS credentials supplied for backup `%s`", key)
}
}
}
return &cfg, nil
}
示例9: LoadConfiguration
//Loads the configurations passed either by flags or by the configuration file
func LoadConfiguration() Config {
flag.Parse()
var cfg Config
if *flConfig != "" {
_ = gcfg.ReadFileInto(&cfg, *flConfig)
} else {
_ = gcfg.ReadStringInto(&cfg, defaultConfig)
}
var env = os.Getenv("EGI_AR_REST_API_ENV")
switch env {
default:
os.Setenv("EGI_AR_REST_API_ENV", "development")
case "test":
case "production":
}
if *flServerIp != "" {
cfg.Server.Bindip = *flServerIp
}
if *flServerPort != 0 {
cfg.Server.Port = *flServerPort
}
if *flServerMaxProcs != 0 {
cfg.Server.Maxprocs = *flServerMaxProcs
}
if *flMongoHost != "" {
cfg.MongoDB.Host = *flMongoHost
}
if *flMongoPort != 0 {
cfg.MongoDB.Port = *flMongoPort
}
if *flMongoDatabase != "" {
cfg.MongoDB.Db = *flMongoDatabase
}
if *flCache == "yes" {
cfg.Server.Cache = true
}
if *flGzip == "no" {
cfg.Server.Gzip = false
}
if *flProfile != "" {
cfg.Profile = *flProfile
}
if *flCert != "" {
cfg.Server.Cert = *flCert
}
if *flPrivKey != "" {
cfg.Server.Privkey = *flPrivKey
}
return cfg
}
示例10: defaultConfig
func defaultConfig() (Config, error) {
var def Config
err := gcfg.ReadStringInto(&def, cfg)
if err != nil {
return Config{}, err
}
def.API.Version = apiversion
return def, nil
}
示例11: LoadConfiguration
func LoadConfiguration(cfgFile string) Config {
var err error
var cfg configFile
if cfgFile != "" {
err = gcfg.ReadFileInto(&cfg, cfgFile)
} else {
err = gcfg.ReadStringInto(&cfg, defaultConfig)
}
if err != nil {
log.Panic(err)
}
return cfg.Mongo
}
示例12: loadConfigFromString
func loadConfigFromString(bytes []byte, user string) (config Configuration, err error) {
inicfg := struct {
Dockersh Configuration
User map[string]*Configuration
}{}
err = gcfg.ReadStringInto(&inicfg, string(bytes))
if err != nil {
return config, err
}
if inicfg.User[user] == nil {
return inicfg.Dockersh, nil
}
return mergeConfigs(inicfg.Dockersh, *inicfg.User[user], false), nil
}
示例13: ExampleReadStringInto
func ExampleReadStringInto() {
cfgStr := `; Comment line
[section]
name=value # comment`
cfg := struct {
Section struct {
Name string
}
}{}
err := gcfg.ReadStringInto(&cfg, cfgStr)
if err != nil {
log.Fatalf("Failed to parse gcfg data: %s", err)
}
fmt.Println(cfg.Section.Name)
// Output: value
}
示例14: ExampleReadStringInto_hyphens
func ExampleReadStringInto_hyphens() {
cfgStr := `; Comment line
[section-name]
variable-name=value # comment`
cfg := struct {
Section_Name struct {
Variable_Name string
}
}{}
err := gcfg.ReadStringInto(&cfg, cfgStr)
if err != nil {
log.Fatalf("Failed to parse gcfg data: %s", err)
}
fmt.Println(cfg.Section_Name.Variable_Name)
// Output: value
}
示例15: ExampleReadStringInto_bool
func ExampleReadStringInto_bool() {
cfgStr := `; Comment line
[section]
switch=on`
cfg := struct {
Section struct {
Switch bool
}
}{}
err := gcfg.ReadStringInto(&cfg, cfgStr)
if err != nil {
log.Fatalf("Failed to parse gcfg data: %s", err)
}
fmt.Println(cfg.Section.Switch)
// Output: true
}