thatll do for now
parent
9dc35a8a80
commit
9af98c5924
13
config.go
13
config.go
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"slices"
|
"slices"
|
||||||
|
|
@ -13,6 +14,7 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Data Data
|
Data Data
|
||||||
|
Output url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
|
|
@ -35,6 +37,9 @@ func newConfig() (Config, error) {
|
||||||
}
|
}
|
||||||
result.Data.Weight.Floor = 12
|
result.Data.Weight.Floor = 12
|
||||||
result.Data.Weight.Range = 20
|
result.Data.Weight.Range = 20
|
||||||
|
result.Output = url.URL{Scheme: "file", Path: "/tmp/f"}
|
||||||
|
result.Data.Title = os.Getenv("TITLE")
|
||||||
|
result.Data.Subtitle = os.Getenv("SUBTITLE")
|
||||||
|
|
||||||
if js := os.Getenv("POINTS_JSON"); js == "" {
|
if js := os.Getenv("POINTS_JSON"); js == "" {
|
||||||
} else if err := json.Unmarshal([]byte(js), &result.Data.Points); err != nil {
|
} else if err := json.Unmarshal([]byte(js), &result.Data.Points); err != nil {
|
||||||
|
|
@ -74,8 +79,12 @@ func newConfig() (Config, error) {
|
||||||
return result, fmt.Errorf("found negative weight floor %d", result.Data.Weight.Floor)
|
return result, fmt.Errorf("found negative weight floor %d", result.Data.Weight.Floor)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data.Title = os.Getenv("TITLE")
|
if s := os.Getenv("OUTPUT"); s == "" {
|
||||||
result.Data.Subtitle = os.Getenv("SUBTITLE")
|
} else if u, err := url.Parse(s); err != nil {
|
||||||
|
return result, fmt.Errorf("failed to parse $OUTPUT (%s): %w", s, err)
|
||||||
|
} else {
|
||||||
|
result.Output = *u
|
||||||
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
main.go
15
main.go
|
|
@ -1,7 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
@ -50,12 +52,15 @@ func run(ctx context.Context) error {
|
||||||
}))
|
}))
|
||||||
scatter.SetXAxis(xs).
|
scatter.SetXAxis(xs).
|
||||||
AddSeries(y, ys)
|
AddSeries(y, ys)
|
||||||
f, _ := os.Create("/tmp/f")
|
|
||||||
defer f.Close()
|
buff := bytes.NewBuffer(nil)
|
||||||
if err := scatter.Render(f); err != nil {
|
if err := scatter.Render(buff); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("firefox /tmp/f")
|
switch config.Output.Scheme {
|
||||||
return nil
|
case "file":
|
||||||
|
return os.WriteFile(config.Output.Path, buff.Bytes(), os.ModePerm)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("not impl output scheme: %s", config.Output.Scheme)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue