本文整理汇总了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 = "/"
}
}
示例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 += "/"
}
}
示例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
}
示例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]
}
}
示例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())
}
}
示例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)
}
示例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
}
示例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 += "/"
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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 = ""
}
}
示例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)
}
示例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 += "/"
}
}