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


Golang gophercloud.BuildRequestBody函數代碼示例

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


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


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