commit - a08b98e6d66406cfca983e2869db42a2704fd68b
commit + 5683f6883cc3f42a6102bbbfb0e9db958dbe4b4e
blob - 41430094f467ef2062b05ee9d2db69e29fd383fa
blob + d606a708d25244cbad788ab9b159bb707cc35ea1
--- examples/couchserver/couchserver.go
+++ examples/couchserver/couchserver.go
var useSyslog = flag.Bool("syslog", false,
"Log to syslog")
-type GroupRow struct {
+type groupRow struct {
Group string `json:"key"`
Value []interface{} `json:"value"`
}
-type GroupResults struct {
- Rows []GroupRow
+type groupResults struct {
+ Rows []groupRow
}
-type Attachment struct {
+type attachment struct {
Type string `json:"content-type"`
Data []byte `json:"data"`
}
return r
}
-func (a *Attachment) MarshalJSON() ([]byte, error) {
+func (a *attachment) MarshalJSON() ([]byte, error) {
m := map[string]string{
"content_type": a.Type,
"data": strings.Map(removeSpace, base64.StdEncoding.EncodeToString(a.Data)),
return json.Marshal(m)
}
-type Article struct {
- MsgId string `json:"_id"`
+type article struct {
+ MsgID string `json:"_id"`
DocType string `json:"type"`
Headers map[string][]string `json:"headers"`
Bytes int `json:"bytes"`
Lines int `json:"lines"`
Nums map[string]int64 `json:"nums"`
- Attachments map[string]*Attachment `json:"_attachments"`
+ Attachments map[string]*attachment `json:"_attachments"`
Added time.Time `json:"added"`
}
-type ArticleResults struct {
+type articleResults struct {
Rows []struct {
Key []interface{} `json:"key"`
- Article Article `json:"doc"`
+ Article article `json:"doc"`
}
}
log.Printf("Filling group cache")
- results := GroupResults{}
+ results := groupResults{}
err := cb.db.Query("_design/groups/_view/active", map[string]interface{}{
"group": true,
}, &results)
return g, nil
}
-func (cb *couchBackend) mkArticle(ar Article) *nntp.Article {
- url := fmt.Sprintf("%s/%s/article", cb.db.DBURL(), cleanupId(ar.MsgId, true))
+func (cb *couchBackend) mkArticle(ar article) *nntp.Article {
+ url := fmt.Sprintf("%s/%s/article", cb.db.DBURL(), cleanupID(ar.MsgID, true))
return &nntp.Article{
Header: textproto.MIMEHeader(ar.Headers),
Body: &lazyOpener{url, nil, nil},
}
func (cb *couchBackend) GetArticle(group *nntp.Group, id string) (*nntp.Article, error) {
- var ar Article
+ var ar article
if intid, err := strconv.ParseInt(id, 10, 64); err == nil {
- results := ArticleResults{}
+ results := articleResults{}
cb.db.Query("_design/articles/_view/list", map[string]interface{}{
"include_docs": true,
"reduce": false,
ar = results.Rows[0].Article
} else {
- err := cb.db.Retrieve(cleanupId(id, false), &ar)
+ err := cb.db.Retrieve(cleanupID(id, false), &ar)
if err != nil {
return nil, nntpserver.ErrInvalidMessageID
}
rv := make([]nntpserver.NumberedArticle, 0, 100)
- results := ArticleResults{}
+ results := articleResults{}
cb.db.Query("_design/articles/_view/list", map[string]interface{}{
"include_docs": true,
"reduce": false,
return rv, nil
}
-func (tb *couchBackend) AllowPost() bool {
+func (cb *couchBackend) AllowPost() bool {
return true
}
-func cleanupId(msgid string, escapedAt bool) string {
+func cleanupID(msgid string, escapedAt bool) string {
s := strings.TrimFunc(msgid, func(r rune) bool {
return r == ' ' || r == '<' || r == '>'
})
return strings.Replace(qe, "%40", "@", -1)
}
-func (cb *couchBackend) Post(article *nntp.Article) error {
- a := Article{
+func (cb *couchBackend) Post(art *nntp.Article) error {
+ a := article{
DocType: "article",
- Headers: map[string][]string(article.Header),
+ Headers: map[string][]string(art.Header),
Nums: make(map[string]int64),
- MsgId: cleanupId(article.Header.Get("Message-Id"), false),
- Attachments: make(map[string]*Attachment),
+ MsgID: cleanupID(art.Header.Get("Message-Id"), false),
+ Attachments: make(map[string]*attachment),
Added: time.Now(),
}
b := []byte{}
buf := bytes.NewBuffer(b)
- n, err := io.Copy(buf, article.Body)
+ n, err := io.Copy(buf, art.Body)
if err != nil {
return err
}
a.Bytes = len(b)
a.Lines = bytes.Count(b, []byte{'\n'})
- a.Attachments["article"] = &Attachment{"text/plain", b}
+ a.Attachments["article"] = &attachment{"text/plain", b}
- for _, g := range strings.Split(article.Header.Get("Newsgroups"), ",") {
+ for _, g := range strings.Split(art.Header.Get("Newsgroups"), ",") {
g = strings.TrimSpace(g)
group, err := cb.GetGroup(g)
if err == nil {
if len(a.Nums) == 0 {
log.Printf("Found no matching groups in %v",
- article.Header["Newsgroups"])
+ art.Header["Newsgroups"])
return nntpserver.ErrPostingFailed
}
return nil
}
-func (tb *couchBackend) Authorized() bool {
+func (cb *couchBackend) Authorized() bool {
return true
}
-func (tb *couchBackend) Authenticate(user, pass string) (nntpserver.Backend, error) {
+func (cb *couchBackend) Authenticate(user, pass string) (nntpserver.Backend, error) {
return nil, nntpserver.ErrAuthRejected
}
}
func main() {
- couchUrl := flag.String("couch", "http://localhost:5984/news",
+ couchURL := flag.String("couch", "http://localhost:5984/news",
"Couch DB.")
flag.Parse()
maybefatal(err, "Error setting up listener: %v", err)
defer l.Close()
- db, err := couch.Connect(*couchUrl)
+ db, err := couch.Connect(*couchURL)
maybefatal(err, "Can't connect to the couch: %v", err)
err = ensureViews(&db)
maybefatal(err, "Error setting up views: %v", err)
blob - c3408d8300d6415fc0fba78d16f5863d40962164
blob + 86da305cfcfa3d3637e329d51112998dd7a19366
--- examples/couchserver/encoder_test.go
+++ examples/couchserver/encoder_test.go
)
func TestJSONMarshalling(t *testing.T) {
- a := Attachment{
+ a := attachment{
"application/octet-stream",
[]byte("some bytes"),
}
blob - 74ba51816fc42b5a68b6eefb85f407cf1b6f9f8a
blob + d839bb686c590a66d3c8f79166920285e99e01a5
--- examples/couchserver/groupcreator/creator.go
+++ examples/couchserver/groupcreator/creator.go
func main() {
- couchUrl := flag.String("couch", "http://localhost:5984/news",
+ couchURL := flag.String("couch", "http://localhost:5984/news",
"Couch DB.")
flag.Parse()
- db, err := couch.Connect(*couchUrl)
+ db, err := couch.Connect(*couchURL)
if err != nil {
log.Fatalf("Can't connect to couch: %v", err)
}
blob - 27b79dfc6a77aa48405f62ef98533c48c9d7c0f4
blob + 6f007215f3a724c804786198deafb0e49b293ed8
--- examples/couchserver/views.go
+++ examples/couchserver/views.go
return err
}
if !viewUpdateOK(r.StatusCode) {
- return errors.New(fmt.Sprintf("Error updating view: %v", r.Status))
+ return fmt.Errorf("error updating view: %v", r.Status)
}
return nil
}
}
if erra != nil || errg != nil {
- return errors.New("Error making views")
+ return errors.New("error making views")
}
return nil