當前位置: 首頁>>代碼示例>>Golang>>正文


Golang textproto.Conn類代碼示例

本文整理匯總了Golang中net/textproto.Conn的典型用法代碼示例。如果您正苦於以下問題:Golang Conn類的具體用法?Golang Conn怎麽用?Golang Conn使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Conn類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: handleList

func handleList(args []string, s *session, c *textproto.Conn) error {
	ltype := "active"
	if len(args) > 0 {
		ltype = strings.ToLower(args[0])
	}

	if ltype == "overview.fmt" {
		return handleListOverviewFmt(c)
	}

	groups, err := s.backend.ListGroups(-1)
	if err != nil {
		return err
	}
	c.PrintfLine("215 list of newsgroups follows")
	dw := c.DotWriter()
	defer dw.Close()
	for _, g := range groups {
		switch ltype {
		case "active":
			fmt.Fprintf(dw, "%s %d %d %v\r\n",
				g.Name, g.High, g.Low, g.Posting)
		case "newsgroups":
			fmt.Fprintf(dw, "%s %s\r\n", g.Name, g.Description)
		}
	}

	return nil
}
開發者ID:diocles,項目名稱:go-nntp,代碼行數:29,代碼來源:server.go

示例2: collectLines

func collectLines(c *textproto.Conn) ([]string, error) {
	var ex error
	var line string
	var msg []string
	var ended bool

	line, ex = c.ReadLine()

	if ex != nil {
		return nil, ex
	}

	if !validLine(line) {
		return nil, ErrShortResponse
	}

	msg = append(msg, line)

	ended = line[3] != '-'

	for ex == nil && !ended {
		line, ex = c.ReadLine()

		if ex != nil {
			return nil, ex
		}

		msg = append(msg, line)
		ended = line[3] != '-'
	}

	return msg, nil
}
開發者ID:influx6,項目名稱:proxies,代碼行數:33,代碼來源:smtp.go

示例3: GetRequest

func GetRequest(request Request, client *textproto.Conn) error {
	var err error
	defer func() {
		if err != nil {
			if err == io.EOF {
			} else {
				log.Println("Conn died with err %s", err)
			}
		}
	}()

	requestHeaders, err := client.ReadMIMEHeader()
	if err != nil {
		return err
	}

	response := fmt.Sprintf("Hello from Baboon!\nHave I seen you before?"+
		"\nI know a bit about you.\n"+
		"For example, your User Agent is %s", requestHeaders["User-Agent"])
	serverHeaders := map[string]string{}
	serverHeaders["Server"] = "Baboon/0.001"
	serverHeaders["Content-Type"] = "text/plain"
	serverHeaders["Content-Length"] = strconv.Itoa(len(response))

	client.PrintfLine("HTTP/1.1 200 OK")
	for key, value := range serverHeaders {
		client.PrintfLine("%s: %s", key, value)
	}
	client.PrintfLine("")
	client.PrintfLine(response)
	return nil
}
開發者ID:jkbbwr,項目名稱:Baboon,代碼行數:32,代碼來源:get.go

示例4: processConnData

func processConnData(conn *textproto.Conn) response {
	res := response{Data: make([]string, 0)}
	for {
		line, err := conn.ReadLine()
		if err != nil {
			res.Err = err
			break
		}
		if line == "OK" {
			break
		}
		match := mpdErrorRegexp.FindStringSubmatch(line)
		if match != nil {
			ack, err := strconv.ParseUint(match[1], 0, 0)
			if err != nil {
				res.Err = err
				break
			}
			cln, err := strconv.ParseUint(match[2], 0, 0)
			if err != nil {
				res.Err = err
				break
			}
			res.MPDErr = &MPDError{uint(ack), uint(cln), match[3], match[4]}
			break
		}
		res.Data = append(res.Data, line)
	}
	return res
}
開發者ID:vincent-petithory,項目名稱:mpdclient,代碼行數:30,代碼來源:client.go

示例5: startReader

func (self *nntpConnection) startReader(daemon *NNTPDaemon, conn *textproto.Conn) {
	log.Println(self.name, "run reader mode")
	for {
		var err error
		select {
		case chnl := <-self.die:
			// we were asked to die
			// send quit
			conn.PrintfLine("QUIT")
			chnl <- true
			break
		case msgid := <-self.article:
			// next article to ask for
			log.Println(self.name, "obtaining", msgid)
			self.messageSetPendingState(msgid, "article")
			err = self.requestArticle(daemon, conn, msgid)
			self.messageSetProcessed(msgid)
			if err != nil {
				log.Println(self.name, "error while in reader mode:", err)
				break
			}
		}
	}
	// close connection
	conn.Close()
}
開發者ID:ZiRo-,項目名稱:srndv2,代碼行數:26,代碼來源:nntp.go

示例6: handleMode

func handleMode(args []string, s *session, c *textproto.Conn) error {
	if s.backend.AllowPost() {
		c.PrintfLine("200 Posting allowed")
	} else {
		c.PrintfLine("201 Posting prohibited")
	}
	return nil
}
開發者ID:welterde,項目名稱:go-nntp,代碼行數:8,代碼來源:server.go

示例7: handle

func handle(c *textproto.Conn, verifyOnly bool) {
	defer c.Close()
	defer func() {
		if r := recover(); r != nil {
			log.Println("Something went wrong:", r)
		}
	}()

	converse(c, verifyOnly)
}
開發者ID:oliverjanik,項目名稱:scalemail,代碼行數:10,代碼來源:daemon.go

示例8: converse

func converse(c *textproto.Conn, verifyOnly bool) {
	write(c, "220 At your service")

	var msg Msg

	for {
		s, err := read(c)
		if err == io.EOF {
			return
		}

		if verifyOnly {
			log.Println("Incoming:", s)
		}

		cmd := strings.ToUpper(s[:4])

		switch cmd {
		case "EHLO":
			write(c, "250-8BITMIME")
			fallthrough
		case "HELO":
			write(c, "250 I need orders")
		case "MAIL":
			msg.From = addrRegex.FindStringSubmatch(s)[1]
			write(c, "250 In your name")
		case "RCPT":
			addr := addrRegex.FindStringSubmatch(s)[1]
			msg.To = append(msg.To, addr)
			write(c, "250 Defending your honour")
		case "DATA":
			if verifyOnly {
				write(c, "502 Verification service only")
				return
			}

			write(c, "354 Give me a quest!")
			data, err := c.ReadDotBytes()
			if err != nil {
				panic(err)
			}
			msg.Data = data

			defaultHandle(&msg)

			write(c, "250 We move")
		case "RSET":
			write(c, "250 OK")
		case "QUIT":
			write(c, "221 For the king")
		default:
			log.Println("Unknown command:", s)
		}
	}
}
開發者ID:oliverjanik,項目名稱:scalemail,代碼行數:55,代碼來源:daemon.go

示例9: handleBody

func handleBody(args []string, s *session, c *textproto.Conn) error {
	article, err := s.getArticle(args)
	if err != nil {
		return err
	}
	c.PrintfLine("222 1 %s", article.MessageId())
	dw := c.DotWriter()
	defer dw.Close()
	_, err = io.Copy(dw, article.Body)
	return err
}
開發者ID:welterde,項目名稱:go-nntp,代碼行數:11,代碼來源:server.go

示例10: newClient

func newClient(conn *textproto.Conn) (*Conn, error) {
	_, msg, err := conn.ReadCodeLine(200)
	if err != nil {
		return nil, err
	}

	return &Conn{
		conn:   conn,
		Banner: msg,
	}, nil
}
開發者ID:hobeone,項目名稱:nntp,代碼行數:11,代碼來源:nntp.go

示例11: startReader

func (self *nntpConnection) startReader(daemon NNTPDaemon, conn *textproto.Conn) {
	log.Println(self.name, "run reader mode")
	var err error
	for err == nil {
		// next article to ask for
		msgid := <-self.article
		err = self.requestArticle(daemon, conn, msgid)
	}
	// report error and close connection
	log.Println(self.name, "error while in reader mode:", err)
	conn.Close()
}
開發者ID:4cdn,項目名稱:srndv2,代碼行數:12,代碼來源:nntp.go

示例12: read

func read(c *textproto.Conn) (string, error) {
	s, err := c.ReadLine()
	if err == io.EOF {
		return s, err
	}

	if err != nil {
		panic(err)
	}

	return s, err
}
開發者ID:oliverjanik,項目名稱:scalemail,代碼行數:12,代碼來源:daemon.go

示例13: handleHead

func handleHead(args []string, s *session, c *textproto.Conn) error {
	article, err := s.getArticle(args)
	if err != nil {
		return err
	}
	c.PrintfLine("221 1 %s", article.MessageId())
	dw := c.DotWriter()
	defer dw.Close()
	for k, v := range article.Header {
		fmt.Fprintf(dw, "%s: %s\r\n", k, v[0])
	}
	return nil
}
開發者ID:welterde,項目名稱:go-nntp,代碼行數:13,代碼來源:server.go

示例14: handleIHave

func handleIHave(args []string, s *session, c *textproto.Conn) error {
	if !s.backend.AllowPost() {
		return NotWanted
	}

	// XXX:  See if we have it.
	article, err := s.backend.GetArticle(nil, args[0])
	if article != nil {
		return NotWanted
	}

	c.PrintfLine("335 send it")
	article = new(nntp.Article)
	article.Header, err = c.ReadMIMEHeader()
	if err != nil {
		return PostingFailed
	}
	article.Body = c.DotReader()
	err = s.backend.Post(article)
	if err != nil {
		return err
	}
	c.PrintfLine("235 article received OK")
	return nil
}
開發者ID:welterde,項目名稱:go-nntp,代碼行數:25,代碼來源:server.go

示例15: handleListOverviewFmt

func handleListOverviewFmt(dw io.Writer, c *textproto.Conn) error {
	err := c.PrintfLine("215 list of newsgroups follows")
	if err != nil {
		return err
	}
	_, err = fmt.Fprintln(dw, `Subject:
From:
Date:
Message-ID:
References:
:bytes
:lines`)
	return err
}
開發者ID:welterde,項目名稱:go-nntp,代碼行數:14,代碼來源:server.go


注:本文中的net/textproto.Conn類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。