本文整理汇总了Golang中github.com/BurntSushi/toml.MetaData.Keys方法的典型用法代码示例。如果您正苦于以下问题:Golang MetaData.Keys方法的具体用法?Golang MetaData.Keys怎么用?Golang MetaData.Keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/BurntSushi/toml.MetaData
的用法示例。
在下文中一共展示了MetaData.Keys方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}
示例2: 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
}
示例3: 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
}