• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang toml.MetaData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: validateConfig

//check validation of config
func validateConfig(conf *Config, md *toml.MetaData) error {
	//for protection when debugging on non production environment
	var errStrings []string

	format := "[%s]"
	inValid := false
	for _, keys := range checkTomlKeys {
		if !md.IsDefined(keys...) {
			switch len(keys) {
			case 1:
				format = "[%s]"
			case 2:
				format = "[%s] %s"
			case 3:
				format = "[%s.%s] %s"
			default:
				//invalid check string
				inValid = true
				break
			}
			keysIfc := u.SliceStrToInterface(keys)
			errStrings = append(errStrings, fmt.Sprintf(format, keysIfc...))
		}
	}

	// Error
	if inValid {
		return errors.New("Error: Check Text has wrong number of parameter")
	}
	if len(errStrings) != 0 {
		return fmt.Errorf("Error: There are lacks of keys : %#v \n", errStrings)
	}

	return nil
}
开发者ID:hiromaily,项目名称:go-book-teacher,代码行数:36,代码来源:config.go


示例2: printTypes

func printTypes(md toml.MetaData) {
	tabw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
	for _, key := range md.Keys() {
		fmt.Fprintf(tabw, "%s%s\t%s\n",
			strings.Repeat("    ", len(key)-1), key, md.Type(key...))
	}
	tabw.Flush()
}
开发者ID:gophergala2016,项目名称:source,代码行数:8,代码来源:main.go


示例3: analyzeFmdConf

func analyzeFmdConf(config map[string]toml.Primitive, md *toml.MetaData) error {
	if section, ok := config["ngxfmd"]; ok {
		err := md.PrimitiveDecode(section, fmConf)
		if err != nil {
			fmt.Println(err.Error())
			return err
		}
		fmt.Printf("(%+v)\n", *fmConf)
		return nil
	} else {
		fmt.Println("analyze nginx files manager configuration failed")
		return errors.New("does not specify fmd section configuration")
	}
}
开发者ID:cxwshawn,项目名称:ornet,代码行数:14,代码来源:ngxfm.go


示例4: analyzeCmddConf

func analyzeCmddConf(config map[string]toml.Primitive, md *toml.MetaData) error {
	if section, ok := config["cmdd"]; ok {
		err := md.PrimitiveDecode(section, cmddConfig)
		if err != nil {
			fmt.Println(err.Error())
			return err
		}
		fmt.Printf("(%+v)\n", *cmddConfig)
		return nil
	} else {
		fmt.Println("analyze cmddConfig failed")
		return errors.New("does not specify cmmd section configuration")
	}
}
开发者ID:cxwshawn,项目名称:ornet,代码行数:14,代码来源:main.go


示例5: validateScriptsConf

func validateScriptsConf(scripts *ScriptsConf, meta toml.MetaData) error {
	if scripts == nil {
		return nil
	}
	if !meta.IsDefined("scripts", "path") {
		return errors.New("scripts section provided without path.")
	}
	if !meta.IsDefined("scripts", "run_interval_ms") {
		return errors.New("scripts section provided without run_interval_ms.")
	}
	if scripts.RunIntervalMS <= 0 {
		return errors.New("scripts.run_interval_ms must be positive")
	}
	return nil
}
开发者ID:sdgdsffdsfff,项目名称:gost,代码行数:15,代码来源:conf.go


示例6: loadSystemConfig

func loadSystemConfig(conf string, isFileName bool) (*SystemConf, error) {
	sc := newSystemConf()
	var decodeMeta toml.MetaData
	var err error
	if isFileName {
		decodeMeta, err = toml.DecodeFile(conf, &sc)
	} else {
		decodeMeta, err = toml.Decode(conf, &sc)
	}
	if err != nil {
		return sc, err
	}
	if len(decodeMeta.Undecoded()) > 0 {
		return sc, fmt.Errorf("undecoded fields in system configuration: %v", decodeMeta.Undecoded())
	}
	sc.md = decodeMeta
	return sc, nil
}
开发者ID:mhenderson-so,项目名称:bosun,代码行数:18,代码来源:system.go


示例7: main

func main() {
	var cfg config
	var md toml.MetaData
	md, err := toml.DecodeFile(configFile, &cfg)
	if err != nil {
		log.Fatal(err)
	}

	for _, o := range cfg.Outs {
		out_plugin := plugin.GetOut(o.Plugin)
		out_cfg_prim := o.Config
		var plugin_conf = out_plugin.GetConfig()
		md.PrimitiveDecode(out_cfg_prim, plugin_conf)
	}

	out := plugin.GetOut("outfile")
	result := out.Write("somestring")
	fmt.Println(result)
}
开发者ID:pik4ez,项目名称:drysh,代码行数:19,代码来源:main.go


示例8: InitHandlerConf

func InitHandlerConf(confs map[string]toml.Primitive, md *toml.MetaData) error {
	var err error
	for k, handler := range CmdHandlers {
		if conf, ok := confs[k]; ok {
			handlerConf := handler.ConfigStruct()
			err = md.PrimitiveDecode(conf, handlerConf)
			if err != nil {
				cmdlog.EPrintln(err.Error())
				return err
			}

			err = handler.Init(handlerConf)
			if err != nil {
				cmdlog.EPrintln(err.Error())
				return err
			}
		}
	}
	return err
}
开发者ID:cxwshawn,项目名称:ornet,代码行数:20,代码来源:cmds.go


示例9: parseConfig

func parseConfig(configFile string) map[string]*Service {
	var config Services
	var md toml.MetaData
	var err error
	if md, err = toml.DecodeFile(configFile, &config); err != nil {
		log.Fatal(err)
	}
	services := make(map[string]*Service)

	for name, serv := range config {
		s := NewService()
		s.Name = name

		services[name] = s

		for _, k := range md.Keys() {
			ks := strings.Split(k.String(), ".")
			if len(ks) > 1 && ks[0] == name {
				switch ks[1] {
				case "srcport":
					s.Srcport = serv.Srcport
				case "srcflags":
					s.Srcflags = serv.Srcflags
				case "srcproto":
					s.Srcproto = serv.Srcproto
				case "dsthost":
					s.Dsthost = serv.Dsthost
				case "dstproto":
					s.Dstproto = serv.Dstproto
				case "dstport":
					s.Dstport = serv.Dstport
				case "enabled":
					s.Enabled = serv.Enabled
				}
			}
		}
	}

	log.Println("Found", len(services), "services")
	return services
}
开发者ID:pho,项目名称:socatgun,代码行数:41,代码来源:main.go


示例10: validateOSStatsConf

func validateOSStatsConf(osStats *OSStatsConf, meta toml.MetaData) error {
	if osStats == nil {
		return nil
	}
	if meta.IsDefined("os_stats", "check_interval_ms") {
		if osStats.CheckIntervalMS <= 0 {
			return errors.New("check_interval_ms must be positive")
		}
	}
	if err := validateMemConf(osStats.Mem); err != nil {
		return err
	}
	if err := validateCPUConf(osStats.CPU); err != nil {
		return err
	}
	// For now, any parseable NetConf is valid.
	for _, diskConf := range osStats.Disk {
		if err := validateDiskConf(diskConf); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:sdgdsffdsfff,项目名称:gost,代码行数:23,代码来源:conf.go


示例11: LoadContainerSettings

//Loads a container configuration object, overriding a base
//This function prevents empty TOML keys (anything you didn't specify) from overriding a preset value.
func LoadContainerSettings(base *Container, inc *Container, meta *toml.MetaData, key ...string) {

	if meta.IsDefined(append(key, "command")...) {
		base.Command = inc.Command
	}

	if meta.IsDefined(append(key, "folder")...) {
		base.Folder = inc.Folder
	}

	if meta.IsDefined(append(key, "privileged")...) {
		base.Privileged = inc.Privileged
	}

	if meta.IsDefined(append(key, "mounts")...) {
		base.Mounts = append(base.Mounts, inc.Mounts...)
	}

	if meta.IsDefined(append(key, "ports")...) {
		base.Ports = append(base.Ports, inc.Ports...)
	}

	if meta.IsDefined(append(key, "dns")...) {
		base.DNS = append(base.DNS, inc.DNS...)
	}

	if meta.IsDefined(append(key, "attach")...) {
		base.Attach = inc.Attach
	}

	if meta.IsDefined(append(key, "purge")...) {
		base.Purge = inc.Purge
	}

	if meta.IsDefined(append(key, "environment")...) {
		base.Environment = append(base.Environment, inc.Environment...)
	}
}
开发者ID:polydawn,项目名称:hroot,代码行数:40,代码来源:parse.go


示例12: SetDefaultConfigValues

func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error {
	neighbors := []neighbor{}
	global := make(map[string]bool)

	for _, key := range md.Keys() {
		if !strings.HasPrefix(key.String(), "Global") {
			continue
		}
		if key.String() != "Global" {
			global[key.String()] = true
		}
	}

	if _, ok := global["Global.AfiSafis.AfiSafiList"]; !ok {
		bt.Global.AfiSafis.AfiSafiList = []AfiSafi{
			AfiSafi{AfiSafiName: "ipv4-unicast"},
			AfiSafi{AfiSafiName: "ipv6-unicast"},
			AfiSafi{AfiSafiName: "l3vpn-ipv4-unicast"},
			AfiSafi{AfiSafiName: "l3vpn-ipv6-unicast"},
			AfiSafi{AfiSafiName: "l2vpn-evpn"},
			AfiSafi{AfiSafiName: "encap"},
			AfiSafi{AfiSafiName: "rtc"},
			AfiSafi{AfiSafiName: "ipv4-flowspec"},
			AfiSafi{AfiSafiName: "l3vpn-ipnv4-flowspec"},
		}
	}

	nidx := 0
	for _, key := range md.Keys() {
		if !strings.HasPrefix(key.String(), "Neighbors.NeighborList") {
			continue
		}
		if key.String() == "Neighbors.NeighborList" {
			neighbors = append(neighbors, neighbor{attributes: make(map[string]bool)})
			nidx++
		} else {
			neighbors[nidx-1].attributes[key.String()] = true
		}
	}
	for i, n := range neighbors {
		neighbor := &bt.Neighbors.NeighborList[i]
		timerConfig := &neighbor.Timers.TimersConfig

		if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.ConnectRetry"]; !ok {
			timerConfig.HoldTime = float64(DEFAULT_CONNECT_RETRY)
		}
		if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.HoldTime"]; !ok {
			timerConfig.HoldTime = float64(DEFAULT_HOLDTIME)
		}
		if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.KeepaliveInterval"]; !ok {
			timerConfig.KeepaliveInterval = timerConfig.HoldTime / 3
		}

		if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.IdleHoldTimeAfterReset"]; !ok {
			timerConfig.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
		}

		if _, ok := n.attributes["Neighbors.NeighborList.AfiSafis.AfiSafiList"]; !ok {
			if neighbor.NeighborConfig.NeighborAddress.To4() != nil {
				neighbor.AfiSafis.AfiSafiList = []AfiSafi{
					AfiSafi{AfiSafiName: "ipv4-unicast"}}
			} else {
				neighbor.AfiSafis.AfiSafiList = []AfiSafi{
					AfiSafi{AfiSafiName: "ipv6-unicast"}}
			}
		} else {
			for _, rf := range neighbor.AfiSafis.AfiSafiList {
				_, err := bgp.GetRouteFamily(rf.AfiSafiName)
				if err != nil {
					return err
				}
			}
		}

		if _, ok := n.attributes["Neighbors.NeighborList.NeighborConfig.PeerType"]; !ok {
			if neighbor.NeighborConfig.PeerAs != bt.Global.GlobalConfig.As {
				neighbor.NeighborConfig.PeerType = PEER_TYPE_EXTERNAL
			} else {
				neighbor.NeighborConfig.PeerType = PEER_TYPE_INTERNAL
			}
		}
	}
	for _, r := range bt.RpkiServers.RpkiServerList {
		if r.RpkiServerConfig.Port == 0 {
			r.RpkiServerConfig.Port = bgp.RPKI_DEFAULT_PORT
		}
	}
	return nil
}
开发者ID:gitter-badger,项目名称:gobgp,代码行数:89,代码来源:default.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ty.Check函数代码示例发布时间:2022-05-24
下一篇:
Golang toml.Unmarshal函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap