golang メソッドチェーン

package main

import (
    "fmt"
    "log"
    "strings"
)

// Repo ...
type Repo struct {
    RawQuery []string
}

// User ...
func (r *Repo) User(id string) *Repo {
    r.RawQuery = append(r.RawQuery, fmt.Sprintf(`user=%s`, id))
    return r
}

// Group ...
func (r *Repo) Group(id string) *Repo {
    r.RawQuery = append(r.RawQuery, fmt.Sprintf(`group=%s`, id))
    return r
}

// Query ...
func (r *Repo) Query() string {
    return strings.Join(r.RawQuery, " and ")
}

func main() {
    r := new(Repo)
    log.Print(r.User("1").Group("2").Query()) // user=1 and group=2 が返る
}