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

Golang gophercloud.BuildRequestBody函数代码示例

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

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



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

示例1: ToServerRebuildMap

// ToServerRebuildMap formats a RebuildOpts struct into a map for use in JSON
func (opts RebuildOpts) ToServerRebuildMap() (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "")
	if err != nil {
		return nil, err
	}

	// If ImageRef isn't provided, check if ImageName was provided to ascertain
	// the image ID.
	if opts.ImageID == "" {
		if opts.ImageName != "" {
			if opts.ServiceClient == nil {
				err := ErrNoClientProvidedForIDByName{}
				err.Argument = "ServiceClient"
				return nil, err
			}
			imageID, err := images.IDFromName(opts.ServiceClient, opts.ImageName)
			if err != nil {
				return nil, err
			}
			b["imageRef"] = imageID
		}
	}

	return map[string]interface{}{"rebuild": b}, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:26,代码来源:requests.go


示例2: ToServerCreateMap

// ToServerCreateMap adds the block device mapping option to the base server
// creation options.
func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error) {
	base, err := opts.CreateOptsBuilder.ToServerCreateMap()
	if err != nil {
		return nil, err
	}

	if len(opts.BlockDevice) == 0 {
		err := gophercloud.ErrMissingInput{}
		err.Argument = "bootfromvolume.CreateOptsExt.BlockDevice"
		return nil, err
	}

	serverMap := base["server"].(map[string]interface{})

	blockDevice := make([]map[string]interface{}, len(opts.BlockDevice))

	for i, bd := range opts.BlockDevice {
		b, err := gophercloud.BuildRequestBody(bd, "")
		if err != nil {
			return nil, err
		}
		blockDevice[i] = b
	}
	serverMap["block_device_mapping_v2"] = blockDevice

	return base, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:requests.go


示例3: ToRuleCreateMap

// ToRuleCreateMap builds the create rule options into a serializable format.
func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
	if opts.FromPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
		return nil, gophercloud.ErrMissingInput{Argument: "FromPort"}
	}
	if opts.ToPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
		return nil, gophercloud.ErrMissingInput{Argument: "ToPort"}
	}
	return gophercloud.BuildRequestBody(opts, "security_group_default_rule")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:10,代码来源:requests.go


示例4: ToUserCreateMap

// ToUserCreateMap assembles a request body based on the contents of a CreateOpts.
func (opts CreateOpts) ToUserCreateMap() (map[string]interface{}, error) {
	if opts.Name == "" && opts.Username == "" {
		err := gophercloud.ErrMissingInput{}
		err.Argument = "users.CreateOpts.Name/users.CreateOpts.Username"
		err.Info = "Either a Name or Username must be provided"
		return nil, err
	}
	return gophercloud.BuildRequestBody(opts, "user")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:10,代码来源:requests.go


示例5: ToLBMonitorUpdateMap

// ToLBMonitorUpdateMap allows UpdateOpts to satisfy the UpdateOptsBuilder
// interface
func (opts UpdateOpts) ToLBMonitorUpdateMap() (map[string]interface{}, error) {
	if opts.Delay > 0 && opts.Timeout > 0 && opts.Delay < opts.Timeout {
		err := gophercloud.ErrInvalidInput{}
		err.Argument = "monitors.CreateOpts.Delay/monitors.CreateOpts.Timeout"
		err.Value = fmt.Sprintf("%d/%d", opts.Delay, opts.Timeout)
		err.Info = "Delay must be greater than or equal to timeout"
		return nil, err
	}
	return gophercloud.BuildRequestBody(opts, "health_monitor")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:12,代码来源:requests.go


示例6: ToMap

// ToMap is a convenience function for creating sub-maps for individual users.
func (opts CreateOpts) ToMap() (map[string]interface{}, error) {
	if opts.Name == "root" {
		err := gophercloud.ErrInvalidInput{}
		err.Argument = "users.CreateOpts.Name"
		err.Value = "root"
		err.Info = "root is a reserved user name and cannot be used"
		return nil, err
	}
	return gophercloud.BuildRequestBody(opts, "")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:11,代码来源:requests.go


示例7: ToSubnetCreateMap

// ToSubnetCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "subnet")
	if err != nil {
		return nil, err
	}

	if m := b["subnet"].(map[string]interface{}); m["gateway_ip"] == "" {
		m["gateway_ip"] = nil
	}

	return b, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:13,代码来源:requests.go


示例8: ToRuleCreateMap

// ToRuleCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "firewall_rule")
	if err != nil {
		return nil, err
	}

	if m := b["firewall_rule"].(map[string]interface{}); m["protocol"] == "any" {
		m["protocol"] = nil
	}

	return b, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:13,代码来源:requests.go


示例9: ToImageCreateMap

// ToImageCreateMap assembles a request body based on the contents of
// a CreateOpts.
func (opts CreateOpts) ToImageCreateMap() (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "")
	if err != nil {
		return nil, err
	}

	if opts.Properties != nil {
		for k, v := range opts.Properties {
			b[k] = v
		}
	}
	return b, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:15,代码来源:requests.go


示例10: BuildRequest

// BuildRequest takes an opts struct and builds a request body for
// Gophercloud to execute
func BuildRequest(opts interface{}, parent string) (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "")
	if err != nil {
		return nil, err
	}

	if b["value_specs"] != nil {
		for k, v := range b["value_specs"].(map[string]interface{}) {
			b[k] = v
		}
		delete(b, "value_specs")
	}

	return map[string]interface{}{parent: b}, nil
}
开发者ID:hooklift,项目名称:terraform,代码行数:17,代码来源:util.go


示例11: ToStackCreateMap

// ToStackCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToStackCreateMap() (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "")
	if err != nil {
		return nil, err
	}

	if err := opts.TemplateOpts.Parse(); err != nil {
		return nil, err
	}

	if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
		return nil, err
	}
	opts.TemplateOpts.fixFileRefs()
	b["template"] = string(opts.TemplateOpts.Bin)

	files := make(map[string]string)
	for k, v := range opts.TemplateOpts.Files {
		files[k] = v
	}

	if opts.EnvironmentOpts != nil {
		if err := opts.EnvironmentOpts.Parse(); err != nil {
			return nil, err
		}
		if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
			return nil, err
		}
		opts.EnvironmentOpts.fixFileRefs()
		for k, v := range opts.EnvironmentOpts.Files {
			files[k] = v
		}
		b["environment"] = string(opts.EnvironmentOpts.Bin)
	}

	if len(files) > 0 {
		b["files"] = files
	}

	if opts.Tags != nil {
		b["tags"] = strings.Join(opts.Tags, ",")
	}

	return b, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:46,代码来源:requests.go


示例12: ToPortUpdateMap

// ToPortUpdateMap casts an UpdateOpts struct to a map.
func (opts UpdateOpts) ToPortUpdateMap() (map[string]interface{}, error) {
	b1, err := opts.UpdateOptsBuilder.ToPortUpdateMap()
	if err != nil {
		return nil, err
	}

	b2, err := gophercloud.BuildRequestBody(opts, "")
	if err != nil {
		return nil, err
	}

	port := b1["port"].(map[string]interface{})

	for k, v := range b2 {
		port[k] = v
	}

	return map[string]interface{}{"port": port}, nil
}
开发者ID:hyperhq,项目名称:kubestack,代码行数:20,代码来源:requests.go


示例13: ToMonitorCreateMap

// ToMonitorCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToMonitorCreateMap() (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "healthmonitor")
	if err != nil {
		return nil, err
	}

	switch opts.Type {
	case TypeHTTP, TypeHTTPS:
		switch opts.URLPath {
		case "":
			return nil, fmt.Errorf("URLPath must be provided for HTTP and HTTPS")
		}
		switch opts.ExpectedCodes {
		case "":
			return nil, fmt.Errorf("ExpectedCodes must be provided for HTTP and HTTPS")
		}
	}

	return b, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:21,代码来源:requests.go


示例14: ToLBMonitorCreateMap

// ToLBMonitorCreateMap allows CreateOpts to satisfy the CreateOptsBuilder
// interface
func (opts CreateOpts) ToLBMonitorCreateMap() (map[string]interface{}, error) {
	if opts.Type == TypeHTTP || opts.Type == TypeHTTPS {
		if opts.URLPath == "" {
			err := gophercloud.ErrMissingInput{}
			err.Argument = "monitors.CreateOpts.URLPath"
			return nil, err
		}
		if opts.ExpectedCodes == "" {
			err := gophercloud.ErrMissingInput{}
			err.Argument = "monitors.CreateOpts.ExpectedCodes"
			return nil, err
		}
	}
	if opts.Delay < opts.Timeout {
		err := gophercloud.ErrInvalidInput{}
		err.Argument = "monitors.CreateOpts.Delay/monitors.CreateOpts.Timeout"
		err.Info = "Delay must be greater than or equal to timeout"
		return nil, err
	}
	return gophercloud.BuildRequestBody(opts, "health_monitor")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:23,代码来源:requests.go


示例15: ToTokenV2CreateMap

// ToTokenV2CreateMap allows AuthOptions to satisfy the AuthOptionsBuilder
// interface in the v2 tokens package
func (opts AuthOptions) ToTokenV2CreateMap() (map[string]interface{}, error) {
	v2Opts := AuthOptionsV2{
		TenantID:   opts.TenantID,
		TenantName: opts.TenantName,
	}

	if opts.Password != "" {
		v2Opts.PasswordCredentials = &PasswordCredentialsV2{
			Username: opts.Username,
			Password: opts.Password,
		}
	} else {
		v2Opts.TokenCredentials = &TokenCredentialsV2{
			ID: opts.TokenID,
		}
	}

	b, err := gophercloud.BuildRequestBody(v2Opts, "auth")
	if err != nil {
		return nil, err
	}
	return b, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:25,代码来源:requests.go


示例16: ToServerCreateImageMap

// ToServerCreateImageMap formats a CreateImageOpts structure into a request body.
func (opts CreateImageOpts) ToServerCreateImageMap() (map[string]interface{}, error) {
	return gophercloud.BuildRequestBody(opts, "createImage")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:4,代码来源:requests.go


示例17: ToServerRescueMap

// ToServerRescueMap formats a RescueOpts as a map that can be used as a JSON
// request body for the Rescue request.
func (opts RescueOpts) ToServerRescueMap() (map[string]interface{}, error) {
	return gophercloud.BuildRequestBody(opts, "rescue")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:5,代码来源:requests.go


示例18: ToVolumeTerminateConnectionMap

// ToVolumeTerminateConnectionMap assembles a request body based on the contents of a
// TerminateConnectionOpts.
func (opts TerminateConnectionOpts) ToVolumeTerminateConnectionMap() (map[string]interface{}, error) {
	b, err := gophercloud.BuildRequestBody(opts, "connector")
	return map[string]interface{}{"os-terminate_connection": b}, err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:6,代码来源:requests.go


示例19: ToVolumeDetachMap

// ToVolumeDetachMap assembles a request body based on the contents of a
// DetachOpts.
func (opts DetachOpts) ToVolumeDetachMap() (map[string]interface{}, error) {
	return gophercloud.BuildRequestBody(opts, "os-detach")
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:5,代码来源:requests.go


示例20: ToShareTypeCreateMap

// ToShareTypeCreateMap assembles a request body based on the contents of a
// CreateOpts.
func (opts CreateOpts) ToShareTypeCreateMap() (map[string]interface{}, error) {
	return gophercloud.BuildRequestBody(opts, "share_type")
}
开发者ID:gophercloud,项目名称:gophercloud,代码行数:5,代码来源:requests.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang gophercloud.ExtractNextURL函数代码示例发布时间:2022-05-23
下一篇:
Golang gophercloud.BuildQueryString函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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