ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 概述 实现了对基于文本的请求/响应协议的通用支持 ## 语法 ### Func ``` func CanonicalMIMEHeaderKey(s string) string func TrimBytes(b []byte) []byte func TrimString(s string) string ``` ### Type ``` 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 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) func (h MIMEHeader) Values(key string) []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 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 ``` ## 实例 ### Reader ``` r := textproto.NewReader(bufio.NewReader(os.Stdin)) for{ line, err := r.ReadLine() if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", line) } ```