亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結(jié)構(gòu)heap) container/list(容器數(shù)據(jù)結(jié)構(gòu)list) container/ring(容器數(shù)據(jù)結(jié)構(gòu)ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調(diào)色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達(dá)式) regexp/syntax runtime runtime(運(yùn)行時) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "net/textproto"

  • 概況

  • 索引

概況

Package textproto 以 HTTP,NNTP 和 SMTP 的風(fēng)格實現(xiàn)對基于文本的請求/響應(yīng)協(xié)議的通用支持。

該軟件包提供:

Error,表示來自服務(wù)器的數(shù)字錯誤響應(yīng)。

Pipeline,管理客戶端中的流水線請求和響應(yīng)。

Reader,讀取數(shù)字響應(yīng)代碼行,鍵:值標(biāo)題,用連續(xù)行上的前導(dǎo)空格包裹的行,以及單獨以行結(jié)束的整個文本塊。

Writer,編寫點編碼的文本塊。

Conn,一種便于閱讀器,書寫器和管道的包裝,可用于單一網(wǎng)絡(luò)連接。

索引

  • func CanonicalMIMEHeaderKey(s string) string

  • func TrimBytes(b []byte) []byte

  • func TrimString(s string) string

  • type Conn

  • func Dial(network, addr string) (*Conn, error)

  • func NewConn(conn io.ReadWriteCloser) *Conn

  • func (c *Conn) Close() error

  • func (c *Conn) Cmd(format string, args ...interface{}) (id uint, err error)

  • type Error

  • func (e *Error) Error() string

  • type MIMEHeader

  • func (h MIMEHeader) Add(key, value string)

  • func (h MIMEHeader) Del(key string)

  • func (h MIMEHeader) Get(key string) string

  • func (h MIMEHeader) Set(key, value string)

  • type Pipeline

  • func (p *Pipeline) EndRequest(id uint)

  • func (p *Pipeline) EndResponse(id uint)

  • func (p *Pipeline) Next() uint

  • func (p *Pipeline) StartRequest(id uint)

  • func (p *Pipeline) StartResponse(id uint)

  • type ProtocolError

  • func (p ProtocolError) Error() string

  • type Reader

  • func NewReader(r *bufio.Reader) *Reader

  • func (r *Reader) DotReader() io.Reader

  • func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err error)

  • func (r *Reader) ReadContinuedLine() (string, error)

  • func (r *Reader) ReadContinuedLineBytes() ([]byte, error)

  • func (r *Reader) ReadDotBytes() ([]byte, error)

  • func (r *Reader) ReadDotLines() ([]string, error)

  • func (r *Reader) ReadLine() (string, error)

  • func (r *Reader) ReadLineBytes() ([]byte, error)

  • func (r *Reader) ReadMIMEHeader() (MIMEHeader, error)

  • func (r *Reader) ReadResponse(expectCode int) (code int, message string, err error)

  • type Writer

  • func NewWriter(w *bufio.Writer) *Writer

  • func (w *Writer) DotWriter() io.WriteCloser

  • func (w *Writer) PrintfLine(format string, args ...interface{}) error

包文件

header.go pipeline.go reader.go textproto.go writer.go

func CanonicalMIMEHeaderKey

func CanonicalMIMEHeaderKey(s string) string

CanonicalMIMEHeaderKey 返回 MIME 標(biāo)頭密鑰的規(guī)范格式。規(guī)范化將第一個字母和連字符后面的任何字母轉(zhuǎn)換為大寫; 其余的都轉(zhuǎn)換為小寫。例如,“accept-encoding”的規(guī)范密鑰是“Accept-Encoding”。假設(shè) MIME 標(biāo)題密鑰僅為 ASCII 。如果 s 包含空格或無效標(biāo)題字段字節(jié),則不做任何修改就返回。

func TrimBytes

func TrimBytes(b []byte) []byte

TrimBytes 返回 b,沒有前導(dǎo)和尾隨 ASCII 空間。

func TrimString

func TrimString(s string) string

TrimString 返回 s,沒有前導(dǎo)和尾隨的 ASCII 空間。

type Conn

Conn 表示文本網(wǎng)絡(luò)協(xié)議連接。它由讀寫器組成,用于管理 I/O 和管道,以便對連接上的并發(fā)請求進(jìn)行排序。這些嵌入式類型帶有它們的方法; 有關(guān)詳細(xì)信息,請參閱這些類型的文檔。

type Conn struct {
        Reader
        Writer
        Pipeline        // contains filtered or unexported fields}

func Dial

func Dial(network, addr string) (*Conn, error)

Dial 使用 net.Dial 連接到給定網(wǎng)絡(luò)上的給定地址,然后為連接返回一個新的 Conn 。

func NewConn

func NewConn(conn io.ReadWriteCloser) *Conn

NewConn 使用 conn 返回一個新的 Conn 用于 I/O 。

func (*Conn) Close

func (c *Conn) Close() error

Close 關(guān)閉連接。

func (*Conn) Cmd

func (c *Conn) Cmd(format string, args ...interface{}) (id uint, err error)

Cmd 是一個方便的方法,它在流水線中等待輪流后發(fā)送命令。命令文本是使用 args 格式化格式并追加 \r \n 的結(jié)果。Cmd 返回命令的 ID,用于 StartResponse 和 EndResponse 。

例如,客戶端可能運(yùn)行 HELP 命令,該命令使用以下命令返回點體:

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)

type Error

錯誤表示來自服務(wù)器的數(shù)字錯誤響應(yīng)。

type Error struct {
        Code int
        Msg  string}

func (*Error) Error

func (e *Error) Error() string

type MIMEHeader

MIMEHeader 表示將值映射到多組值的 MIME 樣式標(biāo)題。

type MIMEHeader map[string][]string

func (MIMEHeader) Add

func (h MIMEHeader) Add(key, value string)

添加將關(guān)鍵字值對添加到標(biāo)題。它附加到與鍵相關(guān)的任何現(xiàn)有值。

func (MIMEHeader) Del

func (h MIMEHeader) Del(key string)

Del 刪除與鍵關(guān)聯(lián)的值。

func (MIMEHeader) Get

func (h MIMEHeader) Get(key string) string

獲取與給定鍵相關(guān)的第一個值。它不區(qū)分大小寫; CanonicalMIMEHeaderKey 用于規(guī)范提供的密鑰。如果沒有與該鍵關(guān)聯(lián)的值,Get 返回“”。要訪問密鑰的多個值或使用非規(guī)范密鑰,請直接訪問地圖。

func (MIMEHeader) Set

func (h MIMEHeader) Set(key, value string)

Set 將與鍵關(guān)聯(lián)的標(biāo)題條目設(shè)置為單個元素值。它取代了任何與鍵相關(guān)的現(xiàn)有值。

type Pipeline

管道管理流水線順序請求/響應(yīng)序列。

要使用管道 p 來管理連接上的多個客戶端,每個客戶端應(yīng)運(yùn)行:

id := p.Next()// take a numberp.StartRequest(id)// wait for turn to send request?send request?
p.EndRequest(id)// notify Pipeline that request is sentp.StartResponse(id)// wait for turn to read response?read response?
p.EndResponse(id)// notify Pipeline that response is read

流水線服務(wù)器可以使用相同的調(diào)用來確保并行計算的響應(yīng)以正確的順序?qū)懭搿?/p>

type Pipeline struct {        // contains filtered or unexported fields}

func (*Pipeline) EndRequest

func (p *Pipeline) EndRequest(id uint)

EndRequest 通知 p 具有給定 ID 的請求已發(fā)送(或者,如果這是一個服務(wù)器,則接收)。

func (*Pipeline) EndResponse

func (p *Pipeline) EndResponse(id uint)

EndResponse 通知 p 已收到給定 ID 的響應(yīng)(或者,如果是服務(wù)器,則發(fā)送)。

func (*Pipeline) Next

func (p *Pipeline) Next() uint

接下來返回請求/響應(yīng)對的下一個 ID 。

func (*Pipeline) StartRequest

func (p *Pipeline) StartRequest(id uint)

StartRequest 阻塞,直到發(fā)送(或者,如果這是服務(wù)器,接收)具有給定 ID 的請求。

func (*Pipeline) StartResponse

func (p *Pipeline) StartResponse(id uint)

StartResponse 塊直到需要接收(或者,如果這是服務(wù)器,發(fā)送)具有給定 ID 的請求。

type ProtocolError

ProtocolError 描述協(xié)議違規(guī),例如無效響應(yīng)或掛斷連接。

type ProtocolError string

func (ProtocolError) Error

func (p ProtocolError) Error() string

type Reader

Reader 實現(xiàn)便捷方法來讀取來自文本協(xié)議網(wǎng)絡(luò)連接的請求或響應(yīng)。

type Reader struct {
        R *bufio.Reader        // contains filtered or unexported fields}

func NewReader

func NewReader(r *bufio.Reader) *Reader

NewReader 從 r 返回一個新的 Reader 讀數(shù)。

為了避免拒絕服務(wù)攻擊,提供的 bufio.Reader 應(yīng)該從 io.LimitReader 或類似的 Reader 中讀取以限制響應(yīng)的大小。

func (*Reader) DotReader

func (r *Reader) DotReader() io.Reader

DotReader 返回一個新的 Reader,它使用從 r 讀取的點編碼塊的解碼文本滿足 Reads。返回的 Reader 只有在下一次調(diào)用 r 時才有效。

點編碼是用于文本協(xié)議(如 SMTP)中的數(shù)據(jù)塊的常用成幀。數(shù)據(jù)由一系列行組成,每行以“\ r \ n”結(jié)尾。序列本身結(jié)束于只包含一個點的一行:“。\ r \ n”。以點開頭的行會用另外一個點進(jìn)行轉(zhuǎn)義,以避免看起來像序列的結(jié)尾。

Reader 的 Read 方法返回的解碼格式會將“\ r \ n”行尾重寫為簡單的“\ n”,如果存在則刪除前導(dǎo)點轉(zhuǎn)義,并在消耗(并放棄)順序線。

func (*Reader) ReadCodeLine

func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err error)

ReadCodeLine 讀取表單的響應(yīng)代碼行

code message

其中代碼是一個三位數(shù)的狀態(tài)碼,并且該消息延伸到該行的其余部分。這樣的一個例子是:

220 plan9.bell-labs.com ESMTP

如果狀態(tài)的前綴與 expectCode 中的數(shù)字不匹配,則 ReadCodeLine 返回,并將 err 設(shè)置為 &Error {code,message } 。例如,如果 expectCode 為31,如果狀態(tài)不在 310,319 范圍內(nèi),則會返回錯誤。

如果響應(yīng)是多行的,則 ReadCodeLine 返回一個錯誤。

expectCode <= 0將禁用狀態(tài)碼的檢查。

func (*Reader) ReadContinuedLine

func (r *Reader) ReadContinuedLine() (string, error)

ReadContinuedLine 從 r 中讀取一個可能的連續(xù)行,消除最后的尾隨 ASCII 空白。如果以空格或制表符開頭,則第一行之后的行被認(rèn)為是連續(xù)的。在返回的數(shù)據(jù)中,延續(xù)線與前一行僅由一個空格分開:刪除了換行符和前導(dǎo)空格。

例如,考慮這個輸入:

Line 1
  continued...Line 2

第一次調(diào)用 ReadContinuedLine 將返回“第1行繼續(xù)...”,第2次將返回“第2行”。

只有白色空間的行不會繼續(xù)。

func (*Reader) ReadContinuedLineBytes

func (r *Reader) ReadContinuedLineBytes() ([]byte, error)

ReadContinuedLineBytes 類似于 ReadContinuedLine,但返回 [] 字節(jié)而不是字符串。

func (*Reader) ReadDotBytes

func (r *Reader) ReadDotBytes() ([]byte, error)

ReadDotBytes 讀取點編碼并返回解碼后的數(shù)據(jù)。

有關(guān)點編碼的詳細(xì)信息,請參閱 DotReader 方法的文檔。

func (*Reader) ReadDotLines

func (r *Reader) ReadDotLines() ([]string, error)

ReadDotLines 讀取一個點編碼并返回一個包含解碼行的片段,最后的 \ r \ n 或 \ n 將被刪除。

有關(guān)點編碼的詳細(xì)信息,請參閱 DotReader 方法的文檔。

func (*Reader) ReadLine

func (r *Reader) ReadLine() (string, error)

ReadLine 從 r 讀取一行,從返回的字符串中刪除最后的 \ n 或 \ r \ n 。

func (*Reader) ReadLineBytes

func (r *Reader) ReadLineBytes() ([]byte, error)

ReadLineBytes 與 ReadLine 類似,但返回 []字節(jié)而不是字符串。

func (*Reader) ReadMIMEHeader

func (r *Reader) ReadMIMEHeader() (MIMEHeader, error)

ReadMIMEHeader 從 r 讀取 MIME 風(fēng)格的頭文件。標(biāo)題是可能繼續(xù)的 Key:Value 行以空行結(jié)尾的序列。返回的映射 m 將 CanonicalMIMEHeaderKey(key)映射為輸入中遇到的相同順序的值序列。

例如,考慮這個輸入:

My-Key: Value 1Long-Key: Even
       Longer Value
My-Key: Value 2

鑒于該輸入,ReadMIMEHeader 返回 map:

map[string][]string{"My-Key": {"Value 1", "Value 2"},"Long-Key": {"Even Longer Value"},}

func (*Reader) ReadResponse

func (r *Reader) ReadResponse(expectCode int) (code int, message string, err error)

ReadResponse 讀取表單的多行響應(yīng):

code-message line 1code-message line 2...code message line n

代碼是一個三位數(shù)的狀態(tài)碼。第一行以代碼和連字符開頭。響應(yīng)由以相同的代碼和空格開始的行結(jié)束。消息中的每一行都用換行符分隔(\ n)。

請參閱 RFC 959(http://www.ietf.org/rfc/rfc959.txt)的第36頁,了解接受的另一種形式的響應(yīng)的詳細(xì)信息:

code-message line 1message line 2...code message line n

如果狀態(tài)的前綴與 expectCode 中的數(shù)字不匹配,則 ReadResponse 返回,并將 err 設(shè)置為 &Error {code,message}。例如,如果 expectCode 為31,如果狀態(tài)不在310,319范圍內(nèi),則會返回錯誤。

expectCode <= 0 將禁用狀態(tài)碼的檢查。

type Writer

Writer 實現(xiàn)方便的方法來編寫對文本協(xié)議網(wǎng)絡(luò)連接的請求或響應(yīng)。

type Writer struct {
        W *bufio.Writer        // contains filtered or unexported fields}

func NewWriter

func NewWriter(w *bufio.Writer) *Writer

NewWriter 返回一個寫入 w 的新 Writer 。

func (*Writer) DotWriter

func (w *Writer) DotWriter() io.WriteCloser

DotWriter 返回一個寫入器,可以用來為 w 寫一個點編碼。它需要在需要時插入前導(dǎo)點,將行結(jié)束符 \ n 轉(zhuǎn)換為 \ r \ n,并在 DotWriter 關(guān)閉時添加最后的 \ r \ n 行。調(diào)用者應(yīng)在下一次調(diào)用 w 上的方法之前關(guān)閉 DotWriter 。

有關(guān)點編碼的詳細(xì)信息,請參閱 Reader 的 DotReader 方法的文檔。

func (*Writer) PrintfLine

func (w *Writer) PrintfLine(format string, args ...interface{}) error

PrintfLine 寫入格式化的輸出,后面跟著 \ r \ n 。

Previous article: Next article: