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


Golang URL.Scheme方法代码示例

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


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

示例1: NewMPSClient

// NewMPSClient constructs a MPSClient from the provided baseURL and
// TLS config.
// If TLS config is nil, the default configuration is used.
func NewMPSClient(baseURL string, tlsConfig *tls.Config) (*MPSClient, error) {
	u, err := url.Parse(baseURL)
	if err != nil {
		return nil, fmt.Errorf("could not parse url: %v", err)
	}
	t := &http.Transport{TLSClientConfig: tlsConfig}
	client := &http.Client{Transport: t}
	if (u.Scheme != "http") && (u.Scheme != "https") {
		return nil, fmt.Errorf("base url must have scheme 'http' or 'https'")
	}
	if u.Host == "" {
		return nil, fmt.Errorf("no host in url")
	}

	var wsURL url.URL
	wsURL = *u
	wsURL.Scheme = "ws"
	if u.Scheme == "https" {
		wsURL.Scheme = "wss"
	}
	httpProxy := httputil.NewSingleHostReverseProxy(u)
	wsProxy := wsutil.NewSingleHostReverseProxy(&wsURL)

	httpProxy.Transport = t
	wsProxy.TLSClientConfig = t.TLSClientConfig
	return &MPSClient{baseURL, client, httpProxy, wsProxy, t}, nil
}
开发者ID:yhat,项目名称:workload-simulator,代码行数:30,代码来源:mps_client.go

示例2: ParseConnectionString

// ParseConnectionString will parse a string to create a valid connection URL
func ParseConnectionString(path string, ssl bool) (url.URL, error) {
	var host string
	var port int

	h, p, err := net.SplitHostPort(path)
	if err != nil {
		if path == "" {
			host = DefaultHost
		} else {
			host = path
		}
		// If they didn't specify a port, always use the default port
		port = DefaultPort
	} else {
		host = h
		port, err = strconv.Atoi(p)
		if err != nil {
			return url.URL{}, fmt.Errorf("invalid port number %q: %s\n", path, err)
		}
	}

	u := url.URL{
		Scheme: "http",
	}
	if ssl {
		u.Scheme = "https"
	}

	u.Host = net.JoinHostPort(host, strconv.Itoa(port))

	return u, nil
}
开发者ID:skia-dev,项目名称:influxdb,代码行数:33,代码来源:influxdb.go

示例3: parseURL

// parseURL parses the URL. The url.Parse function is not used here because
// url.Parse mangles the path.
func parseURL(s string) (*url.URL, error) {
	// From the RFC:
	//
	// ws-URI = "ws:" "//" host [ ":" port ] path [ "?" query ]
	// wss-URI = "wss:" "//" host [ ":" port ] path [ "?" query ]
	//
	// We don't use the net/url parser here because the dialer interface does
	// not provide a way for applications to work around percent deocding in
	// the net/url parser.

	var u url.URL
	switch {
	case strings.HasPrefix(s, "ws://"):
		u.Scheme = "ws"
		s = s[len("ws://"):]
	case strings.HasPrefix(s, "wss://"):
		u.Scheme = "wss"
		s = s[len("wss://"):]
	default:
		return nil, errMalformedURL
	}

	u.Host = s
	u.Opaque = "/"
	if i := strings.Index(s, "/"); i >= 0 {
		u.Host = s[:i]
		u.Opaque = s[i:]
	}

	return &u, nil
}
开发者ID:Christeefym,项目名称:lantern,代码行数:33,代码来源:client.go

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

示例5: makeHTTPRequest

func (c *Conn) makeHTTPRequest(endpoint string, httpMethod string, userAgent string) (req *http.Request, encReq *HTTPRequest, err error) {
	if req, err = http.NewRequest(httpMethod, "", nil); err != nil {
		return
	}
	url := new(url.URL)
	var host string
	if len(c.domain) > 0 {
		host = c.domain
	} else {
		host, _, _ = net.SplitHostPort(c.RemoteAddr().String())
	}
	url.Host = host
	req.Host = host
	req.Method = httpMethod
	req.Proto = "HTTP/1.1"
	if c.isTls {
		url.Scheme = "https"
	} else {
		url.Scheme = "http"
	}
	url.Path = endpoint
	req.URL = url

	if len(userAgent) <= 0 {
		userAgent = "Mozilla/5.0 zgrab/0.x"
	}

	req.Header.Set("User-Agent", userAgent)
	encReq = new(HTTPRequest)
	encReq.Endpoint = endpoint
	encReq.Method = httpMethod
	encReq.UserAgent = userAgent
	return req, encReq, nil
}
开发者ID:aaspring,项目名称:zgrab,代码行数:34,代码来源:conn.go

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

示例7: rpmURL

func rpmURL(cmd RpmCmd, cs RpmControls) string {
	var u url.URL

	u.Host = cmd.Collector
	u.Path = "agent_listener/invoke_raw_method"

	if cs.UseTLS {
		u.Scheme = "https"
	} else {
		u.Scheme = "http"
	}

	query := url.Values{}
	query.Set("marshal_format", "json")
	query.Set("protocol_version", procotolVersion)
	query.Set("method", cmd.Name)
	query.Set("license_key", cs.License)

	if len(cmd.RunID) > 0 {
		query.Set("run_id", cmd.RunID)
	}

	u.RawQuery = query.Encode()
	return u.String()
}
开发者ID:hooklift,项目名称:terraform,代码行数:25,代码来源:collector.go

示例8: parseURL

// parseURL parses the URL.
//
// This function is a replacement for the standard library url.Parse function.
// In Go 1.4 and earlier, url.Parse loses information from the path.
func parseURL(s string) (*url.URL, error) {
	// From the RFC:
	//
	// ws-URI = "ws:" "//" host [ ":" port ] path [ "?" query ]
	// wss-URI = "wss:" "//" host [ ":" port ] path [ "?" query ]

	var u url.URL
	switch {
	case strings.HasPrefix(s, "ws://"):
		u.Scheme = "ws"
		s = s[len("ws://"):]
	case strings.HasPrefix(s, "wss://"):
		u.Scheme = "wss"
		s = s[len("wss://"):]
	default:
		return nil, errMalformedURL
	}

	u.Host = s
	u.Opaque = "/"
	if i := strings.Index(s, "/"); i >= 0 {
		u.Host = s[:i]
		u.Opaque = s[i:]
	}

	if strings.Contains(u.Host, "@") {
		// Don't bother parsing user information because user information is
		// not allowed in websocket URIs.
		return nil, errMalformedURL
	}

	return &u, nil
}
开发者ID:kesyn,项目名称:kanban,代码行数:37,代码来源:client.go

示例9: normalizeSchemeFromURL

func normalizeSchemeFromURL(target *url.URL, source *url.URL) {
	if target.Scheme == "" {
		if source != nil && source.Scheme != "" && strings.HasPrefix(target.Path, "/") {
			target.Scheme = source.Scheme
		} else if target.Host != "" {
			target.Scheme = "http"
		}
	}
}
开发者ID:mkboudreau,项目名称:sitemap,代码行数:9,代码来源:translator.go

示例10: makeURLAbs

// Combine a URL and Request to make the URL absolute
func makeURLAbs(url *url.URL, request *http.Request) {
	if !url.IsAbs() {
		url.Host = request.Host
		if request.TLS != nil || request.Header.Get("X-Forwarded-Proto") == "https" {
			url.Scheme = "https"
		} else {
			url.Scheme = "http"
		}
	}
}
开发者ID:Ablu,项目名称:drone,代码行数:11,代码来源:provider.go

示例11: makeURLAbs

// Combine a URL and Request to make the URL absolute
func makeURLAbs(url *url.URL, request *http.Request) {
	if !url.IsAbs() {
		url.Host = request.Host
		if strings.HasPrefix(request.Proto, "HTTP/") {
			url.Scheme = "http"
		} else {
			url.Scheme = "https"
		}
	}
}
开发者ID:jacobpgallagher,项目名称:oauth,代码行数:11,代码来源:oauth.go

示例12: ValidateRequest

// Validate that the LTI request was signed with the provided consumer secret.
//
// TODO Implement nonce checking and better timestamp checking.
func (tp *LTIToolProvider) ValidateRequest(consumerSecret string, checkTimestamp, checkNonce bool) (bool, error) {
	var err error

	defer func() {
		if err != nil {
			tp.LTIResponse.LTIErrorMessage = errInvalidRequest.Error()
			tp.LTIResponse.LTIErrorLog = err.Error()
		}
	}()

	// First check OAuth Signature
	req := tp.ltiConsumerRequest

	// Create fully qualified URL
	var requestUrl *url.URL
	if tp.requestProxyPath != "" {
		req.URL.Path = fmt.Sprintf("%s%s", tp.requestProxyPath, req.URL.Path)
	}
	if !req.URL.IsAbs() {
		requestUrl = req.URL
		if tp.requestProxyScheme != "" {
			requestUrl.Scheme = tp.requestProxyScheme
		} else if req.TLS == nil {
			requestUrl.Scheme = "http"
		} else {
			requestUrl.Scheme = "https"
		}
		requestUrl.Host = req.Host
	} else {
		requestUrl = req.URL
	}

	reqStr := hmacsha1.RequestSignatureBaseString(req.Method, requestUrl.String(), req.Form)

	if !hmacsha1.CheckMAC(reqStr, consumerSecret, "", tp.LTIHeaders.OAuthSignature) {
		err = errLogInvalidSignature
		return false, err
	}

	// Second verify that timestamp is withing acceptable range
	if checkTimestamp {
		tstamp := tp.LTIHeaders.OAuthTimestamp

		if !acceptTimestamp(tstamp) {
			err = errLogInvalidTimestamp
			return false, err
		}
	}
	// Third, make sure unique nonce
	if checkNonce {
		// TODO: Nonce verification
	}

	return true, nil
}
开发者ID:goalbook,项目名称:go-lti,代码行数:58,代码来源:tool_provider.go

示例13: replaceSchemeWithWS

func replaceSchemeWithWS(u *url.URL) error {
	switch u.Scheme {
	case "http":
		u.Scheme = "ws"
	case "https":
		u.Scheme = "wss"
	default:
		return fmt.Errorf("invalid scheme in url: %s", u.Scheme)
	}
	return nil
}
开发者ID:GregWilson,项目名称:kite,代码行数:11,代码来源:sockjsclient.go

示例14: New

func New(apikey string, https ...bool) (*API, error) {
	u := url.URL{}
	if https[0] {
		u.Scheme = "https"
	} else {
		u.Scheme = "http"
	}
	u.Host = fmt.Sprintf("%s.api.mailchimp.com", datacenter.FindString(apikey))
	u.Path = "/1.3/"
	return &API{apikey, u.String() + "?method="}, nil
}
开发者ID:WhimDatingApp,项目名称:mailchimp,代码行数:11,代码来源:mailchimp.go

示例15: translateURL

func (e *endpoint) translateURL(r *http.Request) string {
	newURL := url.URL{}
	newURL.Host = e.OriginServers[0].Host
	newURL.Path = r.URL.Path
	newURL.Scheme = "http"
	if e.OriginServers[0].HTTPS {
		newURL.Scheme = "https"
	}

	return newURL.String()
}
开发者ID:gophergala2016,项目名称:zoom_and_enhance,代码行数:11,代码来源:proxy.go


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