mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-10-14 05:54:28 +08:00
新增go和tmux
This commit is contained in:
1043
src/docs/go/net/http.html
Normal file
1043
src/docs/go/net/http.html
Normal file
File diff suppressed because it is too large
Load Diff
44
src/docs/go/net/http/cgi.html
Normal file
44
src/docs/go/net/http/cgi.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package cgi</h1>
|
||||
<p><code>import "net/http/cgi"</code>
|
||||
</p><p align="left">cgi包实现了CGI(Common Gateway Interface,公共网关协议),参见<a href="http://tools.ietf.org/html/rfc3875">RFC 3875</a>。</p>
|
||||
<p align="left">注意使用CGI意味着对每一个请求开始一个新的进程,这显然要比使用长期运行的服务程序要低效。本包主要是为了兼容现有的系统。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="Request">func <a href="https://github.com/golang/go/blob/master/src/net/http/cgi/child.go?name=release#29" title="View Source">Request</a> </h2>
|
||||
<pre class="funcdecl">func Request() (*<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>返回一个当前环境下的HTTP请求。它假设当前程序执行在CGI环境下,成功返回的Request的Body是可读取数据的。(如果必要)</p>
|
||||
<h2 id="RequestFromMap">func <a href="https://github.com/golang/go/blob/master/src/net/http/cgi/child.go?name=release#52" title="View Source">RequestFromMap</a> </h2>
|
||||
<pre class="funcdecl">func RequestFromMap(params map[<a href="builtin.htm#string">string</a>]<a href="builtin.htm#string">string</a>) (*<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>使用CGI变量集params创建一个HTTP请求。返回的Request的Body是没有数据的。</p>
|
||||
<h2 id="Serve">func <a href="https://github.com/golang/go/blob/master/src/net/http/cgi/child.go?name=release#146" title="View Source">Serve</a> </h2>
|
||||
<pre class="funcdecl">func Serve(handler <a href="net/http.htm">http</a>.<a href="net/http.htm#Handler">Handler</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>在当前活跃CGI环境下执行handler;如当前无CGI环境,会返回错误。handler为nil时将使用http.DefaultServeMux。</p>
|
||||
<h2 id="Handler">type <a href="https://github.com/golang/go/blob/master/src/net/http/cgi/host.go?name=release#46" title="View Source">Handler</a> </h2>
|
||||
<pre>type Handler struct {
|
||||
<span id="Handler.Path">Path</span> <a href="builtin.htm#string">string</a> <span class="com">// CGI可执行文件的路径</span>
|
||||
<span id="Handler.Root">Root</span> <a href="builtin.htm#string">string</a> <span class="com">// handler的根URI前缀,""代表"/"</span>
|
||||
<span class="com">// Dir指定CGI程序的工作目录。</span>
|
||||
<span class="com">// 如果Dir为""则使用Path的基目录;如果Path没有基目录则使用当前工作目录。</span>
|
||||
<span id="Handler.Dir">Dir</span> <a href="builtin.htm#string">string</a>
|
||||
<span id="Handler.Env">Env</span> []<a href="builtin.htm#string">string</a> <span class="com">// 额外设置的环境变量(如果有),格式为"key=value"</span>
|
||||
<span id="Handler.InheritEnv">InheritEnv</span> []<a href="builtin.htm#string">string</a> <span class="com">// 从host继承的环境变量,只有"key"</span>
|
||||
<span id="Handler.Logger">Logger</span> *<a href="log.htm">log</a>.<a href="log.htm#Logger">Logger</a> <span class="com">// 可选的logger接口切片,如为nil则使用log.Print</span>
|
||||
<span id="Handler.Args">Args</span> []<a href="builtin.htm#string">string</a> <span class="com">// 可选的传递给子进程的参数</span>
|
||||
<span class="com">// 当CGI进程返回一个Location头,且其值以"/"开始时,</span>
|
||||
<span class="com">// 本字段指定处理内部重定向的根部HTTP Handler。参见RFC 3875 § 6.3.2。</span>
|
||||
<span class="com">// 一般会使用http.DefaultServeMux。</span>
|
||||
<span class="com">// 如果为nil,返回一个本地URI路径的CGI回复会发送给客户端,不进行内部跳转。</span>
|
||||
<span id="Handler.PathLocationHandler">PathLocationHandler</span> <a href="net/http.htm">http</a>.<a href="net/http.htm#Handler">Handler</a>
|
||||
}</pre>
|
||||
<p>Handler在子进程中执行具有一个CGI环境的可执行程序。</p>
|
||||
<h3 id="Handler.ServeHTTP">func (*Handler) <a href="https://github.com/golang/go/blob/master/src/net/http/cgi/host.go?name=release#97" title="View Source">ServeHTTP</a> </h3>
|
||||
<pre class="funcdecl">func (h *<a href="#Handler">Handler</a>) ServeHTTP(rw <a href="net/http.htm">http</a>.<a href="net/http.htm#ResponseWriter">ResponseWriter</a>, req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)</pre>
|
||||
</div>
|
47
src/docs/go/net/http/cookiejar.html
Normal file
47
src/docs/go/net/http/cookiejar.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package cookiejar</h1>
|
||||
<p><code>import "net/http/cookiejar"</code>
|
||||
</p><p>cookiejar包实现了保管在内存中的符合<a href="http://tools.ietf.org/html/rfc6265">RFC 6265标准的</a>http.CookieJar接口。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="PublicSuffixList">type <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#34" title="View Source">PublicSuffixList</a> </h2>
|
||||
<pre>type PublicSuffixList interface {
|
||||
<span class="com">// 返回域名的公共后缀。</span><span class="com"></span>
|
||||
<span class="com">// TODO:域名的格式化应该由调用者还是接口方法负责还没有确定。</span>
|
||||
<span id="PublicSuffixList.PublicSuffix">PublicSuffix</span>(domain <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a>
|
||||
<span class="com">// 返回公共后缀列表的来源的说明,该说明一般应该包含时间戳和版本号。</span><span class="com"></span>
|
||||
<span id="PublicSuffixList.String">String</span>() <a href="builtin.htm#string">string</a>
|
||||
}</pre>
|
||||
<p>PublicSuffixList提供域名的公共后缀。例如:</p>
|
||||
<pre>- "example.com"的公共后缀是"com"
|
||||
- "foo1.foo2.foo3.co.uk"的公共后缀是"co.uk"
|
||||
- "bar.pvt.k12.ma.us"的公共后缀是"pvt.k12.ma.us"</pre>
|
||||
<p>PublicSuffixList接口的实现必须是并发安全的。一个总是返回""的实现是合法的,也可以通过测试;但却是不安全的:它允许HTTP服务端跨域名设置cookie。推荐实现:<a href="http://godoc.org/code.google.com/p/go.net/publicsuffix">code.google.com/p/go.net/publicsuffix</a></p>
|
||||
<h2 id="Options">type <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#49" title="View Source">Options</a> </h2>
|
||||
<pre>type Options struct {
|
||||
<span class="com">// PublicSuffixList是公共后缀列表,用于决定HTTP服务端是否能给某域名设置cookie</span>
|
||||
<span class="com">// nil值合法的,也可以通过测试;但却是不安全的:它允许HTTP服务端跨域名设置cookie</span><span class="com"></span>
|
||||
<span id="Options.PublicSuffixList">PublicSuffixList</span> <a href="#PublicSuffixList">PublicSuffixList</a>
|
||||
}</pre>
|
||||
<p>Options是创建新Jar是的选项。</p>
|
||||
<h2 id="Jar">type <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#60" title="View Source">Jar</a> </h2>
|
||||
<pre>type Jar struct {
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Jar类型实现了net/http包的http.CookieJar接口。</p>
|
||||
<h3 id="New">func <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#77" title="View Source">New</a> </h3>
|
||||
<pre class="funcdecl">func New(o *<a href="#Options">Options</a>) (*<a href="#Jar">Jar</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>返回一个新的Jar,nil指针等价于Options零值的指针。</p>
|
||||
<h3 id="Jar.Cookies">func (*Jar) <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#171" title="View Source">Cookies</a> </h3>
|
||||
<pre class="funcdecl">func (j *<a href="#Jar">Jar</a>) Cookies(u *<a href="net/url.htm">url</a>.<a href="net/url.htm#URL">URL</a>) (cookies []*<a href="net/http.htm">http</a>.<a href="net/http.htm#Cookie">Cookie</a>)</pre>
|
||||
<p>实现CookieJar接口的Cookies方法,如果URL协议不是HTTP/HTTPS会返回空切片。</p>
|
||||
<h3 id="Jar.SetCookies">func (*Jar) <a href="https://github.com/golang/go/blob/master/src/net/http/cookiejar/jar.go?name=release#235" title="View Source">SetCookies</a> </h3>
|
||||
<pre class="funcdecl">func (j *<a href="#Jar">Jar</a>) SetCookies(u *<a href="net/url.htm">url</a>.<a href="net/url.htm#URL">URL</a>, cookies []*<a href="net/http.htm">http</a>.<a href="net/http.htm#Cookie">Cookie</a>)</pre>
|
||||
<p>实现CookieJar接口的SetCookies方法,如果URL协议不是HTTP/HTTPS则不会有实际操作。</p>
|
||||
</div>
|
14
src/docs/go/net/http/fcgi.html
Normal file
14
src/docs/go/net/http/fcgi.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package fcgi</h1>
|
||||
<p><code>import "net/http/fcgi"</code>
|
||||
</p><p align="left">fcgi包实现了FastCGI协议。目前只支持响应器的角色。</p>
|
||||
<p align="left">协议定义的地址:<a href="http://www.fastcgi.com/drupal/node/6?q=node/22">http://www.fastcgi.com/drupal/node/6?q=node/22</a></p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="Serve">func <a href="https://github.com/golang/go/blob/master/src/net/http/fcgi/child.go?name=release#285" title="View Source">Serve</a> </h2>
|
||||
<pre class="funcdecl">func Serve(l <a href="net.htm">net</a>.<a href="net.htm#Listener">Listener</a>, handler <a href="net/http.htm">http</a>.<a href="net/http.htm#Handler">Handler</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Serve接受从监视器l传入的FastCGI连接,为每一个FastCGI连接创建一个新的go程。该go程读取请求然后调用handler回复请求。如果l是nil,Serve将从os.Stdin接受连接。如果handler是nil,将使用http.DefaultServeMux。</p>
|
||||
</div>
|
150
src/docs/go/net/http/httptest.html
Normal file
150
src/docs/go/net/http/httptest.html
Normal file
@@ -0,0 +1,150 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package httptest</h1>
|
||||
<p><code>import "net/http/httptest"</code>
|
||||
</p><p>httptest包提供了HTTP测试的常用函数。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="pkg-constants">Constants </h2>
|
||||
<pre>const <span id="DefaultRemoteAddr">DefaultRemoteAddr</span> = "1.2.3.4"</pre>
|
||||
<p>DefaultRemoteAddr是默认的远端地址。如果ResponseRecorder未显式的设置该属性,RemoteAddr方法就会返回该值。</p>
|
||||
<h2 data-kind="f" id="NewRequest">func <a href="https://github.com/golang/go/blob/master/src//net/http/httptest/httptest.go#L41" title="View Source">NewRequest</a> </h2>
|
||||
|
||||
<p>NewRequest 返回一个新的服务器访问请求,这个请求可以传递给 http.Handler 以便进行测试。</p>
|
||||
<p>target 参数的值为 <a href="http://tools.ietf.org/html/rfc7230">RFC 7230</a> 中提到的“请求目标”(request-target): 它可以是一个路径或者一个绝对 URL。如果 target 是一个绝对 URL,那么 URL 中的主机名(host name)将被使用;否则主机名将为 example.com。</p>
|
||||
<p>当 target 的模式为 https 时,TLS 字段的值将被设置为一个非 nil 的随意值(dummy value)。</p>
|
||||
<p>Request.Proto 总是为 HTTP/1.1。</p>
|
||||
<p>如果 method 参数的值为空, 那么使用 GET 方法作为默认值。</p>
|
||||
<p>body 参数的值可以为 nil;另一方面,如果 body 参数的值为 *bytes.Reader 类型、 *strings.Reader 类型或者 *bytes.Buffer 类型,那么 Request.ContentLength 将被设置。</p>
|
||||
<p>为了使用的方便,NewRequest 将在 panic 可以被接受的情况下,使用 panic 代替错误。</p>
|
||||
<p>如果你想要生成的不是服务器访问请求,而是一个客户端 HTTP 请求,那么请使用 net/http 包中的 NewRequest 函数。</p>
|
||||
<h2 id="ResponseRecorder">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/recorder.go?name=release#15" title="View Source">ResponseRecorder</a> </h2>
|
||||
<pre>type ResponseRecorder struct {
|
||||
<span id="ResponseRecorder.Code">Code</span> <a href="builtin.htm#int">int</a> <span class="com">// HTTP回复的状态码</span>
|
||||
<span id="ResponseRecorder.HeaderMap">HeaderMap</span> <a href="net/http.htm">http</a>.<a href="net/http.htm#Header">Header</a> <span class="com">// HTTP回复的头域</span>
|
||||
<span id="ResponseRecorder.Body">Body</span> *<a href="bytes.htm">bytes</a>.<a href="bytes.htm#Buffer">Buffer</a> <span class="com">// 如非nil,会将Write方法写入的数据写入bytes.Buffer</span>
|
||||
<span id="ResponseRecorder.Flushed">Flushed</span> <a href="builtin.htm#bool">bool</a>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>ResponseRecorder实现了http.ResponseWriter接口,它记录了其修改,用于之后的检查。</p>
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default" id="example-ResponseRecorder">
|
||||
<div class="panel-heading" onclick="document.getElementById('ex-ResponseRecorder').style.display = document.getElementById('ex-ResponseRecorder').style.display=='none'?'block':'none';">Example</div>
|
||||
<div class="panel-collapse collapse" id="ex-ResponseRecorder">
|
||||
<div class="panel-body">
|
||||
<pre>handler := func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "something failed", http.StatusInternalServerError)
|
||||
}
|
||||
req, err := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
handler(w, req)
|
||||
fmt.Printf("%d - %s", w.Code, w.Body.String())</pre>
|
||||
<p>Output:
|
||||
</p><pre>500 - something failed
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h3 id="NewRecorder">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/recorder.go?name=release#25" title="View Source">NewRecorder</a> </h3>
|
||||
<pre class="funcdecl">func NewRecorder() *<a href="#ResponseRecorder">ResponseRecorder</a></pre>
|
||||
<p>NewRecorder返回一个初始化了的ResponseRecorder.</p>
|
||||
<h3 id="ResponseRecorder.Flush">func (*ResponseRecorder) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/recorder.go?name=release#67" title="View Source">Flush</a> </h3>
|
||||
<pre class="funcdecl">func (rw *<a href="#ResponseRecorder">ResponseRecorder</a>) Flush()</pre>
|
||||
<p>Flush将rw.Flushed设置为真。</p>
|
||||
<h3 id="ResponseRecorder.Header">func (*ResponseRecorder) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/recorder.go?name=release#38" title="View Source">Header</a> </h3>
|
||||
<pre class="funcdecl">func (rw *<a href="#ResponseRecorder">ResponseRecorder</a>) Header() <a href="net/http.htm">http</a>.<a href="net/http.htm#Header">Header</a></pre>
|
||||
<p>Header返回回复的头域,即Header字段。</p>
|
||||
<h3 class="" data-kind="m" id="ResponseRecorder.Result">func (*ResponseRecorder) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/recorder.go#L162" title="View Source">Result</a> </h3>
|
||||
|
||||
<p>Result 返回处理器生成的响应。</p>
|
||||
<p>处理器返回的响应至少会对状态码(StatusCode)、首部(Header)、主体(Body)以及可选的 Trailer 进行设置。 因为未来可能会有更多字段被设置,所以用户不应该在测试里面对结果调用 DeepEqual。</p>
|
||||
<p>Response.Header 是写入操作第一次调用时的首部快照(snapshot of the headers); 另一方面, 如果处理器没有执行过写入操作, 那么 Response.Header 就是 Result 方法调用时的首部快照。</p>
|
||||
<p>Response.Body 将被生成为一个非 nil 值,而 Body.Read 则保证不会返回除 io.EOF 之外的其他任何错误。</p>
|
||||
<p>Result 必须在处理器执行完毕之后调用。</p>
|
||||
<h3 id="ResponseRecorder.Write">func (*ResponseRecorder) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/recorder.go?name=release#48" title="View Source">Write</a> </h3>
|
||||
<pre class="funcdecl">func (rw *<a href="#ResponseRecorder">ResponseRecorder</a>) Write(buf []<a href="builtin.htm#byte">byte</a>) (<a href="builtin.htm#int">int</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Write总是成功,如果rw.Body非nil会把数据写入该字段。</p>
|
||||
<h3 id="ResponseRecorder.WriteHeader">func (*ResponseRecorder) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/recorder.go?name=release#59" title="View Source">WriteHeader</a> </h3>
|
||||
<pre class="funcdecl">func (rw *<a href="#ResponseRecorder">ResponseRecorder</a>) WriteHeader(code <a href="builtin.htm#int">int</a>)</pre>
|
||||
<p>WriteHeader设置rw.Code。</p>
|
||||
<h3 data-kind="m" id="ResponseRecorder.WriteString">func (*ResponseRecorder) <a href="https://golang.org/src/net/http/httptest/recorder.go#L107" title="View Source">WriteString</a> </h3>
|
||||
|
||||
<p>在 str 不为 nil 的情况下, WriteString 总会成功地将 buf 中的内容写入到 rw.Body 当中。</p>
|
||||
<h2 id="Server">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#21" title="View Source">Server</a> </h2>
|
||||
<pre>type Server struct {
|
||||
<span id="Server.URL">URL</span> <a href="builtin.htm#string">string</a> <span class="com">// 格式为http://ipaddr:port,没有末尾斜杠的基地址</span>
|
||||
<span id="Server.Listener">Listener</span> <a href="net.htm">net</a>.<a href="net.htm#Listener">Listener</a>
|
||||
<span class="com">// TLS是可选的TLS配置,在TLS开始后会填写为新的配置。</span>
|
||||
<span class="com">// 如果在未启动的Server调用StartTLS方法前设置,已经存在的字段会拷贝进新配置里。</span>
|
||||
<span id="Server.TLS">TLS</span> *<a href="crypto/tls.htm">tls</a>.<a href="crypto/tls.htm#Config">Config</a>
|
||||
<span class="com">// Config可能会在调用Start/StartTLS方法之前调用NewUnstartedServer时被修改。</span>
|
||||
<span id="Server.Config">Config</span> *<a href="net/http.htm">http</a>.<a href="net/http.htm#Server">Server</a>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Server是一个HTTP服务端,在本地环回接口的某个系统选择的端口监听,用于点对点HTTP测试。</p>
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default" id="example-Server">
|
||||
<div class="panel-heading" onclick="document.getElementById('ex-Server').style.display = document.getElementById('ex-Server').style.display=='none'?'block':'none';">Example</div>
|
||||
<div class="panel-collapse collapse" id="ex-Server">
|
||||
<div class="panel-body">
|
||||
<pre>ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "Hello, client")
|
||||
}))
|
||||
defer ts.Close()
|
||||
res, err := http.Get(ts.URL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
greeting, err := ioutil.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%s", greeting)</pre>
|
||||
<p>Output:
|
||||
</p><pre>Hello, client
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h3 id="NewServer">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#82" title="View Source">NewServer</a> </h3>
|
||||
<pre class="funcdecl">func NewServer(handler <a href="net/http.htm">http</a>.<a href="net/http.htm#Handler">Handler</a>) *<a href="#Server">Server</a></pre>
|
||||
<p>NewServer返回一个新的、已启动的Server。调用者必须在用完时调用Close方法关闭它。</p>
|
||||
<h3 id="NewTLSServer">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#158" title="View Source">NewTLSServer</a> </h3>
|
||||
<pre class="funcdecl">func NewTLSServer(handler <a href="net/http.htm">http</a>.<a href="net/http.htm#Handler">Handler</a>) *<a href="#Server">Server</a></pre>
|
||||
<p>NewTLSServer返回一个新的、使用TLS的、已启动的Server。调用者必须在用完时调用Close方法关闭它。</p>
|
||||
<h3 id="NewUnstartedServer">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#94" title="View Source">NewUnstartedServer</a> </h3>
|
||||
<pre class="funcdecl">func NewUnstartedServer(handler <a href="net/http.htm">http</a>.<a href="net/http.htm#Handler">Handler</a>) *<a href="#Server">Server</a></pre>
|
||||
<p>NewUnstartedServer返回一个新的、未启动的Server。在修改其配置后,调用者应该调用Start或StartTLS启动它;调在用完时用者必须调用Close方法关闭它。</p>
|
||||
<h3 id="Server.Start">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#102" title="View Source">Start</a> </h3>
|
||||
<pre class="funcdecl">func (s *<a href="#Server">Server</a>) Start()</pre>
|
||||
<p>Start启动NewUnstartedServer返回的服务端。</p>
|
||||
<h3 id="Server.StartTLS">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#117" title="View Source">StartTLS</a> </h3>
|
||||
<pre class="funcdecl">func (s *<a href="#Server">Server</a>) StartTLS()</pre>
|
||||
<p>StartTLS启动NewUnstartedServer函数返回的服务端的TLS监听。</p>
|
||||
<h3 id="Server.CloseClientConnections">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#177" title="View Source">CloseClientConnections</a> </h3>
|
||||
<pre class="funcdecl">func (s *<a href="#Server">Server</a>) CloseClientConnections()</pre>
|
||||
<p>CloseClientConnections关闭当前任何与该服务端建立的HTTP连接。</p>
|
||||
<h3 id="Server.Close">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/http/httptest/server.go?name=release#166" title="View Source">Close</a> </h3>
|
||||
<pre class="funcdecl">func (s *<a href="#Server">Server</a>) Close()</pre>
|
||||
<p>Close关闭服务端,并阻塞直到所有该服务端未完成的请求都结束为止。</p>
|
||||
</div>
|
190
src/docs/go/net/http/httptrace.html
Normal file
190
src/docs/go/net/http/httptrace.html
Normal file
@@ -0,0 +1,190 @@
|
||||
<div class="container">
|
||||
|
||||
<h1 id="pkg-overview">package httptrace</h1>
|
||||
|
||||
<p><code>import "net/http/httptrace"</code>
|
||||
|
||||
</p><p>
|
||||
Package httptrace provides mechanisms to trace the events within
|
||||
HTTP client requests.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="panel-group">
|
||||
|
||||
<div class="panel panel-default" id="example-package">
|
||||
<div class="panel-heading"><a class="accordion-toggle" data-toggle="collapse" href="#ex-package">Example</a></div>
|
||||
<div class="panel-collapse collapse" id="ex-package"><div class="panel-body">
|
||||
|
||||
<p>Code:<span class="pull-right"><a href="?play=package">play</a> </span>
|
||||
</p><pre>req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||
trace := &httptrace.ClientTrace{
|
||||
GotConn: func(connInfo httptrace.GotConnInfo) {
|
||||
fmt.Printf("Got Conn: %+v\n", connInfo)
|
||||
},
|
||||
DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
|
||||
fmt.Printf("DNS Info: %+v\n", dnsInfo)
|
||||
},
|
||||
}
|
||||
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
|
||||
_, err := http.DefaultTransport.RoundTrip(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
</pre>
|
||||
|
||||
</div></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<p><a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go">trace.go</a> </p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 data-kind="f" id="WithClientTrace">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L33" title="View Source">WithClientTrace</a> </h2>
|
||||
<p>
|
||||
WithClientTrace returns a new context based on the provided parent
|
||||
ctx. HTTP client requests made with the returned context will use
|
||||
the provided trace hooks, in addition to any previous hooks
|
||||
registered with ctx. Any hooks defined in the provided trace will
|
||||
be called first.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 data-kind="t" id="ClientTrace">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L79" title="View Source">ClientTrace</a> </h2>
|
||||
<p>
|
||||
ClientTrace is a set of hooks to run at various stages of an outgoing
|
||||
HTTP request. Any particular hook may be nil. Functions may be
|
||||
called concurrently from different goroutines and some may be called
|
||||
after the request has completed or failed.
|
||||
</p>
|
||||
<p>
|
||||
ClientTrace currently traces a single HTTP request & response
|
||||
during a single round trip and has no hooks that span a series
|
||||
of redirected requests.
|
||||
</p>
|
||||
<p>
|
||||
See <a href="https://blog.golang.org/http-tracing">https://blog.golang.org/http-tracing</a> for more.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 data-kind="f" id="ContextClientTrace">func <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L23" title="View Source">ContextClientTrace</a> </h3>
|
||||
<p>
|
||||
ContextClientTrace returns the ClientTrace associated with the
|
||||
provided context. If none, it returns nil.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 data-kind="t" id="DNSDoneInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L204" title="View Source">DNSDoneInfo</a> </h2>
|
||||
<p>
|
||||
DNSDoneInfo contains information about the results of a DNS lookup.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 data-kind="t" id="DNSStartInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L199" title="View Source">DNSStartInfo</a> </h2>
|
||||
<p>
|
||||
DNSStartInfo contains information about a DNS request.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 data-kind="t" id="GotConnInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L226" title="View Source">GotConnInfo</a> </h2>
|
||||
<p>
|
||||
GotConnInfo is the argument to the ClientTrace.GotConn function and
|
||||
contains information about the obtained connection.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 data-kind="t" id="WroteRequestInfo">type <a href="https://github.com/golang/go/blob/master/src/net/http/httptrace/trace.go#L156" title="View Source">WroteRequestInfo</a> </h2>
|
||||
<p>
|
||||
WroteRequestInfo contains information provided to the WroteRequest
|
||||
hook.
|
||||
</p>
|
||||
|
||||
<div class="clearfix" id="x-footer">
|
||||
<div class="container">
|
||||
<a href="http://studygolang.com/" target="_blank">Go语言中文网</a>
|
||||
<span class="text-muted">|</span> <a href="http://golang.org/" target="_blank">Go Language</a>
|
||||
<span class="pull-right"><a href="#">Back to top</a></span>
|
||||
</div>
|
||||
</div>
|
||||
<script src="../assets/jquery-2.0.3.min.js"></script>
|
||||
<script src="../assets/bootstrap.min.js"></script>
|
||||
<script src="../assets/site.js"></script>
|
||||
|
||||
|
||||
</div>
|
117
src/docs/go/net/http/httputil.html
Normal file
117
src/docs/go/net/http/httputil.html
Normal file
@@ -0,0 +1,117 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package httputil</h1>
|
||||
<p><code>import "net/http/httputil"</code>
|
||||
</p><p>httputil包提供了HTTP公用函数,是对net/http包的更常见函数的补充。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="pkg-variables">Variables </h2>
|
||||
<pre>var (
|
||||
<span id="ErrPersistEOF">ErrPersistEOF</span> = &<a href="net/http.htm">http</a>.<a href="net/http.htm#ProtocolError">ProtocolError</a>{ErrorString: "persistent connection closed"}
|
||||
<span id="ErrClosed">ErrClosed</span> = &<a href="net/http.htm">http</a>.<a href="net/http.htm#ProtocolError">ProtocolError</a>{ErrorString: "connection closed by user"}
|
||||
<span id="ErrPipeline">ErrPipeline</span> = &<a href="net/http.htm">http</a>.<a href="net/http.htm#ProtocolError">ProtocolError</a>{ErrorString: "pipeline error"}
|
||||
)</pre>
|
||||
<pre>var <span id="ErrLineTooLong">ErrLineTooLong</span> = <a href="errors.htm">errors</a>.<a href="errors.htm#New">New</a>("header line too long")</pre>
|
||||
<h2 id="DumpRequest">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/dump.go?name=release#176" title="View Source">DumpRequest</a> </h2>
|
||||
<pre class="funcdecl">func DumpRequest(req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>, body <a href="builtin.htm#bool">bool</a>) (dump []<a href="builtin.htm#byte">byte</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>DumpRequest返回req的和被服务端接收到时一样的有线表示,可选地包括请求的主体,用于debug。本函数在语义上是无操作的,但为了转储请求主体,他会读取主体的数据到内存中,并将req.Body修改为指向内存中的拷贝。req的字段的使用细节请参见http.Request的文档。</p>
|
||||
<h2 id="DumpRequestOut">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/dump.go?name=release#61" title="View Source">DumpRequestOut</a> </h2>
|
||||
<pre class="funcdecl">func DumpRequestOut(req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>, body <a href="builtin.htm#bool">bool</a>) ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>DumpRequestOut类似DumpRequest,但会包括标准http.Transport类型添加的头域,如User-Agent。</p>
|
||||
<h2 id="DumpResponse">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/dump.go?name=release#251" title="View Source">DumpResponse</a> </h2>
|
||||
<pre class="funcdecl">func DumpResponse(resp *<a href="net/http.htm">http</a>.<a href="net/http.htm#Response">Response</a>, body <a href="builtin.htm#bool">bool</a>) (dump []<a href="builtin.htm#byte">byte</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>DumpResponse类似DumpRequest,但转储的是一个回复。</p>
|
||||
<h2 id="NewChunkedReader">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/httputil.go?name=release#17" title="View Source">NewChunkedReader</a> </h2>
|
||||
<pre class="funcdecl">func NewChunkedReader(r <a href="io.htm">io</a>.<a href="io.htm#Reader">Reader</a>) <a href="io.htm">io</a>.<a href="io.htm#Reader">Reader</a></pre>
|
||||
<p align="left">NewChunkedReader返回一个io.Reader。返回值的Read方法会将从r读取的采用HTTP "chunked"传输编码的数据翻译之后返回。当读取到最后的零长chunk时,返回值的Read会返回io.EOF。</p>
|
||||
<p align="left">NewChunkedReader在正常的应用中是不需要的,http包在读取回复主体时会自动将"chunked"编码进行解码。</p>
|
||||
<h2 id="NewChunkedWriter">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/httputil.go?name=release#30" title="View Source">NewChunkedWriter</a> </h2>
|
||||
<pre class="funcdecl">func NewChunkedWriter(w <a href="io.htm">io</a>.<a href="io.htm#Writer">Writer</a>) <a href="io.htm">io</a>.<a href="io.htm#WriteCloser">WriteCloser</a></pre>
|
||||
<p align="left">NewChunkedWriter返回一个io.Writer。返回值的Write方法会将写入的数据编码为HTTP "chunked"传输编码格式后再写入w。其Close方法会将最后的零长chunk写入w,标注数据流的结尾。</p>
|
||||
<p align="left">正常的应用中不需要NewChunkedWriter,http包会在处理器未设置Content-Length头时主动进行chunked编码。在处理器内部使用本函数会导致双重chunked或者有Content-Length头的chunked,两个都是错误的。</p>
|
||||
<h2 id="ClientConn">type <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#229" title="View Source">ClientConn</a> </h2>
|
||||
<pre>type ClientConn struct {
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p align="left">ClientConn类型会在尊重HTTP keepalive逻辑的前提下,在下层的连接上发送请求和接收回复的头域。ClientConn类型支持通过Hijack方法劫持下层连接,取回对下层连接的控制权,按照调用者的预期处理该连接。</p>
|
||||
<p align="left">ClientConn是旧的、低层次的。应用程序应使用net/http包的Client类型和Transport类型代替它。</p>
|
||||
<h3 id="NewClientConn">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#247" title="View Source">NewClientConn</a> </h3>
|
||||
<pre class="funcdecl">func NewClientConn(c <a href="net.htm">net</a>.<a href="net.htm#Conn">Conn</a>, r *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Reader">Reader</a>) *<a href="#ClientConn">ClientConn</a></pre>
|
||||
<p>NewClientConn返回一个对c进行读写的ClientConn。如果r不是nil,它是从c读取时使用的缓冲。</p>
|
||||
<h3 id="NewProxyClientConn">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#264" title="View Source">NewProxyClientConn</a> </h3>
|
||||
<pre class="funcdecl">func NewProxyClientConn(c <a href="net.htm">net</a>.<a href="net.htm#Conn">Conn</a>, r *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Reader">Reader</a>) *<a href="#ClientConn">ClientConn</a></pre>
|
||||
<p>NewProxyClientConn类似NewClientConn,但使用Request.WriteProxy方法将请求写入c。</p>
|
||||
<h3 id="ClientConn.Pending">func (*ClientConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#351" title="View Source">Pending</a> </h3>
|
||||
<pre class="funcdecl">func (cc *<a href="#ClientConn">ClientConn</a>) Pending() <a href="builtin.htm#int">int</a></pre>
|
||||
<p>Pending返回该连接上已发送但还未接收到回复的请求的数量。</p>
|
||||
<h3 id="ClientConn.Write">func (*ClientConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#298" title="View Source">Write</a> </h3>
|
||||
<pre class="funcdecl">func (cc *<a href="#ClientConn">ClientConn</a>) Write(req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>) (err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Write写入一个请求。如果该连接已经在HTTP keepalive逻辑上关闭了(表示该连接不会再发送新的请求)返回ErrPersistEOF。如果req.Close设置为真,keepalive连接会在这次请求后逻辑上关闭,并通知远端的服务器。ErrUnexpectedEOF表示远端关闭了下层的TCP连接,这一般被视为优雅的(正常的)关闭。</p>
|
||||
<h3 id="ClientConn.Read">func (*ClientConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#361" title="View Source">Read</a> </h3>
|
||||
<pre class="funcdecl">func (cc *<a href="#ClientConn">ClientConn</a>) Read(req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>) (resp *<a href="net/http.htm">http</a>.<a href="net/http.htm#Response">Response</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Read读取下一个回复。合法的回复可能会和ErrPersistEOF一起返回,这表示远端要求该请求是最后一个被服务的请求。Read可以和Write同时调用,但不能和另一个Read同时调用。</p>
|
||||
<h3 id="ClientConn.Do">func (*ClientConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#423" title="View Source">Do</a> </h3>
|
||||
<pre class="funcdecl">func (cc *<a href="#ClientConn">ClientConn</a>) Do(req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>) (resp *<a href="net/http.htm">http</a>.<a href="net/http.htm#Response">Response</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Do是一个便利方法,它会写入一个请求,并读取一个回复。(能不能保证二者对应?不知道)</p>
|
||||
<h3 id="ClientConn.Hijack">func (*ClientConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#274" title="View Source">Hijack</a> </h3>
|
||||
<pre class="funcdecl">func (cc *<a href="#ClientConn">ClientConn</a>) Hijack() (c <a href="net.htm">net</a>.<a href="net.htm#Conn">Conn</a>, r *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Reader">Reader</a>)</pre>
|
||||
<p>Hijack拆开ClientConn返回下层的连接和读取侧的缓冲,其中可能有部分剩余的数据。Hijack可以在调用者自身或者其Read方法发出keepalive逻辑的终止信号之前调用。调用者不应在Write或Read执行过程中调用Hijack。</p>
|
||||
<h3 id="ClientConn.Close">func (*ClientConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#285" title="View Source">Close</a> </h3>
|
||||
<pre class="funcdecl">func (cc *<a href="#ClientConn">ClientConn</a>) Close() <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Close调用Hijack,然后关闭下层的连接。</p>
|
||||
<h2 id="ServerConn">type <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#36" title="View Source">ServerConn</a> </h2>
|
||||
<pre>type ServerConn struct {
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p align="left">ServerConn类型在下层的连接上接收请求和发送回复,直到HTTP keepalive逻辑结束。ServerConn类型支持通过Hijack方法劫持下层连接,取回对下层连接的控制权,按照调用者的预期处理该连接。ServerConn支持管道内套,例如,请求可以不和回复的发送同步的读取(但仍按照相同的顺序)。</p>
|
||||
<p align="left">ServerConn是旧的、低层次的。应用程序应使用net/http包的Server类型代替它。</p>
|
||||
<h3 id="NewServerConn">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#53" title="View Source">NewServerConn</a> </h3>
|
||||
<pre class="funcdecl">func NewServerConn(c <a href="net.htm">net</a>.<a href="net.htm#Conn">Conn</a>, r *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Reader">Reader</a>) *<a href="#ServerConn">ServerConn</a></pre>
|
||||
<p>NewServerConn返回一个新的从c读写的ServerConn。如果r补位nil,它将作为从c读取时的缓冲。</p>
|
||||
<h3 id="ServerConn.Pending">func (*ServerConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#163" title="View Source">Pending</a> </h3>
|
||||
<pre class="funcdecl">func (sc *<a href="#ServerConn">ServerConn</a>) Pending() <a href="builtin.htm#int">int</a></pre>
|
||||
<p>Pending返回该连接上已接收到但还未回复的请求的数量。</p>
|
||||
<h3 id="ServerConn.Read">func (*ServerConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#87" title="View Source">Read</a> </h3>
|
||||
<pre class="funcdecl">func (sc *<a href="#ServerConn">ServerConn</a>) Read() (req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Read读取下一个请求。如果它优雅的决定不会再有更多的请求(例如,在HTTP/1.0连接的第一个请求之后,或者HTTP/1.1的一个具有" Connection:close "头的请求之后),会返回ErrPersistEOF。</p>
|
||||
<h3 id="ServerConn.Write">func (*ServerConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#172" title="View Source">Write</a> </h3>
|
||||
<pre class="funcdecl">func (sc *<a href="#ServerConn">ServerConn</a>) Write(req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>, resp *<a href="net/http.htm">http</a>.<a href="net/http.htm#Response">Response</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Write写入req的回复resp。如要优雅的关闭该连接,可以设置resp.Close字段为真。Write方法应该尽量执行(以回复尽量多的请求),直到Write本身返回错误,而不应考虑读取侧返回的任何错误。</p>
|
||||
<h3 id="ServerConn.Hijack">func (*ServerConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#64" title="View Source">Hijack</a> </h3>
|
||||
<pre class="funcdecl">func (sc *<a href="#ServerConn">ServerConn</a>) Hijack() (c <a href="net.htm">net</a>.<a href="net.htm#Conn">Conn</a>, r *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Reader">Reader</a>)</pre>
|
||||
<p>Hijack拆开ServerConn返回下层的连接和读取侧的缓冲,其中可能有部分剩余的数据。Hijack可以在调用者自身或者其Read方法发出keepalive逻辑的终止信号之前调用。调用者不应在Write或Read执行过程中调用Hijack。</p>
|
||||
<h3 id="ServerConn.Close">func (*ServerConn) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/persist.go?name=release#75" title="View Source">Close</a> </h3>
|
||||
<pre class="funcdecl">func (sc *<a href="#ServerConn">ServerConn</a>) Close() <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Close调用Hijack,然后关闭下层的连接。</p>
|
||||
<h2 id="ReverseProxy">type <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go?name=release#27" title="View Source">ReverseProxy</a> </h2>
|
||||
<pre>type ReverseProxy struct {
|
||||
<span class="com">// Director必须是将请求修改为新的请求的函数。</span>
|
||||
<span class="com">// 修改后的请求会使用Transport发送,得到的回复会不经修改的返回给客户端。</span>
|
||||
<span id="ReverseProxy.Director">Director</span> func(*<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)
|
||||
<span class="com">// Transport用于执行代理请求。</span>
|
||||
<span class="com">// 如果本字段为nil,会使用http.DefaultTransport。</span>
|
||||
<span id="ReverseProxy.Transport">Transport</span> <a href="net/http.htm">http</a>.<a href="net/http.htm#RoundTripper">RoundTripper</a>
|
||||
<span class="com">// FlushInterval指定拷贝回复的主体时将数据刷新给客户端的时间间隔。</span>
|
||||
<span class="com">// 如果本字段为零值,不会进行周期的刷新。(拷贝完回复主体后再刷新)</span>
|
||||
<span id="ReverseProxy.FlushInterval">FlushInterval</span> <a href="time.htm">time</a>.<a href="time.htm#Duration">Duration</a>
|
||||
}</pre>
|
||||
<p>ReverseProxy是一个HTTP处理器,它接收一个请求,发送给另一个服务端,将回复转发给客户端。</p>
|
||||
<h3 id="NewSingleHostReverseProxy">func <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go?name=release#61" title="View Source">NewSingleHostReverseProxy</a> </h3>
|
||||
<pre class="funcdecl">func NewSingleHostReverseProxy(target *<a href="net/url.htm">url</a>.<a href="net/url.htm#URL">URL</a>) *<a href="#ReverseProxy">ReverseProxy</a></pre>
|
||||
<p align="left">NewSingleHostReverseProxy返回一个新的ReverseProxy。返回值会将请求的URL重写为target参数提供的协议、主机和基路径。如果target参数的Path字段为"/base",接收到的请求的URL.Path为"/dir",修改后的请求的URL.Path将会是"/base/dir"。</p>
|
||||
<h3 id="ReverseProxy.ServeHTTP">func (*ReverseProxy) <a href="https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go?name=release#97" title="View Source">ServeHTTP</a> </h3>
|
||||
<pre class="funcdecl">func (p *<a href="#ReverseProxy">ReverseProxy</a>) ServeHTTP(rw <a href="net/http.htm">http</a>.<a href="net/http.htm#ResponseWriter">ResponseWriter</a>, req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)</pre>
|
||||
</div>
|
49
src/docs/go/net/http/pprof.html
Normal file
49
src/docs/go/net/http/pprof.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package pprof</h1>
|
||||
<p><code>import "net/http/pprof"</code>
|
||||
</p><p align="left">pprof包通过它的HTTP服务端提供pprof可视化工具期望格式的运行时剖面文件数据服务。关于pprof的更多信息,参见<a href="http://code.google.com/p/google-perftools/">http://code.google.com/p/google-perftools/</a>。</p>
|
||||
<p align="left">本包一般只需导入获取其注册HTTP处理器的副作用。处理器的路径以/debug/pprof/开始。</p>
|
||||
<p align="left">要使用pprof,在你的程序里导入本包:</p>
|
||||
<pre>import _ "net/http/pprof"
|
||||
</pre>
|
||||
<p>如果你的应用还没有运行http服务器,你需要开始一个http服务器。添加"net/http"包和"log"包到你的导入列表,然后在main函数开始处添加如下代码:</p>
|
||||
<pre>go func() {
|
||||
log.Println(http.ListenAndServe("localhost:6060", nil))
|
||||
}()
|
||||
</pre>
|
||||
<p>然后使用pprof工具查看堆剖面:</p>
|
||||
<pre>go tool pprof <a href="http://localhost:6060/debug/pprof/heap">http://localhost:6060/debug/pprof/heap</a>
|
||||
</pre>
|
||||
<p>或查看周期30秒的CPU剖面:</p>
|
||||
<pre>go tool pprof <a href="http://localhost:6060/debug/pprof/profile">http://localhost:6060/debug/pprof/profile</a>
|
||||
</pre>
|
||||
<p>或查看go程阻塞剖面:</p>
|
||||
<pre>go tool pprof <a href="http://localhost:6060/debug/pprof/block">http://localhost:6060/debug/pprof/block</a>
|
||||
</pre>
|
||||
<p>要查看所有可用的剖面,在你的浏览器阅读<a href="http://localhost:6060/debug/pprof/">http://localhost:6060/debug/pprof/</a>。要学习这些运转的设施,访问:</p>
|
||||
<pre><a href="http://blog.golang.org/2011/06/profiling-go-programs.html">http://blog.golang.org/2011/06/profiling-go-programs.html</a></pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="Handler">func <a href="https://github.com/golang/go/blob/master/src/net/http/pprof/pprof.go?name=release#150" title="View Source">Handler</a> </h2>
|
||||
<pre class="funcdecl">func Handler(name <a href="builtin.htm#string">string</a>) <a href="net/http.htm">http</a>.<a href="net/http.htm#Handler">Handler</a></pre>
|
||||
<p>Handler返回一个提供name指定的剖面文件的服务的HTTP处理器。</p>
|
||||
<h2 id="Cmdline">func <a href="https://github.com/golang/go/blob/master/src/net/http/pprof/pprof.go?name=release#72" title="View Source">Cmdline</a> </h2>
|
||||
<pre class="funcdecl">func Cmdline(w <a href="net/http.htm">http</a>.<a href="net/http.htm#ResponseWriter">ResponseWriter</a>, r *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)</pre>
|
||||
<p>Cmdline回应执行中程序的命令行,采用NUL字节分隔的参数。本包将它注册在/debug/pprof/cmdline。</p>
|
||||
<h2 id="Index">func <a href="https://github.com/golang/go/blob/master/src/net/http/pprof/pprof.go?name=release#173" title="View Source">Index</a> </h2>
|
||||
<pre class="funcdecl">func Index(w <a href="net/http.htm">http</a>.<a href="net/http.htm#ResponseWriter">ResponseWriter</a>, r *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)</pre>
|
||||
<p>Index回复请求要求的pprof格式的剖面。例如,"/debug/pprof/heap"会回复"heap"剖面。Index会回复"/debug/pprof/" 请求一个列出所有可用的剖面的HTML页面。</p>
|
||||
<h2 id="Profile">func <a href="https://github.com/golang/go/blob/master/src/net/http/pprof/pprof.go?name=release#79" title="View Source">Profile</a> </h2>
|
||||
<pre class="funcdecl">func Profile(w <a href="net/http.htm">http</a>.<a href="net/http.htm#ResponseWriter">ResponseWriter</a>, r *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)</pre>
|
||||
<p>Profile回复pprof格式的CPU剖面。本包将它注册在/debug/pprof/profile。</p>
|
||||
<h2 id="Symbol">func <a href="https://github.com/golang/go/blob/master/src/net/http/pprof/pprof.go?name=release#104" title="View Source">Symbol</a> </h2>
|
||||
<pre class="funcdecl">func Symbol(w <a href="net/http.htm">http</a>.<a href="net/http.htm#ResponseWriter">ResponseWriter</a>, r *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)</pre>
|
||||
<p>Symbol查看请求中列出的程序计数器,回复一个映射程序计数器到函数名的表格。本包将它注册在/debug/pprof/symbol。</p>
|
||||
</div>
|
60
src/docs/go/net/mail.html
Normal file
60
src/docs/go/net/mail.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package mail</h1>
|
||||
<p><code>import "net/mail"</code>
|
||||
</p><p align="left">mail包实现了邮件的解析。</p>
|
||||
<p align="left">本包大部分都遵守<a href="http://tools.ietf.org/html/rfc5322">RFC 5322</a>规定的语法,值得注意的区别是:</p>
|
||||
<pre>* 旧格式地址和嵌入远端信息的地址不会被解析
|
||||
* 组地址不会被解析
|
||||
* 不支持全部的间隔符(CFWS语法元素),如分属两行的地址</pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="pkg-variables">Variables </h2>
|
||||
<pre>var <span id="ErrHeaderNotPresent">ErrHeaderNotPresent</span> = <a href="errors.htm">errors</a>.<a href="errors.htm#New">New</a>("mail: header not in message")</pre>
|
||||
<h2 id="Address">type <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#136" title="View Source">Address</a> </h2>
|
||||
<pre>type Address struct {
|
||||
<span id="Address.Name">Name</span> <a href="builtin.htm#string">string</a> <span class="com">// 固有名,可以为空</span>
|
||||
<span id="Address.Address">Address</span> <a href="builtin.htm#string">string</a> <span class="com">// user@domain</span>
|
||||
}</pre>
|
||||
<p align="left">Address类型表示一个邮箱地址。</p>
|
||||
<p align="left">例如地址"Barry Gibbs <bg@example.com>"表示为Address{Name: "Barry Gibbs", Address: "bg@example.com"}</p>
|
||||
<h3 id="ParseAddress">func <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#142" title="View Source">ParseAddress</a> </h3>
|
||||
<pre class="funcdecl">func ParseAddress(address <a href="builtin.htm#string">string</a>) (*<a href="#Address">Address</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>解析单个的<a href="http://tools.ietf.org/html/rfc5322">RFC 5322</a>地址,例如"Barry Gibbs <bg@example.com>"。</p>
|
||||
<h3 id="Address.String">func (*Address) <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#154" title="View Source">String</a> </h3>
|
||||
<pre class="funcdecl">func (a *<a href="#Address">Address</a>) String() <a href="builtin.htm#string">string</a></pre>
|
||||
<p>将a代表的地址表示为合法的<a href="http://tools.ietf.org/html/rfc5322">RFC 5322</a>地址字符串。如果Name字段包含非ASCII字符将根据<a href="http://tools.ietf.org/html/rfc2047">RFC 2047</a>转义。</p>
|
||||
<h2 id="ParseAddressList">func <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#147" title="View Source">ParseAddressList</a> </h2>
|
||||
<pre class="funcdecl">func ParseAddressList(list <a href="builtin.htm#string">string</a>) ([]*<a href="#Address">Address</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>函数将list作为一串邮箱地址并解析返回。</p>
|
||||
<h2 id="Header">type <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#105" title="View Source">Header</a> </h2>
|
||||
<pre>type Header map[<a href="builtin.htm#string">string</a>][]<a href="builtin.htm#string">string</a></pre>
|
||||
<p>Header代表邮件头域的多个键值对。</p>
|
||||
<h3 id="Header.AddressList">func (Header) <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#125" title="View Source">AddressList</a> </h3>
|
||||
<pre class="funcdecl">func (h <a href="#Header">Header</a>) AddressList(key <a href="builtin.htm#string">string</a>) ([]*<a href="#Address">Address</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>将键key对应的值(字符串)作为邮箱地址列表解析并返回。</p>
|
||||
<h3 id="Header.Date">func (Header) <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#116" title="View Source">Date</a> </h3>
|
||||
<pre class="funcdecl">func (h <a href="#Header">Header</a>) Date() (<a href="time.htm">time</a>.<a href="time.htm#Time">Time</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>解析头域Date项的值并返回。</p>
|
||||
<h3 id="Header.Get">func (Header) <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#109" title="View Source">Get</a> </h3>
|
||||
<pre class="funcdecl">func (h <a href="#Header">Header</a>) Get(key <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
|
||||
<p>返回键key对应的第一个值,如果没有对应值,将返回空字符串。</p>
|
||||
<h2 id="Message">type <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#44" title="View Source">Message</a> </h2>
|
||||
<pre>type Message struct {
|
||||
<span id="Message.Header">Header</span> <a href="#Header">Header</a>
|
||||
<span id="Message.Body">Body</span> <a href="io.htm">io</a>.<a href="io.htm#Reader">Reader</a>
|
||||
}</pre>
|
||||
<p>Message代表一个解析后的邮件。</p>
|
||||
<h3 id="ReadMessage">func <a href="https://github.com/golang/go/blob/master/src/net/mail/message.go?name=release#52" title="View Source">ReadMessage</a> </h3>
|
||||
<pre class="funcdecl">func ReadMessage(r <a href="io.htm">io</a>.<a href="io.htm#Reader">Reader</a>) (msg *<a href="#Message">Message</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>从r读取一个邮件,会解析邮件头域,消息主体可以从r/msg.Body中读取。</p>
|
||||
</div>
|
245
src/docs/go/net/rpc.html
Normal file
245
src/docs/go/net/rpc.html
Normal file
@@ -0,0 +1,245 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package rpc</h1>
|
||||
<p><code>import "net/rpc"</code>
|
||||
</p><p align="left">rpc包提供了通过网络或其他I/O连接对一个对象的导出方法的访问。服务端注册一个对象,使它作为一个服务被暴露,服务的名字是该对象的类型名。注册之后,对象的导出方法就可以被远程访问。服务端可以注册多个不同类型的对象(服务),但注册具有相同类型的多个对象是错误的。</p>
|
||||
<p align="left">只有满足如下标准的方法才能用于远程访问,其余方法会被忽略:</p>
|
||||
<pre>- 方法是导出的
|
||||
- 方法有两个参数,都是导出类型或内建类型
|
||||
- 方法的第二个参数是指针
|
||||
- 方法只有一个error接口类型的返回值</pre>
|
||||
<p>事实上,方法必须看起来像这样:</p>
|
||||
<pre>func (t *T) MethodName(argType T1, replyType *T2) error
|
||||
</pre>
|
||||
<p align="left">其中T、T1和T2都能被encoding/gob包序列化。这些限制即使使用不同的编解码器也适用。(未来,对定制的编解码器可能会使用较宽松一点的限制)</p>
|
||||
<p align="left">方法的第一个参数代表调用者提供的参数;第二个参数代表返回给调用者的参数。方法的返回值,如果非nil,将被作为字符串回传,在客户端看来就和errors.New创建的一样。如果返回了错误,回复的参数将不会被发送给客户端。</p>
|
||||
<p align="left">服务端可能会单个连接上调用ServeConn管理请求。更典型地,它会创建一个网络监听器然后调用Accept;或者,对于HTTP监听器,调用HandleHTTP和http.Serve。</p>
|
||||
<p align="left">想要使用服务的客户端会创建一个连接,然后用该连接调用NewClient。</p>
|
||||
<p align="left">更方便的函数Dial(DialHTTP)会在一个原始的连接(或HTTP连接)上依次执行这两个步骤。</p>
|
||||
<p align="left">生成的Client类型值有两个方法,Call和Go,它们的参数为要调用的服务和方法、一个包含参数的指针、一个用于接收接个的指针。</p>
|
||||
<p align="left">Call方法会等待远端调用完成,而Go方法异步的发送调用请求并使用返回的Call结构体类型的Done通道字段传递完成信号。</p>
|
||||
<p align="left">除非设置了显式的编解码器,本包默认使用<a href="http://godoc.org/encoding/gob">encoding/gob</a>包来传输数据。</p>
|
||||
<p align="left">这是一个简单的例子。一个服务端想要导出Arith类型的一个对象:</p>
|
||||
<pre>package server
|
||||
type Args struct {
|
||||
A, B int
|
||||
}
|
||||
type Quotient struct {
|
||||
Quo, Rem int
|
||||
}
|
||||
type Arith int
|
||||
func (t *Arith) Multiply(args *Args, reply *int) error {
|
||||
*reply = args.A * args.B
|
||||
return nil
|
||||
}
|
||||
func (t *Arith) Divide(args *Args, quo *Quotient) error {
|
||||
if args.B == 0 {
|
||||
return errors.New("divide by zero")
|
||||
}
|
||||
quo.Quo = args.A / args.B
|
||||
quo.Rem = args.A % args.B
|
||||
return nil
|
||||
}
|
||||
</pre>
|
||||
<p>服务端会调用(用于HTTP服务):</p>
|
||||
<pre>arith := new(Arith)
|
||||
rpc.Register(arith)
|
||||
rpc.HandleHTTP()
|
||||
l, e := net.Listen("tcp", ":1234")
|
||||
if e != nil {
|
||||
log.Fatal("listen error:", e)
|
||||
}
|
||||
go http.Serve(l, nil)
|
||||
</pre>
|
||||
<p>此时,客户端可看到服务"Arith"及它的方法"Arith.Multiply"、"Arith.Divide"。要调用方法,客户端首先呼叫服务端:</p>
|
||||
<pre>client, err := rpc.DialHTTP("tcp", serverAddress + ":1234")
|
||||
if err != nil {
|
||||
log.Fatal("dialing:", err)
|
||||
}
|
||||
</pre>
|
||||
<p>然后,客户端可以执行远程调用:</p>
|
||||
<pre>// Synchronous call
|
||||
args := &server.Args{7,8}
|
||||
var reply int
|
||||
err = client.Call("Arith.Multiply", args, &reply)
|
||||
if err != nil {
|
||||
log.Fatal("arith error:", err)
|
||||
}
|
||||
fmt.Printf("Arith: %d*%d=%d", args.A, args.B, reply)
|
||||
</pre>
|
||||
<p>或:</p>
|
||||
<pre>// Asynchronous call
|
||||
quotient := new(Quotient)
|
||||
divCall := client.Go("Arith.Divide", args, quotient, nil)
|
||||
replyCall := <-divCall.Done // will be equal to divCall
|
||||
// check errors, print, etc.
|
||||
</pre>
|
||||
<p>服务端的实现应为客户端提供简单、类型安全的包装。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="pkg-constants">Constants </h2>
|
||||
<pre>const (
|
||||
<span class="com">// HandleHTTP使用的默认值</span>
|
||||
<span id="DefaultRPCPath">DefaultRPCPath</span> = "/_goRPC_"
|
||||
<span id="DefaultDebugPath">DefaultDebugPath</span> = "/debug/rpc"
|
||||
)</pre>
|
||||
<h2 id="pkg-variables">Variables </h2>
|
||||
<pre>var <span id="DefaultServer">DefaultServer</span> = <a href="#NewServer">NewServer</a>()</pre>
|
||||
<p>DefaultServer是*Server的默认实例,本包和Server方法同名的函数都是对其方法的封装。</p>
|
||||
<pre>var <span id="ErrShutdown">ErrShutdown</span> = <a href="errors.htm">errors</a>.<a href="errors.htm#New">New</a>("connection is shut down")</pre>
|
||||
<h2 id="ServerError">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#20" title="View Source">ServerError</a> </h2>
|
||||
<pre>type ServerError <a href="builtin.htm#string">string</a></pre>
|
||||
<p>ServerError represents an error that has been returned from
|
||||
the remote side of the RPC connection.</p>
|
||||
<h3 id="ServerError.Error">func (ServerError) <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#22" title="View Source">Error</a> </h3>
|
||||
<pre class="funcdecl">func (e <a href="#ServerError">ServerError</a>) Error() <a href="builtin.htm#string">string</a></pre>
|
||||
<h2 id="Request">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#167" title="View Source">Request</a> </h2>
|
||||
<pre>type Request struct {
|
||||
<span id="Request.ServiceMethod">ServiceMethod</span> <a href="builtin.htm#string">string</a> <span class="com">// 格式:"Service.Method"</span>
|
||||
<span id="Request.Seq">Seq</span> <a href="builtin.htm#uint64">uint64</a> <span class="com">// 由客户端选择的序列号</span>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Request是每个RPC调用请求的头域。它是被内部使用的,这里的文档用于帮助debug,如分析网络拥堵时。</p>
|
||||
<h2 id="Response">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#176" title="View Source">Response</a> </h2>
|
||||
<pre>type Response struct {
|
||||
<span id="Response.ServiceMethod">ServiceMethod</span> <a href="builtin.htm#string">string</a> <span class="com">// 对应请求的同一字段</span>
|
||||
<span id="Response.Seq">Seq</span> <a href="builtin.htm#uint64">uint64</a> <span class="com">// 对应请求的同一字段</span>
|
||||
<span id="Response.Error">Error</span> <a href="builtin.htm#string">string</a> <span class="com">// 可能的错误</span>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Response是每个RPC调用回复的头域。它是被内部使用的,这里的文档用于帮助debug,如分析网络拥堵时。</p>
|
||||
<h2 id="ClientCodec">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#62" title="View Source">ClientCodec</a> </h2>
|
||||
<pre>type ClientCodec interface {
|
||||
<span class="com">// 本方法必须能安全的被多个go程同时使用</span>
|
||||
<span id="ClientCodec.WriteRequest">WriteRequest</span>(*<a href="#Request">Request</a>, interface{}) <a href="builtin.htm#error">error</a>
|
||||
<span id="ClientCodec.ReadResponseHeader">ReadResponseHeader</span>(*<a href="#Response">Response</a>) <a href="builtin.htm#error">error</a>
|
||||
<span id="ClientCodec.ReadResponseBody">ReadResponseBody</span>(interface{}) <a href="builtin.htm#error">error</a>
|
||||
<span id="ClientCodec.Close">Close</span>() <a href="builtin.htm#error">error</a>
|
||||
}</pre>
|
||||
<p>ClientCodec接口实现了RPC会话的客户端一侧RPC请求的写入和RPC回复的读取。客户端调用WriteRequest来写入请求到连接,然后成对调用ReadRsponseHeader和ReadResponseBody以读取回复。客户端在结束该连接的事务时调用Close方法。ReadResponseBody可以使用nil参数调用,以强制回复的主体被读取然后丢弃。</p>
|
||||
<h2 id="ServerCodec">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#618" title="View Source">ServerCodec</a> </h2>
|
||||
<pre>type ServerCodec interface {
|
||||
<span id="ServerCodec.ReadRequestHeader">ReadRequestHeader</span>(*<a href="#Request">Request</a>) <a href="builtin.htm#error">error</a>
|
||||
<span id="ServerCodec.ReadRequestBody">ReadRequestBody</span>(interface{}) <a href="builtin.htm#error">error</a>
|
||||
<span class="com">// 本方法必须能安全的被多个go程同时使用</span>
|
||||
<span id="ServerCodec.WriteResponse">WriteResponse</span>(*<a href="#Response">Response</a>, interface{}) <a href="builtin.htm#error">error</a>
|
||||
<span id="ServerCodec.Close">Close</span>() <a href="builtin.htm#error">error</a>
|
||||
}</pre>
|
||||
<p>ServerCodec接口实现了RPC会话的服务端一侧RPC请求的读取和RPC回复的写入。服务端通过成对调用方法ReadRequestHeader和ReadRequestBody从连接读取请求,然后调用WriteResponse来写入回复。服务端在结束该连接的事务时调用Close方法。ReadRequestBody可以使用nil参数调用,以强制请求的主体被读取然后丢弃。</p>
|
||||
<h2 id="Call">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#29" title="View Source">Call</a> </h2>
|
||||
<pre>type Call struct {
|
||||
<span id="Call.ServiceMethod">ServiceMethod</span> <a href="builtin.htm#string">string</a> <span class="com">// 调用的服务和方法的名称</span>
|
||||
<span id="Call.Args">Args</span> interface{} <span class="com">// 函数的参数(下层为结构体指针)</span>
|
||||
<span id="Call.Reply">Reply</span> interface{} <span class="com">// 函数的回复(下层为结构体指针)</span>
|
||||
<span id="Call.Error">Error</span> <a href="builtin.htm#error">error</a> <span class="com">// 在调用结束后,保管错误的状态</span>
|
||||
<span id="Call.Done">Done</span> chan *<a href="#Call">Call</a> <span class="com">// 对其的接收操作会阻塞,直到远程调用结束</span>
|
||||
}</pre>
|
||||
<p>Call类型代表一个执行中/执行完毕的RPC会话。</p>
|
||||
<h2 id="Client">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#41" title="View Source">Client</a> </h2>
|
||||
<pre>type Client struct {
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Client类型代表RPC客户端。同一个客户端可能有多个未返回的调用,也可能被多个go程同时使用。</p>
|
||||
<h3 id="NewClient">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#188" title="View Source">NewClient</a> </h3>
|
||||
<pre class="funcdecl">func NewClient(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>) *<a href="#Client">Client</a></pre>
|
||||
<p>NewClient返回一个新的Client,以管理对连接另一端的服务的请求。它添加缓冲到连接的写入侧,以便将回复的头域和有效负载作为一个单元发送。</p>
|
||||
<h3 id="NewClientWithCodec">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#196" title="View Source">NewClientWithCodec</a> </h3>
|
||||
<pre class="funcdecl">func NewClientWithCodec(codec <a href="#ClientCodec">ClientCodec</a>) *<a href="#Client">Client</a></pre>
|
||||
<p>NewClientWithCodec类似NewClient,但使用指定的编解码器,以编码请求主体和解码回复主体。</p>
|
||||
<h3 id="Dial">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#269" title="View Source">Dial</a> </h3>
|
||||
<pre class="funcdecl">func Dial(network, address <a href="builtin.htm#string">string</a>) (*<a href="#Client">Client</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Dial在指定的网络和地址与RPC服务端连接。</p>
|
||||
<h3 id="DialHTTP">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#236" title="View Source">DialHTTP</a> </h3>
|
||||
<pre class="funcdecl">func DialHTTP(network, address <a href="builtin.htm#string">string</a>) (*<a href="#Client">Client</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>DialHTTP在指定的网络和地址与在默认HTTP RPC路径监听的HTTP RPC服务端连接。</p>
|
||||
<h3 id="DialHTTPPath">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#242" title="View Source">DialHTTPPath</a> </h3>
|
||||
<pre class="funcdecl">func DialHTTPPath(network, address, path <a href="builtin.htm#string">string</a>) (*<a href="#Client">Client</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>DialHTTPPath在指定的网络、地址和路径与HTTP RPC服务端连接。</p>
|
||||
<h3 id="Client.Call">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#314" title="View Source">Call</a> </h3>
|
||||
<pre class="funcdecl">func (client *<a href="#Client">Client</a>) Call(serviceMethod <a href="builtin.htm#string">string</a>, args interface{}, reply interface{}) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Call调用指定的方法,等待调用返回,将结果写入reply,然后返回执行的错误状态。</p>
|
||||
<h3 id="Client.Go">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#292" title="View Source">Go</a> </h3>
|
||||
<pre class="funcdecl">func (client *<a href="#Client">Client</a>) Go(serviceMethod <a href="builtin.htm#string">string</a>, args interface{}, reply interface{}, done chan *<a href="#Call">Call</a>) *<a href="#Call">Call</a></pre>
|
||||
<p>Go异步的调用函数。本方法Call结构体类型指针的返回值代表该次远程调用。通道类型的参数done会在本次调用完成时发出信号(通过返回本次Go方法的返回值)。如果done为nil,Go会申请一个新的通道(写入返回值的Done字段);如果done非nil,done必须有缓冲,否则Go方法会故意崩溃。</p>
|
||||
<h3 id="Client.Close">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/rpc/client.go?name=release#277" title="View Source">Close</a> </h3>
|
||||
<pre class="funcdecl">func (client *<a href="#Client">Client</a>) Close() <a href="builtin.htm#error">error</a></pre>
|
||||
<h2 id="Server">type <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#184" title="View Source">Server</a> </h2>
|
||||
<pre>type Server struct {
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Server代表RPC服务端。</p>
|
||||
<h3 id="NewServer">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#194" title="View Source">NewServer</a> </h3>
|
||||
<pre class="funcdecl">func NewServer() *<a href="#Server">Server</a></pre>
|
||||
<p>NewServer创建并返回一个*Server。</p>
|
||||
<h3 id="Server.Register">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#227" title="View Source">Register</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) Register(rcvr interface{}) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Register在server注册并公布rcvr的方法集中满足如下要求的方法:</p>
|
||||
<pre>- 方法是导出的
|
||||
- 方法有两个参数,都是导出类型或内建类型
|
||||
- 方法的第二个参数是指针
|
||||
- 方法只有一个error接口类型的返回值</pre>
|
||||
<p>如果rcvr不是一个导出类型的值,或者该类型没有满足要求的方法,Register会返回错误。Register也会使用<a href="http://godoc.org/log">log</a>包将错误写入日志。客户端可以使用格式为"Type.Method"的字符串访问这些方法,其中Type是rcvr的具体类型。</p>
|
||||
<h3 id="Server.RegisterName">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#233" title="View Source">RegisterName</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) RegisterName(name <a href="builtin.htm#string">string</a>, rcvr interface{}) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>RegisterName类似Register,但使用提供的name代替rcvr的具体类型名作为服务名。</p>
|
||||
<h3 id="Server.Accept">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#592" title="View Source">Accept</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) Accept(lis <a href="net.htm">net</a>.<a href="net.htm#Listener">Listener</a>)</pre>
|
||||
<p>Accept接收监听器l获取的连接,然后服务每一个连接。Accept会阻塞,调用者应另开线程:"go server.Accept(l)"</p>
|
||||
<h3 id="Server.ServeConn">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#427" title="View Source">ServeConn</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) ServeConn(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>)</pre>
|
||||
<p>ServeConn在单个连接上执行server。ServeConn会阻塞,服务该连接直到客户端挂起。调用者一般应另开线程调用本函数:"go server.ServeConn(conn)"。ServeConn在该连接使用gob(参见encoding/gob包)有线格式。要使用其他的编解码器,可调用ServeCodec方法。</p>
|
||||
<h3 id="Server.ServeCodec">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#435" title="View Source">ServeCodec</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) ServeCodec(codec <a href="#ServerCodec">ServerCodec</a>)</pre>
|
||||
<p>ServeCodec类似ServeConn,但使用指定的编解码器,以编码请求主体和解码回复主体。</p>
|
||||
<h3 id="Server.ServeRequest">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#460" title="View Source">ServeRequest</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) ServeRequest(codec <a href="#ServerCodec">ServerCodec</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>ServeRequest类似ServeCodec,但异步的服务单个请求。它不会在调用结束后关闭codec。</p>
|
||||
<h3 id="Server.ServeHTTP">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#657" title="View Source">ServeHTTP</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) ServeHTTP(w <a href="net/http.htm">http</a>.<a href="net/http.htm#ResponseWriter">ResponseWriter</a>, req *<a href="net/http.htm">http</a>.<a href="net/http.htm#Request">Request</a>)</pre>
|
||||
<p>ServeHTTP实现了回应RPC请求的http.Handler接口。</p>
|
||||
<h3 id="Server.HandleHTTP">func (*Server) <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#676" title="View Source">HandleHTTP</a> </h3>
|
||||
<pre class="funcdecl">func (server *<a href="#Server">Server</a>) HandleHTTP(rpcPath, debugPath <a href="builtin.htm#string">string</a>)</pre>
|
||||
<p>HandleHTTP注册server的RPC信息HTTP处理器对应到rpcPath,注册server的debug信息HTTP处理器对应到debugPath。HandleHTTP会注册到http.DefaultServeMux。之后,仍需要调用http.Serve(),一般会另开线程:"go http.Serve(l, nil)"</p>
|
||||
<h2 id="Register">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#603" title="View Source">Register</a> </h2>
|
||||
<pre class="funcdecl">func Register(rcvr interface{}) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Register在DefaultServer注册并公布rcvr的方法。</p>
|
||||
<h2 id="RegisterName">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#607" title="View Source">RegisterName</a> </h2>
|
||||
<pre class="funcdecl">func RegisterName(name <a href="builtin.htm#string">string</a>, rcvr interface{}) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>RegisterName函数类似Register函数,但使用提供的name代替rcvr的具体类型名作为服务名。</p>
|
||||
<h2 id="Accept">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#651" title="View Source">Accept</a> </h2>
|
||||
<pre class="funcdecl">func Accept(lis <a href="net.htm">net</a>.<a href="net.htm#Listener">Listener</a>)</pre>
|
||||
<p>Accept接收监听器l获取的连接,然后将每一个连接交给DefaultServer服务。Accept会阻塞,调用者应另开线程:"go server.Accept(l)"</p>
|
||||
<h2 id="ServeConn">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#632" title="View Source">ServeConn</a> </h2>
|
||||
<pre class="funcdecl">func ServeConn(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>)</pre>
|
||||
<p>ServeConn在单个连接上执行DefaultServer。ServeConn会阻塞,服务该连接直到客户端挂起。调用者一般应另开线程调用本函数:"go ServeConn(conn)"。ServeConn在该连接使用gob(参见encoding/gob包)有线格式。要使用其他的编解码器,可调用ServeCodec方法。</p>
|
||||
<h2 id="ServeCodec">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#638" title="View Source">ServeCodec</a> </h2>
|
||||
<pre class="funcdecl">func ServeCodec(codec <a href="#ServerCodec">ServerCodec</a>)</pre>
|
||||
<p>ServeCodec类似ServeConn,但使用指定的编解码器,以编码请求主体和解码回复主体。</p>
|
||||
<h2 id="ServeRequest">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#644" title="View Source">ServeRequest</a> </h2>
|
||||
<pre class="funcdecl">func ServeRequest(codec <a href="#ServerCodec">ServerCodec</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>ServeRequest类似ServeCodec,但异步的服务单个请求。它不会在调用结束后关闭codec。</p>
|
||||
<h2 id="HandleHTTP">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/server.go?name=release#684" title="View Source">HandleHTTP</a> </h2>
|
||||
<pre class="funcdecl">func HandleHTTP()</pre>
|
||||
<p>HandleHTTP函数注册DefaultServer的RPC信息HTTP处理器对应到DefaultRPCPath,和DefaultServer的debug处理器对应到DefaultDebugPath。HandleHTTP函数会注册到http.DefaultServeMux。之后,仍需要调用http.Serve(),一般会另开线程:"go http.Serve(l, nil)"</p>
|
||||
</div>
|
29
src/docs/go/net/rpc/jsonrpc.html
Normal file
29
src/docs/go/net/rpc/jsonrpc.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package jsonrpc</h1>
|
||||
<p><code>import "net/rpc/jsonrpc"</code>
|
||||
</p><p>jsonrpc包实现了JSON-RPC的ClientCodec和ServerCodec接口,可用于rpc包。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="Dial">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/jsonrpc/client.go?name=release#117" title="View Source">Dial</a> </h2>
|
||||
<pre class="funcdecl">func Dial(network, address <a href="builtin.htm#string">string</a>) (*<a href="net/rpc.htm">rpc</a>.<a href="net/rpc.htm#Client">Client</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Dial在指定的网络和地址连接一个JSON-RPC服务端。</p>
|
||||
<h2 id="NewClient">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/jsonrpc/client.go?name=release#112" title="View Source">NewClient</a> </h2>
|
||||
<pre class="funcdecl">func NewClient(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>) *<a href="net/rpc.htm">rpc</a>.<a href="net/rpc.htm#Client">Client</a></pre>
|
||||
<p>NewClient返回一个新的rpc.Client,以管理对连接另一端的服务的请求。</p>
|
||||
<h2 id="NewClientCodec">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/jsonrpc/client.go?name=release#36" title="View Source">NewClientCodec</a> </h2>
|
||||
<pre class="funcdecl">func NewClientCodec(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>) <a href="net/rpc.htm">rpc</a>.<a href="net/rpc.htm#ClientCodec">ClientCodec</a></pre>
|
||||
<p>NewClientCodec返回一个在连接上使用JSON-RPC的rpc.ClientCodec。</p>
|
||||
<h2 id="NewServerCodec">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/jsonrpc/server.go?name=release#37" title="View Source">NewServerCodec</a> </h2>
|
||||
<pre class="funcdecl">func NewServerCodec(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>) <a href="net/rpc.htm">rpc</a>.<a href="net/rpc.htm#ServerCodec">ServerCodec</a></pre>
|
||||
<p>NewServerCodec返回一个在连接上使用JSON-RPC的rpc. ServerCodec。</p>
|
||||
<h2 id="ServeConn">func <a href="https://github.com/golang/go/blob/master/src/net/rpc/jsonrpc/server.go?name=release#132" title="View Source">ServeConn</a> </h2>
|
||||
<pre class="funcdecl">func ServeConn(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>)</pre>
|
||||
<p>ServeConn在单个连接上执行DefaultServer。ServeConn会阻塞,服务该连接直到客户端挂起。调用者一般应另开线程调用本函数:"go serveConn(conn)"。ServeConn在该连接使用JSON编解码格式。</p>
|
||||
</div>
|
162
src/docs/go/net/smtp.html
Normal file
162
src/docs/go/net/smtp.html
Normal file
@@ -0,0 +1,162 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package smtp</h1>
|
||||
<p><code>import "net/smtp"</code>
|
||||
</p><p>smtp包实现了简单邮件传输协议(SMTP),参见<a href="http://tools.ietf.org/html/rfc5321">RFC 5321</a>。同时本包还实现了如下扩展:</p>
|
||||
<pre>8BITMIME <a href="http://tools.ietf.org/html/rfc1652">RFC 1652</a>
|
||||
AUTH <a href="http://tools.ietf.org/html/rfc2554">RFC 2554</a>
|
||||
STARTTLS <a href="http://tools.ietf.org/html/rfc3207">RFC 3207</a>
|
||||
</pre>
|
||||
<p>客户端可以自行管理其他的扩展。</p>
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default" id="example-package">
|
||||
<div class="panel-heading" onclick="document.getElementById('ex-package').style.display = document.getElementById('ex-package').style.display=='none'?'block':'none';">Example</div>
|
||||
<div class="panel-collapse collapse" id="ex-package">
|
||||
<div class="panel-body">
|
||||
<pre><span class="com">// Connect to the remote SMTP server.</span>
|
||||
c, err := smtp.Dial("mail.example.com:25")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
<span class="com">// Set the sender and recipient first</span>
|
||||
if err := c.Mail("sender@example.org"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := c.Rcpt("recipient@example.net"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
<span class="com">// Send the email body.</span>
|
||||
wc, err := c.Data()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = fmt.Fprintf(wc, "This is the email body")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = wc.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
<span class="com">// Send the QUIT command and close the connection.</span>
|
||||
err = c.Quit()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="ServerInfo">type <a href="https://github.com/golang/go/blob/master/src/net/smtp/auth.go?name=release#35" title="View Source">ServerInfo</a> </h2>
|
||||
<pre>type ServerInfo struct {
|
||||
<span id="ServerInfo.Name">Name</span> <a href="builtin.htm#string">string</a> <span class="com">// SMTP服务器的名字</span>
|
||||
<span id="ServerInfo.TLS">TLS</span> <a href="builtin.htm#bool">bool</a> <span class="com">// Name有合法的证书并使用TLS时为真</span>
|
||||
<span id="ServerInfo.Auth">Auth</span> []<a href="builtin.htm#string">string</a> <span class="com">// 支持的认证机制</span>
|
||||
}</pre>
|
||||
<p>ServerInfo类型记录一个SMTP服务器的信息。</p>
|
||||
<h2 id="Auth">type <a href="https://github.com/golang/go/blob/master/src/net/smtp/auth.go?name=release#15" title="View Source">Auth</a> </h2>
|
||||
<pre>type Auth interface {
|
||||
<span class="com">// 方法开始和服务端的认证。</span>
|
||||
<span class="com">// 它返回认证协议的名字和可能有的应发送给服务端的包含初始认证信息的数据。</span>
|
||||
<span class="com">// 如果返回值proto == "",表示应跳过认证;</span>
|
||||
<span class="com">// 如果返回一个非nil的错误,SMTP客户端应中断认证身份的尝试并关闭连接。</span>
|
||||
<span id="Auth.Start">Start</span>(server *<a href="#ServerInfo">ServerInfo</a>) (proto <a href="builtin.htm#string">string</a>, toServer []<a href="builtin.htm#byte">byte</a>, err <a href="builtin.htm#error">error</a>)
|
||||
<span class="com">// 方法继续认证过程。fromServer为服务端刚发送的数据。</span>
|
||||
<span class="com">// 如果more为真,服务端会期望一个回复,回复内容应被Next返回,即toServer;</span>
|
||||
<span class="com">// 否则返回值toServer应为nil。</span>
|
||||
<span class="com">// 如果返回一个非nil的错误,SMTP客户端应中断认证身份的尝试并关闭连接。</span>
|
||||
<span id="Auth.Next">Next</span>(fromServer []<a href="builtin.htm#byte">byte</a>, more <a href="builtin.htm#bool">bool</a>) (toServer []<a href="builtin.htm#byte">byte</a>, err <a href="builtin.htm#error">error</a>)
|
||||
}</pre>
|
||||
<p>Auth接口应被每一个SMTP认证机制实现。</p>
|
||||
<h3 id="CRAMMD5Auth">func <a href="https://github.com/golang/go/blob/master/src/net/smtp/auth.go?name=release#91" title="View Source">CRAMMD5Auth</a> </h3>
|
||||
<pre class="funcdecl">func CRAMMD5Auth(username, secret <a href="builtin.htm#string">string</a>) <a href="#Auth">Auth</a></pre>
|
||||
<p>返回一个实现了CRAM-MD5身份认证机制(参见<a href="http://tools.ietf.org/html/rfc2195">RFC 2195</a>)的Auth接口。返回的接口使用给出的用户名和密码,采用响应——回答机制与服务端进行身份认证。</p>
|
||||
<h3 id="PlainAuth">func <a href="https://github.com/golang/go/blob/master/src/net/smtp/auth.go?name=release#51" title="View Source">PlainAuth</a> </h3>
|
||||
<pre class="funcdecl">func PlainAuth(identity, username, password, host <a href="builtin.htm#string">string</a>) <a href="#Auth">Auth</a></pre>
|
||||
<p>返回一个实现了PLAIN身份认证机制(参见<a href="http://tools.ietf.org/html/rfc4616">RFC 4616</a>)的Auth接口。返回的接口使用给出的用户名和密码,通过TLS连接到主机认证,采用identity为身份管理和行动(通常应设identity为"",以便使用username为身份)。</p>
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default" id="example-PlainAuth">
|
||||
<div class="panel-heading" onclick="document.getElementById('ex-PlainAuth').style.display = document.getElementById('ex-PlainAuth').style.display=='none'?'block':'none';">Example</div>
|
||||
<div class="panel-collapse collapse" id="ex-PlainAuth">
|
||||
<div class="panel-body">
|
||||
<pre><span class="com">// Set up authentication information.</span>
|
||||
auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com")
|
||||
<span class="com">// Connect to the server, authenticate, set the sender and recipient,</span>
|
||||
<span class="com">// and send the email all in one step.</span>
|
||||
to := []string{"recipient@example.net"}
|
||||
msg := []byte("This is the email body.")
|
||||
err := smtp.SendMail("mail.example.com:25", auth, "sender@example.org", to, msg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h2 id="Client">type <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#24" title="View Source">Client</a> </h2>
|
||||
<pre>type Client struct {
|
||||
<span class="com">// 代表被Client使用的textproto.Conn,它可以导出,以便使用者添加扩展。</span>
|
||||
<span id="Client.Text">Text</span> *<a href="net/textproto.htm">textproto</a>.<a href="net/textproto.htm#Conn">Conn</a>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Client代表一个连接到SMTP服务器的客户端。</p>
|
||||
<h3 id="Dial">func <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#45" title="View Source">Dial</a> </h3>
|
||||
<pre class="funcdecl">func Dial(addr <a href="builtin.htm#string">string</a>) (*<a href="#Client">Client</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Dial返回一个连接到地址为addr的SMTP服务器的*Client;addr必须包含端口号。</p>
|
||||
<h3 id="NewClient">func <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#56" title="View Source">NewClient</a> </h3>
|
||||
<pre class="funcdecl">func NewClient(conn <a href="net.htm">net</a>.<a href="net.htm#Conn">Conn</a>, host <a href="builtin.htm#string">string</a>) (*<a href="#Client">Client</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>NewClient使用已经存在的连接conn和作为服务器名的host(用于身份认证)来创建一个*Client。</p>
|
||||
<h3 id="Client.Extension">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#325" title="View Source">Extension</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Extension(ext <a href="builtin.htm#string">string</a>) (<a href="builtin.htm#bool">bool</a>, <a href="builtin.htm#string">string</a>)</pre>
|
||||
<p>Extension返回服务端是否支持某个扩展,扩展名是大小写不敏感的。如果扩展被支持,方法还会返回一个包含指定给该扩展的各个参数的字符串。</p>
|
||||
<h3 id="Client.Hello">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#89" title="View Source">Hello</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Hello(localName <a href="builtin.htm#string">string</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Hello发送给服务端一个HELO或EHLO命令。本方法只有使用者需要控制使用的本地主机名时才应使用,否则程序会将本地主机名设为“localhost”,Hello方法只能在最开始调用。</p>
|
||||
<h3 id="Client.Auth">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#175" title="View Source">Auth</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Auth(a <a href="#Auth">Auth</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Auth使用提供的认证机制进行认证。失败的认证会关闭该连接。只有服务端支持AUTH时,本方法才有效。(但是不支持时,调用会默默的成功)</p>
|
||||
<h3 id="Client.Verify">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#164" title="View Source">Verify</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Verify(addr <a href="builtin.htm#string">string</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Verify检查一个邮箱地址在其服务器是否合法,如果合法会返回nil;但非nil的返回值并不代表不合法,因为许多服务器出于安全原因不支持这种查询。</p>
|
||||
<h3 id="Client.StartTLS">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#146" title="View Source">StartTLS</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) StartTLS(config *<a href="crypto/tls.htm">tls</a>.<a href="crypto/tls.htm#Config">Config</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>StartTLS方法发送STARTTLS命令,并将之后的所有数据往来加密。只有服务器附加了STARTTLS扩展,这个方法才有效。</p>
|
||||
<h3 id="Client.Mail">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#222" title="View Source">Mail</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Mail(from <a href="builtin.htm#string">string</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Mail发送MAIL命令和邮箱地址from到服务器。如果服务端支持8BITMIME扩展,本方法会添加BODY=8BITMIME参数。方法初始化一次邮件传输,后应跟1到多个Rcpt方法的调用。</p>
|
||||
<h3 id="Client.Rcpt">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#239" title="View Source">Rcpt</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Rcpt(to <a href="builtin.htm#string">string</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Rcpt发送RCPT命令和邮箱地址to到服务器。调用Rcpt方法之前必须调用了Mail方法,之后可以再一次调用Rcpt方法,也可以调用Data方法。</p>
|
||||
<h3 id="Client.Data">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#259" title="View Source">Data</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Data() (<a href="io.htm">io</a>.<a href="io.htm#WriteCloser">WriteCloser</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Data发送DATA指令到服务器并返回一个io.WriteCloser,用于写入邮件信息。调用者必须在调用c的下一个方法之前关闭这个io.WriteCloser。方法必须在一次或多次Rcpt方法之后调用。</p>
|
||||
<h3 id="Client.Reset">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#339" title="View Source">Reset</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Reset() <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Reset向服务端发送REST命令,中断当前的邮件传输。</p>
|
||||
<h3 id="Client.Quit">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#348" title="View Source">Quit</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Quit() <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Quit发送QUIT命令并关闭到服务端的连接。</p>
|
||||
<h3 id="Client.Close">func (*Client) <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#68" title="View Source">Close</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Client">Client</a>) Close() <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Close关闭连接。</p>
|
||||
<h2 id="SendMail">func <a href="https://github.com/golang/go/blob/master/src/net/smtp/smtp.go?name=release#273" title="View Source">SendMail</a> </h2>
|
||||
<pre class="funcdecl">func SendMail(addr <a href="builtin.htm#string">string</a>, a <a href="#Auth">Auth</a>, from <a href="builtin.htm#string">string</a>, to []<a href="builtin.htm#string">string</a>, msg []<a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>SendMail连接到addr指定的服务器;如果支持会开启TLS;如果支持会使用a认证身份;然后以from为邮件源地址发送邮件msg到目标地址to。(可以是多个目标地址:群发)</p>
|
||||
</div>
|
215
src/docs/go/net/textproto.html
Normal file
215
src/docs/go/net/textproto.html
Normal file
@@ -0,0 +1,215 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package textproto</h1>
|
||||
<p><code>import "net/textproto"</code>
|
||||
</p><p align="left">textproto实现了对基于文本的请求/回复协议的一般性支持,包括HTTP、NNTP和SMTP。</p>
|
||||
<p align="left">本包提供:</p>
|
||||
<p align="left">错误,代表服务端回复的错误码。Pipeline,以管理客户端中的管道化的请求/回复。Reader,读取数值回复码行,键值对形式的头域,一个作为后续行先导的空行,以及以只有一个"."的一行为结尾的整个文本块。Writer,写入点编码的文本。Conn,对Reader、Writer和Pipline的易用的包装,用于单个网络连接。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="ProtocolError">type <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#47" title="View Source">ProtocolError</a> </h2>
|
||||
<pre>type ProtocolError <a href="builtin.htm#string">string</a></pre>
|
||||
<p>ProtocolError描述一个违反协议的错误,如不合法的回复或者挂起的连接。</p>
|
||||
<h3 id="ProtocolError.Error">func (ProtocolError) <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#49" title="View Source">Error</a> </h3>
|
||||
<pre class="funcdecl">func (p <a href="#ProtocolError">ProtocolError</a>) Error() <a href="builtin.htm#string">string</a></pre>
|
||||
<h2 id="Error">type <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#36" title="View Source">Error</a> </h2>
|
||||
<pre>type Error struct {
|
||||
<span id="Error.Code">Code</span> <a href="builtin.htm#int">int</a>
|
||||
<span id="Error.Msg">Msg</span> <a href="builtin.htm#string">string</a>
|
||||
}</pre>
|
||||
<p>Error代表一个服务端返回的数值状态码/错误码。</p>
|
||||
<h3 id="Error.Error">func (*Error) <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#41" title="View Source">Error</a> </h3>
|
||||
<pre class="funcdecl">func (e *<a href="#Error">Error</a>) Error() <a href="builtin.htm#string">string</a></pre>
|
||||
<h2 id="CanonicalMIMEHeaderKey">func <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#543" title="View Source">CanonicalMIMEHeaderKey</a> </h2>
|
||||
<pre class="funcdecl">func CanonicalMIMEHeaderKey(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
|
||||
<p>返回一个MIME头的键的规范格式。该标准会将首字母和所有"-"之后的字符改为大写,其余字母改为小写。举个例子,"accept-encoding"作为键的标准格式是"Accept-Encoding"。MIME头的键必须是ASCII码构成。</p>
|
||||
<h2 id="TrimBytes">func <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#137" title="View Source">TrimBytes</a> </h2>
|
||||
<pre class="funcdecl">func TrimBytes(b []<a href="builtin.htm#byte">byte</a>) []<a href="builtin.htm#byte">byte</a></pre>
|
||||
<p>去掉b前后的ASCII码空白(不去Unicode空白)</p>
|
||||
<h2 id="TrimString">func <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#126" title="View Source">TrimString</a> </h2>
|
||||
<pre class="funcdecl">func TrimString(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
|
||||
<p>去掉s前后的ASCII码空白(不去Unicode空白)</p>
|
||||
<h2 id="MIMEHeader">type <a href="https://github.com/golang/go/blob/master/src/net/textproto/header.go?name=release#9" title="View Source">MIMEHeader</a> </h2>
|
||||
<pre>type MIMEHeader map[<a href="builtin.htm#string">string</a>][]<a href="builtin.htm#string">string</a></pre>
|
||||
<p>MIMEHeader代表一个MIME头,将键映射为值的集合。</p>
|
||||
<h3 id="MIMEHeader.Get">func (MIMEHeader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/header.go?name=release#29" title="View Source">Get</a> </h3>
|
||||
<pre class="funcdecl">func (h <a href="#MIMEHeader">MIMEHeader</a>) Get(key <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
|
||||
<p>Get方法返回键对应的值集的第一个值。如果键没有关联值,返回""。如要获得键对应的值集直接用map。</p>
|
||||
<h3 id="MIMEHeader.Set">func (MIMEHeader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/header.go?name=release#21" title="View Source">Set</a> </h3>
|
||||
<pre class="funcdecl">func (h <a href="#MIMEHeader">MIMEHeader</a>) Set(key, value <a href="builtin.htm#string">string</a>)</pre>
|
||||
<p>Set方法将键对应的值集设置为只含有value一个值。没有就新建,有则删掉原有的值。</p>
|
||||
<h3 id="MIMEHeader.Add">func (MIMEHeader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/header.go?name=release#13" title="View Source">Add</a> </h3>
|
||||
<pre class="funcdecl">func (h <a href="#MIMEHeader">MIMEHeader</a>) Add(key, value <a href="builtin.htm#string">string</a>)</pre>
|
||||
<p>Add方法向h中添加键值对,它会把新的值添加到键对应的值的集合里。</p>
|
||||
<h3 id="MIMEHeader.Del">func (MIMEHeader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/header.go?name=release#41" title="View Source">Del</a> </h3>
|
||||
<pre class="funcdecl">func (h <a href="#MIMEHeader">MIMEHeader</a>) Del(key <a href="builtin.htm#string">string</a>)</pre>
|
||||
<p>Del方法删除键对应的值集。</p>
|
||||
<h2 id="Reader">type <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#22" title="View Source">Reader</a> </h2>
|
||||
<pre>type Reader struct {
|
||||
<span id="Reader.R">R</span> *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Reader">Reader</a>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Reader实现了从一个文本协议网络连接中方便的读取请求/回复的方法。</p>
|
||||
<h3 id="NewReader">func <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#29" title="View Source">NewReader</a> </h3>
|
||||
<pre class="funcdecl">func NewReader(r *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Reader">Reader</a>) *<a href="#Reader">Reader</a></pre>
|
||||
<p>NewReader返回一个从r读取数据的Reader。</p>
|
||||
<h3 id="Reader.DotReader">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#286" title="View Source">DotReader</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) DotReader() <a href="io.htm">io</a>.<a href="io.htm#Reader">Reader</a></pre>
|
||||
<p align="left">DotReader方法返回一个io.Reader,该接口自动解码r中读取的点编码块。注意该接口仅在下一次调用r的方法之前才有效。点编码是文本协议如SMTP用于文本块的通用框架。数据包含多个行,每行以"\r\n"结尾。数据本身以一个只含有一个点的一行".\r\n"来结尾。以点起始的行会添加额外的点,来避免看起来像是文本的结尾。</p>
|
||||
<p align="left">返回接口的Read方法会将行尾的"\r\n"修改为"\n",去掉起头的转义点,并在底层读取到(并抛弃掉)表示文本结尾的行时停止解码并返回io.EOF错误。</p>
|
||||
<h3 id="Reader.ReadLine">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#35" title="View Source">ReadLine</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadLine() (<a href="builtin.htm#string">string</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>ReadLine方法从r读取单行,去掉最后的\r\n或\n。</p>
|
||||
<h3 id="Reader.ReadLineBytes">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#41" title="View Source">ReadLineBytes</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadLineBytes() ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>ReadLineBytes类似ReadLine但返回[]byte切片。</p>
|
||||
<h3 id="Reader.ReadContinuedLine">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#90" title="View Source">ReadContinuedLine</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadContinuedLine() (<a href="builtin.htm#string">string</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p align="left">ReadContinuedLine从r中读取可能有后续的行,会将该行尾段的ASCII空白剔除,并将该行后面所有以空格或者tab起始的行视为其后续,后续部分会剔除行头部的空白,所有这些行包括第一行以单个空格连接起来返回。</p>
|
||||
<p align="left">举例如下:</p>
|
||||
<pre>Line 1
|
||||
continued...
|
||||
Line 2</pre>
|
||||
<p align="left">第一次调用ReadContinuedLine会返回"Line 1 continued...",第二次会返回"Line 2"</p>
|
||||
<p align="left">只有空格的行不被视为有后续的行。</p>
|
||||
<h3 id="Reader.ReadContinuedLineBytes">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#111" title="View Source">ReadContinuedLineBytes</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadContinuedLineBytes() ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>ReadContinuedLineBytes类似ReadContinuedLine但返回[]byte切片。</p>
|
||||
<h3 id="Reader.ReadDotBytes">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#402" title="View Source">ReadDotBytes</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadDotBytes() ([]<a href="builtin.htm#byte">byte</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>ReadDotBytes读取点编码文本返回解码后的数据,点编码详见DotReader方法。</p>
|
||||
<h3 id="Reader.ReadDotLines">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#410" title="View Source">ReadDotLines</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadDotLines() ([]<a href="builtin.htm#string">string</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>ReadDotLines方法读取一个点编码文本块并返回一个包含解码后各行的切片,各行最后的\r\n或\n去掉。</p>
|
||||
<h3 id="Reader.ReadCodeLine">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#219" title="View Source">ReadCodeLine</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadCodeLine(expectCode <a href="builtin.htm#int">int</a>) (code <a href="builtin.htm#int">int</a>, message <a href="builtin.htm#string">string</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>方法读取回复的状态码行,格式如下:</p>
|
||||
<pre>code message
|
||||
</pre>
|
||||
<p>状态码是3位数字,message进一步描述状态,例如:</p>
|
||||
<pre>220 plan9.bell-labs.com ESMTP
|
||||
</pre>
|
||||
<p align="left">如果状态码字符串的前缀不匹配expectCode,方法返回错误&Error{code, message}。例如expectCode是31,则如果状态码不在区间[310, 319]内就会返回错误。如果回复是多行的则会返回错误。</p>
|
||||
<p align="left">如果expectCode <= 0,将不会检查状态码。</p>
|
||||
<h3 id="Reader.ReadResponse">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#249" title="View Source">ReadResponse</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadResponse(expectCode <a href="builtin.htm#int">int</a>) (code <a href="builtin.htm#int">int</a>, message <a href="builtin.htm#string">string</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>ReadResponse方法读取如下格式的多行回复:</p>
|
||||
<pre>code-message line 1
|
||||
code-message line 2
|
||||
...
|
||||
code message line n</pre>
|
||||
<p align="left">其中code是三位数的状态码。第一行以code和连字符开始,最后以同code后跟空格的行结束。返回值message每行以\n分隔。细节参见<a href="http://tools.ietf.org/html/rfc959">RFC 959</a>(<a href="http://www.ietf.org/rfc/rfc959.txt">http://www.ietf.org/rfc/rfc959.txt</a>)第36页。</p>
|
||||
<p align="left">如果状态码字符串的前缀不匹配expectCode,方法返回时err设为&Error{code, message}。例如expectCode是31,则如果状态码不在区间[310, 319]内就会返回错误。如果回复是多行的则会返回错误。</p>
|
||||
<p align="left">如果expectCode <= 0,将不会检查状态码。</p>
|
||||
<h3 id="Reader.ReadMIMEHeader">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#458" title="View Source">ReadMIMEHeader</a> </h3>
|
||||
<pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadMIMEHeader() (<a href="#MIMEHeader">MIMEHeader</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p align="left">ReadMIMEHeader从r读取MIME风格的头域。该头域包含一系列可能有后续的键值行,以空行结束。返回的map映射CanonicalMIMEHeaderKey(key)到值的序列(顺序与输入相同)。</p>
|
||||
<p align="left">举例如下:</p>
|
||||
<pre>My-Key: Value 1
|
||||
Long-Key: Even
|
||||
Longer Value
|
||||
My-Key: Value 2</pre>
|
||||
<p>对此输入,ReadMIMEHeader返回:</p>
|
||||
<pre>map[string][]string{
|
||||
"My-Key": {"Value 1", "Value 2"},
|
||||
"Long-Key": {"Even Longer Value"},
|
||||
}</pre>
|
||||
<h2 id="Writer">type <a href="https://github.com/golang/go/blob/master/src/net/textproto/writer.go?name=release#15" title="View Source">Writer</a> </h2>
|
||||
<pre>type Writer struct {
|
||||
<span id="Writer.W">W</span> *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Writer">Writer</a>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Writer实现了方便的方法在一个文本协议网络连接中写入请求/回复。</p>
|
||||
<h3 id="NewWriter">func <a href="https://github.com/golang/go/blob/master/src/net/textproto/writer.go?name=release#21" title="View Source">NewWriter</a> </h3>
|
||||
<pre class="funcdecl">func NewWriter(w *<a href="bufio.htm">bufio</a>.<a href="bufio.htm#Writer">Writer</a>) *<a href="#Writer">Writer</a></pre>
|
||||
<p>NewWriter函数返回一个底层写入w的Writer。</p>
|
||||
<h3 id="Writer.DotWriter">func (*Writer) <a href="https://github.com/golang/go/blob/master/src/net/textproto/writer.go?name=release#43" title="View Source">DotWriter</a> </h3>
|
||||
<pre class="funcdecl">func (w *<a href="#Writer">Writer</a>) DotWriter() <a href="io.htm">io</a>.<a href="io.htm#WriteCloser">WriteCloser</a></pre>
|
||||
<p>DotWriter方法返回一个io.WriteCloser,用于将点编码文本写入w。返回的接口会在必要时添加转义点,将行尾的\n替换为\r\n,并在关闭时添加最后的.\r\n行。调用者必须在下一次调用w的方法前关闭该接口。点编码文本格式参见Reader.DotReader方法。</p>
|
||||
<h3 id="Writer.PrintfLine">func (*Writer) <a href="https://github.com/golang/go/blob/master/src/net/textproto/writer.go?name=release#29" title="View Source">PrintfLine</a> </h3>
|
||||
<pre class="funcdecl">func (w *<a href="#Writer">Writer</a>) PrintfLine(format <a href="builtin.htm#string">string</a>, args ...interface{}) <a href="builtin.htm#error">error</a></pre>
|
||||
<p>PrintfLine方法将格式化的输出写入底层并在最后写入\r\n。</p>
|
||||
<h2 id="Pipeline">type <a href="https://github.com/golang/go/blob/master/src/net/textproto/pipeline.go?name=release#28" title="View Source">Pipeline</a> </h2>
|
||||
<pre>type Pipeline struct {
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p align="left">Pipeline管理管道化的有序请求/回复序列。</p>
|
||||
<p align="left">为了使用Pipeline管理一个连接的多个客户端,每个客户端应像下面一样运行:</p>
|
||||
<pre>id := p.Next() // 获取一个数字id
|
||||
p.StartRequest(id) // 等待轮到该id发送请求
|
||||
«send request»
|
||||
p.EndRequest(id) // 通知Pipeline请求发送完毕
|
||||
p.StartResponse(id) // 等待该id读取回复
|
||||
«read response»
|
||||
p.EndResponse(id) // 通知Pipeline回复已经读取</pre>
|
||||
<p>一个管道化的服务器可以使用相同的调用来保证回复并行的生成并以正确的顺序写入。</p>
|
||||
<h3 id="Pipeline.Next">func (*Pipeline) <a href="https://github.com/golang/go/blob/master/src/net/textproto/pipeline.go?name=release#36" title="View Source">Next</a> </h3>
|
||||
<pre class="funcdecl">func (p *<a href="#Pipeline">Pipeline</a>) Next() <a href="builtin.htm#uint">uint</a></pre>
|
||||
<p>返回下一对request/response的id。</p>
|
||||
<h3 id="Pipeline.StartRequest">func (*Pipeline) <a href="https://github.com/golang/go/blob/master/src/net/textproto/pipeline.go?name=release#46" title="View Source">StartRequest</a> </h3>
|
||||
<pre class="funcdecl">func (p *<a href="#Pipeline">Pipeline</a>) StartRequest(id <a href="builtin.htm#uint">uint</a>)</pre>
|
||||
<p>阻塞程序,直到轮到给定id来发送(读取)request。</p>
|
||||
<h3 id="Pipeline.StartResponse">func (*Pipeline) <a href="https://github.com/golang/go/blob/master/src/net/textproto/pipeline.go?name=release#58" title="View Source">StartResponse</a> </h3>
|
||||
<pre class="funcdecl">func (p *<a href="#Pipeline">Pipeline</a>) StartResponse(id <a href="builtin.htm#uint">uint</a>)</pre>
|
||||
<p>阻塞程序,直到轮到给定id来读取(发送)response。</p>
|
||||
<h3 id="Pipeline.EndRequest">func (*Pipeline) <a href="https://github.com/golang/go/blob/master/src/net/textproto/pipeline.go?name=release#52" title="View Source">EndRequest</a> </h3>
|
||||
<pre class="funcdecl">func (p *<a href="#Pipeline">Pipeline</a>) EndRequest(id <a href="builtin.htm#uint">uint</a>)</pre>
|
||||
<p>通知p,给定id的request的操作已经结束了。</p>
|
||||
<h3 id="Pipeline.EndResponse">func (*Pipeline) <a href="https://github.com/golang/go/blob/master/src/net/textproto/pipeline.go?name=release#64" title="View Source">EndResponse</a> </h3>
|
||||
<pre class="funcdecl">func (p *<a href="#Pipeline">Pipeline</a>) EndResponse(id <a href="builtin.htm#uint">uint</a>)</pre>
|
||||
<p>通知p,给定id的response的操作已经结束了。</p>
|
||||
<h2 id="Conn">type <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#58" title="View Source">Conn</a> </h2>
|
||||
<pre>type Conn struct {
|
||||
<a href="#Reader">Reader</a>
|
||||
<a href="#Writer">Writer</a>
|
||||
<a href="#Pipeline">Pipeline</a>
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Conn代表一个文本网络协议的连接。它包含一个Reader和一个Writer来管理读写,一个Pipeline来对连接中并行的请求进行排序。匿名嵌入的类型字段是Conn可以调用它们的方法。</p>
|
||||
<h3 id="NewConn">func <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#66" title="View Source">NewConn</a> </h3>
|
||||
<pre class="funcdecl">func NewConn(conn <a href="io.htm">io</a>.<a href="io.htm#ReadWriteCloser">ReadWriteCloser</a>) *<a href="#Conn">Conn</a></pre>
|
||||
<p>NewConn函数返回以I/O为底层的Conn。</p>
|
||||
<h3 id="Dial">func <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#81" title="View Source">Dial</a> </h3>
|
||||
<pre class="funcdecl">func Dial(network, addr <a href="builtin.htm#string">string</a>) (*<a href="#Conn">Conn</a>, <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p>Dial函数使用net.Dial在给定网络上和给定地址建立网络连接,并返回用于该连接的Conn。</p>
|
||||
<h3 id="Conn.Cmd">func (*Conn) <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#114" title="View Source">Cmd</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Conn">Conn</a>) Cmd(format <a href="builtin.htm#string">string</a>, args ...interface{}) (id <a href="builtin.htm#uint">uint</a>, err <a href="builtin.htm#error">error</a>)</pre>
|
||||
<p align="left">Cmd方法用于在管道中等待轮到它执行,并发送命令。命令文本是用给定的format字符串和参数格式化生成的。并会在最后添加上\r\n。Cmd函数返回该命令的Pipeline id,用于StartResponse和EndResponse方法。</p>
|
||||
<p align="left">例如,一个客户端可以使用如下代码执行HELP命令并返回解码后的点编码文本:</p>
|
||||
<pre>id, err := c.Cmd("HELP")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.StartResponse(id)
|
||||
defer c.EndResponse(id)
|
||||
if _, _, err = c.ReadCodeLine(110); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
text, err := c.ReadDotBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.ReadCodeLine(250)</pre>
|
||||
<h3 id="Conn.Close">func (*Conn) <a href="https://github.com/golang/go/blob/master/src/net/textproto/textproto.go?name=release#75" title="View Source">Close</a> </h3>
|
||||
<pre class="funcdecl">func (c *<a href="#Conn">Conn</a>) Close() <a href="builtin.htm#error">error</a></pre>
|
||||
<p>Close方法关闭连接。</p>
|
||||
<h2 id="pkg-note-bug">Bugs </h2>
|
||||
<p><a href="https://github.com/golang/go/blob/master/src/net/textproto/reader.go?name=release#16" title="View Source">☞</a>为了让调用者处理拒绝服务攻击,Reader接口应该允许他们设置和重设从连接读取的字节数。 </p></div>
|
175
src/docs/go/net/url.html
Normal file
175
src/docs/go/net/url.html
Normal file
@@ -0,0 +1,175 @@
|
||||
<div class="container">
|
||||
<h1 id="pkg-overview">package url</h1>
|
||||
<p><code>import "net/url"</code>
|
||||
</p><p>url包解析URL并实现了查询的逸码,参见<a href="http://tools.ietf.org/html/rfc3986">RFC 3986</a>。</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="QueryEscape">func <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#173" title="View Source">QueryEscape</a> </h2>
|
||||
<pre class="funcdecl">func QueryEscape(s <a href="http://godoc.org/builtin#string">string</a>) <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>QueryEscape函数对s进行转码使之可以安全的用在URL查询里。</p>
|
||||
<h2 id="QueryUnescape">func <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#112" title="View Source">QueryUnescape</a> </h2>
|
||||
<pre class="funcdecl">func QueryUnescape(s <a href="http://godoc.org/builtin#string">string</a>) (<a href="http://godoc.org/builtin#string">string</a>, <a href="http://godoc.org/builtin#error">error</a>)</pre>
|
||||
<p align="left">QueryUnescape函数用于将QueryEscape转码的字符串还原。它会把%AB改为字节0xAB,将'+'改为' '。如果有某个%后面未跟两个十六进制数字,本函数会返回错误。</p>
|
||||
<h2 id="Error">type <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#18" title="View Source">Error</a> </h2>
|
||||
<pre>type Error struct {
|
||||
<span id="Error.Op">Op</span> <a href="http://godoc.org/builtin#string">string</a>
|
||||
<span id="Error.URL">URL</span> <a href="http://godoc.org/builtin#string">string</a>
|
||||
<span id="Error.Err">Err</span> <a href="http://godoc.org/builtin#error">error</a>
|
||||
}</pre>
|
||||
<p>Error会报告一个错误,以及导致该错误发生的URL和操作。</p>
|
||||
<h3 id="Error.Error">func (*Error) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#24" title="View Source">Error</a> </h3>
|
||||
<pre class="funcdecl">func (e *<a href="#Error">Error</a>) Error() <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<h2 id="EscapeError">type <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#59" title="View Source">EscapeError</a> </h2>
|
||||
<pre>type EscapeError <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<h3 id="EscapeError.Error">func (EscapeError) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#61" title="View Source">Error</a> </h3>
|
||||
<pre class="funcdecl">func (e <a href="#EscapeError">EscapeError</a>) Error() <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<h2 id="URL">type <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#230" title="View Source">URL</a> </h2>
|
||||
<pre>type URL struct {
|
||||
<span id="URL.Scheme">Scheme</span> <a href="http://godoc.org/builtin#string">string</a>
|
||||
<span id="URL.Opaque">Opaque</span> <a href="http://godoc.org/builtin#string">string</a> <span class="com">// 编码后的不透明数据</span>
|
||||
<span id="URL.User">User</span> *<a href="#Userinfo">Userinfo</a> <span class="com">// 用户名和密码信息</span>
|
||||
<span id="URL.Host">Host</span> <a href="http://godoc.org/builtin#string">string</a> <span class="com">// host或host:port</span>
|
||||
<span id="URL.Path">Path</span> <a href="http://godoc.org/builtin#string">string</a>
|
||||
<span id="URL.RawQuery">RawQuery</span> <a href="http://godoc.org/builtin#string">string</a> <span class="com">// 编码后的查询字符串,没有'?'</span>
|
||||
<span id="URL.Fragment">Fragment</span> <a href="http://godoc.org/builtin#string">string</a> <span class="com">// 引用的片段(文档位置),没有'#'</span>
|
||||
}</pre>
|
||||
<p>URL类型代表一个解析后的URL(或者说,一个URL参照)。URL基本格式如下:</p>
|
||||
<pre>scheme://[userinfo@]host/path[?query][#fragment]
|
||||
</pre>
|
||||
<p>scheme后不是冒号加双斜线的URL被解释为如下格式:</p>
|
||||
<pre>scheme:opaque[?query][#fragment]
|
||||
</pre>
|
||||
<p>注意路径字段是以解码后的格式保存的,如/%47%6f%2f会变成/Go/。这导致我们无法确定Path字段中的斜线是来自原始URL还是解码前的%2f。除非一个客户端必须使用其他程序/函数来解析原始URL或者重构原始URL,这个区别并不重要。此时,HTTP服务端可以查询req.RequestURI,而HTTP客户端可以使用URL{Host: "example.com", Opaque: "//example.com/Go%2f"}代替{Host: "example.com", Path: "/Go/"}。</p>
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default" id="example-URL">
|
||||
<div class="panel-heading" onclick="document.getElementById('ex-URL').style.display = document.getElementById('ex-URL').style.display=='none'?'block':'none';">Example</div>
|
||||
<div class="panel-collapse collapse" id="ex-URL">
|
||||
<div class="panel-body">
|
||||
<pre>u, err := url.Parse("http://bing.com/search?q=dotnet")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
u.Scheme = "https"
|
||||
u.Host = "google.com"
|
||||
q := u.Query()
|
||||
q.Set("q", "golang")
|
||||
u.RawQuery = q.Encode()
|
||||
fmt.Println(u)</pre>
|
||||
<p>Output:
|
||||
</p><pre>https://google.com/search?q=golang
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h3 id="Parse">func <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#333" title="View Source">Parse</a> </h3>
|
||||
<pre class="funcdecl">func Parse(rawurl <a href="http://godoc.org/builtin#string">string</a>) (url *<a href="#URL">URL</a>, err <a href="http://godoc.org/builtin#error">error</a>)</pre>
|
||||
<p>Parse函数解析rawurl为一个URL结构体,rawurl可以是绝对地址,也可以是相对地址。</p>
|
||||
<h3 id="ParseRequestURI">func <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#353" title="View Source">ParseRequestURI</a> </h3>
|
||||
<pre class="funcdecl">func ParseRequestURI(rawurl <a href="http://godoc.org/builtin#string">string</a>) (url *<a href="#URL">URL</a>, err <a href="http://godoc.org/builtin#error">error</a>)</pre>
|
||||
<p>ParseRequestURI函数解析rawurl为一个URL结构体,本函数会假设rawurl是在一个HTTP请求里,因此会假设该参数是一个绝对URL或者绝对路径,并会假设该URL没有#fragment后缀。(网页浏览器会在去掉该后缀后才将网址发送到网页服务器)</p>
|
||||
<h3 id="URL.IsAbs">func (*URL) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#624" title="View Source">IsAbs</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#URL">URL</a>) IsAbs() <a href="http://godoc.org/builtin#bool">bool</a></pre>
|
||||
<p>函数在URL是绝对URL时才返回真。</p>
|
||||
<h3 id="URL.Query">func (*URL) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#677" title="View Source">Query</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#URL">URL</a>) Query() <a href="#Values">Values</a></pre>
|
||||
<p>Query方法解析RawQuery字段并返回其表示的Values类型键值对。</p>
|
||||
<h3 id="URL.RequestURI">func (*URL) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#684" title="View Source">RequestURI</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#URL">URL</a>) RequestURI() <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>RequestURI方法返回编码好的path?query或opaque?query字符串,用在HTTP请求里。</p>
|
||||
<h3 id="URL.String">func (*URL) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#443" title="View Source">String</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#URL">URL</a>) String() <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>String将URL重构为一个合法URL字符串。</p>
|
||||
<h3 id="URL.Parse">func (*URL) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#631" title="View Source">Parse</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#URL">URL</a>) Parse(ref <a href="http://godoc.org/builtin#string">string</a>) (*<a href="#URL">URL</a>, <a href="http://godoc.org/builtin#error">error</a>)</pre>
|
||||
<p align="left">Parse方法以u为上下文来解析一个URL,ref可以是绝对或相对URL。</p>
|
||||
<p align="left">本方法解析失败会返回nil, err;否则返回结果和ResolveReference一致。</p>
|
||||
<h3 id="URL.ResolveReference">func (*URL) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#645" title="View Source">ResolveReference</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#URL">URL</a>) ResolveReference(ref *<a href="#URL">URL</a>) *<a href="#URL">URL</a></pre>
|
||||
<p>本方法根据一个绝对URI将一个URI补全为一个绝对URI,参见<a href="http://tools.ietf.org/html/rfc3986">RFC 3986</a> 节 5.2。参数ref可以是绝对URI或者相对URI。ResolveReference总是返回一个新的URL实例,即使该实例和u或者ref完全一样。如果ref是绝对URI,本方法会忽略参照URI并返回ref的一个拷贝。</p>
|
||||
<h2 id="Userinfo">type <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#261" title="View Source">Userinfo</a> </h2>
|
||||
<pre>type Userinfo struct {
|
||||
<span class="com">// 内含隐藏或非导出字段</span>
|
||||
}</pre>
|
||||
<p>Userinfo类型是一个URL的用户名和密码细节的一个不可修改的封装。一个真实存在的Userinfo值必须保证有用户名(但根据 <a href="http://tools.ietf.org/html/rfc2396">RFC 2396</a>可以是空字符串)以及一个可选的密码。</p>
|
||||
<h3 id="User">func <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#242" title="View Source">User</a> </h3>
|
||||
<pre class="funcdecl">func User(username <a href="http://godoc.org/builtin#string">string</a>) *<a href="#Userinfo">Userinfo</a></pre>
|
||||
<p>User函数返回一个用户名设置为username的不设置密码的*Userinfo。</p>
|
||||
<h3 id="UserPassword">func <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#253" title="View Source">UserPassword</a> </h3>
|
||||
<pre class="funcdecl">func UserPassword(username, password <a href="http://godoc.org/builtin#string">string</a>) *<a href="#Userinfo">Userinfo</a></pre>
|
||||
<p align="left">UserPassword函数返回一个用户名设置为username、密码设置为password的*Userinfo。</p>
|
||||
<p align="left">这个函数应该只用于老式的站点,因为风险很大,不建议使用,参见<a href="http://tools.ietf.org/html/rfc2396">RFC 2396</a>。</p>
|
||||
<h3 id="Userinfo.Username">func (*Userinfo) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#268" title="View Source">Username</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#Userinfo">Userinfo</a>) Username() <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>Username方法返回用户名。</p>
|
||||
<h3 id="Userinfo.Password">func (*Userinfo) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#273" title="View Source">Password</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#Userinfo">Userinfo</a>) Password() (<a href="http://godoc.org/builtin#string">string</a>, <a href="http://godoc.org/builtin#bool">bool</a>)</pre>
|
||||
<p>如果设置了密码返回密码和真,否则会返回假。</p>
|
||||
<h3 id="Userinfo.String">func (*Userinfo) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#282" title="View Source">String</a> </h3>
|
||||
<pre class="funcdecl">func (u *<a href="#Userinfo">Userinfo</a>) String() <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>String方法返回编码后的用户信息,格式为"username[:password]"。</p>
|
||||
<h2 id="Values">type <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#482" title="View Source">Values</a> </h2>
|
||||
<pre>type Values map[<a href="http://godoc.org/builtin#string">string</a>][]<a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>Values将建映射到值的列表。它一般用于查询的参数和表单的属性。不同于http.Header这个字典类型,Values的键是大小写敏感的。</p>
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default" id="example-Values">
|
||||
<div class="panel-heading" onclick="document.getElementById('ex-Values').style.display = document.getElementById('ex-Values').style.display=='none'?'block':'none';">Example</div>
|
||||
<div class="panel-collapse collapse" id="ex-Values">
|
||||
<div class="panel-body">
|
||||
<pre>v := url.Values{}
|
||||
v.Set("name", "Ava")
|
||||
v.Add("friend", "Jess")
|
||||
v.Add("friend", "Sarah")
|
||||
v.Add("friend", "Zoe")
|
||||
<span class="com">// v.Encode() == "name=Ava&friend=Jess&friend=Sarah&friend=Zoe"</span>
|
||||
fmt.Println(v.Get("name"))
|
||||
fmt.Println(v.Get("friend"))
|
||||
fmt.Println(v["friend"])</pre>
|
||||
<p>Output:
|
||||
</p><pre>Ava
|
||||
Jess
|
||||
[Jess Sarah Zoe]
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h3 id="ParseQuery">func <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#521" title="View Source">ParseQuery</a> </h3>
|
||||
<pre class="funcdecl">func ParseQuery(query <a href="http://godoc.org/builtin#string">string</a>) (m <a href="#Values">Values</a>, err <a href="http://godoc.org/builtin#error">error</a>)</pre>
|
||||
<p>ParseQuery函数解析一个URL编码的查询字符串,并返回可以表示该查询的Values类型的字典。本函数总是返回一个包含了所有合法查询参数的非nil字典,err用来描述解码时遇到的(如果有)第一个错误。</p>
|
||||
<h3 id="Values.Get">func (Values) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#488" title="View Source">Get</a> </h3>
|
||||
<pre class="funcdecl">func (v <a href="#Values">Values</a>) Get(key <a href="http://godoc.org/builtin#string">string</a>) <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>Get会获取key对应的值集的第一个值。如果没有对应key的值集会返回空字符串。获取值集请直接用map。</p>
|
||||
<h3 id="Values.Set">func (Values) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#501" title="View Source">Set</a> </h3>
|
||||
<pre class="funcdecl">func (v <a href="#Values">Values</a>) Set(key, value <a href="http://godoc.org/builtin#string">string</a>)</pre>
|
||||
<p>Set方法将key对应的值集设为只有value,它会替换掉已有的值集。</p>
|
||||
<h3 id="Values.Add">func (Values) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#507" title="View Source">Add</a> </h3>
|
||||
<pre class="funcdecl">func (v <a href="#Values">Values</a>) Add(key, value <a href="http://godoc.org/builtin#string">string</a>)</pre>
|
||||
<p>Add将value添加到key关联的值集里原有的值的后面。</p>
|
||||
<h3 id="Values.Del">func (Values) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#512" title="View Source">Del</a> </h3>
|
||||
<pre class="funcdecl">func (v <a href="#Values">Values</a>) Del(key <a href="http://godoc.org/builtin#string">string</a>)</pre>
|
||||
<p>Del删除key关联的值集。</p>
|
||||
<h3 id="Values.Encode">func (Values) <a href="https://github.com/golang/go/blob/master/src/net/url/url.go?name=release#563" title="View Source">Encode</a> </h3>
|
||||
<pre class="funcdecl">func (v <a href="#Values">Values</a>) Encode() <a href="http://godoc.org/builtin#string">string</a></pre>
|
||||
<p>Encode方法将v编码为url编码格式("bar=baz&foo=quux"),编码时会以键进行排序。</p>
|
||||
</div>
|
Reference in New Issue
Block a user