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


Golang URL.RequestURI方法代码示例

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


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

示例1: SortURLParams

// SortURLParams return url with sorted get parameters
func SortURLParams(u *url.URL) string {
	query := u.Query()

	if len(query) == 0 {
		return u.RequestURI()
	}

	result := u.Path + "?"

	var sortedQuery []string

	for qp := range query {
		sortedQuery = append(sortedQuery, qp)
	}

	sort.Strings(sortedQuery)

	for _, qp := range sortedQuery {
		value := strings.Join(query[qp], "")

		if value == "" {
			result += qp + "&"
		} else {
			result += qp + "=" + value + "&"
		}
	}

	result = result[0 : len(result)-1]

	if u.Fragment != "" {
		result += "#" + u.Fragment
	}

	return result
}
开发者ID:essentialkaos,项目名称:mockka,代码行数:36,代码来源:urlutil.go

示例2: writeRequests

func writeRequests(conn net.Conn, ch <-chan int, requestsChan chan<- int, testUri *url.URL) {
	var requestsWritten int
	w := bufio.NewWriter(conn)
	requestUri := testUri.RequestURI()
	delimiter := "?"
	if strings.Contains(requestUri, "?") {
		delimiter = "&"
	}
	for _ = range ch {
		requestStr := []byte(fmt.Sprintf("GET %s%s%d HTTP/1.1\r\nHost: %s\r\nUser-Agent: go-cdn-booster-bench\r\n\r\n",
			requestUri, delimiter, rand.Intn(*filesCount), testUri.Host))
		if _, err := w.Write(requestStr); err != nil {
			log.Fatalf("Error=[%s] when writing HTTP request [%d] to connection\n", err, requestsWritten)
		}
		requestsWritten += 1
		select {
		case requestsChan <- requestsWritten:
		default:
			if err := w.Flush(); err != nil {
				log.Fatalf("Error when flushing requests' buffer: [%s]\n", err)
			}
			requestsChan <- requestsWritten
		}
		if requestsWritten == *requestsPerConnectionCount {
			break
		}
	}
	if err := w.Flush(); err != nil {
		log.Fatalf("Error when flushing requests' buffer: [%s]\n", err)
	}
}
开发者ID:valyala,项目名称:ybc,代码行数:31,代码来源:main.go

示例3: sendUnix

// sendUnix sends a request or response via a Unix socket.
func sendUnix(addr *url.URL, payload interface{}) error {
	conn, err := net.Dial("unix", addr.RequestURI())
	if err != nil {
		log.WithFields(log.Fields{
			"error":   err,
			"addr":    addr,
			"payload": payload,
		}).Error("failed to connect to unix socket")
		return err
	}
	defer logx.LogReturnedErr(conn.Close,
		log.Fields{"addr": addr},
		"failed to close unix connection",
	)

	if err := SendConnData(conn, payload); err != nil {
		return err
	}

	resp := &Response{}
	if err := UnmarshalConnData(conn, resp); err != nil {
		return err
	}

	return resp.Error
}
开发者ID:mistifyio,项目名称:acomm,代码行数:27,代码来源:response.go

示例4: debugUrl

func debugUrl(u *url.URL) {
	logger.Println("Host:", u.Host)
	logger.Println("Path:", u.Path)
	logger.Println("Request URI:", u.RequestURI())
	logger.Println("Scheme:", u.Scheme)
	logger.Println("Query:", u.RawQuery)
	logger.Println("Fragment:", u.Fragment)
	logger.Println("IsAbs:", u.IsAbs())
}
开发者ID:simonz05,项目名称:cw,代码行数:9,代码来源:debug.go

示例5: parse

func parse(s string, base url.URL) (ln []string, as []string) {
	z := html.NewTokenizer(strings.NewReader(s))
	lnm := make(map[string]struct{})
	asm := make(map[string]struct{})

	// anonymous func used to get attribute values
	attr := func(a string) string {
		var av string
		for {
			if k, v, ha := z.TagAttr(); string(k) == a {
				av = string(v)
				break
			} else if ha == false {
				break
			}
		}
		return av
	}

	// convert map to slice
	slc := func(m map[string]struct{}) []string {
		var v []string

		for k := range m {
			v = append(v, k)
		}
		sort.Strings(v)
		return v
	}

	for {
		tt := z.Next()
		switch tt {
		case html.ErrorToken:
			return slc(lnm), slc(asm)
		case html.StartTagToken, html.EndTagToken:
			if tn, ha := z.TagName(); ha {
				tg := string(tn)
				if av := attr(attrs[tg]); av != "" {
					switch tg {
					case atag:
						if url, err := base.Parse(av); err == nil {
							if url.Host == base.Host && url.RequestURI() != base.RequestURI() {
								lnm[url.RequestURI()] = struct{}{}
							}
						}
					case stag, itag, ltag:
						asm[av] = struct{}{}
					}
				}
			}
		}
	}
}
开发者ID:RBeaudoin,项目名称:gobot,代码行数:54,代码来源:crawler.go

示例6: NewClientHtppCodec

// NewClientCodec returns a new rpc.ClientCodec using Yar-RPC on conn.
func NewClientHtppCodec(conn io.ReadWriteCloser, u *url.URL, packagerName string) rpc.ClientCodec {
	packer, _ := getPackager(packagerName)
	return &clientHttpCodec{
		r:       bufio.NewReader(conn),
		w:       conn,
		c:       conn,
		host:    u.Host,
		path:    u.RequestURI(),
		pending: make(map[uint64]string),
		packer:  packer,
	}
}
开发者ID:chinaweilu,项目名称:yar-go,代码行数:13,代码来源:httpClient.go

示例7: canonicalURI

func (s *V4Signer) canonicalURI(u *url.URL) string {
	canonicalPath := u.RequestURI()
	if u.RawQuery != "" {
		canonicalPath = canonicalPath[:len(canonicalPath)-len(u.RawQuery)-1]
	}
	slash := strings.HasSuffix(canonicalPath, "/")
	canonicalPath = path.Clean(canonicalPath)
	if canonicalPath != "/" && slash {
		canonicalPath += "/"
	}
	return canonicalPath
}
开发者ID:joeshaw,项目名称:goamz,代码行数:12,代码来源:sign.go

示例8: NewRequest

// NewRequest constructs a minimal Request instance given a method and
// a target URL.
func NewRequest(method string, u *url.URL) *Request {
	return &Request{
		Method: method,
		URI:    u.RequestURI(),
		Major:  1,
		Minor:  1,
		Fields: Fields{
			{"Host", u.Host},
		},
		Scheme: u.Scheme,
		Remote: u.Host,
	}
}
开发者ID:erkl,项目名称:heat,代码行数:15,代码来源:request.go

示例9: normalizePath

func normalizePath(p string) string {
	if strings.Contains(p, "./") || strings.Contains(p, "..") {
		p, _ = filepath.Abs(p)
	}

	if strings.Contains(p, "//") {
		p = strings.Replace(p, "//", "/", -1)
	}

	u := url.URL{Path: p}

	return u.RequestURI()
}
开发者ID:dockerstack,项目名称:amazon-ecs-agent,代码行数:13,代码来源:sign.go

示例10: crawl

func crawl(url url.URL, ch chan<- SiteMap) {
	var sm SiteMap

	// make sure this link hasn't been crawled
	lc.mux.Lock()
	_, ok := lc.links[url.RequestURI()]

	if !ok {
		lc.links[url.RequestURI()] = struct{}{}
		lc.mux.Unlock()
		log.Printf("Crawling URL: %s\n", url.String())

		b, err := fetch(url)
		if err != nil {
			log.Printf("Error fetching page for URL: %s, err: %s\n", url.String(), err)
			ch <- SiteMap{}
		}

		ln, as := parse(b, url)

		// create new sitemap and add indexed page
		sm = SiteMap{URL: url.String()}
		pg := Page{Path: url.Path, Links: ln, Assets: as}
		sm.Pages = append(sm.Pages, pg)

		c := make(chan SiteMap)
		chLnks := 0
		for _, v := range ln {
			chURL, err := url.Parse(v)
			if err != nil {
				log.Printf("Unable parse url for child link %s, error: %s", v, err)
				continue
			}
			go crawl(*chURL, c)
			chLnks++
		}
		// results of child link crawls
		for i := 0; i < chLnks; i++ {
			chsm := <-c
			if len(chsm.Pages) > 0 {
				sm.Pages = append(sm.Pages, chsm.Pages...)
			}
		}
	} else {
		lc.mux.Unlock()
	}
	// send a SiteMap, even if empty
	ch <- sm
}
开发者ID:RBeaudoin,项目名称:gobot,代码行数:49,代码来源:crawler.go

示例11: logHTTP

// buildCommonLogLine builds a log entry for req in Apache Common Log Format.
// ts is the timestamp with which the entry should be logged.
// status and size are used to provide the response HTTP status and size.
// Copied from gorilla/handlers/handlers.go, converted to strings instead of byte[]
func logHTTP(req *http.Request, url url.URL, ts time.Time, status int, size int) {
	host, _, err := net.SplitHostPort(req.RemoteAddr)

	if err != nil {
		host = req.RemoteAddr
	}

	uri := req.RequestURI

	// Requests using the CONNECT method over HTTP/2.0 must use
	// the authority field (aka r.Host) to identify the target.
	// Refer: https://httpwg.github.io/specs/rfc7540.html#CONNECT
	if req.ProtoMajor == 2 && req.Method == "CONNECT" {
		uri = req.Host
	}
	if uri == "" {
		uri = url.RequestURI()
	}

	log.WithFields(log.Fields{
		"host":   host,
		"method": req.Method,
		"uri":    uri,
		"proto":  req.Proto,
		"status": status,
		"size":   size,
	}).Info(status)
}
开发者ID:e-gov,项目名称:fox,代码行数:32,代码来源:UtilHandlers.go

示例12: buildLogLine

// Log entry for req similar to Apache Common Log Format.
// ts is the timestamp with which the entry should be logged.
// status, size are used to provide the response HTTP status and size.
func buildLogLine(req *http.Request, url url.URL, ts time.Time, status int, size int) []byte {
	username := "-"
	if url.User != nil {
		if name := url.User.Username(); name != "" {
			username = name
		}
	}

	host, _, err := net.SplitHostPort(req.RemoteAddr)

	if err != nil {
		host = req.RemoteAddr
	}

	duration := float64(time.Now().Sub(ts)) / float64(time.Second)

	logLine := fmt.Sprintf("%s - %s [%s] %s %q %s %d %d %q %0.3f\n",
		host,
		username,
		ts.Format("02/Jan/2006:15:04:05 -0700"),
		req.Method,
		url.RequestURI(),
		req.Proto,
		status,
		size,
		req.UserAgent(),
		duration,
	)
	return []byte(logLine)
}
开发者ID:pombredanne,项目名称:sortdb,代码行数:33,代码来源:logging_handler.go

示例13: buildCommonLogLine

// buildCommonLogLine builds a log entry for req in Apache Common Log Format.
// ts is the timestamp with which the entry should be logged.
// status and size are used to provide the response HTTP status and size.
func buildCommonLogLine(req *http.Request, url url.URL, ts time.Time, status int, size int) []byte {
	username := "-"
	if url.User != nil {
		if name := url.User.Username(); name != "" {
			username = name
		}
	}

	host, _, err := net.SplitHostPort(req.RemoteAddr)

	if err != nil {
		host = req.RemoteAddr
	}

	uri := url.RequestURI()

	buf := make([]byte, 0, 3*(len(host)+len(username)+len(req.Method)+len(uri)+len(req.Proto)+50)/2)
	buf = append(buf, host...)
	buf = append(buf, " - "...)
	buf = append(buf, username...)
	buf = append(buf, " ["...)
	buf = append(buf, ts.Format("02/Jan/2006:15:04:05 -0700")...)
	buf = append(buf, `] "`...)
	buf = append(buf, req.Method...)
	buf = append(buf, " "...)
	buf = appendQuoted(buf, uri)
	buf = append(buf, " "...)
	buf = append(buf, req.Proto...)
	buf = append(buf, `" `...)
	buf = append(buf, strconv.Itoa(status)...)
	buf = append(buf, " "...)
	buf = append(buf, strconv.Itoa(size)...)
	return buf
}
开发者ID:number9code,项目名称:dogestry,代码行数:37,代码来源:handlers.go

示例14: NewClient

func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header) (c *Conn, response *http.Response, err error) {
	key, err := calcKey()
	if err != nil {
		return nil, nil, err
	}
	acceptKey := calcAcceptKey(key)

	c = NewConn(netConn, false)

	buf := bytes.NewBufferString("GET ")
	buf.WriteString(u.RequestURI())
	buf.WriteString(" HTTP/1.1\r\nHost: ")
	buf.WriteString(u.Host)
	buf.WriteString("\r\nUpgrade: websocket\r\nConnection: upgrade\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: ")
	buf.WriteString(key)
	buf.WriteString("\r\n")

	for k, vs := range requestHeader {
		for _, v := range vs {
			buf.WriteString(k)
			buf.WriteString(": ")
			buf.WriteString(v)
			buf.WriteString("\r\n")
		}
	}

	buf.WriteString("\r\n")
	p := buf.Bytes()
	if _, err := netConn.Write(p); err != nil {
		return nil, nil, err
	}

	resp, err := http.ReadResponse(c.br, &http.Request{Method: "GET", URL: u})
	if err != nil {
		return nil, nil, err
	}

	if resp.StatusCode != 101 ||
		!strings.EqualFold(resp.Header.Get("Upgrade"), "websocket") ||
		!strings.EqualFold(resp.Header.Get("Connection"), "upgrade") ||
		resp.Header.Get("Sec-Websocket-Accept") != acceptKey {
		return nil, resp, ErrBadHandshake
	}
	return c, resp, nil
}
开发者ID:kingpro,项目名称:golib,代码行数:45,代码来源:client.go

示例15: NewClient

// NewClient creates a new client connection using the given net connection.
// The URL u specifies the host and request URI. Use requestHeader to specify
// the origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies
// (Cookie). Use the response.Header to get the selected subprotocol
// (Sec-WebSocket-Protocol) and cookies (Set-Cookie).
//
// If the WebSocket handshake fails, ErrBadHandshake is returned along with a
// non-nil *http.Response so that callers can handle redirects, authentication,
// etc.
func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufSize, writeBufSize int) (c *Conn, response *http.Response, err error) {
	challengeKey, err := generateChallengeKey()
	if err != nil {
		return nil, nil, err
	}
	acceptKey := computeAcceptKey(challengeKey)

	c = newConn(netConn, false, readBufSize, writeBufSize)
	p := c.writeBuf[:0]
	p = append(p, "GET "...)
	p = append(p, u.RequestURI()...)
	p = append(p, " HTTP/1.1\r\nHost: "...)
	p = append(p, u.Host...)
	// "Upgrade" is capitalized for servers that do not use case insensitive
	// comparisons on header tokens.
	p = append(p, "\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: "...)
	p = append(p, challengeKey...)
	p = append(p, "\r\n"...)
	for k, vs := range requestHeader {
		for _, v := range vs {
			p = append(p, k...)
			p = append(p, ": "...)
			p = append(p, v...)
			p = append(p, "\r\n"...)
		}
	}
	p = append(p, "\r\n"...)

	if _, err := netConn.Write(p); err != nil {
		return nil, nil, err
	}

	resp, err := http.ReadResponse(c.br, &http.Request{Method: "GET", URL: u})
	if err != nil {
		return nil, nil, err
	}
	if resp.StatusCode != 101 ||
		!strings.EqualFold(resp.Header.Get("Upgrade"), "websocket") ||
		!strings.EqualFold(resp.Header.Get("Connection"), "upgrade") ||
		resp.Header.Get("Sec-Websocket-Accept") != acceptKey {
		return nil, resp, ErrBadHandshake
	}
	c.subprotocol = resp.Header.Get("Sec-Websocket-Protocol")
	return c, resp, nil
}
开发者ID:glycerine,项目名称:rmq,代码行数:54,代码来源:client.go


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