mirror of
https://github.com/golang/go
synced 2024-11-22 05:04:40 -07:00
doc: use consistent receiver names, when it makes sense.
Makes for prettier docs. R=golang-dev, dsymonds, r, rsc CC=golang-dev https://golang.org/cl/5576056
This commit is contained in:
parent
25c96cba2e
commit
eb53d472ef
@ -57,8 +57,8 @@ type FileHeader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FileInfo returns an os.FileInfo for the FileHeader.
|
// FileInfo returns an os.FileInfo for the FileHeader.
|
||||||
func (fh *FileHeader) FileInfo() os.FileInfo {
|
func (h *FileHeader) FileInfo() os.FileInfo {
|
||||||
return headerFileInfo{fh}
|
return headerFileInfo{h}
|
||||||
}
|
}
|
||||||
|
|
||||||
// headerFileInfo implements os.FileInfo.
|
// headerFileInfo implements os.FileInfo.
|
||||||
|
@ -546,15 +546,15 @@ Loop:
|
|||||||
// Read tokens until we find the end element.
|
// Read tokens until we find the end element.
|
||||||
// Token is taking care of making sure the
|
// Token is taking care of making sure the
|
||||||
// end element matches the start element we saw.
|
// end element matches the start element we saw.
|
||||||
func (p *Decoder) Skip() error {
|
func (d *Decoder) Skip() error {
|
||||||
for {
|
for {
|
||||||
tok, err := p.Token()
|
tok, err := d.Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch tok.(type) {
|
switch tok.(type) {
|
||||||
case StartElement:
|
case StartElement:
|
||||||
if err := p.Skip(); err != nil {
|
if err := d.Skip(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case EndElement:
|
case EndElement:
|
||||||
|
@ -112,13 +112,13 @@ func (bp *Part) populateHeaders() error {
|
|||||||
|
|
||||||
// Read reads the body of a part, after its headers and before the
|
// Read reads the body of a part, after its headers and before the
|
||||||
// next part (if any) begins.
|
// next part (if any) begins.
|
||||||
func (bp *Part) Read(p []byte) (n int, err error) {
|
func (p *Part) Read(d []byte) (n int, err error) {
|
||||||
if bp.buffer.Len() >= len(p) {
|
if p.buffer.Len() >= len(d) {
|
||||||
// Internal buffer of unconsumed data is large enough for
|
// Internal buffer of unconsumed data is large enough for
|
||||||
// the read request. No need to parse more at the moment.
|
// the read request. No need to parse more at the moment.
|
||||||
return bp.buffer.Read(p)
|
return p.buffer.Read(d)
|
||||||
}
|
}
|
||||||
peek, err := bp.mr.bufReader.Peek(4096) // TODO(bradfitz): add buffer size accessor
|
peek, err := p.mr.bufReader.Peek(4096) // TODO(bradfitz): add buffer size accessor
|
||||||
unexpectedEof := err == io.EOF
|
unexpectedEof := err == io.EOF
|
||||||
if err != nil && !unexpectedEof {
|
if err != nil && !unexpectedEof {
|
||||||
return 0, fmt.Errorf("multipart: Part Read: %v", err)
|
return 0, fmt.Errorf("multipart: Part Read: %v", err)
|
||||||
@ -133,10 +133,10 @@ func (bp *Part) Read(p []byte) (n int, err error) {
|
|||||||
// string.
|
// string.
|
||||||
nCopy := 0
|
nCopy := 0
|
||||||
foundBoundary := false
|
foundBoundary := false
|
||||||
if idx := bytes.Index(peek, bp.mr.nlDashBoundary); idx != -1 {
|
if idx := bytes.Index(peek, p.mr.nlDashBoundary); idx != -1 {
|
||||||
nCopy = idx
|
nCopy = idx
|
||||||
foundBoundary = true
|
foundBoundary = true
|
||||||
} else if safeCount := len(peek) - len(bp.mr.nlDashBoundary); safeCount > 0 {
|
} else if safeCount := len(peek) - len(p.mr.nlDashBoundary); safeCount > 0 {
|
||||||
nCopy = safeCount
|
nCopy = safeCount
|
||||||
} else if unexpectedEof {
|
} else if unexpectedEof {
|
||||||
// If we've run out of peek buffer and the boundary
|
// If we've run out of peek buffer and the boundary
|
||||||
@ -145,11 +145,11 @@ func (bp *Part) Read(p []byte) (n int, err error) {
|
|||||||
return 0, io.ErrUnexpectedEOF
|
return 0, io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
if nCopy > 0 {
|
if nCopy > 0 {
|
||||||
if _, err := io.CopyN(bp.buffer, bp.mr.bufReader, int64(nCopy)); err != nil {
|
if _, err := io.CopyN(p.buffer, p.mr.bufReader, int64(nCopy)); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n, err = bp.buffer.Read(p)
|
n, err = p.buffer.Read(d)
|
||||||
if err == io.EOF && !foundBoundary {
|
if err == io.EOF && !foundBoundary {
|
||||||
// If the boundary hasn't been reached there's more to
|
// If the boundary hasn't been reached there's more to
|
||||||
// read, so don't pass through an EOF from the buffer
|
// read, so don't pass through an EOF from the buffer
|
||||||
@ -158,8 +158,8 @@ func (bp *Part) Read(p []byte) (n int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bp *Part) Close() error {
|
func (p *Part) Close() error {
|
||||||
io.Copy(ioutil.Discard, bp)
|
io.Copy(ioutil.Discard, p)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,29 +177,29 @@ type Reader struct {
|
|||||||
|
|
||||||
// NextPart returns the next part in the multipart or an error.
|
// NextPart returns the next part in the multipart or an error.
|
||||||
// When there are no more parts, the error io.EOF is returned.
|
// When there are no more parts, the error io.EOF is returned.
|
||||||
func (mr *Reader) NextPart() (*Part, error) {
|
func (r *Reader) NextPart() (*Part, error) {
|
||||||
if mr.currentPart != nil {
|
if r.currentPart != nil {
|
||||||
mr.currentPart.Close()
|
r.currentPart.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
expectNewPart := false
|
expectNewPart := false
|
||||||
for {
|
for {
|
||||||
line, err := mr.bufReader.ReadSlice('\n')
|
line, err := r.bufReader.ReadSlice('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("multipart: NextPart: %v", err)
|
return nil, fmt.Errorf("multipart: NextPart: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mr.isBoundaryDelimiterLine(line) {
|
if r.isBoundaryDelimiterLine(line) {
|
||||||
mr.partsRead++
|
r.partsRead++
|
||||||
bp, err := newPart(mr)
|
bp, err := newPart(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
mr.currentPart = bp
|
r.currentPart = bp
|
||||||
return bp, nil
|
return bp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasPrefixThenNewline(line, mr.dashBoundaryDash) {
|
if hasPrefixThenNewline(line, r.dashBoundaryDash) {
|
||||||
// Expected EOF
|
// Expected EOF
|
||||||
return nil, io.EOF
|
return nil, io.EOF
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ func (mr *Reader) NextPart() (*Part, error) {
|
|||||||
return nil, fmt.Errorf("multipart: expecting a new Part; got line %q", string(line))
|
return nil, fmt.Errorf("multipart: expecting a new Part; got line %q", string(line))
|
||||||
}
|
}
|
||||||
|
|
||||||
if mr.partsRead == 0 {
|
if r.partsRead == 0 {
|
||||||
// skip line
|
// skip line
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ func (mr *Reader) NextPart() (*Part, error) {
|
|||||||
// body of the previous part and the boundary line we
|
// body of the previous part and the boundary line we
|
||||||
// now expect will follow. (either a new part or the
|
// now expect will follow. (either a new part or the
|
||||||
// end boundary)
|
// end boundary)
|
||||||
if bytes.Equal(line, mr.nl) {
|
if bytes.Equal(line, r.nl) {
|
||||||
expectNewPart = true
|
expectNewPart = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ func valueOrDefault(value, def string) string {
|
|||||||
const defaultUserAgent = "Go http package"
|
const defaultUserAgent = "Go http package"
|
||||||
|
|
||||||
// Write writes an HTTP/1.1 request -- header and body -- in wire format.
|
// Write writes an HTTP/1.1 request -- header and body -- in wire format.
|
||||||
// This method consults the following fields of req:
|
// This method consults the following fields of the request:
|
||||||
// Host
|
// Host
|
||||||
// URL
|
// URL
|
||||||
// Method (defaults to "GET")
|
// Method (defaults to "GET")
|
||||||
@ -284,18 +284,18 @@ const defaultUserAgent = "Go http package"
|
|||||||
// If Body is present, Content-Length is <= 0 and TransferEncoding
|
// If Body is present, Content-Length is <= 0 and TransferEncoding
|
||||||
// hasn't been set to "identity", Write adds "Transfer-Encoding:
|
// hasn't been set to "identity", Write adds "Transfer-Encoding:
|
||||||
// chunked" to the header. Body is closed after it is sent.
|
// chunked" to the header. Body is closed after it is sent.
|
||||||
func (req *Request) Write(w io.Writer) error {
|
func (r *Request) Write(w io.Writer) error {
|
||||||
return req.write(w, false, nil)
|
return r.write(w, false, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteProxy is like Write but writes the request in the form
|
// WriteProxy is like Write but writes the request in the form
|
||||||
// expected by an HTTP proxy. In particular, WriteProxy writes the
|
// expected by an HTTP proxy. In particular, WriteProxy writes the
|
||||||
// initial Request-URI line of the request with an absolute URI, per
|
// initial Request-URI line of the request with an absolute URI, per
|
||||||
// section 5.1.2 of RFC 2616, including the scheme and host. In
|
// section 5.1.2 of RFC 2616, including the scheme and host.
|
||||||
// either case, WriteProxy also writes a Host header, using either
|
// In either case, WriteProxy also writes a Host header, using
|
||||||
// req.Host or req.URL.Host.
|
// either r.Host or r.URL.Host.
|
||||||
func (req *Request) WriteProxy(w io.Writer) error {
|
func (r *Request) WriteProxy(w io.Writer) error {
|
||||||
return req.write(w, true, nil)
|
return r.write(w, true, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// extraHeaders may be nil
|
// extraHeaders may be nil
|
||||||
|
@ -174,7 +174,7 @@ func (r *Response) ProtoAtLeast(major, minor int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Writes the response (header, body and trailer) in wire format. This method
|
// Writes the response (header, body and trailer) in wire format. This method
|
||||||
// consults the following fields of resp:
|
// consults the following fields of the response:
|
||||||
//
|
//
|
||||||
// StatusCode
|
// StatusCode
|
||||||
// ProtoMajor
|
// ProtoMajor
|
||||||
@ -186,28 +186,28 @@ func (r *Response) ProtoAtLeast(major, minor int) bool {
|
|||||||
// ContentLength
|
// ContentLength
|
||||||
// Header, values for non-canonical keys will have unpredictable behavior
|
// Header, values for non-canonical keys will have unpredictable behavior
|
||||||
//
|
//
|
||||||
func (resp *Response) Write(w io.Writer) error {
|
func (r *Response) Write(w io.Writer) error {
|
||||||
|
|
||||||
// RequestMethod should be upper-case
|
// RequestMethod should be upper-case
|
||||||
if resp.Request != nil {
|
if r.Request != nil {
|
||||||
resp.Request.Method = strings.ToUpper(resp.Request.Method)
|
r.Request.Method = strings.ToUpper(r.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status line
|
// Status line
|
||||||
text := resp.Status
|
text := r.Status
|
||||||
if text == "" {
|
if text == "" {
|
||||||
var ok bool
|
var ok bool
|
||||||
text, ok = statusText[resp.StatusCode]
|
text, ok = statusText[r.StatusCode]
|
||||||
if !ok {
|
if !ok {
|
||||||
text = "status code " + strconv.Itoa(resp.StatusCode)
|
text = "status code " + strconv.Itoa(r.StatusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
io.WriteString(w, "HTTP/"+strconv.Itoa(resp.ProtoMajor)+".")
|
io.WriteString(w, "HTTP/"+strconv.Itoa(r.ProtoMajor)+".")
|
||||||
io.WriteString(w, strconv.Itoa(resp.ProtoMinor)+" ")
|
io.WriteString(w, strconv.Itoa(r.ProtoMinor)+" ")
|
||||||
io.WriteString(w, strconv.Itoa(resp.StatusCode)+" "+text+"\r\n")
|
io.WriteString(w, strconv.Itoa(r.StatusCode)+" "+text+"\r\n")
|
||||||
|
|
||||||
// Process Body,ContentLength,Close,Trailer
|
// Process Body,ContentLength,Close,Trailer
|
||||||
tw, err := newTransferWriter(resp)
|
tw, err := newTransferWriter(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ func (resp *Response) Write(w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rest of header
|
// Rest of header
|
||||||
err = resp.Header.WriteSubset(w, respExcludeHeader)
|
err = r.Header.WriteSubset(w, respExcludeHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1078,8 +1078,8 @@ func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Han
|
|||||||
// of the server's certificate followed by the CA's certificate.
|
// of the server's certificate followed by the CA's certificate.
|
||||||
//
|
//
|
||||||
// If srv.Addr is blank, ":https" is used.
|
// If srv.Addr is blank, ":https" is used.
|
||||||
func (s *Server) ListenAndServeTLS(certFile, keyFile string) error {
|
func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
|
||||||
addr := s.Addr
|
addr := srv.Addr
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
addr = ":https"
|
addr = ":https"
|
||||||
}
|
}
|
||||||
@ -1101,7 +1101,7 @@ func (s *Server) ListenAndServeTLS(certFile, keyFile string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tlsListener := tls.NewListener(conn, config)
|
tlsListener := tls.NewListener(conn, config)
|
||||||
return s.Serve(tlsListener)
|
return srv.Serve(tlsListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeoutHandler returns a Handler that runs h with the given time limit.
|
// TimeoutHandler returns a Handler that runs h with the given time limit.
|
||||||
|
@ -431,30 +431,30 @@ func ParseWithReference(rawurlref string) (url *URL, err error) {
|
|||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// String reassembles url into a valid URL string.
|
// String reassembles the URL into a valid URL string.
|
||||||
func (url *URL) String() string {
|
func (u *URL) String() string {
|
||||||
// TODO: Rewrite to use bytes.Buffer
|
// TODO: Rewrite to use bytes.Buffer
|
||||||
result := ""
|
result := ""
|
||||||
if url.Scheme != "" {
|
if u.Scheme != "" {
|
||||||
result += url.Scheme + ":"
|
result += u.Scheme + ":"
|
||||||
}
|
}
|
||||||
if url.Opaque != "" {
|
if u.Opaque != "" {
|
||||||
result += url.Opaque
|
result += u.Opaque
|
||||||
} else {
|
} else {
|
||||||
if url.Host != "" || url.User != nil {
|
if u.Host != "" || u.User != nil {
|
||||||
result += "//"
|
result += "//"
|
||||||
if u := url.User; u != nil {
|
if u := u.User; u != nil {
|
||||||
result += u.String() + "@"
|
result += u.String() + "@"
|
||||||
}
|
}
|
||||||
result += url.Host
|
result += u.Host
|
||||||
}
|
}
|
||||||
result += escape(url.Path, encodePath)
|
result += escape(u.Path, encodePath)
|
||||||
}
|
}
|
||||||
if url.RawQuery != "" {
|
if u.RawQuery != "" {
|
||||||
result += "?" + url.RawQuery
|
result += "?" + u.RawQuery
|
||||||
}
|
}
|
||||||
if url.Fragment != "" {
|
if u.Fragment != "" {
|
||||||
result += "#" + escape(url.Fragment, encodeFragment)
|
result += "#" + escape(u.Fragment, encodeFragment)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -585,8 +585,8 @@ func resolvePath(basepath string, refpath string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsAbs returns true if the URL is absolute.
|
// IsAbs returns true if the URL is absolute.
|
||||||
func (url *URL) IsAbs() bool {
|
func (u *URL) IsAbs() bool {
|
||||||
return url.Scheme != ""
|
return u.Scheme != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse parses a URL in the context of a base URL. The URL in ref
|
// Parse parses a URL in the context of a base URL. The URL in ref
|
||||||
|
Loading…
Reference in New Issue
Block a user