示例#1
1
文件: config.go 项目: sparkymat/wain
func Load() Config {
	file, err := os.Open(Path())

	var wConfig Config

	if err != nil {
		log.Printf("Config file not found. Creating new...")
		err = CreateNewConfigFile()

		if err != nil {
			log.Fatalf("Unable to create new config file. Error: %v", err)
			os.Exit(1)
		}

		file, err = os.Open(Path())
		if err != nil {
			log.Fatalf("Unable to read new config file. Error: %v", err)
			os.Exit(1)
		}
	}

	defer file.Close()

	toml.DecodeReader(file, &wConfig)

	return wConfig
}
示例#2
0
func (o *Server) LoadRingConfig(config interface{}) (err error) {
	o.Lock()
	defer o.Unlock()
	e := NewEnvGetter(fmt.Sprintf("OORT_%s", strings.ToUpper(o.serviceName)), "_")
	localConfig := e.Get("LOCAL_CONFIG")
	if localConfig != "" {
		_, err = toml.DecodeFile(localConfig, config)
		if err != nil {
			return err
		}
	}
	log.Println("Using ring version:", o.ring.Version())
	b := bytes.NewReader(o.ring.Config())
	if b.Len() > 0 {
		_, err = toml.DecodeReader(b, config)
		if err != nil {
			return err
		}
	}
	// Now overlay per node config on top
	n := o.ring.LocalNode()
	if n == nil {
		panic("n is nil")
	}
	b = bytes.NewReader(o.ring.LocalNode().Config())
	if b.Len() > 0 {
		_, err = toml.DecodeReader(b, config)
		if err != nil {
			return err
		}
	}
	log.Printf("Local Node config is: \n%s", o.ring.LocalNode().Config())
	log.Printf("Ring config is: \n%s", o.ring.Config())
	return nil
}
示例#3
0
文件: config.go 项目: unirita/remexec
// loadReader loads config from reader.
func loadReader(reader io.Reader) (*Config, error) {
	c := new(Config)
	if _, err := toml.DecodeReader(reader, c); err != nil {
		return nil, err
	}
	return c, nil
}
示例#4
0
文件: main.go 项目: nicollet/bosun
func readConf() *conf.Conf {
	conf := &conf.Conf{
		Freq: 15,
	}
	loc := *flagConf
	if *flagConf == "" {
		p, err := exePath()
		if err != nil {
			slog.Error(err)
			return conf
		}
		dir := filepath.Dir(p)
		loc = filepath.Join(dir, "scollector.toml")
	}
	f, err := os.Open(loc)
	if err != nil {
		if *flagConf != "" {
			slog.Fatal(err)
		}
		if *flagDebug {
			slog.Error(err)
		}
	} else {
		defer f.Close()
		md, err := toml.DecodeReader(f, conf)
		if err != nil {
			slog.Fatal(err)
		}
		if u := md.Undecoded(); len(u) > 0 {
			slog.Fatalf("extra keys in %s: %v", loc, u)
		}
	}
	return conf
}
示例#5
0
文件: layout.go 项目: kierdavis/k12
func Read(r io.Reader) (layout *Layout, err error) {
	_, err = toml.DecodeReader(r, &layout)
	if err != nil {
		return nil, err
	}
	return layout, nil
}
示例#6
0
文件: api.go 项目: aftran/robustirc
func handlePostConfig(w http.ResponseWriter, r *http.Request) {
	revision, err := strconv.ParseInt(r.Header.Get("X-RobustIRC-Config-Revision"), 0, 64)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	var unused config.Network
	var body bytes.Buffer
	if _, err := toml.DecodeReader(io.TeeReader(r.Body, &body), &unused); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	if node.State() != raft.Leader {
		maybeProxyToLeader(w, r, nopCloser{&body})
		return
	}

	if err := applyConfig(int(revision), body.String()); err != nil {
		if err == raft.ErrNotLeader {
			maybeProxyToLeader(w, r, nopCloser{&body})
			return
		}

		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
}
示例#7
0
func loadConfDir() error {
	if len(C.Confdir) > 0 {
		return filepath.Walk(C.Confdir, func(path string, f os.FileInfo, err error) error {
			if path == C.Confdir {
				// ignore root
				return nil
			}

			if strings.HasSuffix(path, ".toml") {
				r, e := os.Open(path)
				if e != nil {
					return e
				}
				var f File
				if _, e := toml.DecodeReader(r, &f); e != nil {
					r.Close()
					return fmt.Errorf("TOML(%s): %s", path, e)
				}
				r.Close()
				C.Files = append(C.Files, f)
			}

			return nil
		})
	}
	return nil
}
示例#8
0
文件: tq.go 项目: zoncoen/tq
func main() {
	flag.Parse()

	if opt.help {
		flag.Usage()
		os.Exit(0)
	}

	var t interface{}
	_, err := toml.DecodeReader(os.Stdin, &t)
	if err != nil {
		log.Fatalf("parse error: %s", err)
	}

	var filter ast.Filter
	if flag.NArg() > 0 {
		str := flag.Arg(0)
		r := strings.NewReader(str)
		filter = parser.Parse(r)
		t, err = transformer.Transform(t, filter)
		if err != nil {
			log.Fatalf("%s", err)
		}
	}

	err = write(os.Stdout, t)
	if err != nil {
		log.Fatalf("%s", err)
	}
}
示例#9
0
func Init(f string) error {
	r, e := os.Open(f)
	if e != nil {
		return e
	}
	defer r.Close()
	if _, e := toml.DecodeReader(r, &C); e != nil {
		return fmt.Errorf("TOML: %s", e)
	}
	if e := loadConfDir(); e != nil {
		return e
	}

	if e := prepareRegexp(); e != nil {
		return e
	}

	Hostname, e = os.Hostname()
	if e != nil {
		return e
	}

	DB, e = bolt.Open(C.Db, 0600, &bolt.Options{Timeout: 1 * time.Second})
	if e != nil {
		return e
	}
	return nil
}
示例#10
0
func TestOpen(t *testing.T) {
	cfgfile := os.Getenv("DBCONFIG")
	if cfgfile == "" {
		cfgfile = "config.toml"
	}
	cfg := new(Config)
	if f, err := os.Open(cfgfile); err != nil {
		t.Fatal(err, "(did you set the DBCONFIG env variable?)")
	} else {
		if _, err := toml.DecodeReader(f, cfg); err != nil {
			t.Fatal(err)
		}
	}

	d := NewDriver("ClusterSql", mysql.MySQLDriver{})

	for _, ncfg := range cfg.Nodes {
		if ncfg.Password != "" {
			d.AddNode(ncfg.Name, fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", ncfg.UserName, ncfg.Password, ncfg.HostName, ncfg.Port, ncfg.DBName))
		} else {
			d.AddNode(ncfg.Name, fmt.Sprintf("%s@tcp(%s:%d)/%s", ncfg.UserName, ncfg.HostName, ncfg.Port, ncfg.DBName))
		}
	}

	sql.Register("cluster", d)
	var err error
	db, err = sql.Open("cluster", "galera")
	if err != nil {
		t.Error(err)
	}
}
示例#11
0
func Read(r io.Reader) (footprints map[string]*Footprint, err error) {
	_, err = toml.DecodeReader(r, &footprints)
	if err != nil {
		return nil, err
	}
	return footprints, nil
}
示例#12
0
// OpenRepository opens a Repository and creates a new Repository instance.
func OpenRepository(basePath string) (*Repository, error) {
	rootPath, err := filepath.Abs(basePath)
	if err != nil {
		return nil, err
	}

	for {
		configDirPath := filepath.Join(rootPath, DirNameConfig)

		fi, err := os.Stat(configDirPath)
		if err != nil {
			if err.(*os.PathError).Err != syscall.ENOENT {
				return nil, err
			}
		} else {
			if fi.IsDir() {
				break
			} else {
				return nil, ErrInvalidRepository
			}
		}

		parentPath := filepath.Clean(filepath.Join(rootPath, ".."))
		if rootPath == parentPath {
			return nil, ErrNotRepository
		}
		rootPath = parentPath
	}

	configFilePath := filepath.Join(rootPath, DirNameConfig, FileNameConfig)

	fi, err := os.Stat(configFilePath)
	if err != nil {
		return nil, err
	}
	if fi.IsDir() {
		return nil, ErrInvalidRepository
	}

	configFile, err := os.Open(configFilePath)
	if err != nil {
		return nil, err
	}
	defer configFile.Close()

	c := DefaultRepositoryConfig()
	if _, err = toml.DecodeReader(configFile, c); err != nil {
		return nil, err
	}

	c.Normalize(rootPath)

	r, err := NewRepository(c)
	if err != nil {
		return nil, err
	}

	return r, nil
}
示例#13
0
文件: config.go 项目: postfix/dpar
func ParseConfig(reader io.Reader) (*DParConfig, error) {
	config := defaultConfiguration()
	if _, err := toml.DecodeReader(reader, config); err == nil {
		return config, nil
	} else {
		return config, err
	}
}
示例#14
0
func parseAsToml(r io.Reader) (conf, error) {
	var conf conf
	_, err := toml.DecodeReader(r, &conf)
	if err != nil {
		return nil, err
	}
	return conf, nil
}
示例#15
0
func UpdateConfigFromFile(conf *Config, f io.Reader) error {
	_, err := toml.DecodeReader(f, conf)
	if err != nil {
		return err
	}

	return nil
}
示例#16
0
文件: config.go 项目: unikk/cuto
func loadReader(reader io.Reader) (*ServantConfig, error) {
	sc := new(ServantConfig)
	if _, err := toml.DecodeReader(reader, sc); err != nil {
		return nil, err
	}

	sc.replaceCutoroot()

	return sc, nil
}
示例#17
0
文件: config.go 项目: netvl/imaged
func (c *ConfigWrapper) Load(reader io.Reader) error {
	// We completely replace config object here instead of in-place loading
	// This is needed for safe runtime config reload
	var conf Config
	if _, err := toml.DecodeReader(reader, &conf); err != nil {
		return err
	}
	c.Config = &conf
	return nil
}
示例#18
0
func decode(r io.Reader) (configuration, error) {
	cfg := configuration{}
	res, err := toml.DecodeReader(r, &cfg)
	if err != nil {
		return cfg, fmt.Errorf("can't parse gender config: %s", err)
	}
	if und := res.Undecoded(); len(und) > 0 {
		log.Printf("WARNING: Unknown values in gender config file: %v", und)
	}

	return cfg, nil
}
示例#19
0
func loadReader(reader io.Reader) error {
	c := new(config)

	if _, err := toml.DecodeReader(reader, c); err != nil {
		return err
	}

	Aws = &c.Aws
	Log = &c.Log

	return nil
}
示例#20
0
文件: conf.go 项目: sdgdsffdsfff/gost
func ParseConf() (*Conf, error) {
	conf := &Conf{}
	f, err := os.Open(*configFile)
	if err != nil {
		return nil, err
	}
	meta, err := toml.DecodeReader(f, conf)
	if err != nil {
		return nil, fmt.Errorf("Error decoding %s: %s", *configFile, err)
	}

	for _, field := range []string{"graphite_addr", "port", "debug_port", "flush_interval_ms", "namespace"} {
		if !meta.IsDefined(field) {
			return nil, fmt.Errorf("field %s is required", field)
		}
	}
	if conf.FlushIntervalMS <= 0 {
		return nil, errors.New("flush_interval_ms must be positive")
	}

	if meta.IsDefined("forwarding_addr") {
		conf.forwardingEnabled = true
	}

	if meta.IsDefined("forwarder_listen_addr") {
		conf.forwarderEnabled = true
		if !meta.IsDefined("forwarded_namespace") {
			return nil, errors.New("forwarded_namespace is required if gost is configured as a forwarder")
		}
	}
	conf.OSStats = nil
	conf.Scripts = nil
	/**
		if err := validateOSStatsConf(conf.OSStats, meta); err != nil {
			return nil, err
		}
		if !meta.IsDefined("os_stats", "check_interval_ms") {
			conf.OSStats.CheckIntervalMS = conf.FlushIntervalMS
		}
		if err := validateScriptsConf(conf.Scripts, meta); err != nil {
			return nil, err
		}
	**/
	if conf.Namespace == "" {
		conf.Namespace = "default"
	}
	conf.ForwardedNamespace, err = filterNamespace(conf.ForwardedNamespace)
	if err != nil {
		return nil, err
	}
	return conf, nil
}
示例#21
0
文件: api.go 项目: dopuskh3/robustirc
func handlePostConfig(w http.ResponseWriter, r *http.Request) {
	revision, err := strconv.ParseInt(r.Header.Get("X-RobustIRC-Config-Revision"), 0, 64)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	configMu.Lock()

	if got, want := int(revision), netConfig.Revision; got != want {
		http.Error(w, fmt.Sprintf("Revision mismatch (got %d, want %d). Try again.", got, want), http.StatusBadRequest)
		return
	}

	var unused config.Network
	var body bytes.Buffer
	if _, err := toml.DecodeReader(io.TeeReader(r.Body, &body), &unused); err != nil {
		configMu.Unlock()
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	if node.State() != raft.Leader {
		maybeProxyToLeader(w, r, nopCloser{&body})
		return
	}

	applyMu.Lock()
	msg := ircServer.NewRobustMessage(types.RobustConfig, types.RobustId{}, body.String())
	msg.Revision = int(revision) + 1
	msgbytes, err := json.Marshal(msg)
	if err != nil {
		applyMu.Unlock()
		configMu.Unlock()
		http.Error(w, fmt.Sprintf("Could not store message, cannot encode it as JSON: %v", err),
			http.StatusBadRequest)
		return
	}

	f := node.Apply(msgbytes, 10*time.Second)
	applyMu.Unlock()
	err = f.Error()
	configMu.Unlock()
	if err != nil {
		if err == raft.ErrNotLeader {
			maybeProxyToLeader(w, r, nopCloser{&body})
			return
		}
		http.Error(w, fmt.Sprintf("Apply(): %v", err), http.StatusInternalServerError)
		return
	}
}
示例#22
0
文件: config.go 项目: deweerdt/amua
func NewConfig(filename string) (*Config, error) {
	cfg := &Config{}
	file, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer file.Close()
	if _, err := toml.DecodeReader(bufio.NewReader(file), &cfg); err != nil {
		return nil, err
	}

	return cfg, nil
}
示例#23
0
func (c *Config) Read(filename string) error {
	file, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer file.Close()

	if _, err = toml.DecodeReader(file, c); err != nil {
		return err
	}

	return nil
}
示例#24
0
// decodeEmotes parses the data from the reader into a list of emotes.
func decodeEmotes(r io.Reader) ([]emote, error) {
	cfgs := emoteConfigs{}

	res, err := toml.DecodeReader(r, &cfgs)
	if err != nil {
		return nil, fmt.Errorf("Error parsing emote config file: %s", err)
	}

	if und := res.Undecoded(); len(und) > 0 {
		log.Printf("WARNING: Unknown values in emote config file: %v", und)
	}
	return cfgs.Emote, nil
}
示例#25
0
func loadReader(r io.Reader) error {
	c := new(Config)
	if _, err := toml.DecodeReader(r, c); err != nil {
		return err
	}

	replaceCutoroot(c)

	Server = c.Server
	Log = c.Log
	Jobnet = c.Jobnet

	return nil
}
示例#26
0
// GetStellarToml returns stellar.toml file for a given domain
func (r *Resolver) GetStellarToml(domain string) (stellarToml StellarToml, err error) {
	var resp *http.Response
	resp, err = http.Get("https://www." + domain + "/.well-known/stellar.toml")
	if err != nil {
		return
	}
	if resp.StatusCode != 200 {
		err = errors.New("stellar.toml response status code indicates error")
		return
	}

	_, err = toml.DecodeReader(resp.Body, &stellarToml)
	return
}
示例#27
0
// Parse converts the config file into a readable map
func (c Config) Parse() (*ConfigMap, error) {
	config := &ConfigMap{}
	file, err := c.Open()
	if err != nil {
		return nil, err
	}

	_, err = toml.DecodeReader(file, config)
	if err != nil {
		return nil, err
	}

	return config, nil
}
示例#28
0
func LoadDBConf(r io.Reader) (conf *DBConf, err error) {
	defer func() {
		if perr := recover(); perr != nil {
			err = perr.(error)
		}
	}()
	conf = DefaultDBConf.DeepCopy()

	if _, err := toml.DecodeReader(r, &conf); err != nil {
		return nil, err
	}

	return conf, nil
}
示例#29
0
文件: config.go 项目: unikk/cuto
func loadReader(reader io.Reader) error {
	c := new(config)
	c.Job.AttemptLimit = 1
	if _, err := toml.DecodeReader(reader, c); err != nil {
		return err
	}

	replaceCutoroot(c)

	Dir = &c.Dir
	Job = &c.Job
	DB = &c.DB
	Log = &c.Log
	return nil
}
示例#30
0
文件: main.go 项目: kplimack/gh-keys
func main() {
	if flag.NArg() != 0 {
		flag.Usage()
	}

	var tmp interface{}
	if _, err := toml.DecodeReader(os.Stdin, &tmp); err != nil {
		log.Fatalf("Error decoding TOML: %s", err)
	}

	typedTmp := translate(tmp)
	if err := json.NewEncoder(os.Stdout).Encode(typedTmp); err != nil {
		log.Fatalf("Error encoding JSON: %s", err)
	}
}