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

Golang handler.Resource类代码示例

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

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



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

示例1: Execute

func (command *commandDeleteMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsDeleteMetadata)
	containerName := params.containerName
	objectName := params.objectName

	currentMetadata, err := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	for _, k := range params.metadataKeys {
		currentMetadata[k] = ""
	}

	updateOpts := osObjects.UpdateOpts{
		Metadata: currentMetadata,
	}
	updateResponse := objects.Update(command.Ctx.ServiceClient, containerName, objectName, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully deleted metadata with keys [%s] from object [%s].\n", strings.Join(params.metadataKeys, ", "), objectName)
}
开发者ID:jc7998,项目名称:rack,代码行数:25,代码来源:deletemetadata.go


示例2: PreCSV

func (command *commandUpdateMetadata) PreCSV(resource *handler.Resource) {
	resource.Result = map[string]interface{}{
		"Metadata": resource.Result,
	}
	resource.Keys = []string{"Metadata"}
	resource.FlattenMap("Metadata")
}
开发者ID:nelsnelson,项目名称:rack,代码行数:7,代码来源:updatemetadata.go


示例3: Execute

func (command *commandUpdateMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpdateMetadata)

	updateOpts := osAccounts.UpdateOpts{
		Metadata: params.metadata,
	}
	updateResponse := accounts.Update(command.Ctx.ServiceClient, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}

	metadata, err := accounts.Get(command.Ctx.ServiceClient).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	updatedMetadata := make(map[string]string, len(params.metadata))
	for k := range params.metadata {
		k = strings.Title(k)
		updatedMetadata[k] = metadata[k]
	}

	resource.Result = updatedMetadata
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:26,代码来源:updatemetadata.go


示例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
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:7,代码来源:getschema.go


示例5: 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
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:26,代码来源:listevents.go


示例6: Execute

func (command *commandSetMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsSetMetadata)

	currentMetadata, err := accounts.Get(command.Ctx.ServiceClient).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	i := 0
	keys := make([]string, len(currentMetadata))
	for k := range currentMetadata {
		keys[i] = k
		i++
	}

	updateOpts := osAccounts.UpdateOpts{
		Metadata:       params.metadata,
		DeleteMetadata: keys,
	}
	updateResponse := accounts.Update(command.Ctx.ServiceClient, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}

	metadata, err := accounts.Get(command.Ctx.ServiceClient).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	resource.Result = metadata
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:34,代码来源:setmetadata.go


示例7: Execute

func (command *commandRebuild) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsRebuild)
	opts := params.opts
	serverID := params.serverID
	server, err := servers.Rebuild(command.Ctx.ServiceClient, serverID, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}

	if params.wait {
		err = osServers.WaitForStatus(command.Ctx.ServiceClient, serverID, "ACTIVE", 600)
		if err != nil {
			resource.Err = err
			return
		}

		server, err = servers.Get(command.Ctx.ServiceClient, serverID).Extract()
		if err != nil {
			resource.Err = err
			return
		}
	}

	resource.Result = serverSingle(server)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:26,代码来源:rebuild.go


示例8: Execute

func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	pager := osVolumes.List(command.Ctx.ServiceClient, opts)
	var volumes []map[string]interface{}
	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		info, err := osVolumes.ExtractVolumes(page)
		if err != nil {
			return false, err
		}
		result := make([]map[string]interface{}, len(info))
		for j, volume := range info {
			result[j] = volumeSingle(&volume)
		}
		volumes = append(volumes, result...)
		return true, nil
	})
	if err != nil {
		resource.Err = err
		return
	}
	if len(volumes) == 0 {
		resource.Result = nil
	} else {
		resource.Result = volumes
	}
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:26,代码来源:list.go


示例9: Execute

func (command *commandListAddressesByNetwork) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsListAddressesByNetwork)
	pager := servers.ListAddressesByNetwork(command.Ctx.ServiceClient, params.serverID, params.network)
	var result []map[string]interface{}
	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		addresses, err := servers.ExtractNetworkAddresses(page)
		if err != nil {
			return false, err
		}
		for _, address := range addresses {
			m := map[string]interface{}{
				"Type":    params.network,
				"Version": address.Version,
				"Address": address.Address,
			}
			result = append(result, m)
		}
		return true, nil
	})
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = result
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:25,代码来源:listaddressesbynetwork.go


示例10: Execute

func (command *commandDelete) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsDelete)
	containerName := params.container
	objectName := params.object

	listOpts := osObjects.ListOpts{
		Prefix: objectName,
	}
	allPages, err := osObjects.List(command.Ctx.ServiceClient, containerName, listOpts).AllPages()
	if err != nil {
		resource.Err = err
		return
	}

	objectNames, err := osObjects.ExtractNames(allPages)
	if err != nil {
		resource.Err = err
		return
	}

	for _, thisName := range objectNames {
		rawResponse := osObjects.Delete(command.Ctx.ServiceClient, containerName, thisName, osObjects.DeleteOpts{})
		if rawResponse.Err != nil {
			resource.Err = rawResponse.Err
			return
		}
	}

	resource.Result = fmt.Sprintf("Deleted object [%s] from container [%s]", objectName, containerName)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:30,代码来源:delete.go


示例11: 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)
}
开发者ID:pratikmallya,项目名称:rack,代码行数:8,代码来源:list.go


示例12: PreCSV

func (command *commandSetMetadata) PreCSV(resource *handler.Resource) error {
	resource.Result = map[string]interface{}{
		"Metadata": resource.Result,
	}
	resource.Keys = []string{"Metadata"}
	resource.FlattenMap("Metadata")
	return nil
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:8,代码来源:setmetadata.go


示例13: JSON

func (command *commandDownload) JSON(resource *handler.Resource) {
	bytes, err := ioutil.ReadAll(resource.Result.(io.Reader))
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = string(bytes)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:8,代码来源:download.go


示例14: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	securityGroupRuleID := resource.Params.(*paramsGet).securityGroupRuleID
	securityGroupRule, err := securityGroupRules.Get(command.Ctx.ServiceClient, securityGroupRuleID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = securityGroupRuleSingle(securityGroupRule)
}
开发者ID:smashwilson,项目名称:rack,代码行数:9,代码来源:get.go


示例15: Execute

func (command *commandAdopt) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsAdopt).opts
	result, err := stacks.Adopt(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = stackSingle(result)
}
开发者ID:reaperzn,项目名称:rack,代码行数:9,代码来源:adopt.go


示例16: Execute

func (command *commandCreate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsCreate).opts
	volume, err := osVolumes.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = volumeSingle(volume)
}
开发者ID:nelsnelson,项目名称:rack,代码行数:9,代码来源:create.go


示例17: Execute

func (command *commandCreate) Execute(resource *handler.Resource) {
	createOpts := resource.Params.(*paramsCreate)
	imageID, err := osServers.CreateImage(command.Ctx.ServiceClient, createOpts.serverID, createOpts.opts).ExtractImageID()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = map[string]interface{}{"ID": imageID}
}
开发者ID:ktbartholomew,项目名称:rack,代码行数:9,代码来源:create.go


示例18: 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:satyamkotakonda,项目名称:rack,代码行数:9,代码来源:get.go


示例19: Execute

func (command *commandUpdateMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpdateMetadata)
	metadata, err := osServers.UpdateMetadata(command.Ctx.ServiceClient, params.serverID, params.opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = metadata
}
开发者ID:nelsnelson,项目名称:rack,代码行数:9,代码来源:updatemetadata.go


示例20: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	subnetID := resource.Params.(*paramsGet).subnetID
	subnet, err := subnets.Get(command.Ctx.ServiceClient, subnetID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = subnetSingle(subnet)
}
开发者ID:nelsnelson,项目名称:rack,代码行数:9,代码来源:get.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang cli.NewApp函数代码示例发布时间:2022-05-28
下一篇:
Golang handler.Handle函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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