/usr/share/gocode/src/github.com/go-logfmt/logfmt/example_test.go is in golang-github-go-logfmt-logfmt-dev 0.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | package logfmt_test
import (
"errors"
"fmt"
"os"
"strings"
"time"
"github.com/go-logfmt/logfmt"
)
func ExampleEncoder() {
check := func(err error) {
if err != nil {
panic(err)
}
}
e := logfmt.NewEncoder(os.Stdout)
check(e.EncodeKeyval("id", 1))
check(e.EncodeKeyval("dur", time.Second+time.Millisecond))
check(e.EndRecord())
check(e.EncodeKeyval("id", 1))
check(e.EncodeKeyval("path", "/path/to/file"))
check(e.EncodeKeyval("err", errors.New("file not found")))
check(e.EndRecord())
// Output:
// id=1 dur=1.001s
// id=1 path=/path/to/file err="file not found"
}
func ExampleDecoder() {
in := `
id=1 dur=1.001s
id=1 path=/path/to/file err="file not found"
`
d := logfmt.NewDecoder(strings.NewReader(in))
for d.ScanRecord() {
for d.ScanKeyval() {
fmt.Printf("k: %s v: %s\n", d.Key(), d.Value())
}
fmt.Println()
}
if d.Err() != nil {
panic(d.Err())
}
// Output:
// k: id v: 1
// k: dur v: 1.001s
//
// k: id v: 1
// k: path v: /path/to/file
// k: err v: file not found
}
|