當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。