thatll do for now
parent
9dc35a8a80
commit
9af98c5924
15
config.go
15
config.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"slices"
|
||||
|
|
@ -12,7 +13,8 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
Data Data
|
||||
Data Data
|
||||
Output url.URL
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
|
|
@ -35,6 +37,9 @@ func newConfig() (Config, error) {
|
|||
}
|
||||
result.Data.Weight.Floor = 12
|
||||
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 == "" {
|
||||
} 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)
|
||||
}
|
||||
|
||||
result.Data.Title = os.Getenv("TITLE")
|
||||
result.Data.Subtitle = os.Getenv("SUBTITLE")
|
||||
if s := os.Getenv("OUTPUT"); s == "" {
|
||||
} 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
|
||||
}
|
||||
|
|
|
|||
15
main.go
15
main.go
|
|
@ -1,7 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -50,12 +52,15 @@ func run(ctx context.Context) error {
|
|||
}))
|
||||
scatter.SetXAxis(xs).
|
||||
AddSeries(y, ys)
|
||||
f, _ := os.Create("/tmp/f")
|
||||
defer f.Close()
|
||||
if err := scatter.Render(f); err != nil {
|
||||
|
||||
buff := bytes.NewBuffer(nil)
|
||||
if err := scatter.Render(buff); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("firefox /tmp/f")
|
||||
return nil
|
||||
switch config.Output.Scheme {
|
||||
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