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


Golang URL.RawQuery方法代码示例

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


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

示例1: SignAmazonUrl

func SignAmazonUrl(origUrl *url.URL, api AmazonProductAPI) (signedUrl string, err error) {

	escapeUrl := strings.Replace(origUrl.RawQuery, ",", "%2C", -1)
	escapeUrl = strings.Replace(escapeUrl, ":", "%3A", -1)

	params := strings.Split(escapeUrl, "&")
	sort.Strings(params)
	sortedParams := strings.Join(params, "&")

	toSign := fmt.Sprintf("GET\n%s\n%s\n%s", origUrl.Host, origUrl.Path, sortedParams)

	hasher := hmac.New(sha256.New, []byte(api.SecretKey))
	_, err = hasher.Write([]byte(toSign))
	if err != nil {
		return "", err
	}

	hash := base64.StdEncoding.EncodeToString(hasher.Sum(nil))

	hash = url.QueryEscape(hash)

	newParams := fmt.Sprintf("%s&Signature=%s", sortedParams, hash)

	origUrl.RawQuery = newParams

	return origUrl.String(), nil
}
开发者ID:matthistuff,项目名称:go-amazon-product-api,代码行数:27,代码来源:urlgen.go

示例2: sortQuery

func sortQuery(u *url.URL) {
	q := u.Query()
	if len(q) == 0 {
		return
	}
	arKeys := make([]string, len(q))
	i := 0
	for k, _ := range q {
		arKeys[i] = k
		i++
	}
	sort.Strings(arKeys)
	buf := new(bytes.Buffer)
	for _, k := range arKeys {
		sort.Strings(q[k])
		for _, v := range q[k] {
			if buf.Len() > 0 {
				buf.WriteRune('&')
			}
			buf.WriteString(fmt.Sprintf("%s=%s", k, url.QueryEscape(v)))
		}
	}

	// Rebuild the raw query string
	u.RawQuery = buf.String()
}
开发者ID:rogpeppe,项目名称:purell,代码行数:26,代码来源:purell.go

示例3: Detect_language

func Detect_language(q string) string {
	var Url *url.URL
	Url, err := url.Parse("https://www.googleapis.com")
	if err != nil {
		fmt.Println(err)
	}

	Url.Path += "/language/translate/v2/detect"
	parameters := url.Values{}
	parameters.Add("q", q)
	parameters.Add("key", Google_key())
	Url.RawQuery = parameters.Encode()

	resp, err := http.Get(Url.String())
	if err != nil {
		fmt.Println(err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)

	var data gtresponse
	json.Unmarshal(body, &data)

	lang := data.Data.Detections[0][0].Language
	return lang
}
开发者ID:jackcook,项目名称:upptacka,代码行数:26,代码来源:translate.go

示例4: url

func (cam *Camera) url(action string, params *map[string]string) string {
	u := url.URL{}
	q := url.Values{}

	u.Scheme = "http"
	u.Host = cam.ipaddress
	u.Path = "/camera/" + action

	if params != nil {
		for key, value := range *params {
			q.Set(key, value)
		}
	}

	// GoPro expects parameters in a certain order,
	// the password always has to be the first.
	// So this won't work at the moment:
	// q.Set("t", cam.password)

	// Instead we prepend the password "manually":
	u.RawQuery = "t=" + cam.password

	if query := q.Encode(); len(query) > 0 {
		u.RawQuery += "&" + query
	}

	return u.String()
}
开发者ID:KonradIT,项目名称:gopro.go,代码行数:28,代码来源:camera.go

示例5: returnlatlng

func returnlatlng(address string) interface{} {
	var Url *url.URL
	Url, err := url.Parse("http://maps.google.com")
	if err != nil {
		panic("Error Panic")
	}

	Url.Path += "/maps/api/geocode/json"
	//fmt.Println(address)
	parameters := url.Values{}
	parameters.Add("address", address)
	Url.RawQuery = parameters.Encode()
	Url.RawQuery += "&sensor=false"

	// fmt.Println("URL " + Url.String())

	res, err := http.Get(Url.String())
	//
	if err != nil {
		panic("Error Panic")
	}
	//  fmt.Println(res)
	defer res.Body.Close()
	var v map[string]interface{}
	dec := json.NewDecoder(res.Body)
	if err := dec.Decode(&v); err != nil {
		fmt.Println("ERROR: " + err.Error())
	}

	lat := v["results"].([]interface{})[0].(map[string]interface{})["geometry"].(map[string]interface{})["location"] //.(map[string]interface{})["lat"]
	//fmt.Println(lat)
	// lng := v["results"].([]interface{})[0].(map[string] interface{})["geometry"].(map[string] interface{})["location"].(map[string]interface{})["lng"]
	//fmt.Println("The latittude",lat,"and the longitude",lng)
	return lat
}
开发者ID:UnmeshDeshmukh,项目名称:Location-Finder--Google-Maps-API-MongoDB-,代码行数:35,代码来源:GoogleAPI.go

示例6: Test_buildRequestUrl

func Test_buildRequestUrl(t *testing.T) {
	user, _ := user.Current()
	url1 := url.URL{Scheme: "http", Host: "localhost:8080", Path: "/webhdfs/v1/test"}

	q := url1.Query()
	q.Set("user.name", user.Username)
	url1.RawQuery = q.Encode()

	conf := Configuration{Addr: url1.Host}

	u, err := buildRequestUrl(conf, &Path{Name: "/test"}, nil)
	if err != nil {
		t.Fatal(err)
	}
	if url1 != *u {
		t.Errorf("Expecting url [%v], but got [%v]", url1.String(), u.String())
	}

	// test with params
	v := url.Values{}
	v.Add("op1", "OP_1")
	v.Add("op2", "OP_2")
	v.Add("user.name", user.Username)
	url1.RawQuery = v.Encode()

	params := map[string]string{
		"op1": "OP_1",
		"op2": "OP_2",
	}

	u, err = buildRequestUrl(conf, &Path{Name: "/test"}, &params)
	if url1 != *u {
		t.Errorf("Expecting url [%v], but got [%v]", url1.String(), u.String())
	}
}
开发者ID:xiekeyang,项目名称:gowfs,代码行数:35,代码来源:fs_test.go

示例7: getLinkToNextPage

func getLinkToNextPage(
	requestURL url.URL,
	offset int64,
	limit int64,
	total int64,
) LinkType {
	maxOffset := GetMaxOffset(total, limit)

	if offset+limit <= maxOffset {
		offset = offset + limit
		q := requestURL.Query()
		q.Set("offset", strconv.FormatInt(offset, 10))
		requestURL.RawQuery = q.Encode()
	} else if offset == 0 {
		offset = 0
		q := requestURL.Query()
		q.Del("offset")
		requestURL.RawQuery = q.Encode()
	}

	return LinkType{
		Rel:   "next",
		Href:  requestURL.String(),
		Title: getPageNumberAsTitle(offset, limit),
	}
}
开发者ID:riseofthetigers,项目名称:microcosm,代码行数:26,代码来源:links.go

示例8: RewriteQuery

// Parses the querystring (q= parameter) and moves special tokens such as
// "lang:c" from the querystring into separate arguments.
func RewriteQuery(u url.URL) url.URL {
	// query is a copy which we will modify using Set() and use in the result
	query := u.Query()

	querystr := query.Get("q")
	queryWords := []string{}
	for _, word := range strings.Split(querystr, " ") {
		fmt.Printf("word = %v\n", word)
		lower := strings.ToLower(word)
		if strings.HasPrefix(lower, "filetype:") {
			query.Add("filetype", strings.ToLower(word[len("filetype:"):]))
		} else if strings.HasPrefix(lower, "-filetype:") {
			query.Add("nfiletype", strings.ToLower(word[len("-filetype:"):]))
		} else if strings.HasPrefix(lower, "package:") {
			query.Set("package", word[len("package:"):])
		} else if strings.HasPrefix(lower, "pkg:") {
			query.Set("package", word[len("pkg:"):])
		} else if strings.HasPrefix(lower, "-package:") {
			query.Add("npackage", word[len("-package:"):])
		} else if strings.HasPrefix(lower, "-pkg:") {
			query.Add("npackage", word[len("-pkg:"):])
		} else if strings.HasPrefix(lower, "path:") || strings.HasPrefix(lower, "file:") {
			query.Add("path", word[len("path:"):])
		} else if strings.HasPrefix(lower, "-path:") || strings.HasPrefix(lower, "-file:") {
			query.Add("npath", word[len("-path:"):])
		} else {
			queryWords = append(queryWords, word)
		}
	}
	query.Set("q", strings.Join(queryWords, " "))
	u.RawQuery = query.Encode()

	return u
}
开发者ID:jamessan,项目名称:dcs,代码行数:36,代码来源:query-rewrite.go

示例9: buildURL

func (s *server) buildURL(method, id string, opts streamOpts) string {
	loc := url.URL{
		Scheme: "http",
		Host:   s.config.Addr,
		Path:   fmt.Sprintf("/%s/%s", method, id),
	}
	if s.config.TLSConfig != nil {
		loc.Scheme = "https"
	}

	query := url.Values{}
	if opts.stdin {
		query.Add(urlParamStdin, "1")
	}
	if opts.stdout {
		query.Add(urlParamStdout, "1")
	}
	if opts.stderr {
		query.Add(urlParamStderr, "1")
	}
	if opts.tty {
		query.Add(urlParamTTY, "1")
	}
	for _, c := range opts.command {
		query.Add(urlParamCommand, c)
	}
	loc.RawQuery = query.Encode()

	return loc.String()
}
开发者ID:maisem,项目名称:kubernetes,代码行数:30,代码来源:server.go

示例10: match

func (c *chain) match(URL *url.URL) bool {
	path := strings.Split(URL.EscapedPath(), "/")
	lenPath := len(path)
	query := URL.Query()

	if c.lenPattern > lenPath {
		return false
	}

	if c.pattern[c.lenPattern-1] != "*" && c.lenPattern < lenPath {
		return false
	}

	for key, value := range c.pattern {
		if len(value) == 0 {
			if len(path[key]) == 0 {
				continue
			}

			return false
		}

		if value[0] == ':' {
			query.Add(value[1:], path[key])
			continue
		}

		if value[0] != '*' && value != path[key] {
			return false
		}
	}

	URL.RawQuery = query.Encode()
	return true
}
开发者ID:nexcode,项目名称:wenex,代码行数:35,代码来源:hain.go

示例11: apicall

func apicall(u *neturl.URL) (*http.Response, error) {
	apikeys := []string{
		"sehm98r8ss3fddjfs8rwxur435xjav94",
		"trtrn4tdhzeruuypctm55a8m5td9z4ce",
		"cc7qrdaxn9h47ds39nmgzb9hnutxfsrr",
		"cbygdtw624xmfn2hr2sw3ayaeekg9cvy",
		"7zsnd2q7npg5bch8hacae7t28xskn8vr",
	}

	// if val, ok := options["apikey"]; ok {
	// 	apikeys = append([]string{to.String(val)}, apikeys...)
	// }

	rawQuery := u.RawQuery
	if len(rawQuery) > 0 {
		rawQuery += "&apikey="
	} else {
		rawQuery += "apikey="
	}

	var resp *http.Response
	var apierr error
	for _, apikey := range apikeys {
		u.RawQuery = rawQuery + apikey
		resp, apierr = http.Get(u.String())
		if apierr == nil {
			return resp, nil
		}
	}

	return nil, merry.Wrap(apierr)
}
开发者ID:kdar,项目名称:morphgen,代码行数:32,代码来源:battlenet.go

示例12: rpmURL

func rpmURL(cmd RpmCmd, cs RpmControls) string {
	var u url.URL

	u.Host = cmd.Collector
	u.Path = "agent_listener/invoke_raw_method"

	if cs.UseTLS {
		u.Scheme = "https"
	} else {
		u.Scheme = "http"
	}

	query := url.Values{}
	query.Set("marshal_format", "json")
	query.Set("protocol_version", procotolVersion)
	query.Set("method", cmd.Name)
	query.Set("license_key", cs.License)

	if len(cmd.RunID) > 0 {
		query.Set("run_id", cmd.RunID)
	}

	u.RawQuery = query.Encode()
	return u.String()
}
开发者ID:hooklift,项目名称:terraform,代码行数:25,代码来源:collector.go

示例13: encodeToken

func encodeToken(referal *url.URL, outhToken *oauth2.Token) error {
	str := outhToken.Extra("expires_in")
	expiresIn, err := strconv.Atoi(fmt.Sprintf("%v", str))
	if err != nil {
		return errs.WithStack(errors.New("cant convert expires_in to integer " + err.Error()))
	}
	str = outhToken.Extra("refresh_expires_in")
	refreshExpiresIn, err := strconv.Atoi(fmt.Sprintf("%v", str))
	if err != nil {
		return errs.WithStack(errors.New("cant convert refresh_expires_in to integer " + err.Error()))
	}
	tokenData := &app.TokenData{
		AccessToken:      &outhToken.AccessToken,
		RefreshToken:     &outhToken.RefreshToken,
		TokenType:        &outhToken.TokenType,
		ExpiresIn:        &expiresIn,
		RefreshExpiresIn: &refreshExpiresIn,
	}
	b, err := json.Marshal(tokenData)
	if err != nil {
		return errs.WithStack(errors.New("cant marshal token data struct " + err.Error()))
	}

	parameters := url.Values{}
	parameters.Add("token", outhToken.AccessToken) // Temporary keep the old "token" param. We will drop this param as soon as UI adopt the new json param.
	parameters.Add("token_json", string(b))
	referal.RawQuery = parameters.Encode()

	return nil
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:30,代码来源:service.go

示例14: BuildSwfPlayUrl

func BuildSwfPlayUrl(conf *Configure, fileType FileType, videoUrl, swfUrl string, timeOut time.Duration) (string, error) {
	fid := ""
	for _, p := range strings.Split(videoUrl, "&") {
		kv := strings.Split(p, "=")
		if len(kv) == 2 && kv[0] == "fid" {
			fid = kv[1]
			break
		}
	}

	if len(fid) == 0 {
		return "", errors.New("invalid vidoe url, fid not found!")
	}

	if len(swfUrl) == 0 {
		swfUrl = SwfUrl
	}

	playUrl := url.URL{}
	playUrl.Path = swfUrl

	params := url.Values{}
	params.Add("vk", videoUrl)

	if fileType == Private {
		playToken := CreatePlayToken(conf.AccessKey, conf.SecretKey, fid, timeOut)

		params.Add("tk", playToken)
	}

	playUrl.RawQuery = params.Encode()

	return playUrl.String(), nil
}
开发者ID:bfhhq,项目名称:go-sdk,代码行数:34,代码来源:url.go

示例15: NewRequest

// NewRequest creates a new HTTP request and applies necessary auth headers if
// set.
func (c *Client) NewRequest(params map[string]string, method string, u url.URL, body io.Reader) *http.Request {

	p := url.Values{}

	// Build up our request parameters
	for k, v := range params {
		p.Add(k, v)
	}

	// Add the params to our URL
	u.RawQuery = p.Encode()

	// Build the request, no point in checking for errors here as we're just
	// passing a string version of an url.URL struct and http.NewRequest returns
	// error only if can't process an url.ParseRequestURI().
	req, _ := http.NewRequest(method, u.String(), body)

	if c.VCDAuthHeader != "" && c.VCDToken != "" {
		// Add the authorization header
		req.Header.Add(c.VCDAuthHeader, c.VCDToken)
		// Add the Accept header for VCD
		req.Header.Add("Accept", "application/*+xml;version=5.6")
	}

	return req

}
开发者ID:MerlinDMC,项目名称:machine,代码行数:29,代码来源:api.go


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