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


Golang URL.Fragment方法代码示例

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


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

示例1: GitClone

func GitClone(repo url.URL, destination string) error {
	gitPath, err := exec.LookPath("git")
	if err != nil {
		return err
	}

	branch := repo.Fragment
	repo.Fragment = ""
	gitUrl := repo.String()

	err = performGitClone(gitPath,
		[]string{
			"--depth",
			"1",
			"--recursive",
			gitUrl,
			destination,
		}, branch)

	if err != nil {
		err = performGitClone(gitPath,
			[]string{
				"--recursive",
				gitUrl,
				destination,
			}, branch)

		if err != nil {
			return fmt.Errorf("Failed to clone git repository at %s", gitUrl)
		}
	}

	return nil
}
开发者ID:davidwadden,项目名称:lattice-release,代码行数:34,代码来源:git_buildpack.go

示例2: GetLink

func GetLink(links *bolt.Bucket, stats *het.CountStats, url *url.URL) (het.Link, error) {
	url.Fragment = ""

	lbytes := links.Get([]byte(url.String()))
	link := het.Link{}
	if lbytes != nil {
		// link already exists, return early
		json.Unmarshal(lbytes, &link)

		// follow redirects in the links bucket
		if link.Redirect {
			return GetLink(links, stats, &link.URL)
		}

		return link, nil
	}

	resp, err := http.Get(url.String())
	if err != nil {
		return link, err
	}

	defer resp.Body.Close()

	finalURL := resp.Request.URL
	finalURL.Fragment = ""

	link = het.Link{
		URL:          *finalURL,
		StatusCode:   resp.StatusCode,
		ContentType:  resp.Header.Get("Content-Type"),
		LastModified: strings.Trim(resp.Header.Get("Last-Modified"), " \t\n"),
	}

	lbytes, err = json.Marshal(&link)
	if err != nil {
		log.Fatal(err)
	}

	links.Put([]byte(finalURL.String()), lbytes)
	stats.LinkCount++

	// redirect link
	if finalURL.String() != url.String() {
		lrbytes, err := json.Marshal(&het.Link{
			URL:      *finalURL,
			Redirect: true,
		})

		if err != nil {
			log.Fatal(err)
		}

		links.Put([]byte(url.String()), lrbytes)
		stats.LinkCount++
	}

	return link, nil

}
开发者ID:ziahamza,项目名称:het,代码行数:60,代码来源:crawl.go

示例3: NewResourceLocation

// NewResourceLocation appends a resource id to the end of the requested URL path.
func NewResourceLocation(reqURL *url.URL, id string) string {
	var u url.URL
	u = *reqURL
	u.Path = path.Join(u.Path, id)
	u.RawQuery = ""
	u.Fragment = ""
	return u.String()
}
开发者ID:Tecsisa,项目名称:dex,代码行数:9,代码来源:http.go

示例4: enqueue

func (c *Crawler) enqueue(link *url.URL, base *url.URL) {
	if base != nil {
		link = base.ResolveReference(link)
		link.Fragment = ""
	}

	if link.Path == "" {
		link.Path = "/"
	}

	link.Fragment = ""

	if link.Host != "" {
		link.Host = c.normalize_host(link.Host)
	}

	if c.known.Exists([]byte(link.String())) {
		return
	}

	c.known.Insert([]byte(link.String()))

	c.report_found(link)

	if link.Scheme == "http" {
		if c.domains[link.Host] {
			c.waiter.Add(1)
			c.queue.Enqueue(&task{url: link})
			return
		} else {
			c.report_ignored(link, 0, "external domain")
			return
		}
	} else {
		c.report_ignored(link, 0, "wrong scheme: "+link.Scheme)
		return
	}

	/*c.waiter.Add(1)*/
	/*c.queue <- u.String()*/
}
开发者ID:fd,项目名称:butler-standalone,代码行数:41,代码来源:main.go

示例5: MungeNoProtocolURL

// MungeNoProtocolURL will take a URL returned from net/url.Parse and make
// corrections to the URL when no protocol is specified in the Scheme, where there
// are valid protocol-less git url spec formats that result in either file:// or ssh:// protocol usage;
// if an explicit protocol is already specified, then the
// URL is left unchaged and the method simply returns with no error reported,
// since the URL is
func (h *stiGit) MungeNoProtocolURL(source string, uri *url.URL) error {
	if uri == nil {
		return nil
	}

	// only deal with protocol-less url's
	if uri.Scheme != "" {
		return nil
	}

	details, mods, err := ParseFile(source)
	if err != nil {
		return err
	}

	if details.BadRef {
		return fmt.Errorf("bad reference following # in %s", source)
	}
	if !details.FileExists {
		mods2, err := ParseSSH(source)
		if err != nil {
			glog.Errorf("ssh git clone spec error: %v", err)
			return err
		}
		mods = mods2
	}

	// update the either file or ssh url accordingly
	if mods != nil {
		if len(mods.User) > 0 {
			uri.User = url.User(mods.User)
		}
		if len(mods.Scheme) > 0 {
			uri.Scheme = mods.Scheme
		}
		if len(mods.Host) > 0 {
			uri.Host = mods.Host
		}
		if len(mods.Path) > 0 {
			uri.Path = mods.Path
		}
		if len(mods.Ref) > 0 {
			uri.Fragment = mods.Ref
		}
	}
	return nil
}
开发者ID:abhgupta,项目名称:origin,代码行数:53,代码来源:git.go

示例6: Clean

// Clean returns the sanitized HTML (based on a tag and attribute whitelist) and
// the text contents of s. Links are made relative to u, if non-nil.
func Clean(s string, u *url.URL) (string, string) {
	r := bytes.NewReader([]byte(strings.TrimSpace(s)))
	z := html.NewTokenizer(r)
	buf := &bytes.Buffer{}
	strip := &bytes.Buffer{}
	skip := 0
	if u != nil {
		u.RawQuery = ""
		u.Fragment = ""
	}
	for {
		if z.Next() == html.ErrorToken {
			if err := z.Err(); err == io.EOF {
				break
			} else {
				return s, s
			}
		}

		t := z.Token()
		if t.Type == html.StartTagToken || t.Type == html.SelfClosingTagToken {
			if !AcceptableElements[t.Data] {
				if UnacceptableElementsWithEndTag[t.Data] && t.Type != html.SelfClosingTagToken {
					skip += 1
				}
			} else {
				cleanAttributes(u, &t)
				buf.WriteString(t.String())
			}
		} else if t.Type == html.EndTagToken {
			if !AcceptableElements[t.Data] {
				if UnacceptableElementsWithEndTag[t.Data] {
					skip -= 1
				}
			} else {
				buf.WriteString(t.String())
			}
		} else if skip == 0 {
			buf.WriteString(t.String())
			if t.Type == html.TextToken {
				strip.WriteString(t.String())
			}
		}
	}

	return buf.String(), strip.String()
}
开发者ID:pombredanne,项目名称:htmlclean-1,代码行数:49,代码来源:clean.go

示例7: RepositoryURL

// RepositoryURL creates the public URL for the named git repo. If both config.URL and
// request are nil, the returned URL will be nil.
func RepositoryURL(config *Config, name string, r *http.Request) *url.URL {
	var url url.URL
	switch {
	case config.URL != nil:
		url = *config.URL
	case r != nil:
		url = *r.URL
		url.Host = r.Host
		url.Scheme = "http"
	default:
		return nil
	}
	url.Path = "/" + name
	url.RawQuery = ""
	url.Fragment = ""
	return &url
}
开发者ID:johnmccawley,项目名称:origin,代码行数:19,代码来源:initializer.go

示例8: ensureCanonical

func ensureCanonical(u *url.URL) bool {

	if u.Scheme != "http" && u.Scheme != "https" {
		return false
	}
	// consider https as http to reduce redundancy
	u.Scheme = "http"

	// remove trailing slash to reduce redundancy
	if len(u.Path) != 0 && u.Path[len(u.Path)-1] == '/' {
		u.Path = u.Path[:len(u.Path)-1]
	}

	// clear fragment to reduce redundancy
	u.Fragment = ""

	return true
}
开发者ID:fueledbymarvin,项目名称:gocardless,代码行数:18,代码来源:crawler.go

示例9: GitClone

func GitClone(repo url.URL, destination string) error {
	gitPath, err := exec.LookPath("git")
	if err != nil {
		return err
	}

	branch := repo.Fragment
	repo.Fragment = ""
	gitUrl := repo.String()

	args := []string{
		"clone",
		"-depth",
		"1",
	}

	if branch != "" {
		args = append(args, "-b", branch)
	}

	args = append(args, "--recursive", gitUrl, destination)
	cmd := exec.Command(gitPath, args...)

	err = cmd.Run()

	if err != nil {
		cmd = exec.Command(gitPath, "clone", "--recursive", gitUrl, destination)
		err = cmd.Run()
		if err != nil {
			return fmt.Errorf("Failed to clone git repository at %s", gitUrl)
		}

		if branch != "" {
			cmd = exec.Command(gitPath, "--git-dir="+destination+"/.git", "--work-tree="+destination, "checkout", branch)
			err = cmd.Run()
			if err != nil {
				return fmt.Errorf("Failed to checkout branch '%s' for git repository at %s", branch, gitUrl)
			}
		}
	}

	return nil
}
开发者ID:rajkumargithub,项目名称:lattice,代码行数:43,代码来源:git_buildpack.go

示例10: Normalize

func Normalize(u *url.URL) error {
	if !utf8.ValidString(u.String()) {
		return fmt.Errorf("normalize URL: invalid UTF-8 string: %q", u.String())
	}

	u.Scheme = strings.ToLower(u.Scheme)
	if u.Scheme != "http" && u.Scheme != "https" {
		return fmt.Errorf("normalize URL: unsupported scheme: %v", u.Scheme)
	}
	host, port, err := net.SplitHostPort(u.Host)
	if err != nil { // missing port
		host, port = u.Host, ""
	}
	if host == "" {
		return errors.New("normalize URL: empty host")
	} else if v, err := validateHost(host); err != nil {
		return fmt.Errorf("normalize URL: invalid host %q: %v", host, err)
	} else {
		u.Host = v
	}

	if (u.Scheme == "http" && port == "80") ||
		(u.Scheme == "https" && port == "443") {
		port = ""
	}
	if port != "" {
		u.Host = net.JoinHostPort(u.Host, port)
	}

	clean := func(pth string) string {
		p := path.Clean(pth)
		if p == "." {
			p = ""
		} else if strings.HasSuffix(pth, "/") && !strings.HasSuffix(p, "/") {
			p += "/"
		}
		return p
	}
	u.Path = clean(u.Path)
	u.RawPath = clean(u.RawPath)
	u.Fragment = ""
	return nil
}
开发者ID:fanyang01,项目名称:crawler,代码行数:43,代码来源:normalize.go

示例11: cloneArgs

func cloneArgs(remoteURL *url.URL, root string) []string {
	args := []string{"clone", "--recursive"}
	shallow := len(remoteURL.Fragment) == 0

	if shallow && strings.HasPrefix(remoteURL.Scheme, "http") {
		res, err := http.Head(fmt.Sprintf("%s/info/refs?service=git-upload-pack", remoteURL))
		if err != nil || res.Header.Get("Content-Type") != "application/x-git-upload-pack-advertisement" {
			shallow = false
		}
	}

	if shallow {
		args = append(args, "--depth", "1")
	}

	if remoteURL.Fragment != "" {
		remoteURL.Fragment = ""
	}

	return append(args, remoteURL.String(), root)
}
开发者ID:get3w,项目名称:get3w,代码行数:21,代码来源:git.go

示例12: ReorderAndCrop

//ReorderAndCrop removes the anchor (#sth) Fragment,
//sorts, removes and encodes query string parameters
//and lowercases Host
func ReorderAndCrop(conf *config.ParsingConfig, url *url.URL) {
	url.Path = strings.TrimSuffix(strings.TrimSpace(url.Path), "/")
	if conf.StripQueryString {
		url.RawQuery = ""
	} else {
		stringURL := url.String()
		query := url.Query()
		for _, filter := range conf.Params {
			if filter.Regex.MatchString(stringURL) {
				//If only specified params are relevent
				if filter.Include {
					for key := range query {
						//Check if param is allowed
						found := false
						for _, param := range filter.Params {
							if param == key {
								found = true
							}
						}
						//If not remove
						if !found {
							query.Del(key)
						}
					}
					//If params are irrelevant
				} else {
					for _, param := range filter.Params {
						query.Del(param)
					}
				}
			}
		}
		url.RawQuery = query.Encode()
	}
	url.Fragment = ""
	url.Host = strings.ToLower(url.Host)
	if conf.StripWWW {
		url.Host = StripWWW(url.Host)
	}
}
开发者ID:kivi,项目名称:sitemap-generator,代码行数:43,代码来源:validator.go

示例13: Crawl

func (ca *CrawlerApp) Crawl(rootURL *url.URL, depth int) {
	defer ca.waitGroup.Done()

	if depth <= 0 {
		ca.Errors <- errors.New("Reached max depth")
		return
	}

	rootURL.Fragment = ""

	ca.mutex.Lock()
	if _, found := ca.Visited[rootURL.String()]; found {
		ca.mutex.Unlock()
		return
	} else if !found {
		ca.Visited[rootURL.String()] = true
		ca.mutex.Unlock()
	}

	results, err := ca.Fetch(rootURL.String())
	if err != nil {
		ca.Errors <- err
		return
	}

	ca.PrettyPrint(rootURL, results)

	for internalURLString, _ := range results.internalURLs {
		internalURL, err := url.Parse(internalURLString)
		if err != nil {
			ca.Errors <- err
			return
		}

		ca.waitGroup.Add(1)
		go ca.Crawl(internalURL, depth-1)
	}
}
开发者ID:adrianduke,项目名称:crawler,代码行数:38,代码来源:crawler.go

示例14: links

func (e *Extractor) links(u *url.URL, doc *goquery.Document) ([]*url.URL, error) {
	urls := make([]*url.URL, 0, 5)

	doc.Find("a[href]").Each(func(i int, sel *goquery.Selection) {
		val, _ := sel.Attr("href")
		u, err := u.Parse(val)

		if err != nil {
			e.log.WithError(err).Errorf("Error resolving URL %s", val)
			return
		}

		u.Fragment = ""

		if u.Path != "" && u.Path[len(u.Path)-1:] == "/" {
			u.Path = u.Path[:len(u.Path)-1]
		}

		urls = append(urls, u)
	})

	return urls, nil
}
开发者ID:gophergala2016,项目名称:blogalert,代码行数:23,代码来源:extractor.go

示例15: removeFragment

func removeFragment(u *url.URL) (*url.URL, error) {
	u.Fragment = ""
	return u, nil
}
开发者ID:rajnmithun,项目名称:purell,代码行数:4,代码来源:purell.go


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