當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。