This is a creation in Article, where the information may have evolved or changed.
Golang Standard library Http/url Values
Today we update the article, the main promotion is the go language, of course, now the hot search is still golang, today we mainly explain the Golang standard library inside the net/url of the bottom of these
[PHP]
Type Values
Func parsequery (query string) (M Values, err Error)
Func (v Values) ADD (key, value string)
Func (v Values) Del (key string)
Func (v Values) Encode () string
Func (v Values) Get (key String) string
Func (v Values) Set (key, value string)
[/php]
Why do we say this, because we use HTTP again. What are the main newrequest for processing? To give a simple example, such as the analog post submission needs stitching URL, below we simply introduce it!
[PHP]
Func parsequery (query string) (M Values, err Error)//passed in a set of strings, returning a map type Values map[string][]string and an incorrect interface
[/php]
What is the method above? What role does it have? In fact, I feel more chicken help, what do you think? Let's look at a simple example
[PHP]
V, err: = URL. Parserequesturi ("http://www.baidu.com/s?wd=%e5%be%ae%e5%ba%a6%e7%bd%91%e7%bb%9c&rsv_spt=1&issp=1& Rsv_bp=0&ie=utf-8&tn=baiduhome_pg&rsv_sug3=2&rsv_sug4=172&rsv_sug1=1 ")
If err! = Nil {
Fmt. PRINTLN (ERR)
}
U: = v.rawquery
Parsequery incoming must be a parameter, that is, the URL inside the rawquery value is the URL? After the path
Fmt. Println (URL. Parsequery (U))
URL here. Query () is parsed directly into map.
Fmt. Println (V.query ())
[/php]
It's worth one here. Type Values map[string][]string Remember types
[PHP]
Func (v Values) ADD (key, value string)
[/php]
Here's our point, we're going to splice the address.
[PHP]
V:=url. values{}//Instantiate the values structure we see that values is a map[string][]string structure, so actually instantiation can
c: = URL. Values{"method": {"Show"}, "id": {"1"}}
Fmt. Println (C.encode ())
[/php]
Of course we're going to introduce the use of add Del Set get
[PHP]
Get
Fmt. Println (C.get ("id"))//parse our URL to get the value of a parameter this is relative to the previous example of parsing
[/php]
Usage of Set
[PHP]
Or the above example Id=1&method=show
C.set ("method", "see")
After the output is Id=1&method=see
[/php]
Del is used to remove a method from the URL
[PHP]
Or the above example Id=1&method=show
C.del ("method")//Incoming key
After the output is id=1
[/php]
Add method, look at the meaning of the literal is to understand that is the addition of parameters
[PHP]
Or the above example Id=1&method=show
C.add ("Nihao", "hello")//Incoming key
After the output is hello=word&id=1
[/php]
This article in detail about the Golang standard library in the Net/url inside the values, if everyone has what do not understand can ask me ~ ~
without permission, may not reprint this site any article: the Micro degree Network»golang language standard library Http/url's values detailed introduction