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


Golang url.QueryEscape函数代码示例

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


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

示例1: writeCookies

// writeCookies writes the wire representation of the cookies
// to w. Each cookie is written on a separate "Cookie: " line.
// This choice is made because HTTP parsers tend to have a limit on
// line-length, so it seems safer to place cookies on separate lines.
func writeCookies(w io.Writer, kk []*http.Cookie) os.Error {
	lines := make([]string, 0, len(kk))
	var b bytes.Buffer
	for _, c := range kk {
		b.Reset()
		n := c.Name
		// TODO(petar): c.Value (below) should be unquoted if it is recognized as quoted
		fmt.Fprintf(&b, "%s=%s", http.CanonicalHeaderKey(n), c.Value)
		if len(c.Path) > 0 {
			fmt.Fprintf(&b, "; $Path=%s", url.QueryEscape(c.Path))
		}
		if len(c.Domain) > 0 {
			fmt.Fprintf(&b, "; $Domain=%s", url.QueryEscape(c.Domain))
		}
		if c.HttpOnly {
			fmt.Fprintf(&b, "; $HttpOnly")
		}
		lines = append(lines, "Cookie: "+b.String()+"\r\n")
	}
	sort.Strings(lines)
	for _, l := range lines {
		if _, err := io.WriteString(w, l); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:niltonkummer,项目名称:web.go,代码行数:31,代码来源:cookie.go

示例2: PostFacebookLink

func PostFacebookLink(text string, urls []string) {
	u := make(url.Values)
	u.Add("access_token", accessToken)
	u.Add("link", url.QueryEscape(urls[0]))
	u.Add("message", url.QueryEscape(text))
	http.PostForm(linkURL, u)
}
开发者ID:robteix,项目名称:smartertweets,代码行数:7,代码来源:smartertweets.go

示例3: getResponse

func (b *HttpRequestBuilder) getResponse() (*http.Response, os.Error) {
	var paramBody string
	if b.params != nil && len(b.params) > 0 {
		var buf bytes.Buffer
		for k, v := range b.params {
			buf.WriteString(url.QueryEscape(k))
			buf.WriteByte('=')
			buf.WriteString(url.QueryEscape(v))
			buf.WriteByte('&')
		}
		paramBody = buf.String()
		paramBody = paramBody[0 : len(paramBody)-1]
	}
	if b.req.Method == "GET" && len(paramBody) > 0 {
		if strings.Index(b.url, "?") != -1 {
			b.url += "&" + paramBody
		} else {
			b.url = b.url + "?" + paramBody
		}
	} else if b.req.Method == "POST" && b.req.Body == nil && len(paramBody) > 0 {
		b.Header("Content-Type", "application/x-www-form-urlencoded")
		b.req.Body = nopCloser{bytes.NewBufferString(paramBody)}
		b.req.ContentLength = int64(len(paramBody))
	}

	conn, resp, err := getResponse(b.url, b.req)
	b.clientConn = conn
	return resp, err
}
开发者ID:axel-b,项目名称:httplib.go,代码行数:29,代码来源:httplib.go

示例4: CreateAuthenticationRequest

func CreateAuthenticationRequest(OPEndPoint, ClaimedID, Realm, ReturnTo string) string {
	var p = make(map[string]string)

	p["openid.ns"] = "http://specs.openid.net/auth/2.0"
	p["openid.mode"] = "checkid_setup"

	if len(ClaimedID) == 0 {
		p["openid.claimed_id"] = "http://specs.openid.net/auth/2.0/identifier_select"
		p["openid.identity"] = "http://specs.openid.net/auth/2.0/identifier_select"
	} else {
		p["openid.claimed_id"] = ClaimedID
		p["openid.identity"] = ClaimedID
	}

	p["openid.return_to"] = Realm + ReturnTo
	p["openid.realm"] = Realm

	var url_ string
	url_ = OPEndPoint + "?"

	for k, v := range p {
		url_ += url.QueryEscape(k) + "=" + url.QueryEscape(v) + "&"
	}
	return url_
}
开发者ID:brianolson,项目名称:go-openid,代码行数:25,代码来源:authrequest.go

示例5: Urlencode

func Urlencode(data map[string]string) string {
	var buf bytes.Buffer
	for k, v := range data {
		buf.WriteString(url.QueryEscape(k))
		buf.WriteByte('=')
		buf.WriteString(url.QueryEscape(v))
		buf.WriteByte('&')
	}
	s := buf.String()
	return s[0 : len(s)-1]
}
开发者ID:andrewzeneski,项目名称:web.go,代码行数:11,代码来源:web.go

示例6: RetrieveActivityList

func RetrieveActivityList(client oauth2_client.OAuth2Client, userId, collection string, m url.Values) (*ActivityListResponse, os.Error) {
	if userId == "" {
		userId = "me"
	}
	if collection == "" {
		collection = "public"
	}
	p := new(ActivityListResponse)
	uri := ACTIVITY_LIST_ENDPOINT + url.QueryEscape(userId) + "/activities/" + url.QueryEscape(collection)
	err := retrieveInfo(client, uri, m, p)
	return p, err
}
开发者ID:pombredanne,项目名称:contacts.go,代码行数:12,代码来源:service.go

示例7: signupPost

func signupPost(w http.ResponseWriter, r *http.Request) {
	responseType, client, err := params(r)
	if err != nil {
		err.WriteTo(w)
		return
	}
	email, password := r.FormValue("email"), r.FormValue("password")
	emailRegexp := regexp.MustCompile(`^[a-z0-9._%\-+][email protected][a-z0-9.\-]+\.[a-z]+$`)
	msgs := make([]string, 0, 5)
	if !emailRegexp.MatchString(email) {
		msgs = append(msgs, "Invalid email address")
	}
	if len(password) < 6 {
		msgs = append(msgs, "Password is too short")
	}
	//  Also check if email already exists
	user := model.NewUser(email)
	context := appengine.NewContext(r)
	countExists, e := datastore.NewQuery("User").Filter("EmailHash =", user.EmailHash).Count(context)
	if e != nil {
		context.Errorf("%v", e)
		http.Error(w, e.String(), http.StatusInternalServerError)
		return
	}
	if countExists > 0 {
		msgs = append(msgs, "Email already exists")
	}

	if msgsLen := len(msgs); msgsLen > 0 {
		http.RedirectHandler("/oauth2/signup?response_type="+url.QueryEscape(responseType)+"&client_id="+
			url.QueryEscape(client.Id)+"&msgs="+url.QueryEscape(strings.Join(msgs, "|")), 303).ServeHTTP(w, r)
	} else {
		userKey, err := datastore.Put(context, datastore.NewIncompleteKey(context, "User", nil), user)
		if err != nil {
			context.Errorf("Error saving: %v", err)
			w.Write([]byte("Error saving: " + err.String()))
			return
		}
		auth := model.NewPasswordAuth(userKey, password)
		if _, err = datastore.Put(context, datastore.NewIncompleteKey(context, "Authentication", nil), auth); err != nil {
			context.Errorf("Error saving: %v", err)
			w.Write([]byte("Error saving: " + err.String()))
			return
		}
		key := newCodeKey(userKey.StringID(), client.Id, context)
		http.RedirectHandler(client.redirectUrl(key), 303).ServeHTTP(w, r)
	}
}
开发者ID:cmc333333,项目名称:fragspace,代码行数:48,代码来源:signup.go

示例8: GetAuthorizeURL

// Obtain a URL which will allow the current user to authorize access to their
// OAuth-protected data.
func (c *UserConfig) GetAuthorizeURL(service *Service) (string, os.Error) {
	if c.RequestTokenKey == "" || c.RequestTokenSecret == "" {
		return "", os.NewError("No configured request token")
	}
	token := url.QueryEscape(c.RequestTokenKey)
	return service.AuthorizeURL + "?oauth_token=" + token, nil
}
开发者ID:paul-lalonde,项目名称:golibs,代码行数:9,代码来源:userconfig.go

示例9: remoteSearch

func remoteSearch(query string) (res *http.Response, err os.Error) {
	search := "/search?f=text&q=" + url.QueryEscape(query)

	// list of addresses to try
	var addrs []string
	if *serverAddr != "" {
		// explicit server address - only try this one
		addrs = []string{*serverAddr}
	} else {
		addrs = []string{
			defaultAddr,
			"golang.org",
		}
	}

	// remote search
	for _, addr := range addrs {
		url := "http://" + addr + search
		res, err = http.Get(url)
		if err == nil && res.StatusCode == http.StatusOK {
			break
		}
	}

	if err == nil && res.StatusCode != http.StatusOK {
		err = os.NewError(res.Status)
	}

	return
}
开发者ID:WXB506,项目名称:golang,代码行数:30,代码来源:main.go

示例10: renameTag

func renameTag(req *web.Request) {
	// oldTag := req.Param.Get("oldTag")
	newTag := req.Param.Get("newTag")
	// updateTag(oldTag, newTag)
	url := fmt.Sprintf("/tag/%s", url.QueryEscape(newTag))
	req.Redirect(url, false)
}
开发者ID:ngerakines,项目名称:gobook,代码行数:7,代码来源:main.go

示例11: getLinkUrl

func (i *Item) getLinkUrl(handlerFunc interface{}, values interface{}) string {

	valueStubs, _, needsHash := makeStubs(values, false)

	stubs := allStubs{Func: getFunctionName(handlerFunc), Values: valueStubs}

	hashQuery := ""
	if needsHash {
		hash := getHash(stubs)
		stubs.Hash = hash
		hashQuery = "&_hash=" + hash
	}

	qstring := ""
	for _, v := range stubs.Values {
		if len(qstring) == 0 {
			qstring += "?"
		} else {
			qstring += "&"
		}

		qstring += v.N + "=" + url.QueryEscape(toString(v.V))
	}
	href := "/" + stubs.Func + qstring + hashQuery

	return href

}
开发者ID:davelondon,项目名称:twist,代码行数:28,代码来源:item.go

示例12: shorten

func shorten(long string) (short string) {
	key := "R_e659dbb5514e34edc3540a7c95b0041b"
	login := "jvermillion"

	long = url.QueryEscape(long)

	url_ := fmt.Sprintf("http://api.bit.ly/v3/shorten?login=%s&apiKey=%s&longUrl=%s&format=json", login, key, long)
	r, err := http.Get(url_)
	defer r.Body.Close()

	if err != nil {
		return "Error connecting to bit.ly"
	}

	b, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return "Error reading bit.ly response"
	}

	var j map[string]interface{}

	err = json.Unmarshal(b, &j)
	if err != nil {
		return "Unable to shorten URL."
	}

	var data map[string]interface{} = j["data"].(map[string]interface{})

	return data["url"].(string)
}
开发者ID:thevermi,项目名称:rbot,代码行数:30,代码来源:bitly.go

示例13: GetOAuthParams

// Returns a map of all of the oauth_* (including signature) parameters for the
// given request, and the signature base string used to generate the signature.
func (s *HmacSha1Signer) GetOAuthParams(request *http.Request, clientConfig *ClientConfig, userConfig *UserConfig, nonce string, timestamp string) (map[string]string, string) {
	request.ParseForm()
	oauthParams := map[string]string{
		"oauth_consumer_key":     clientConfig.ConsumerKey,
		"oauth_nonce":            nonce,
		"oauth_signature_method": "HMAC-SHA1",
		"oauth_timestamp":        timestamp,
		"oauth_version":          "1.0",
	}
	tokenKey, tokenSecret := userConfig.GetToken()
	if tokenKey != "" {
		oauthParams["oauth_token"] = tokenKey
	}
	signingParams := map[string]string{}
	for key, value := range oauthParams {
		signingParams[key] = value
	}
	for key, value := range request.URL.Query() {
		//TODO: Support multiple parameters with the same name.
		signingParams[key] = value[0]
	}
	for key, value := range request.Form {
		//TODO: Support multiple parameters with the same name.
		signingParams[key] = value[0]
	}
	signingUrl := fmt.Sprintf("%v://%v%v", request.URL.Scheme, request.URL.RawAuthority, request.URL.Path)
	signatureParts := []string{
		request.Method,
		url.QueryEscape(signingUrl),
		s.encodeParameters(signingParams)}
	signatureBase := strings.Join(signatureParts, "&")
	oauthParams["oauth_signature"] = s.GetSignature(clientConfig.ConsumerSecret, tokenSecret, signatureBase)
	return oauthParams, signatureBase
}
开发者ID:paul-lalonde,项目名称:golibs,代码行数:36,代码来源:oauth1a.go

示例14: slurpURL

func slurpURL(urlStr string) []byte {
	diskFile := filepath.Join(os.TempDir(), "google-api-cache-"+url.QueryEscape(urlStr))
	if *useCache {
		bs, err := ioutil.ReadFile(diskFile)
		if err == nil && len(bs) > 0 {
			return bs
		}
	}

	req, err := http.NewRequest("GET", urlStr, nil)
	if err != nil {
		log.Fatal(err)
	}
	if *publicOnly {
		req.Header.Add("X-User-IP", "0.0.0.0") // hack
	}
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatalf("Error fetching URL %s: %v", urlStr, err)
	}
	bs, err := ioutil.ReadAll(res.Body)
	if err != nil {
		log.Fatalf("Error reading body of URL %s: %v", urlStr, err)
	}
	if *useCache {
		if err := ioutil.WriteFile(diskFile, bs, 0666); err != nil {
			log.Printf("Warning: failed to write JSON of %s to disk file %s: %v", urlStr, diskFile, err)
		}
	}
	return bs
}
开发者ID:Anupam007,项目名称:google-api-go-client-git,代码行数:31,代码来源:gen.go

示例15: addQueryVariables

func addQueryVariables(url_ string, variables map[string]string) string {
	var addition string
	newUrl := url_

	i := 0
	for key, value := range variables {
		if i == 0 {
			addition = fmt.Sprintf("?%s=%s", key, url.QueryEscape(value))
		} else {
			addition = fmt.Sprintf("&%s=%s", key, url.QueryEscape(value))
		}
		newUrl += addition
		i++
	}

	return newUrl
}
开发者ID:paul-lalonde,项目名称:twitter,代码行数:17,代码来源:util.go


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