本文整理汇总了Golang中github.com/rackspace/rack/internal/github.com/fatih/structs.Map函数的典型用法代码示例。如果您正苦于以下问题:Golang Map函数的具体用法?Golang Map怎么用?Golang Map使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Map函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: subnetSingle
func subnetSingle(subnet *osSubnets.Subnet) map[string]interface{} {
m := structs.Map(subnet)
tmpMap := make([]map[string]interface{}, len(m["AllocationPools"].([]osSubnets.AllocationPool)))
for i, pool := range m["AllocationPools"].([]osSubnets.AllocationPool) {
tmpMap[i] = structs.Map(pool)
}
m["AllocationPools"] = tmpMap
/*
m["Host Routes"] = m["HostRoutes"]
delete(m, "HostRoutes")
if hostRoutes, ok := m["Host Routes"].([]osSubnets.HostRoute); ok && len(hostRoutes) > 0 {
fmt.Printf("hostRoutes: %+v\n", hostRoutes)
out := []string{"Destination CIDR\tNext Hop"}
for _, route := range hostRoutes {
out = append(out, fmt.Sprintf("%s\t%s", route.DestinationCIDR, route.NextHop))
}
m["Host Routes"] = strings.Join(out, "\n")
} else {
m["Host Routes"] = ""
}
*/
if nameServers, ok := m["DNSNameservers"].([]string); ok && len(nameServers) > 0 {
m["DNSNameservers"] = strings.Join(nameServers, ", ")
} else {
m["DNSNameservers"] = ""
}
return m
}
示例2: portSingle
func portSingle(port *osPorts.Port) map[string]interface{} {
m := structs.Map(port)
tmpMap := make([]map[string]interface{}, len(m["FixedIPs"].([]osPorts.IP)))
for i, pool := range m["FixedIPs"].([]osPorts.IP) {
tmpMap[i] = structs.Map(pool)
}
m["FixedIPs"] = tmpMap
m["Up"] = m["AdminStateUp"]
/*
if fixedIPs, ok := m["FixedIPs"].([]osPorts.IP); ok && len(fixedIPs) > 0 {
out := []string{"Subnet ID\tIP Address"}
for _, ip := range fixedIPs {
out = append(out, fmt.Sprintf("%s\t%s", ip.SubnetID, ip.IPAddress))
}
m["FixedIPs"] = strings.Join(out, "\n")
} else {
m["FixedIPs"] = ""
}
*/
if nameServers, ok := m["SecurityGroups"].([]string); ok && len(nameServers) > 0 {
m["SecurityGroups"] = strings.Join(nameServers, "\n")
} else {
m["SecurityGroups"] = ""
}
return m
}
示例3: securityGroupSingle
func securityGroupSingle(securityGroup *osSecurityGroups.SecGroup) map[string]interface{} {
m := structs.Map(securityGroup)
tmpMap := make([]map[string]interface{}, len(m["Rules"].([]osSecurityGroupRules.SecGroupRule)))
for i, pool := range m["Rules"].([]osSecurityGroupRules.SecGroupRule) {
tmpMap[i] = map[string]interface{}{
"ID": pool.ID,
"Direction": pool.Direction,
"EtherType": pool.EtherType,
"Protocol": pool.Protocol,
}
}
m["Rules"] = tmpMap
/*
if rules, ok := m["Rules"].([]osSecurityGroupRules.SecGroupRule); ok && len(rules) > 0 {
out := []string{"ID\tDirection\tEtherType\tProtocol"}
for _, rule := range rules {
out = append(out, fmt.Sprintf("%s\t%s\t%s\t%s", rule.ID, rule.Direction, rule.EtherType, rule.Protocol))
}
m["Rules"] = strings.Join(out, "\n")
} else {
m["Rules"] = ""
}
*/
return m
}
示例4: PreCSV
func (command *commandGetSchema) PreCSV(resource *handler.Resource) error {
resource.Result = structs.Map(resource.Result)
resource.FlattenMap("Attributes")
resource.FlattenMap("Properties")
resource.FlattenMap("SupportStatus")
return nil
}
示例5: securityGroupRuleSingle
func securityGroupRuleSingle(rule *osSecurityGroupRules.SecGroupRule) map[string]interface{} {
m := structs.Map(rule)
m["SecurityGroupID"] = m["SecGroupID"]
return m
}
示例6: resourceSingle
func resourceSingle(rawResource interface{}) map[string]interface{} {
m := structs.Map(rawResource)
switch resource := rawResource.(type) {
case *osStackResources.Resource:
if resource.CreationTime.Unix() != -62135596800 {
m["CreationTime"] = resource.CreationTime
} else {
m["CreationTime"] = ""
}
if resource.UpdatedTime.Unix() != -62135596800 {
m["UpdatedTime"] = resource.UpdatedTime
} else {
m["UpdatedTime"] = ""
}
if resource.Links != nil {
links := make([]map[string]interface{}, len(resource.Links))
for i, link := range resource.Links {
links[i] = map[string]interface{}{
"Href": link.Href,
"Rel": link.Rel,
}
}
m["Links"] = links
}
return m
}
return nil
}
示例7: Execute
func (command *commandListEvents) Execute(resource *handler.Resource) {
params := resource.Params.(*paramsListEvents)
opts := params.opts
stackName := params.stackName
stackID := params.stackID
resourceName := params.resourceName
pager := stackevents.ListResourceEvents(command.Ctx.ServiceClient, stackName, stackID, resourceName, opts)
pages, err := pager.AllPages()
if err != nil {
resource.Err = err
return
}
info, err := osStackEvents.ExtractResourceEvents(pages)
if err != nil {
resource.Err = err
return
}
result := make([]map[string]interface{}, len(info))
for j, event := range info {
result[j] = structs.Map(&event)
result[j]["Time"] = event.Time
}
resource.Result = result
}
示例8: Execute
func (command *commandList) Execute(resource *handler.Resource) {
opts := resource.Params.(*paramsList).opts
opts.Full = true
containerName := resource.Params.(*paramsList).container
allPages := resource.Params.(*paramsList).allPages
pager := objects.List(command.Ctx.ServiceClient, containerName, opts)
if allPages {
pages, err := pager.AllPages()
if err != nil {
resource.Err = err
return
}
info, err := objects.ExtractInfo(pages)
if err != nil {
resource.Err = err
return
}
result := make([]map[string]interface{}, len(info))
for j, obj := range info {
result[j] = structs.Map(&obj)
}
resource.Result = result
} else {
limit := opts.Limit
err := pager.EachPage(func(page pagination.Page) (bool, error) {
info, err := objects.ExtractInfo(page)
if err != nil {
return false, err
}
result := make([]map[string]interface{}, len(info))
for j, obj := range info {
result[j] = structs.Map(&obj)
}
resource.Result = result
if len(info) >= limit {
return false, nil
}
limit -= len(info)
command.Ctx.Results <- resource
return true, nil
})
if err != nil {
resource.Err = err
return
}
}
}
示例9: Execute
func (command *commandGet) Execute(resource *handler.Resource) {
buildids, err := buildinfo.Get(command.Ctx.ServiceClient).Extract()
if err != nil {
resource.Err = err
return
}
resource.Result = structs.Map(buildids)
}
示例10: PreCSV
func (command *commandAbandon) PreCSV(resource *handler.Resource) error {
resource.Result = structs.Map(resource.Result)
resource.FlattenMap("Template")
resource.FlattenMap("Files")
resource.FlattenMap("Environment")
resource.FlattenMap("Resources")
return nil
}
示例11: networkSingle
func networkSingle(network *osNetworks.Network) map[string]interface{} {
m := structs.Map(network)
m["Up"] = m["AdminStateUp"]
if subnets, ok := m["Subnets"].([]string); ok {
m["Subnets"] = strings.Join(subnets, ",")
}
return m
}
示例12: volumeSingle
func volumeSingle(volume *volumes.Volume) map[string]interface{} {
m := structs.Map(volume)
for k, v := range m {
if v == nil {
m[k] = ""
}
}
return m
}
示例13: Execute
func (command *commandCreate) Execute(resource *handler.Resource) {
params := resource.Params.(*paramsCreate)
volumeAttachment, err := osVolumeAttach.Create(command.Ctx.ServiceClient, params.serverID, params.opts).Extract()
if err != nil {
resource.Err = err
return
}
resource.Result = structs.Map(volumeAttachment)
}
示例14: Execute
func (command *commandGet) Execute(resource *handler.Resource) {
flavorID := resource.Params.(*paramsGet).flavor
flavor, err := flavors.Get(command.Ctx.ServiceClient, flavorID).Extract()
if err != nil {
resource.Err = err
return
}
resource.Result = structs.Map(flavor)
}
示例15: Execute
func (command *commandUpload) Execute(resource *handler.Resource) {
opts := resource.Params.(*paramsUpload).opts
keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
if err != nil {
resource.Err = err
return
}
resource.Result = structs.Map(keypair)
}