Created
June 5, 2014 05:39
-
-
Save doloopwhile/5544ca551547a5526071 to your computer and use it in GitHub Desktop.
ltsv with method chaining
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type Pair struct { | |
Key string | |
Value string | |
} | |
type LTSV struct { | |
values []Pair | |
} | |
func Log() *LTSV { | |
return <SV{} | |
} | |
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