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


Golang URL.Path方法代碼示例

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


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

示例1: moveBucketToHost

// moveBucketToHost moves the bucket name from the URI path to URL host.
func moveBucketToHost(u *url.URL, bucket string) {
	u.Host = bucket + "." + u.Host
	u.Path = strings.Replace(u.Path, "/{Bucket}", "", -1)
	if u.Path == "" {
		u.Path = "/"
	}
}
開發者ID:ColourboxDevelopment,項目名稱:aws-sdk-go,代碼行數:8,代碼來源:host_style_bucket.go

示例2: addTrailingSlash

func addTrailingSlash(u *url.URL) {
	if l := len(u.Path); l > 0 && !strings.HasSuffix(u.Path, "/") {
		u.Path += "/"
	} else if l = len(u.Host); l > 0 && !strings.HasSuffix(u.Host, "/") {
		u.Host += "/"
	}
}
開發者ID:rogpeppe,項目名稱:purell,代碼行數:7,代碼來源:purell.go

示例3: Detect_language

func Detect_language(q string) string {
	var Url *url.URL
	Url, err := url.Parse("https://www.googleapis.com")
	if err != nil {
		fmt.Println(err)
	}

	Url.Path += "/language/translate/v2/detect"
	parameters := url.Values{}
	parameters.Add("q", q)
	parameters.Add("key", Google_key())
	Url.RawQuery = parameters.Encode()

	resp, err := http.Get(Url.String())
	if err != nil {
		fmt.Println(err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)

	var data gtresponse
	json.Unmarshal(body, &data)

	lang := data.Data.Detections[0][0].Language
	return lang
}
開發者ID:jackcook,項目名稱:upptacka,代碼行數:26,代碼來源:translate.go

示例4: removeTrailingSlash

func removeTrailingSlash(u *url.URL) {
	if l := len(u.Path); l > 0 && strings.HasSuffix(u.Path, "/") {
		u.Path = u.Path[:l-1]
	} else if l = len(u.Host); l > 0 && strings.HasSuffix(u.Host, "/") {
		u.Host = u.Host[:l-1]
	}
}
開發者ID:rogpeppe,項目名稱:purell,代碼行數:7,代碼來源:purell.go

示例5: purge

func (c *client) purge(host string, f gfind.File, k int, id int) {
	var Url *url.URL
	Url, err := url.Parse(host)
	chkErr(err)
	Url.Path += "/purge"
	Url.Path += f.Relpath
	var u string
	u = Url.String()
	if security != "" {
		u += "?" + ParseNgxSecurityLink(security, host, f)
	}
	req, err := http.NewRequest("HEAD", u, nil)
	req.Close = true
	if vhost != "client.com" {
		req.Host = vhost
	}
	resp, err := c.c.Do(req)
	chkErr(err)
	if resp.StatusCode == 200 {
		color.Printf("%6v-%-2d @{g}%[email protected]{|} %v %v\n", k, id, "PURGE:SUCCESS", Url.String(), f.Size())
	} else if resp.StatusCode == 404 {
		color.Printf("%6v-%-2d @{y}%[email protected]{|} %v %v\n", k, id, "PURGE:NOFILE", Url.String(), f.Size())
	}

}
開發者ID:kiyor,項目名稱:precache,代碼行數:25,代碼來源:precache.go

示例6: LTMVirtualServerNameList

// LTMVirtualServerNameList show local traffic manager specific virtual server
func LTMVirtualServerNameList(c *gin.Context) {
	lbpair := c.Params.ByName("lbpair")
	vservername := c.Params.ByName("virtual")
	f5url, err := ltm.Loadbalancer(lbpair, conf.Ltmdevicenames)
	if err != nil {
		respondWithStatus(err.Status, vservername, nil, err.Message, conf.Documentation["ltmvirtualdocumentationuri"], c)
		return
	}
	res, virtualservernamelist, err := ltm.ShowLTMVirtualServerName(f5url, vservername)
	if err != nil {
		respondWithStatus(err.Status, vservername, nil, err.Message, conf.Documentation["ltmvirtualdocumentationuri"], c)
		return
	}
	json.Unmarshal([]byte(res.Body), &returnerror)
	u1 := new(url.URL)
	u1.Scheme = common.Protocol
	u1.Path = path.Join(c.Request.Host, c.Request.RequestURI, common.ProfilesURI)
	u2 := new(url.URL)
	u2.Scheme = common.Protocol
	u2.Path = path.Join(c.Request.Host, c.Request.RequestURI, common.FwURI)
	virtualservernamelist.ProfilesReference = u1.String()
	virtualservernamelist.FwRulesReference = u2.String()
	if len(virtualservernamelist.Pool) > 0 {
		u := new(url.URL)
		u.Scheme = common.Protocol
		u.Path = path.Join(c.Request.Host, "/api/ltms/", lbpair, common.PoolsURI, util.ReplaceCommon(virtualservernamelist.Pool))
		virtualservernamelist.PoolsReference = u.String()
	}
	respondWithStatus(res.Status, "", virtualservernamelist, returnerror.ErrorMessage(), conf.Documentation["ltmvirtualdocumentationuri"], c)
}
開發者ID:zalando,項目名稱:baboon-proxy,代碼行數:31,代碼來源:client.go

示例7: CreateAndConnect

// CreateAndConnect connects and creates the requested DB (dropping
// if exists) then returns a new connection to the created DB.
func CreateAndConnect(pgURL url.URL, name string) (*gosql.DB, error) {
	{
		pgURL.Path = ""
		db, err := gosql.Open("postgres", pgURL.String())
		if err != nil {
			return nil, err
		}
		defer db.Close()

		if _, err := db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", name)); err != nil {
			return nil, err
		}

		if _, err := db.Exec(fmt.Sprintf(`CREATE DATABASE %s`, name)); err != nil {
			return nil, err
		}
	}

	pgURL.Path = name

	db, err := gosql.Open("postgres", pgURL.String())
	if err != nil {
		return nil, err
	}
	return db, nil
}
開發者ID:CubeLite,項目名稱:cockroach,代碼行數:28,代碼來源:setup.go

示例8: removeDotSegments

func removeDotSegments(u *url.URL) {
	if len(u.Path) > 0 {
		var dotFree []string
		var lastIsDot bool

		sections := strings.Split(u.Path, "/")
		for _, s := range sections {
			if s == ".." {
				if len(dotFree) > 0 {
					dotFree = dotFree[:len(dotFree)-1]
				}
			} else if s != "." {
				dotFree = append(dotFree, s)
			}
			lastIsDot = (s == "." || s == "..")
		}
		// Special case if host does not end with / and new path does not begin with /
		u.Path = strings.Join(dotFree, "/")
		if !strings.HasSuffix(u.Host, "/") && !strings.HasPrefix(u.Path, "/") {
			u.Path = "/" + u.Path
		}
		// Special case if the last segment was a dot, make sure the path ends with a slash
		if lastIsDot && !strings.HasSuffix(u.Path, "/") {
			u.Path += "/"
		}
	}
}
開發者ID:niltonkummer,項目名稱:purell,代碼行數:27,代碼來源:purell.go

示例9: generateDownloadPlist

func generateDownloadPlist(baseURL *url.URL, ipaPath string, plinfo *plistBundle) ([]byte, error) {
	dp := new(downloadPlist)
	item := new(plItem)
	baseURL.Path = ipaPath
	ipaUrl := baseURL.String()
	item.Assets = append(item.Assets, &plAsset{
		Kind: "software-package",
		URL:  ipaUrl,
	})

	iconFiles := plinfo.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles
	if iconFiles != nil && len(iconFiles) > 0 {
		baseURL.Path = "/-/unzip/" + ipaPath + "/-/**/" + iconFiles[0] + ".png"
		imgUrl := baseURL.String()
		item.Assets = append(item.Assets, &plAsset{
			Kind: "display-image",
			URL:  imgUrl,
		})
	}

	item.Metadata.Kind = "software"

	item.Metadata.BundleIdentifier = plinfo.CFBundleIdentifier
	item.Metadata.BundleVersion = plinfo.CFBundleVersion
	item.Metadata.Title = plinfo.CFBundleName
	if item.Metadata.Title == "" {
		item.Metadata.Title = filepath.Base(ipaUrl)
	}

	dp.Items = append(dp.Items, item)
	data, err := goplist.MarshalIndent(dp, goplist.XMLFormat, "    ")
	return data, err
}
開發者ID:RainYang0925,項目名稱:gohttpserver,代碼行數:33,代碼來源:ipa.go

示例10: NewSpawn

// create a spawn instance
func NewSpawn(sourcehost string, host string) (sp *spawn) {
	sp = &spawn{}
	sp.host = host
	sp.sourcehost = sourcehost

	// target host ( has fleetapi running on it )
	u := url.URL{}
	u.Scheme = "http"
	u.Host = sp.host + ":" + port
	u.Path = api

	sp.api = u

	// source host ( has astralboot + spawn running on it )
	u2 := url.URL{}
	u2.Scheme = "http"
	u2.Host = sp.sourcehost + ":" + sourceport
	u2.Path = sourceapi

	sp.sourceapi = u2
	// create the data maps
	sp.unitText = make(map[string]string)
	sp.units = make(map[string]*Unit)
	return
}
開發者ID:brianredbeard,項目名稱:astralboot,代碼行數:26,代碼來源:spawn.go

示例11: Url

func (req *PubnubRequest) Url(publishKey string, subscribeKey string, secretKey string) string {
	if req.url != "" {
		return req.url
	}

	var Url *url.URL
	if req.ssl {
		Url, _ = url.Parse("https://" + OriginHost)
	} else {
		Url, _ = url.Parse("http://" + OriginHost)
	}

	switch req.operation {
	case "time":
		Url.Path += "/" + req.operation + "/0"
	case "here_now":
		Url.Path += "/v2/presence/sub-key/" + subscribeKey + "/channel/" + req.Channel
	case "publish":
		messageBytes, err := json.Marshal(req.Message)
		if err != nil {
			panic(err)
		}
		Url.Path += "/" + req.operation + "/" + publishKey + "/" + subscribeKey + "/" + secretKey + "/" + req.Channel + "/0/" + string(messageBytes)
	case "subscribe":
		timetoken := "0"
		if req.Timetoken != "" {
			timetoken = req.Timetoken
		}
		Url.Path += "/" + req.operation + "/" + subscribeKey + "/" + req.Channel + "/0/" + timetoken + "?uuid=" + req.UUID
	}

	req.url = Url.String()
	return req.url
}
開發者ID:pfeairheller,項目名稱:gopu,代碼行數:34,代碼來源:pubnub_request.go

示例12: v2AuthURL

func v2AuthURL(ep url.URL, action string, name string) *url.URL {
	if name != "" {
		ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action, name)
		return &ep
	}
	ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action)
	return &ep
}
開發者ID:kjplatz,項目名稱:vic,代碼行數:8,代碼來源:auth_user.go

示例13: pathInHost

func pathInHost(u *url.URL) {
	if u.Host == "" && u.Path != "" {
		u.Host = u.Path
		u.Path = ""
	}
	if u.Host[len(u.Host)-1] == ':' && u.Path != "" {
		u.Host += u.Path
		u.Path = ""
	}
}
開發者ID:fcavani,項目名稱:net,代碼行數:10,代碼來源:url.go

示例14: setPath

/*
setPath builds a JSON url.Path for a given resource type.
*/
func setPath(url *url.URL, resource string) {

	// ensure that path is "/" terminated before concatting resource
	if url.Path != "" && !strings.HasSuffix(url.Path, "/") {
		url.Path = url.Path + "/"
	}

	// don't pluralize resource automagically, JSON API spec is agnostic
	url.Path = fmt.Sprintf("%s%s", url.Path, resource)
}
開發者ID:derekdowling,項目名稱:go-json-spec-handler,代碼行數:13,代碼來源:client.go

示例15: cleanPath

func cleanPath(u *url.URL) {
	hasSlash := strings.HasSuffix(u.Path, "/")

	// clean up path, removing duplicate `/`
	u.Path = path.Clean(u.Path)
	u.RawPath = path.Clean(u.RawPath)

	if hasSlash && !strings.HasSuffix(u.Path, "/") {
		u.Path += "/"
		u.RawPath += "/"
	}
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:12,代碼來源:build.go


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