當前位置: 首頁>>代碼示例>>Golang>>正文


Golang structs.Map函數代碼示例

本文整理匯總了Golang中github.com/jrperritt/rack/internal/github.com/fatih/structs.Map函數的典型用法代碼示例。如果您正苦於以下問題:Golang Map函數的具體用法?Golang Map怎麽用?Golang Map使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Map函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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.WaitGroup.Add(1)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
開發者ID:hdansou,項目名稱:rack,代碼行數:48,代碼來源:list.go

示例2: securityGroupRuleSingle

func securityGroupRuleSingle(rule *osSecurityGroupRules.SecGroupRule) map[string]interface{} {
	m := structs.Map(rule)

	m["SecurityGroupID"] = m["SecGroupID"]

	return m
}
開發者ID:hdansou,項目名稱:rack,代碼行數:7,代碼來源:common.go

示例3: Execute

func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	allPages := resource.Params.(*paramsList).allPages
	pager := flavors.ListDetail(command.Ctx.ServiceClient, opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := flavors.ExtractFlavors(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, flavor := range info {
			result[j] = structs.Map(flavor)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := flavors.ExtractFlavors(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, flavor := range info {
				result[j] = structs.Map(flavor)
			}
			resource.Result = result
			if len(info) >= opts.Limit {
				return false, nil
			}
			limit -= len(info)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
開發者ID:harshalhshah,項目名稱:rack,代碼行數:45,代碼來源:list.go

示例4: 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)
}
開發者ID:harshalhshah,項目名稱:rack,代碼行數:9,代碼來源:create.go

示例5: 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
}
開發者ID:hdansou,項目名稱:rack,代碼行數:9,代碼來源:common.go

示例6: Execute

func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(keypair)
}
開發者ID:harshalhshah,項目名稱:rack,代碼行數:9,代碼來源:generate.go

示例7: 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)
}
開發者ID:harshalhshah,項目名稱:rack,代碼行數:9,代碼來源:get.go

示例8: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	imageID := resource.Params.(*paramsGet).image
	image, err := images.Get(command.Ctx.ServiceClient, imageID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(image)
}
開發者ID:hdansou,項目名稱:rack,代碼行數:9,代碼來源:get.go

示例9: networkSingle

func networkSingle(network *osNetworks.Network) map[string]interface{} {
	m := structs.Map(network)
	m["Up"] = m["AdminStateUp"]
	m["Tenant ID"] = m["TenantID"]
	if subnets, ok := m["Subnets"].([]string); ok {
		m["Subnets"] = strings.Join(subnets, ",")
	}
	return m
}
開發者ID:hdansou,項目名稱:rack,代碼行數:9,代碼來源:common.go

示例10: snapshotSingle

func snapshotSingle(snapshot *osSnapshots.Snapshot) map[string]interface{} {
	m := structs.Map(snapshot)
	if attachments := m["Attachments"].([]string); len(attachments) > 0 {
		m["Attachments"] = strings.Join(attachments, ",")
	} else {
		m["Attachments"] = ""
	}
	return m
}
開發者ID:hdansou,項目名稱:rack,代碼行數:9,代碼來源:common.go

示例11: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	containerInfo, err := containers.Get(command.Ctx.ServiceClient, containerName).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(containerInfo)
	resource.Result.(map[string]interface{})["Name"] = containerName
}
開發者ID:hdansou,項目名稱:rack,代碼行數:10,代碼來源:get.go

示例12: Execute

func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	c := command.Ctx.CLIContext
	if c.IsSet("json") || c.IsSet("csv") || c.GlobalIsSet("json") || c.GlobalIsSet("csv") {
		resource.Result = structs.Map(keypair)
	} else {
		resource.Result = printGenerate(keypair)
	}
}
開發者ID:mrhillsman,項目名稱:rack,代碼行數:14,代碼來源:generate.go

示例13: Execute

func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}

	if command.Ctx.OutputFormat == "json" || command.Ctx.OutputFormat == "csv" {
		resource.Result = structs.Map(keypair)
	} else {
		resource.Result = printGenerate(keypair)
	}
}
開發者ID:hdansou,項目名稱:rack,代碼行數:14,代碼來源:generate.go

示例14: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	objectName := resource.Params.(*paramsGet).object
	objectRaw := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil)
	objectInfo, err := objectRaw.Extract()
	if err != nil {
		resource.Err = err
		return
	}
	objectMetadata, err := objectRaw.ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(objectInfo)
	resource.Result.(map[string]interface{})["Name"] = objectName
	resource.Result.(map[string]interface{})["Metadata"] = objectMetadata
}
開發者ID:harshalhshah,項目名稱:rack,代碼行數:18,代碼來源:get.go

示例15: serverSingle

func serverSingle(rawServer interface{}) map[string]interface{} {
	server, ok := rawServer.(*osServers.Server)
	if !ok {
		return nil
	}
	m := structs.Map(rawServer)
	m["Public IPv4"] = server.AccessIPv4
	m["Public IPv6"] = server.AccessIPv6
	m["Private IPv4"] = ""
	ips, ok := server.Addresses["private"].([]interface{})
	if ok || len(ips) > 0 {
		priv, ok := ips[0].(map[string]interface{})
		if ok {
			m["Private IPv4"] = priv["addr"]
		}
	}
	m["Flavor"] = server.Flavor["id"]
	m["Image"] = server.Image["id"]
	return m
}
開發者ID:hdansou,項目名稱:rack,代碼行數:20,代碼來源:common.go


注:本文中的github.com/jrperritt/rack/internal/github.com/fatih/structs.Map函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。