当前位置: 首页>>代码示例>>Golang>>正文


Golang Resource.Err方法代码示例

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


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

示例1: Execute

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

	getResponse := containers.Get(command.Ctx.ServiceClient, containerName)
	if getResponse.Err != nil {
		resource.Err = getResponse.Err
		return
	}

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

	metadata, err := containers.Get(command.Ctx.ServiceClient, containerName).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:harshalhshah,项目名称:rack,代码行数:33,代码来源:updatemetadata.go

示例2: Execute

func (command *commandUpload) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpload)
	containerName := params.container
	objectName := params.object
	opts := params.opts
	var readSeeker io.ReadSeeker
	var err error
	if stream := params.stream; stream {
		readSeeker = os.Stdin
	} else if fileName := params.fileName; fileName != "" {
		// this file will be closed by Gophercloud, if not closed before then
		readSeeker, err = os.Open(fileName)
		if err != nil {
			resource.Err = err
			return
		}
	} else {
		content := params.content
		readSeeker = strings.NewReader(content)
	}
	rawResponse := objects.Create(command.Ctx.ServiceClient, containerName, objectName, readSeeker, opts)
	if rawResponse.Err != nil {
		resource.Err = rawResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully uploaded object [%s] to container [%s]\n", objectName, containerName)
}
开发者ID:mrhillsman,项目名称:rack,代码行数:27,代码来源:upload.go

示例3: 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:harshalhshah,项目名称:rack,代码行数:25,代码来源:deletemetadata.go

示例4: Execute

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

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

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

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

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

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

示例5: 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

示例6: Execute

func (command *commandListAddresses) Execute(resource *handler.Resource) {
	serverID := resource.Params.(*paramsListAddresses).serverID
	pager := servers.ListAddresses(command.Ctx.ServiceClient, serverID)
	var result []map[string]interface{}
	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		addressesMap, err := servers.ExtractAddresses(page)
		if err != nil {
			return false, err
		}
		for t, addresses := range addressesMap {
			for _, address := range addresses {
				m := map[string]interface{}{
					"Type":    t,
					"Version": address.Version,
					"Address": address.Address,
				}
				result = append(result, m)
			}
		}
		return true, nil
	})
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = result
}
开发者ID:harshalhshah,项目名称:rack,代码行数:27,代码来源:listaddresses.go

示例7: 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:harshalhshah,项目名称:rack,代码行数:26,代码来源:list.go

示例8: Execute

func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	allPages := resource.Params.(*paramsList).allPages
	pager := subnets.List(command.Ctx.ServiceClient, opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := osSubnets.ExtractSubnets(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, subnet := range info {
			result[j] = subnetSingle(&subnet)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := osSubnets.ExtractSubnets(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, subnet := range info {
				result[j] = subnetSingle(&subnet)
			}
			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:flazz,项目名称:rack,代码行数:46,代码来源:list.go

示例9: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	containerRaw := containers.Get(command.Ctx.ServiceClient, containerName)
	containerInfo, err := containerRaw.Extract()
	if err != nil {
		resource.Err = err
		return
	}
	containerMetadata, err := containerRaw.ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(containerInfo)
	resource.Result.(map[string]interface{})["Name"] = containerName
	resource.Result.(map[string]interface{})["Metadata"] = containerMetadata
}
开发者ID:harshalhshah,项目名称:rack,代码行数:17,代码来源:get.go

示例10: 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:harshalhshah,项目名称:rack,代码行数:8,代码来源:download.go

示例11: Execute

func (command *commandDelete) Execute(resource *handler.Resource) {
	snapshotID := resource.Params.(*paramsDelete).snapshotID
	err := osSnapshots.Delete(command.Ctx.ServiceClient, snapshotID).ExtractErr()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = fmt.Sprintf("Deleting snapshot [%s]\n", snapshotID)
}
开发者ID:hdansou,项目名称:rack,代码行数:9,代码来源:delete.go

示例12: Execute

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

示例13: Execute

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

示例14: Execute

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

示例15: Execute

func (command *commandDelete) Execute(resource *handler.Resource) {
	keypairName := resource.Params.(*paramsDelete).keypair
	err := keypairs.Delete(command.Ctx.ServiceClient, keypairName).ExtractErr()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = fmt.Sprintf("Successfully deleted keypair [%s]\n", keypairName)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:9,代码来源:delete.go


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