本文整理汇总了Golang中net/textproto.Reader类的典型用法代码示例。如果您正苦于以下问题:Golang Reader类的具体用法?Golang Reader怎么用?Golang Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reader类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: extractCommand
func extractCommand(reader *textproto.Reader) (command, error) {
line, err := reader.ReadLine()
if err != nil {
return getStats, err
}
for index, commandName := range commandNames {
if commandName == line {
return command(index), nil
}
}
return getStats, errInvalidCommand
}
示例2: putTextprotoReader
func putTextprotoReader(r *textproto.Reader) {
r.R = nil
select {
case textprotoReaderCache <- r:
default:
}
}
示例3: parseHeaderStr
/**
The Email Header is expected to follow this spec:
Mail Header: Return-Path: <[email protected]t.localdomain>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: by domain.de (Postfix, from userid 0)
id 034C710090703; Sat, 16 Mar 2013 02:05:26 +0100 (CET)
To: [email protected], [email protected], [...]
Subject: Test Message
Message-Id: <[email protected]>
Date: Sat, _6 Mar 2013 02:05:26 +0100 (CET)
From: [email protected] (root)
which translates to a more generic form of:
Key : Blank Value \newline
*/
func parseHeaderStr(header string) (*Header, error) {
if 0 == len(header) {
return nil, errors.New("Header string is empty")
}
var (
reader *textproto.Reader = textproto.NewReader(bufio.NewReader(bytes.NewBufferString(header)))
mHeader textproto.MIMEHeader
err error
)
if mHeader, err = reader.ReadMIMEHeader(); err != nil && err != io.EOF {
return nil, err
}
// for key, val := range mHeader {
// fmt.Printf("&&&& %s -> %s\n", key, val)
// }
return parseMainHeaderContent(mHeader)
}
示例4: reader
func (s *Service) reader(r *textproto.Reader) {
for {
str, e := r.ReadLine()
if e != nil {
break
}
req := rxreq.FindStringSubmatch(str)
if req == nil {
break
}
if req[1] == "QUIT" {
break
}
switch req[1] {
case "PULL":
if s.Debug {
fmt.Println("got pull", req[2])
}
k, e := base64.StdEncoding.DecodeString(req[2])
if e == nil {
s.rpull <- k
}
case "PUSH":
_, e = io.ReadFull(r.R, s.rblock)
if e == nil {
h := sha512.New()
h.Write(s.rblock)
hash := h.Sum([]byte{})
if s.acc.Accept(hash) {
if s.Debug {
fmt.Println("got push", base64.StdEncoding.EncodeToString(hash), "accept")
}
s.bck.Store(hash, s.rblock)
} else {
if s.Debug {
fmt.Println("got push", base64.StdEncoding.EncodeToString(hash), "refuse")
}
}
}
}
}
}
示例5: putTextprotoReader
func putTextprotoReader(r *textproto.Reader) {
r.R = nil
textprotoReaderPool.Put(r)
}