当前位置: 首页>>代码示例>>Golang>>正文


Golang toml.DecodeReader函数代码示例

本文整理汇总了Golang中github.com/BurntSushi/toml.DecodeReader函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeReader函数的具体用法?Golang DecodeReader怎么用?Golang DecodeReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DecodeReader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Load

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
}
开发者ID:sparkymat,项目名称:wain,代码行数:27,代码来源:config.go

示例2: LoadRingConfig

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
}
开发者ID:getcfs,项目名称:cfs-binary-release,代码行数:35,代码来源:config.go

示例3: loadReader

// 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
}
开发者ID:unirita,项目名称:remexec,代码行数:8,代码来源:config.go

示例4: readConf

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
}
开发者ID:nicollet,项目名称:bosun,代码行数:34,代码来源:main.go

示例5: Read

func Read(r io.Reader) (layout *Layout, err error) {
	_, err = toml.DecodeReader(r, &layout)
	if err != nil {
		return nil, err
	}
	return layout, nil
}
开发者ID:kierdavis,项目名称:k12,代码行数:7,代码来源:layout.go

示例6: handlePostConfig

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
	}
}
开发者ID:aftran,项目名称:robustirc,代码行数:29,代码来源:api.go

示例7: loadConfDir

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
}
开发者ID:mpdroog,项目名称:deltareport,代码行数:27,代码来源:config.go

示例8: main

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)
	}
}
开发者ID:zoncoen,项目名称:tq,代码行数:30,代码来源:tq.go

示例9: Init

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
}
开发者ID:mpdroog,项目名称:deltareport,代码行数:28,代码来源:config.go

示例10: TestOpen

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:%[email protected](%s:%d)/%s", ncfg.UserName, ncfg.Password, ncfg.HostName, ncfg.Port, ncfg.DBName))
		} else {
			d.AddNode(ncfg.Name, fmt.Sprintf("%[email protected](%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)
	}
}
开发者ID:mhannig,项目名称:clustersql,代码行数:31,代码来源:cluster_test.go

示例11: Read

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
}
开发者ID:kierdavis,项目名称:k12,代码行数:7,代码来源:footprint.go

示例12: OpenRepository

// 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
}
开发者ID:directorz,项目名称:mailfull-go,代码行数:60,代码来源:repository.go

示例13: ParseConfig

func ParseConfig(reader io.Reader) (*DParConfig, error) {
	config := defaultConfiguration()
	if _, err := toml.DecodeReader(reader, config); err == nil {
		return config, nil
	} else {
		return config, err
	}
}
开发者ID:postfix,项目名称:dpar,代码行数:8,代码来源:config.go

示例14: parseAsToml

func parseAsToml(r io.Reader) (conf, error) {
	var conf conf
	_, err := toml.DecodeReader(r, &conf)
	if err != nil {
		return nil, err
	}
	return conf, nil
}
开发者ID:Talos208,项目名称:conflag,代码行数:8,代码来源:parser.go

示例15: UpdateConfigFromFile

func UpdateConfigFromFile(conf *Config, f io.Reader) error {
	_, err := toml.DecodeReader(f, conf)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:jamessharp,项目名称:coreinit,代码行数:8,代码来源:config.go


注:本文中的github.com/BurntSushi/toml.DecodeReader函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。