Visualizer #3
|
@ -24,9 +24,9 @@ import (
|
||||||
var static embed.FS
|
var static embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) != 3 {
|
if len(os.Args) != 2 && len(os.Args) != 3 {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
log.Fatalf("usage: %s <fifo> <json-dup-prefix>", os.Args[0])
|
log.Fatalf("usage: %s <fifo> [<json-dup-prefix>]", os.Args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
var mutex sync.Mutex
|
var mutex sync.Mutex
|
||||||
|
@ -35,15 +35,21 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
path := os.Args[1]
|
path := os.Args[1]
|
||||||
dupPath := os.Args[2] + "." + time.Now().Format(time.RFC3339)
|
var dupPath string
|
||||||
thomas marked this conversation as resolved
Outdated
|
|||||||
|
if len(os.Args) == 3 {
|
||||||
|
dupPath = os.Args[2] + "." + time.Now().Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
|
||||||
fh, err := os.Open(path)
|
fh, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
dupFh, err := os.Create(dupPath)
|
var dupFh *os.File
|
||||||
if err != nil {
|
if dupPath != "" {
|
||||||
log.Fatal(err)
|
dupFh, err = os.Create(dupPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r := bufio.NewReader(fh)
|
r := bufio.NewReader(fh)
|
||||||
|
@ -56,9 +62,11 @@ func main() {
|
||||||
|
|
||||||
// Duplicate JSON input to a file so it can be replayed later
|
// Duplicate JSON input to a file so it can be replayed later
|
||||||
// if necessary
|
// if necessary
|
||||||
_, err = dupFh.WriteString(line)
|
if dupFh != nil {
|
||||||
if err != nil {
|
_, err = dupFh.WriteString(line)
|
||||||
log.Fatalf("write %q: %v", dupPath, err)
|
if err != nil {
|
||||||
|
log.Fatalf("write %q: %v", dupPath, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send to all listeners
|
// Send to all listeners
|
||||||
|
@ -73,9 +81,11 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("close %q: %v", path, err)
|
log.Fatalf("close %q: %v", path, err)
|
||||||
}
|
}
|
||||||
err = dupFh.Close()
|
if dupFh != nil {
|
||||||
if err != nil {
|
err = dupFh.Close()
|
||||||
log.Fatalf("close %q: %v", dupPath, err)
|
if err != nil {
|
||||||
|
log.Fatalf("close %q: %v", dupPath, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue
Eine Idee dazu noch: wenn man wirklich ein Replay von einem früheren JSON-Dump startet, indem man diesen statt dem FIFO als Args[1] angibt, wäre es cool, wenn man Args[2] weglassen könnte oder zumindest /dev/null angeben könnte. Letzteres geht leider nicht wegen dem Anhängen der Uhrzeit (was an sich aber schon sinnvoll ist).
Ist implementiert. Habs auch gleich rebased.
Schaut gut aus. Dann merge ich das mal :)