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


Golang http.URLEscape函數代碼示例

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


在下文中一共展示了URLEscape函數的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", http.URLEscape(c.Path))
		}
		if len(c.Domain) > 0 {
			fmt.Fprintf(&b, "; $Domain=%s", http.URLEscape(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:kpumuk,項目名稱:web.go,代碼行數:31,代碼來源:cookie.go

示例2: Request

func (t *Tracker) Request(uploaded int, downloaded int, left int, status string) (peers *list.List, err os.Error) {
	err = nil
	url := fmt.Sprint(t.url,
		"?",
		"info_hash=", http.URLEscape(t.infoHash),
		"&peer_id=", http.URLEscape(t.peerId),
		"&port=", http.URLEscape(t.port),
		"&uploaded=", strconv.Itoa(uploaded),
		"&downloaded=", strconv.Itoa(downloaded),
		"&left=", strconv.Itoa(left),
		"&status=", http.URLEscape(status))
	println(url)
	response, _, err := http.Get(url)
	if err != nil {
		return
	}

	if response.StatusCode != http.StatusOK {
		err = os.NewError("http error")
	}
	buf := new(bencode.BeString)
	resReader := bufio.NewReader(response.Body)
	be, err := buf.Decode(resReader)
	if err != nil {
		return
	}
	if be.Betype != bencode.Bedict {
		err = os.NewError("unexpected response from tracker")
		return
	}
	if failure, ok := be.Bedict["failure reason"]; !ok {
		err = os.NewError("unexpected response from tracker")
		return
	} else {
		print(failure)
		return
	}
	if interval, ok := be.Bedict["interval"]; !ok {
		err = os.NewError("unexpected response from tracker")
		return
	} else {
		t.interval, err = strconv.Atoi(interval.Bestr)
	}
	if _, ok := be.Bedict["peers"]; !ok {
		err = os.NewError("unexpected response from tracker")
		return
	}
	list := list.New()
	for i := range be.Bedict["peers"].Belist.Iter() {
		if i.(*bencode.BeNode).Betype == bencode.Bedict {
			list.PushFront(i.(*bencode.BeNode).Bedict)
		} else {
			err = os.NewError("unexpected response from tracker")
			return
		}
	}
	peers = list
	return
}
開發者ID:peernode,項目名稱:gobit,代碼行數:59,代碼來源:gotracker.go

示例3: Urlencode

func Urlencode(data map[string]string) string {
	var buf bytes.Buffer
	for k, v := range data {
		buf.WriteString(http.URLEscape(k))
		buf.WriteByte('=')
		buf.WriteString(http.URLEscape(v))
		buf.WriteByte('&')
	}
	s := buf.String()
	return s[0 : len(s)-1]
}
開發者ID:surapaneni,項目名稱:web.go,代碼行數:11,代碼來源:web.go

示例4: toQuery

func toQuery(params map[string]string) string {
	buf := bytes.NewBuffer(nil)

	flag := false
	for key, val := range params {
		if flag {
			buf.WriteString("&" + key + "=" + http.URLEscape(val))
		} else {
			flag = true
			buf.WriteString(key + "=" + http.URLEscape(val))
		}
	}

	return buf.String()
}
開發者ID:mcspring,項目名稱:googl.go,代碼行數:15,代碼來源:googl.go

示例5: remoteSearch

func remoteSearch(query string) (res *http.Response, err os.Error) {
	search := "/search?f=text&q=" + http.URLEscape(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:ssrl,項目名稱:go,代碼行數:30,代碼來源:main.go

示例6: escape

func escape(str string) string {
	str = http.URLEscape(str)
	str = strings.Replace(str, ":", "%3A", -1)
	str = strings.Replace(str, "/", "%2F", -1)

	return str
}
開發者ID:hpcorona,項目名稱:goa1,代碼行數:7,代碼來源:goa1.go

示例7: tf

func tf(c *http.Conn, b string, e string, n int, y int, s string) int {

	var qs string
	var ntf int = 0

	if len(s) < 1 {
		return ntf
	}

	if s[0] == '#' && len(s) > 1 {
		qs = s
	} else {
		qs = "from:" + s
	}
	r, _, err := http.Get(fmt.Sprintf(queryURI,
		qformat, http.URLEscape(qs), b, e, n))
	if err == nil {
		if r.StatusCode == http.StatusOK {
			ntf = readjson(c, r.Body, b, e, y)
		} else {
			fmt.Printf("Twitter is unable to search for %s (%s)\n", s, r.Status)
		}
		r.Body.Close()
	} else {
		fmt.Printf("%v\n", err)
	}
	return ntf
}
開發者ID:J5lx,項目名稱:luminous,代碼行數:28,代碼來源:wtf.go

示例8: StatusesUpdate

func (c *Client) StatusesUpdate(status string, replyId uint64) (err os.Error) {
	var params string

	if status == "" {
		return os.NewError("must need \"status\" parameter.")
	}

	params = addParam(params, "status", http.URLEscape(status))

	if replyId != 0 {
		params = addParam(params, "in_reply_to_status_id", fmt.Sprintf("%d", replyId))
	}

	url := c.makeAuthURL(statusesUpdate, params)
	res, err := http.Post(url, "", bytes.NewBufferString(""))
	if err != nil {
		return err
	}

	if res.Status != "200 OK" {
		return os.NewError("Request failed")
	}

	return nil
}
開發者ID:kazura-utb,項目名稱:TwitterWithGo,代碼行數:25,代碼來源:twitter.go

示例9: TestSuccessfulTokenRequest

func TestSuccessfulTokenRequest(t *testing.T) {
	c := basicConsumer()
	m := newMocks(t)
	m.install(c)

	m.httpClient.ExpectGet(
		"http://www.mrjon.es/requesttoken",
		map[string]string{
			"oauth_callback":         http.URLEscape("http://www.mrjon.es/callback"),
			"oauth_consumer_key":     "consumerkey",
			"oauth_nonce":            "2",
			"oauth_signature":        "MOCK_SIGNATURE",
			"oauth_signature_method": "HMAC-SHA1",
			"oauth_timestamp":        "1",
			"oauth_version":          "1.0",
		},
		"oauth_token=TOKEN&oauth_token_secret=SECRET")

	token, url, err := c.GetRequestTokenAndUrl("http://www.mrjon.es/callback")
	if err != nil {
		t.Fatal(err)
	}

	assertEq(t, "TOKEN", token.Token)
	assertEq(t, "SECRET", token.Secret)
	assertEq(t, "consumersecret&", m.signer.UsedKey)
	assertEq(t, "http://www.mrjon.es/authorizetoken?oauth_token=TOKEN", url)
}
開發者ID:newblue,項目名稱:oauth,代碼行數:28,代碼來源:oauth_test.go

示例10: downloadBlob

func (self *Federation) downloadBlob(rawurl, blobref string) (dependencies []string, err os.Error) {
	// Get the blob
	var client http.Client
	req, err := client.Get(rawurl + "?blobref=" + http.URLEscape(blobref))
	if err != nil {
		return nil, err
	}
	// TODO: Improve for large files
	blob, err := ioutil.ReadAll(req.Body)
	if err != nil {
		log.Printf("Error reading request body")
		return nil, err
	}
	log.Printf("Downloaded %v\n", string(blob))
	req.Body.Close()
	self.store.StoreBlob(blob, "")
	// Check whether the retrieved blob is a schema blob
	mimetype := grapher.MimeType(blob)
	if mimetype == "application/x-lightwave-schema" {
		var schema depSchema
		err = json.Unmarshal(blob, &schema)
		if err != nil {
			log.Printf("Malformed schema blob: %v\n", err)
			return nil, err
		}
		dependencies = schema.Dependencies
	}
	return
}
開發者ID:AaronO,項目名稱:lightwave,代碼行數:29,代碼來源:federation.go

示例11: handleLogout

func handleLogout(w http.ResponseWriter, r *http.Request) {
	c = appengine.NewContext(r)
	returnURL := "/"
	// parse form
	err := r.ParseForm()
	if err != nil {
		serveError(c, w, err)
		return
	}
	if r.FormValue("continue") != "" {
		returnURL = r.FormValue("continue")
	}

	if useOpenID {
		// adjust returnURL to bring us back to a local user login form
		laterReturnUrl := returnURL
		returnURL = "/Login/?chooseLogin=1&continue=" + http.URLEscape(laterReturnUrl)
	}
	// redirect to google logout (for OpenID as well, or else we won't be locally logged out)
	lourl, err := user.LogoutURL(c, returnURL)
	if err != nil {
		c.Errorf("handleLogout: error getting LogoutURL")
	}
	c.Debugf("handleLogout: redirecting to logoutURL=%v", lourl)
	http.Redirect(w, r, lourl, http.StatusFound)
	return
}
開發者ID:jrandall,項目名稱:cambridge-challenge.appspot.com,代碼行數:27,代碼來源:handle-logout.go

示例12: main

// for each search term on the commandline, create a photo grid
func main() {
	for i := 1; i < len(os.Args); i++ {
		canvas.Start(width, height)
		canvas.Rect(0, 0, width, height, "fill:black")
		fs(http.URLEscape(os.Args[i]))
		canvas.End()
	}
}
開發者ID:krasin,項目名稱:svgo,代碼行數:9,代碼來源:f50.go

示例13: 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, http.URLEscape(value))
		} else {
			addition = fmt.Sprintf("&%s=%s", key, http.URLEscape(value))
		}
		newUrl += addition
		i++
	}

	return newUrl
}
開發者ID:rene-dev,項目名稱:go-twitter,代碼行數:17,代碼來源:util.go

示例14: FormEncodedBytes

// FormEncodedBytes returns a buffer containing the URL form encoding of the
// map.
func (m Values) FormEncodedBytes() []byte {
	var b bytes.Buffer
	sep := false
	for key, values := range m {
		escapedKey := http.URLEscape(key)
		for _, value := range values {
			if sep {
				b.WriteByte('&')
			} else {
				sep = true
			}
			b.WriteString(escapedKey)
			b.WriteByte('=')
			b.WriteString(http.URLEscape(value))
		}
	}
	return b.Bytes()
}
開發者ID:stevela,項目名稱:twister,代碼行數:20,代碼來源:parammap.go

示例15: TweetJson

func TweetJson(client *Client, message string) (responseStr string, err os.Error) {
	message = http.URLEscape(message)
	var form = map[string][]string{
		"status": []string{message},
	}
	// send request
	responseStr, err = send(URLSendTweet, "POST", form, client, "status="+message)
	return
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:9,代碼來源:twitter.go


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