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


Golang http.ParseURL函數代碼示例

本文整理匯總了Golang中http.ParseURL函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseURL函數的具體用法?Golang ParseURL怎麽用?Golang ParseURL使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: GetQueue

func GetQueue() (Q *sqs.Queue, err os.Error) {
	proxyURL, err := GetProxyURL()
	if err != nil {
		return
	}
	id, err := GetAWSIdentity()
	if err != nil {
		return
	}
	if queueURL != nil && *queueURL != "" {
		qrl, err := http.ParseURL(*queueURL)
		if err == nil {
			ep := awsconn.NewEndpoint(qrl, proxyURL)
			Q = sqs.NewQueueURL(ep)
		}
	} else if queueName != nil && *queueName != "" {
		ep, err := http.ParseURL(*sqsEndpoint)
		if err == nil {
			log.Printf("Parsed EP url: %v", ep)
			ep := awsconn.NewEndpoint(ep, proxyURL)
			_sqs := sqs.NewService(ep)
			Q, err = _sqs.CreateQueue(id, *queueName, 90)
			if err != nil {
				log.Fatalf("Qerr: [%v]", err)
			}
		}
	} else {
		err = os.NewError("Either Queue(+Endpoint) or QueueURL are required")
	}
	return
}
開發者ID:tkawachi,項目名稱:GoAWS,代碼行數:31,代碼來源:common_flags.go

示例2: NewWaveUrl

func NewWaveUrl(url string) (result *WaveUrl, err os.Error) {
	u, err := http.ParseURL(url)
	if err != nil {
		return nil, err
	}
	if u.Scheme != "wave" {
		return nil, os.NewError("Not a wave url")
	}
	result = &WaveUrl{WaveletDomain: u.Host}

	wave := u.Path[1:]
	i := strings.Index(wave, "/")
	if i == -1 || i == len(wave)-1 {
		return nil, os.NewError("Malformed wave url")
	}
	result.WaveletId = wave[i+1:]
	wave = wave[:i]
	i = strings.Index(wave, "$")
	if i == -1 {
		result.WaveDomain = result.WaveletDomain
		result.WaveId = wave
	} else {
		result.WaveDomain = wave[:i]
		result.WaveId = wave[i+1:]
	}
	// TODO: Check that only allowed characters are used
	return result, nil
}
開發者ID:AaronO,項目名稱:lightwave,代碼行數:28,代碼來源:waveot.go

示例3: Forward

func (self *Federation) Forward(blobref string, users []string) {
	// Determine the servers that have to be informed
	urls := make(map[string]vec.StringVector)
	for _, user := range users {
		if user == self.userID {
			continue
		}
		rawurl, err := self.ns.Lookup(user)
		if err != nil {
			log.Print("Unknown user", err)
			continue
		}
		_, err = http.ParseURL(rawurl)
		if err != nil {
			log.Printf("Malformed URL: %v\n", rawurl)
			continue
		}
		urlList, _ := urls[rawurl]
		urlList.Push(user[strings.Index(user, "@")+1:])
		urls[rawurl] = urlList
	}

	if len(urls) > 0 {
		log.Printf("Forwarding %v to %v\n", blobref, users)
	}

	for url, urlUsers := range urls {
		q := self.getQueue(url)
		q <- queueEntry{urlUsers, blobref}
	}
}
開發者ID:AaronO,項目名稱:lightwave,代碼行數:31,代碼來源:federation.go

示例4: TestGetConnectionMethodWorks

func TestGetConnectionMethodWorks(*testing.T) {
	drv := new(DummyDriver)
	func(d Driver) {
		url, _ := http.ParseURL("foo://[email protected]/testdb")
		_, _ = d.Connect(url)
	}(drv)
}
開發者ID:thomaslee,項目名稱:go-dbi,代碼行數:7,代碼來源:driver_test.go

示例5: NewRequest

func NewRequest(method string, url string, doc IDocument) *http.Request {
	var req http.Request
	req.Method = method
	req.ProtoMajor = 1
	req.ProtoMinor = 1
	req.Close = true
	req.Header = map[string]string{
		"Content-Type":    "application/json",
		"X-Riak-ClientId": "riak.go",
	}
	if doc.VectorClock() != "" {
		req.Header["X-Riak-Vclock"] = doc.VectorClock()
	}
	req.TransferEncoding = []string{"chunked"}
	req.URL, _ = http.ParseURL(url)

	if doc.Json() != "" {
		cb := &ClosingBuffer{bytes.NewBufferString(doc.Json())}
		var rc io.ReadCloser
		rc = cb
		req.Body = rc
	}
	fmt.Println(req.URL)
	return &req
}
開發者ID:c141charlie,項目名稱:riak.go,代碼行數:25,代碼來源:riak.go

示例6: Dial

/*
Dial opens a new client connection to a Web Socket.

A trivial example client:

	package main

	import (
		"websocket"
		"strings"
	)

	func main() {
	 	ws, err := websocket.Dial("ws://localhost/ws", "", "http://localhost/");
	 	if err != nil {
			panic("Dial: " + err.String())
		}
		if _, err := ws.Write([]byte("hello, world!\n")); err != nil {
			panic("Write: " + err.String())
		}
		var msg = make([]byte, 512);
		if n, err := ws.Read(msg); err != nil {
			panic("Read: " + err.String())
		}
		// use msg[0:n]
	}
*/
func Dial(url, protocol, origin string) (ws *Conn, err os.Error) {
	var client net.Conn

	parsedUrl, err := http.ParseURL(url)
	if err != nil {
		goto Error
	}

	switch parsedUrl.Scheme {
	case "ws":
		client, err = net.Dial("tcp", "", parsedUrl.Host)

	case "wss":
		client, err = tls.Dial("tcp", "", parsedUrl.Host)

	default:
		err = ErrBadScheme
	}
	if err != nil {
		goto Error
	}

	ws, err = newClient(parsedUrl.RawPath, parsedUrl.Host, origin, url, protocol, client, handshake)
	if err != nil {
		goto Error
	}
	return

Error:
	return nil, &DialError{url, protocol, origin, err}
}
開發者ID:GNA-SERVICES-INC,項目名稱:MoNGate,代碼行數:58,代碼來源:client.go

示例7: AskRobots

func (w *Worker) AskRobots(url *http.URL) (bool, *FetchResult) {
	robots_url_str := fmt.Sprintf("%s://%s/robots.txt", url.Scheme, url.Host)
	robots_url, err := http.ParseURL(robots_url_str)
	if err != nil {
		return false, ErrorResult(url.Raw, err.String())
	}

	fetch_result := w.Fetch(robots_url)

	if !fetch_result.Success {
		fetch_result.Status = "Robots download error: " + fetch_result.Status
		return false, fetch_result
	}

	var robots *robotstxt.RobotsData
	robots, err = robotstxt.FromResponseBytes(fetch_result.StatusCode, fetch_result.Body, false)
	if err != nil {
		fetch_result.Status = "Robots parse error: " + err.String()
		return false, fetch_result
	}

	robots.DefaultAgent = "HeroshiBot"

	var allow bool
	allow, err = robots.Test(url.RawPath)
	if err != nil {
		return false, ErrorResult(url.Raw, "Robots test error: "+err.String())
	}

	if !allow {
		return allow, ErrorResult(url.Raw, "Robots disallow")
	}

	return allow, nil
}
開發者ID:GunioRobot,項目名稱:heroshi,代碼行數:35,代碼來源:worker.go

示例8: send

// sent a request off to twitter. Returns the response's body or an error.
func send(url, method string, form map[string][]string, client *Client, body string) (result string, err os.Error) {
	req := new(http.Request)
	req.Method = method
	req.RawURL = url
	req.Host = URLHost
	req.Referer = "none"
	req.UserAgent = HTTPUserAgent
	req.Form = form
	req.Header = map[string]string{
		"Connection":    "Keep Alive",
		"Authorization": getAuthHeader(client),
	}
	req.Body = strings.NewReader(body)
	req.URL, err = http.ParseURL(req.RawURL)
	if err != nil {
		return "", err
	}

	// send request
	resp := new(http.Response)
	resp, err = http.Send(req)
	if err != nil {
		return "", err
	}
	result = getResponseBody(resp)
	return result, nil
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:28,代碼來源:twitter.go

示例9: ListQueues

// List all queues available at an endpoint.
func (self *Service) ListQueues(id cryptools.NamedSigner, prefix string) (out []*Queue, err os.Error) {
	sqsReq, err := self.signedRequest(id, "/", map[string]string{
		"Action": "ListQueues",
	})
	if err != nil {
		return
	}
	xresp := &listQueuesResponse{}
	xerr := &errorResponse{}
	err = self.Endpoint.SendParsable(sqsReq, xresp, xerr)
	if err != nil {
		return
	}
	out = make([]*Queue, len(xresp.ListQueuesResult.QueueUrl))
	for i := range xresp.ListQueuesResult.QueueUrl {
		url, err := http.ParseURL(xresp.ListQueuesResult.QueueUrl[i])
		if err != nil {
			break
		}
		ep := awsconn.NewEndpoint(url, self.Endpoint.ProxyURL)
		out[i] = NewQueueURL(ep)
	}
	//log.Printf("ListQueue: %v",  out)
	return
}
開發者ID:tkawachi,項目名稱:GoAWS,代碼行數:26,代碼來源:service.go

示例10: buildTestRequest

func buildTestRequest(method string, path string, body string, headers map[string]string) *Request {
	host := "127.0.0.1"
	port := "80"
	rawurl := "http://" + host + ":" + port + path
	url, _ := http.ParseURL(rawurl)

	proto := "HTTP/1.1"
	useragent := "web.go test framework"

	if headers == nil {
		headers = map[string]string{}
	}

	if method == "POST" {
		headers["Content-Length"] = fmt.Sprintf("%d", len(body))
		headers["Content-Type"] = "text/plain"
	}

	req := Request{Method: method,
		RawURL:    rawurl,
		URL:       url,
		Proto:     proto,
		Host:      host,
		UserAgent: useragent,
		Headers:   headers,
		Body:      bytes.NewBufferString(body),
	}

	return &req
}
開發者ID:iamnafets,項目名稱:web.go,代碼行數:30,代碼來源:web_test.go

示例11: TestURL

func TestURL(t *testing.T) {
	for _, ex := range examples {
		req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(ex.request)))
		if err != nil {
			t.Error(err)
		}

		if len(req.Header) > 1 {
			// Only works on requests without any headers
			// Host header has been removed
			continue
		}

		date := req.Header.Get("Date")

		url, err := http.ParseURL("http://" + req.Host + req.URL.RawPath)
		if err != nil {
			t.Error(err)
		}

		signed, err := URL(url, AWSAccessKeyId, AWSSecretAccessKey, req.Method, date)
		if err != nil {
			t.Error(err)
		}

		// Fudge a bit on this test.  The date should be in Unix timestamp
		// but we can only compare against known signatures for now so use
		// the existing date.

		if auth := addAuth(url.Raw, ex.auth, date); auth != signed.Raw {
			t.Error("Fail URL:", ex.name, "got:", signed.Raw, "want:", auth, "headers:", len(req.Header))
		}
	}
}
開發者ID:streadway,項目名稱:s3sig,代碼行數:34,代碼來源:sign_test.go

示例12: CreateQueue

// Create a queue, returning the Queue object.
func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq *Queue, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "CreateQueue")
	parms.Set("QueueName", name)
	parms.Set("DefaultVisibilityTimeout", strconv.Itoa(dvtimeout))

	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
			if resp.StatusCode == http.StatusOK {
				xmlresp := createQueueResponse{}
				err = xml.Unmarshal(resp.Body, &xmlresp)
				if err == nil {
					var qrl *http.URL
					qrl, err = http.ParseURL(xmlresp.QueueURL)
					if err == nil {
						mq = NewQueue(qrl)
					}
				}
			} else {
				err = os.NewError("Unexpected response")
			}
		}
	}

	return
}
開發者ID:abneptis,項目名稱:GoAWS,代碼行數:32,代碼來源:service.go

示例13: authPut

// Put issues a PUT to the specified URL.
//
// Caller should close r.Body when done reading it.
func authPut(url, user, pwd, client, clientURL, version, agent, bodyType string,
	body io.Reader) (r *http.Response, err os.Error) {
	var req http.Request
	req.Method = "PUT"
	req.Body = body.(io.ReadCloser)
	if user != "" && pwd != "" {
		req.Header = map[string][]string{
			"Content-Type":         {bodyType},
			"Transfer-Encoding":    {"chunked"},
			"User-Agent":           {agent},
			"X-FluidDB-Client":     {client},
			"X-FluidDB-Client-URL": {clientURL},
			"X-FluidDB-Version":    {version},
			"Authorization":        {"Basic " + encodedUsernameAndPassword(user, pwd)},
		}
	} else {
		req.Header = map[string][]string{
			"Content-Type":         {bodyType},
			"Transfer-Encoding":    {"chunked"},
			"User-Agent":           {agent},
			"X-FluidDB-Client":     {client},
			"X-FluidDB-Client-URL": {clientURL},
			"X-FluidDB-Version":    {version},
		}
	}

	req.URL, err = http.ParseURL(url)
	if err != nil {
		return nil, err
	}

	return send(&req)
}
開發者ID:elimisteve,項目名稱:GoFluidDB,代碼行數:36,代碼來源:fluiddb.go

示例14: Get

// Perform a GET request for the test t.
func Get(t *Test) (r *http.Response, finalUrl string, cookies []*http.Cookie, err os.Error) {
	var url = t.Url // <-- Patched

	var req http.Request
	req.Method = "GET"
	req.ProtoMajor = 1
	req.ProtoMinor = 1
	req.Header = http.Header{}

	if len(t.Param) > 0 {
		ep := http.EncodeQuery(t.Param)
		if strings.Contains(url, "?") {
			url = url + "&" + ep
		} else {
			url = url + "?" + ep
		}
	}
	req.URL, err = http.ParseURL(url)
	if err != nil {
		err = &http.URLError{"Get", url, err}
		return
	}

	addHeadersAndCookies(&req, t)
	url = req.URL.String()
	debug("Will get from %s", req.URL.String())
	r, finalUrl, cookies, err = DoAndFollow(&req, t.Dump)
	return
}
開發者ID:vdobler,項目名稱:ft,代碼行數:30,代碼來源:http.go

示例15: ParseURL

func ParseURL(url string) (parsed_url *http.URL) {
	parsed_url, err := http.ParseURL(url)
	if err != nil {
		log.Fatal(err)
	}
	return parsed_url
}
開發者ID:wjlroe,項目名稱:gopher,代碼行數:7,代碼來源:campfire.go


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