本文整理汇总了Golang中github.com/jeffail/gabs.Container.ExistsP方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.ExistsP方法的具体用法?Golang Container.ExistsP怎么用?Golang Container.ExistsP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jeffail/gabs.Container
的用法示例。
在下文中一共展示了Container.ExistsP方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mergeVolumeConfig
// Merge guest volume/block device configuration with any volumes found in
// host container.
func mergeVolumeConfig(volumeconfig []volumeConfig, guest *gabs.Container) (err error) {
var mounts *gabs.Container
if guest.ExistsP("mount") {
mounts = guest.S("mount")
} else {
mounts, _ = guest.ObjectP("mount")
}
mmap, _ := mounts.ChildrenMap()
for _, mount := range mmap {
var source string
var path string
var ok bool
if source, ok = mount.Path("source").Data().(string); !ok {
continue
}
if path, ok = mount.Path("path").Data().(string); !ok {
continue
}
if source == "blk" && strings.HasPrefix(path, "/dev/ld") {
return fmt.Errorf("Guest configuration defines " +
"/dev/ld* block devices, cannot merge with " +
"host volumes")
}
}
blkIndex := 0
for _, v := range volumeconfig {
mp := "/" + v.name
obj, _ := guest.Object("mount", mp)
obj.Set("blk", "source")
obj.Set(fmt.Sprintf("/dev/ld%va", blkIndex), "path")
blkIndex += 1
}
return
}
示例2: mergeNetConfig
// Merge ("generate?") guest network configuration from host configuration.
func mergeNetConfig(netconfig *netConfig, guest *gabs.Container) (err error) {
if guest.ExistsP("hostname") {
log.Print("Guest already defines hostname, not overriden")
} else {
guest.SetP(netconfig.hostname, "hostname")
}
if guest.ExistsP("net") {
return fmt.Errorf("Guest already defines net configuration")
}
addrs, _ := guest.ArrayOfSizeP(1, "net.interfaces.vioif0.addrs")
addr, _ := addrs.ObjectI(0)
addr.Set("inet", "type")
addr.Set("static", "method")
addr.Set(netconfig.ipAddress, "addr")
gateways, _ := guest.ArrayOfSizeP(1, "net.gateways")
gw, _ := gateways.ObjectI(0)
gw.Set("inet", "type")
gw.Set(netconfig.gateway, "addr")
dns, _ := guest.ObjectP("net.dns")
dns.Set(netconfig.dnsServers, "nameservers")
dns.Set(netconfig.dnsSearch, "search")
return
}