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


Golang URL.EscapedPath方法代碼示例

本文整理匯總了Golang中net/url.URL.EscapedPath方法的典型用法代碼示例。如果您正苦於以下問題:Golang URL.EscapedPath方法的具體用法?Golang URL.EscapedPath怎麽用?Golang URL.EscapedPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/url.URL的用法示例。


在下文中一共展示了URL.EscapedPath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: FullOriginal

func (p *postInfo) FullOriginal() string {
	if p.HasOriginal() {
		var u = url.URL{Path: p.FullFile() + "/" + p.Original}
		return u.EscapedPath()
	}
	return p.FullFile()
}
開發者ID:andrius4669,項目名稱:afcgw,代碼行數:7,代碼來源:render_post.go

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

示例3: Complete

func (s *SQLStore) Complete(u *url.URL) (err error) {
	tx, err := s.DB.Beginx()
	if err != nil {
		return
	}
	defer func() {
		if err != nil {
			tx.Rollback() // TODO: handle error
		} else {
			err = tx.Commit()
		}
	}()

	if _, err = tx.Exec(`
	UPDATE url SET done = TRUE
	WHERE scheme = $1 AND host = $2 AND path = $3 AND query = $4`,
		u.Scheme,
		u.Host,
		u.EscapedPath(),
		u.Query().Encode(),
	); err != nil {
		return
	}
	_, err = tx.Exec(`UPDATE count SET finish_count = finish_count + 1`)
	return
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:26,代碼來源:store.go

示例4: UpdateFunc

func (s *SQLStore) UpdateFunc(u *url.URL, f func(*crawler.URL)) (err error) {
	tx, err := s.DB.Beginx()
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			tx.Rollback()
		} else {
			err = tx.Commit()
		}
	}()
	var w wrapper
	if err = tx.QueryRowx(
		`SELECT * FROM url
	    WHERE scheme = $1 AND host = $2 AND path = $3 AND query = $4`,
		u.Scheme, u.Host, u.EscapedPath(), u.Query().Encode(),
	).StructScan(&w); err != nil {
		return
	}
	uu := w.ToURL()
	f(uu)
	w.fromURL(uu)
	_, err = s.DB.NamedExec(`
	UPDATE url SET num_error = :num_error, num_visit = :num_visit, last = :last, status = :status
	WHERE scheme = :scheme AND host = :host AND path = :path AND query = :query`, w)
	return

}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:29,代碼來源:store.go

示例5: GetDepth

func (s *SQLStore) GetDepth(u *url.URL) (depth int, err error) {
	err = s.DB.QueryRow(
		`SELECT depth FROM url
    	WHERE scheme = $1 AND host = $2 AND path = $3 AND query = $4`,
		u.Scheme, u.Host, u.EscapedPath(), u.Query().Encode(),
	).Scan(&depth)
	return
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:8,代碼來源:store.go

示例6: Match

func (p *pattern) Match(u *url.URL) bool {
	us, uh, up := u.String(), u.Host, u.EscapedPath()
	dir, file := path.Split(up)
	f := matchString
	return f(us, p.Reject, p.Accept) &&
		f(uh, p.ExcludeHost, p.Host) &&
		f(dir, p.ExcludeDir, p.Dir) &&
		f(file, p.ExcludeFile, p.File)
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:9,代碼來源:pattern.go

示例7: appFromDeisRemote

func appFromDeisRemote(remote *url.URL) (string, error) {
	re := regexp.MustCompile("^/([a-zA-Z0-9-_.]+).git")
	matches := re.FindStringSubmatch(remote.EscapedPath())

	if len(matches) == 0 {
		return "", ErrRemoteNotApp
	}

	return string(matches[1]), nil
}
開發者ID:Codaisseur,項目名稱:deis-backing-services,代碼行數:10,代碼來源:app.go

示例8: TestExpand

func TestExpand(t *testing.T) {
	for i, test := range expandTests {
		u := url.URL{
			Path: test.in,
		}
		Expand(&u, test.expansions)
		got := u.EscapedPath()
		if got != test.want {
			t.Errorf("got %q expected %q in test %d", got, test.want, i+1)
		}
	}
}
開發者ID:trythings,項目名稱:trythings,代碼行數:12,代碼來源:googleapi_test.go

示例9: Has

// Has searches the trie to check whether there are similar URLs. It will
// return true either the number of children of some node on the lookup
// path is greater than or equal to the threshold, or an exact match is
// found.
func (t *Trie) Has(u *url.URL, threshold func(depth int) int) bool {
	depth := 0
	pnode := &t.root
	segments := strings.Split(u.EscapedPath(), "/")
	// Consider github.com/{user}. If the number of users is equal to
	// threshold, github.com/someone-stored/{repo} should still be enabled.
	for _, seg := range segments[1:] {
		depth++
		if pnode == nil || pnode.child == nil {
			return false
		}
		child, ok := pnode.child[seg]
		if !ok {
			if threshold != nil && len(pnode.child) >= threshold(depth) {
				return true
			}
			return false
		}
		pnode = child
	}

	query := sorted(u.Query())
	if len(query) == 0 {
		return true
	} else if pnode == nil {
		return false
	}
	primary := pnode.query
	qnode := &QueryNode{next: primary}

	for _, kv := range query {
		depth++
		if qnode == nil {
			return false
		} else if primary = qnode.next; primary == nil {
			return false
		}
		secondary := primary[kv.k]
		if secondary == nil {
			return false
		}
		var ok bool
		qnode, ok = secondary[kv.v]
		if !ok {
			if threshold != nil && len(secondary) >= threshold(depth) {
				return true
			}
			return false
		}
	}
	// Totally match
	return true
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:57,代碼來源:urltrie.go

示例10: GetFunc

func (s *SQLStore) GetFunc(u *url.URL, f func(*crawler.URL)) error {
	var w wrapper
	if err := s.DB.QueryRowx(
		`SELECT * FROM url
	    WHERE scheme = $1 AND host = $2 AND path = $3 AND query = $4`,
		u.Scheme, u.Host, u.EscapedPath(), u.Query().Encode(),
	).StructScan(&w); err != nil {
		return err
	}
	f(w.ToURL())
	return nil
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:12,代碼來源:store.go

示例11: getURIPath

func getURIPath(u *url.URL) string {
	var uri string

	if len(u.Opaque) > 0 {
		uri = "/" + strings.Join(strings.Split(u.Opaque, "/")[3:], "/")
	} else {
		uri = u.EscapedPath()
	}

	if len(uri) == 0 {
		uri = "/"
	}

	return uri
}
開發者ID:ClearcodeHQ,項目名稱:Go-Forward,代碼行數:15,代碼來源:uri_path.go

示例12: genPath

func (d *Downloader) genPath(u *url.URL) string {
	pth := u.EscapedPath()
	if strings.HasSuffix(pth, "/") {
		pth += "index.html"
	} else if path.Ext(pth) == "" {
		pth += "/index.html"
	}
	if u.RawQuery != "" {
		pth += "?" + u.Query().Encode()
	}
	return filepath.Join(
		d.Dir,
		u.Host,
		filepath.FromSlash(path.Clean(pth)),
	)
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:16,代碼來源:download.go

示例13: MatchPart

func (p *pattern) MatchPart(u *url.URL, part int) bool {
	us, uh, up := u.String(), u.Host, u.EscapedPath()
	dir, file := path.Split(up)
	f := matchString
	switch part {
	case PartURL:
		return f(us, p.Reject, p.Accept)
	case PartHost:
		return f(uh, p.ExcludeHost, p.Host)
	case PartDir:
		return f(dir, p.ExcludeDir, p.Dir)
	case PartFile:
		return f(file, p.ExcludeFile, p.File)
	}
	return false
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:16,代碼來源:pattern.go

示例14: SBSgetServersByDatacenter

// SBSgetServersByDatacenter returns a list of servers associated with data center @dc.
func (c *Client) SBSgetServersByDatacenter(dc string) (res []string, err error) {
	var u = url.URL{Path: fmt.Sprintf("datacenters/%s/servers", dc)}
	err = c.getSBSResponse("GET", u.EscapedPath(), nil, &res)
	return
}
開發者ID:grrtrr,項目名稱:clcv2,代碼行數:6,代碼來源:sbs.go

示例15: escapeForUrl

func escapeForUrl(q string) string {
	u := url.URL{Path: q}
	return strings.Replace(u.EscapedPath(), "/", "%2f", -1)
}
開發者ID:Debian,項目名稱:dcs,代碼行數:4,代碼來源:serverrendered.go


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