...
1
2
3
4
5 package raw
6
7 import (
8 "fmt"
9 "io"
10
11 "internal/trace/version"
12 )
13
14
15 type TextWriter struct {
16 w io.Writer
17 v version.Version
18 }
19
20
21 func NewTextWriter(w io.Writer, v version.Version) (*TextWriter, error) {
22 _, err := fmt.Fprintf(w, "Trace Go1.%d\n", v)
23 if err != nil {
24 return nil, err
25 }
26 return &TextWriter{w: w, v: v}, nil
27 }
28
29
30 func (w *TextWriter) WriteEvent(e Event) error {
31
32 if e.Version != w.v {
33 return fmt.Errorf("mismatched version between writer (go 1.%d) and event (go 1.%d)", w.v, e.Version)
34 }
35
36
37 _, err := fmt.Fprintln(w.w, e.String())
38 return err
39 }
40
View as plain text