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


Golang gophercloud.BuildQueryString函数代码示例

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


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

示例1: TestBuildQueryString

func TestBuildQueryString(t *testing.T) {
	type testVar string
	iFalse := false
	opts := struct {
		J  int       `q:"j"`
		R  string    `q:"r,required"`
		C  bool      `q:"c"`
		S  []string  `q:"s"`
		TS []testVar `q:"ts"`
		TI []int     `q:"ti"`
		F  *bool     `q:"f"`
	}{
		J:  2,
		R:  "red",
		C:  true,
		S:  []string{"one", "two", "three"},
		TS: []testVar{"a", "b"},
		TI: []int{1, 2},
		F:  &iFalse,
	}
	expected := &url.URL{RawQuery: "c=true&f=false&j=2&r=red&s=one&s=two&s=three&ti=1&ti=2&ts=a&ts=b"}
	actual, err := gophercloud.BuildQueryString(&opts)
	if err != nil {
		t.Errorf("Error building query string: %v", err)
	}
	th.CheckDeepEquals(t, expected, actual)

	opts = struct {
		J  int       `q:"j"`
		R  string    `q:"r,required"`
		C  bool      `q:"c"`
		S  []string  `q:"s"`
		TS []testVar `q:"ts"`
		TI []int     `q:"ti"`
		F  *bool     `q:"f"`
	}{
		J: 2,
		C: true,
	}
	_, err = gophercloud.BuildQueryString(&opts)
	if err == nil {
		t.Errorf("Expected error: 'Required field not set'")
	}
	th.CheckDeepEquals(t, expected, actual)

	_, err = gophercloud.BuildQueryString(map[string]interface{}{"Number": 4})
	if err == nil {
		t.Errorf("Expected error: 'Options type is not a struct'")
	}
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:50,代码来源:params_test.go

示例2: ToObjectCreateParams

// ToObjectCreateParams formats a CreateOpts into a query string and map of
// headers.
func (opts CreateOpts) ToObjectCreateParams() (io.Reader, map[string]string, string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	if err != nil {
		return nil, nil, "", err
	}
	h, err := gophercloud.BuildHeaders(opts)
	if err != nil {
		return nil, nil, "", err
	}

	for k, v := range opts.Metadata {
		h["X-Object-Meta-"+k] = v
	}

	hash := md5.New()
	buf := bytes.NewBuffer([]byte{})
	_, err = io.Copy(io.MultiWriter(hash, buf), opts.Content)
	if err != nil {
		return nil, nil, "", err
	}
	localChecksum := fmt.Sprintf("%x", hash.Sum(nil))
	h["ETag"] = localChecksum

	return buf, h, q.String(), nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:27,代码来源:requests.go

示例3: ToRuleListQuery

// ToRuleListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToRuleListQuery() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	if err != nil {
		return "", err
	}
	return q.String(), nil
}
开发者ID:mhlias,项目名称:terraform,代码行数:8,代码来源:requests.go

示例4: List

// List returns a Pager which allows you to iterate over a collection of
// floating IP resources. It accepts a ListOpts struct, which allows you to
// filter and sort the returned collection for greater efficiency.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
	q, err := gophercloud.BuildQueryString(&opts)
	if err != nil {
		return pagination.Pager{Err: err}
	}
	u := rootURL(c) + q.String()
	return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
		return FloatingIPPage{pagination.LinkedPageBase{PageResult: r}}
	})
}
开发者ID:hyperhq,项目名称:kubestack,代码行数:13,代码来源:requests.go

示例5: ToObjectDownloadParams

// ToObjectDownloadParams formats a DownloadOpts into a query string and map of
// headers.
func (opts DownloadOpts) ToObjectDownloadParams() (map[string]string, string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	if err != nil {
		return nil, "", err
	}
	h, err := gophercloud.BuildHeaders(opts)
	if err != nil {
		return nil, q.String(), err
	}
	return h, q.String(), nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:13,代码来源:requests.go

示例6: TestQueriesAreEscaped

func TestQueriesAreEscaped(t *testing.T) {
	type foo struct {
		Name  string `q:"something"`
		Shape string `q:"else"`
	}

	expected := &url.URL{RawQuery: "else=Triangl+e&something=blah%2B%3F%21%21foo"}

	actual, err := gophercloud.BuildQueryString(foo{Name: "blah+?!!foo", Shape: "Triangl e"})
	th.AssertNoErr(t, err)

	th.AssertDeepEquals(t, expected, actual)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:13,代码来源:params_test.go

示例7: List

// List enumerates endpoints in a paginated collection, optionally filtered by ListOpts criteria.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
	u := listURL(client)
	if opts != nil {
		q, err := gophercloud.BuildQueryString(opts)
		if err != nil {
			return pagination.Pager{Err: err}
		}
		u += q.String()
	}
	return pagination.NewPager(client, u, func(r pagination.PageResult) pagination.Page {
		return EndpointPage{pagination.LinkedPageBase{PageResult: r}}
	})
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:14,代码来源:requests.go

示例8: ToObjectListParams

// ToObjectListParams formats a ListOpts into a query string and boolean
// representing whether to list complete information for each object.
func (opts ListOpts) ToObjectListParams() (bool, string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return opts.Full, q.String(), err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:6,代码来源:requests.go

示例9: ToEndpointListParams

func (opts ListOpts) ToEndpointListParams() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return q.String(), err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:4,代码来源:requests.go

示例10: ToMembersListQuery

// ToMemberListQuery formats a ListOpts into a query string.
func (opts ListMembersOpts) ToMembersListQuery() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return q.String(), err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:5,代码来源:requests.go

示例11: ToShareTypeListQuery

// ToShareTypeListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToShareTypeListQuery() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return q.String(), err
}
开发者ID:gophercloud,项目名称:gophercloud,代码行数:5,代码来源:requests.go

示例12: ToFirewallListQuery

// ToFirewallListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToFirewallListQuery() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return q.String(), err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:5,代码来源:requests.go

示例13: ToServiceListMap

func (opts ListOpts) ToServiceListMap() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return q.String(), err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:4,代码来源:requests.go

示例14: ToLoadBalancerListQuery

// ToLoadbalancerListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToLoadBalancerListQuery() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return q.String(), err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:5,代码来源:requests.go

示例15: ToCDNAssetDeleteParams

// ToCDNAssetDeleteParams formats a DeleteOpts into a query string.
func (opts DeleteOpts) ToCDNAssetDeleteParams() (string, error) {
	q, err := gophercloud.BuildQueryString(opts)
	return q.String(), err
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:5,代码来源:requests.go


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