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


Golang URL.Query方法代码示例

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


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

示例1: lookup

func lookup(uri *url.URL, q string, suffix bool) (refResult *RefererResult) {
	refResult = &RefererResult{URI: uri, Medium: "unknown"}
	for medium, mediumData := range data {
		for refName, refconfig := range mediumData {
			for _, domain := range refconfig["domains"] {
				if (!suffix && q == domain) || (suffix && (strings.HasSuffix(q, domain) || strings.HasPrefix(q, domain))) {
					refResult.Known = true
					refResult.Referer = refName
					refResult.Medium = medium
					params, paramExists := refconfig["parameters"]
					if paramExists {
						for _, param := range params {
							sterm := uri.Query().Get(param)
							if sterm != "" {
								refResult.SearchParameter = param
								refResult.SearchTerm = sterm
							}
						}
					}
					return refResult
				}
			}
		}
	}
	return
}
开发者ID:203webgroup,项目名称:referer-parser,代码行数:26,代码来源:refererparser.go

示例2: Start

func (d *UDPClient) Start(uri *url.URL) error {
	d.url = uri
	d.stop = make(chan struct{})

	params := uri.Query()
	// The address must not have a port, as otherwise both announce and lookup
	// sockets would try to bind to the same port.
	addr, err := net.ResolveUDPAddr(d.url.Scheme, params.Get("listenaddress")+":0")
	if err != nil {
		return err
	}
	d.listenAddress = addr

	broadcastSeconds, err := strconv.ParseUint(params.Get("broadcast"), 0, 0)
	if err != nil {
		d.globalBroadcastInterval = DefaultGlobalBroadcastInterval
	} else {
		d.globalBroadcastInterval = time.Duration(broadcastSeconds) * time.Second
	}

	retrySeconds, err := strconv.ParseUint(params.Get("retry"), 0, 0)
	if err != nil {
		d.errorRetryInterval = DefaultErrorRetryInternval
	} else {
		d.errorRetryInterval = time.Duration(retrySeconds) * time.Second
	}

	d.wg.Add(1)
	go d.broadcast()
	return nil
}
开发者ID:KFDCompiled,项目名称:syncthing,代码行数:31,代码来源:client_udp.go

示例3: 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

示例4: getConfigOverrides

func getConfigOverrides(uri *url.URL) (*kube_client_cmd.ConfigOverrides, error) {
	kubeConfigOverride := kube_client_cmd.ConfigOverrides{
		ClusterInfo: kube_client_cmd_api.Cluster{
			APIVersion: APIVersion,
		},
	}
	if len(uri.Scheme) != 0 && len(uri.Host) != 0 {
		kubeConfigOverride.ClusterInfo.Server = fmt.Sprintf("%s://%s", uri.Scheme, uri.Host)
	}

	opts := uri.Query()

	if len(opts["apiVersion"]) >= 1 {
		kubeConfigOverride.ClusterInfo.APIVersion = opts["apiVersion"][0]
	}

	if len(opts["insecure"]) > 0 {
		insecure, err := strconv.ParseBool(opts["insecure"][0])
		if err != nil {
			return nil, err
		}
		kubeConfigOverride.ClusterInfo.InsecureSkipTLSVerify = insecure
	}

	return &kubeConfigOverride, nil
}
开发者ID:kubernetes,项目名称:contrib,代码行数:26,代码来源:kubernetes.go

示例5: performHandshakeAndValidation

func performHandshakeAndValidation(conn *tls.Conn, uri *url.URL) error {
	if err := conn.Handshake(); err != nil {
		return err
	}

	cs := conn.ConnectionState()
	if !cs.NegotiatedProtocolIsMutual || cs.NegotiatedProtocol != protocol.ProtocolName {
		return fmt.Errorf("protocol negotiation error")
	}

	q := uri.Query()
	relayIDs := q.Get("id")
	if relayIDs != "" {
		relayID, err := syncthingprotocol.DeviceIDFromString(relayIDs)
		if err != nil {
			return fmt.Errorf("relay address contains invalid verification id: %s", err)
		}

		certs := cs.PeerCertificates
		if cl := len(certs); cl != 1 {
			return fmt.Errorf("unexpected certificate count: %d", cl)
		}

		remoteID := syncthingprotocol.NewDeviceID(certs[0].Raw)
		if remoteID != relayID {
			return fmt.Errorf("relay id does not match. Expected %v got %v", relayID, remoteID)
		}
	}

	return nil
}
开发者ID:hernad,项目名称:syncthing,代码行数:31,代码来源:static.go

示例6: getCursor

func getCursor(u *url.URL) interface{} {
	vals, ok := u.Query()["next"]
	if !ok {
		return nil
	}
	return vals[0]
}
开发者ID:rajatchopra,项目名称:flannel,代码行数:7,代码来源:server.go

示例7: DownloadOneStockPerDay

func DownloadOneStockPerDay(symbol string, date string) error {
	u := url.URL{Scheme: "http", Host: "market.finance.sina.com.cn", Path: "/downxls.php"}
	q := u.Query()
	q.Set("date", date)
	q.Set("symbol", symbol)
	u.RawQuery = q.Encode()

	log.Println(u.String())

	td := GetStockInOneDay(u.String())
	if len(td) > 0 {

		var ops DBOps
		ops.Init()
		err := ops.Open()
		if err != nil {
			log.Println("open the database failed.")
			log.Fatal(err)
		}
		defer ops.Close()

		ops.CopyDataIntoTable(td)
	} else {
		log.Printf("%s:%s#No DATA\n", symbol, date)
	}

	return nil
}
开发者ID:saiyaw,项目名称:example,代码行数:28,代码来源:stock.go

示例8: GetNameBySymbol

func GetNameBySymbol(s string) (string, bool) {
	u := url.URL{Scheme: "http", Host: "hq.sinajs.cn", Path: "/"}
	q := u.Query()
	q.Set("list", s)
	u.RawQuery = q.Encode()
	log.Println(u.String())

	res, err := http.Get(u.String())
	if err != nil {
		log.Println(err.Error())
		return "", false
	}
	body, err := ioutil.ReadAll(res.Body)
	defer res.Body.Close()
	if err != nil {
		log.Println(err.Error())
		return "", false
	}
	//	log.Println(GBKtoUTF8(string(body)))
	content := string(body)
	if strings.Contains(content, ",") != true {
		log.Println("Invalid symbol")
		return "", false
	}
	name := content[strings.Index(content, "\"")+1 : strings.Index(content, ",")]
	log.Println(GBKtoUTF8(name))

	//	log.Printf("length:%d\n", len(name))

	return GBKtoUTF8(name), true

}
开发者ID:saiyaw,项目名称:example,代码行数:32,代码来源:stock.go

示例9: TestRefreshParam

func TestRefreshParam(t *testing.T) {
	var requrl *url.URL
	InitTests(true)
	c := NewTestConn()
	c.RequestTracer = func(method, urlStr, body string) {
		requrl, _ = url.Parse(urlStr)
	}
	date := time.Unix(1257894000, 0)
	data := map[string]interface{}{"name": "smurfs", "age": 22, "date": date}

	// Now tests small batches
	indexer := c.NewBulkIndexer(1)
	indexer.Refresh = true

	indexer.Start()
	<-time.After(time.Millisecond * 20)

	indexer.Index("users", "user", "2", "", "", &date, data)

	<-time.After(time.Millisecond * 200)
	//	indexer.Flush()
	indexer.Stop()

	assert.T(t, requrl.Query().Get("refresh") == "true", "Should have set refresh query param to true")
}
开发者ID:rdterner,项目名称:elastigo,代码行数:25,代码来源:corebulk_test.go

示例10: hotpFromURL

func hotpFromURL(u *url.URL) (*HOTP, string, error) {
	label := u.Path[1:]
	v := u.Query()

	secret := v.Get("secret")
	if secret == "" {
		return nil, "", ErrInvalidURL
	}

	var digits = 6
	if sdigit := v.Get("digits"); sdigit != "" {
		tmpDigits, err := strconv.ParseInt(sdigit, 10, 8)
		if err != nil {
			return nil, "", err
		}
		digits = int(tmpDigits)
	}

	var counter uint64 = 0
	if scounter := v.Get("counter"); scounter != "" {
		var err error
		counter, err = strconv.ParseUint(scounter, 10, 64)
		if err != nil {
			return nil, "", err
		}
	}

	key, err := base32.StdEncoding.DecodeString(secret)
	if err != nil {
		return nil, "", err
	}
	otp := NewHOTP(key, counter, digits)
	return otp, label, nil
}
开发者ID:kisom,项目名称:cryptutils,代码行数:34,代码来源:hotp.go

示例11: Parse

func (lp *LinkParser) Parse(newPost *post.Post, raw []byte) post.Flow {
	if !lp.ready {
		lp.ready = true
		return post.Continue
	}

	if bytes.HasPrefix(raw, []byte("post/view?")) {
		newPost.Link = "http://www.javaworld.com.tw/jute/" + string(raw)

		var postLink *url.URL
		postLink, lp.err = url.Parse(newPost.Link)
		if lp.err != nil {
			return post.Error
		}

		values := postLink.Query()
		newPost.Id, lp.err = strconv.Atoi(values.Get("id"))
		if lp.err != nil {
			return post.Error
		}

		newPost.Bid, lp.err = strconv.Atoi(values.Get("bid"))
		if lp.err != nil {
			return post.Error
		}

		return post.Stop
	}

	return post.Continue
}
开发者ID:postfix,项目名称:spamdefender,代码行数:31,代码来源:parse.go

示例12: queryValue

func queryValue(u *url.URL, key string) string {
	vals, ok := u.Query()[key]
	if !ok || len(vals) != 1 {
		return ""
	}
	return vals[0]
}
开发者ID:hwinkel,项目名称:rkt,代码行数:7,代码来源:metadata_service.go

示例13: parsePrefix

func parsePrefix(u *url.URL) string {
	t := u.Query().Get("prefix")
	if t != "" {
		return t
	}
	return SyslogPrefix
}
开发者ID:huhoo,项目名称:vulcand,代码行数:7,代码来源:trace.go

示例14: TestGetBlobSASURI

func (s *StorageBlobSuite) TestGetBlobSASURI(c *chk.C) {
	api, err := NewClient("foo", "YmFy", DefaultBaseURL, "2013-08-15", true)
	c.Assert(err, chk.IsNil)
	cli := api.GetBlobService()
	expiry := time.Time{}

	expectedParts := url.URL{
		Scheme: "https",
		Host:   "foo.blob.core.windows.net",
		Path:   "container/name",
		RawQuery: url.Values{
			"sv":  {"2013-08-15"},
			"sig": {"/OXG7rWh08jYwtU03GzJM0DHZtidRGpC6g69rSGm3I0="},
			"sr":  {"b"},
			"sp":  {"r"},
			"se":  {"0001-01-01T00:00:00Z"},
		}.Encode()}

	u, err := cli.GetBlobSASURI("container", "name", expiry, "r")
	c.Assert(err, chk.IsNil)
	sasParts, err := url.Parse(u)
	c.Assert(err, chk.IsNil)
	c.Assert(expectedParts.String(), chk.Equals, sasParts.String())
	c.Assert(expectedParts.Query(), chk.DeepEquals, sasParts.Query())
}
开发者ID:gilbertchen,项目名称:azure-sdk-for-go,代码行数:25,代码来源:blob_test.go

示例15: queryHTTPTracker

func queryHTTPTracker(infoHashes []string, u *url.URL) (tr []InfoHashDetails, err error) {
	uq := u.Query()
	for _, infoHash := range infoHashes {
		uq.Add("info_hash", infoHash)
	}

	log.Println("HTTP INFO HASH DEBUG REMOVE THIS", uq)

	// Don't report IPv6 address, the user might prefer to keep
	// that information private when communicating with IPv4 hosts.
	if false {
		ipv6Address, err := findLocalIPV6AddressFor(u.Host)
		if err == nil {
			log.Println("our ipv6", ipv6Address)
			uq.Add("ipv6", ipv6Address)
		}
	}

	// This might reorder the existing query string in the Announce url
	// This might break some broken trackers that don't parse URLs properly.

	u.RawQuery = uq.Encode()

	tr, err = getTrackerInfo(u.String())
	if tr == nil || err != nil {
		log.Println("Error: Could not fetch tracker info:", err)
	}
	return
}
开发者ID:sdgoij,项目名称:TheDistributedBay,代码行数:29,代码来源:trackerClient.go


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