Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Created June 5, 2014 05:39
Show Gist options
  • Save doloopwhile/5544ca551547a5526071 to your computer and use it in GitHub Desktop.
Save doloopwhile/5544ca551547a5526071 to your computer and use it in GitHub Desktop.
ltsv with method chaining
package main
type Pair struct {
Key string
Value string
}
type LTSV struct {
values []Pair
}
func Log() *LTSV {
return &LTSV{}
}
func (t *LTSV) V(k string, v string) *LTSV {
t.values = append(t.values, Pair{k, v})
return t
}
func (t *LTSV) p(level string) {
print("Level:" + level)
for _, p := range t.values {
print("\t" + p.Key + "\t" + p.Value)
}
print("\n")
}
func (t *LTSV) Error() {
t.p("Error")
}
func (t *LTSV) Info() {
t.p("Info")
}
func main() {
Log().
V("Kind", "Connected failed").
V("Client", "127.0.0.1").
V("Session", "xxxxxxxxxxxxxxxx").
Error()
Log().
V("Kind", "Uploaded").
V("Client", "127.0.0.1").
V("Session", "xxxxxxxxxxxxxxxx").
V("Url", "http://xxxxxx.example.com/xxxx/yyyy").
Info()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment