/usr/share/gocode/src/go.pedge.io/lion/write_pusher.go is in golang-go.pedge-lion-dev 0.0~git20171203.2a81062-5.
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 61 | package lion
import (
"io"
"os"
"sync"
"github.com/mattn/go-isatty"
)
var (
newlineBytes = []byte{'\n'}
)
type syncer interface {
Sync() error
}
type writePusher struct {
writer io.Writer
marshaller Marshaller
lock *sync.Mutex
}
func newWritePusher(writer io.Writer, marshaller Marshaller) *writePusher {
writePusher := &writePusher{
writer,
marshaller,
&sync.Mutex{},
}
if file, ok := writer.(*os.File); ok {
if textMarshaller, ok := writePusher.marshaller.(TextMarshaller); ok {
if isatty.IsTerminal(file.Fd()) {
writePusher.marshaller = textMarshaller.WithColors()
}
}
}
return writePusher
}
func (w *writePusher) Flush() error {
if syncer, ok := w.writer.(syncer); ok {
return syncer.Sync()
} else if flusher, ok := w.writer.(Flusher); ok {
return flusher.Flush()
}
return nil
}
func (w *writePusher) Push(entry *Entry) error {
data, err := w.marshaller.Marshal(entry)
if err != nil {
return err
}
w.lock.Lock()
defer w.lock.Unlock()
if _, err := w.writer.Write(data); err != nil {
return err
}
return nil
}
|