mirror of https://github.com/nealey/spongy
progress on cgi
This commit is contained in:
parent
5a8f53c5e4
commit
2a0f045f3d
|
@ -3,9 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"github.com/go-fsnotify/fsnotify"
|
||||||
"strconv"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Network struct {
|
type Network struct {
|
||||||
|
@ -14,6 +17,7 @@ type Network struct {
|
||||||
lineno int64
|
lineno int64
|
||||||
|
|
||||||
basePath string
|
basePath string
|
||||||
|
seq int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Update struct {
|
type Update struct {
|
||||||
|
@ -38,8 +42,10 @@ func (nw *Network) SetPosition(filename string, lineno int64) {
|
||||||
|
|
||||||
func (nw *Network) Tail(out chan<- *Update) error {
|
func (nw *Network) Tail(out chan<- *Update) error {
|
||||||
if nw.currentLog == "" {
|
if nw.currentLog == "" {
|
||||||
|
var err error
|
||||||
|
|
||||||
currentfn := path.Join(nw.basePath, "log", "current")
|
currentfn := path.Join(nw.basePath, "log", "current")
|
||||||
nw.currentfn, err := os.Readlink(currentfn)
|
nw.currentLog, err = os.Readlink(currentfn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -58,7 +64,7 @@ func (nw *Network) Tail(out chan<- *Update) error {
|
||||||
}
|
}
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
|
|
||||||
watcher.add(filepath)
|
watcher.Add(filepath)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
lines := make([]string, 0)
|
lines := make([]string, 0)
|
||||||
|
@ -70,7 +76,7 @@ func (nw *Network) Tail(out chan<- *Update) error {
|
||||||
parts := strings.Split(t, " ")
|
parts := strings.Split(t, " ")
|
||||||
if (len(parts) >= 4) && (parts[2] == "NEXTLOG") {
|
if (len(parts) >= 4) && (parts[2] == "NEXTLOG") {
|
||||||
watcher.Remove(filepath)
|
watcher.Remove(filepath)
|
||||||
filename = parts[3]
|
filename := parts[3]
|
||||||
filepath = path.Join(NetworkDir, filename)
|
filepath = path.Join(NetworkDir, filename)
|
||||||
f.Close()
|
f.Close()
|
||||||
f, err = os.Open(filepath)
|
f, err = os.Open(filepath)
|
||||||
|
@ -80,9 +86,9 @@ func (nw *Network) Tail(out chan<- *Update) error {
|
||||||
watcher.Add(filepath)
|
watcher.Add(filepath)
|
||||||
nw.lineno = 0
|
nw.lineno = 0
|
||||||
}
|
}
|
||||||
lines = append(lines, t))
|
lines = append(lines, t)
|
||||||
}
|
}
|
||||||
if len(update.Lines) > 0 {
|
if len(lines) > 0 {
|
||||||
update := Update{
|
update := Update{
|
||||||
Lines: lines,
|
Lines: lines,
|
||||||
LastEventId: nw.LastEventId(),
|
LastEventId: nw.LastEventId(),
|
||||||
|
@ -101,5 +107,12 @@ func (nw *Network) Tail(out chan<- *Update) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nw *Network) Write(line string) {
|
func (nw *Network) Write(data []byte) {
|
||||||
fn := path.Join(nw.baseDir
|
epoch := time.Now().Unix()
|
||||||
|
pid := os.Getpid()
|
||||||
|
filename := fmt.Sprintf("%d-%d-%d.txt", epoch, pid, nw.seq)
|
||||||
|
|
||||||
|
filepath := path.Join(nw.basePath, "outq", filename)
|
||||||
|
ioutil.WriteFile(filepath, data, 0750)
|
||||||
|
nw.seq += 1
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue