Esempio n. 1
0
func (lp *LinkParser) Parse(newPost *post.Post, raw []byte) post.Flow {
	if !lp.ready {
		lp.ready = true
		return post.Continue
	}

	if bytes.HasPrefix(raw, []byte("post/view?")) {
		newPost.Link = "http://www.javaworld.com.tw/jute/" + string(raw)

		var postLink *url.URL
		postLink, lp.err = url.Parse(newPost.Link)
		if lp.err != nil {
			return post.Error
		}

		values := postLink.Query()
		newPost.Id, lp.err = strconv.Atoi(values.Get("id"))
		if lp.err != nil {
			return post.Error
		}

		newPost.Bid, lp.err = strconv.Atoi(values.Get("bid"))
		if lp.err != nil {
			return post.Error
		}

		return post.Stop
	}

	return post.Continue
}
Esempio n. 2
0
func (cp *ContentParser) Parse(newPost *post.Post, raw []byte) post.Flow {
	if bytes.HasPrefix(raw, []byte("\n---------- ")) {
		newPost.Content = cp.buf.String()
		return post.Stop
	}

	cp.buf.Write(raw)
	return post.Continue
}
Esempio n. 3
0
func (sp *SenderParser) Parse(newPost *post.Post, raw []byte) post.Flow {
	sp.count += 1
	if sp.count < 5 {
		return post.Continue
	}

	newPost.Sender = string(bytes.TrimSpace(raw))
	return post.Next
}
Esempio n. 4
0
func (sp *SubjectParser) Parse(newPost *post.Post, raw []byte) post.Flow {
	if sp.ready {
		newPost.Subject = string(bytes.TrimSpace(raw))
		return post.Next
	}

	if bytes.HasPrefix(raw, []byte("\nSubject:")) {
		sp.ready = true
	}

	return post.Continue
}
Esempio n. 5
0
func (rp *ReceiverParser) Parse(newPost *post.Post, raw []byte) post.Flow {

	if rp.count > 2 {
		rp.err = errors.New("parse receiver failed: out of range")
		return post.Error
	}

	if !bytes.HasPrefix(raw, []byte("\nHi")) {
		rp.count += 1
		return post.Continue
	}

	fields := bytes.Split(raw, []byte(","))
	if len(fields) != 2 {
		rp.err = errors.New(fmt.Sprintf("parse receiver failed: %s", raw))
		return post.Error
	}

	newPost.Receiver = string(bytes.TrimSpace(fields[1]))
	return post.Next
}