## What's new - TOML config support - add config init command to justfile https://github.com/versenilvis/IRIS/pull/9/commits/a5bb6c23d74ca73385b3590d2eb275ce6429906b - add copy binary file to local bin on reload https://github.com/versenilvis/IRIS/pull/9/commits/4da3acdbc58c28f20fa0021d15fec82823ba392b - init config on setup https://github.com/versenilvis/IRIS/pull/9/commits/fb48b6bb832f38e24fab9211d92858bab9a58a07 ## Fix - add lsof to support macos because /proc filesystem is Linux-specific and does not exist on macOS 0439d829573864fcf902fc4127f7d45384bfab01 - git push doesnt suggest current branch, fix https://github.com/versenilvis/IRIS/pull/9/commits/b498532b401b764a4a1a2c70b3cb44b7caf72320 - use timeout context for lsof command in reload handler https://github.com/versenilvis/IRIS/pull/9/commits/1a2baee951e6538a729da12aedfe53960e51102d
69 lines
1.0 KiB
Go
69 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type UpdaterState struct {
|
|
LastCheckTime time.Time `toml:"last-check-time"`
|
|
SeenVersion string `toml:"seen-version"`
|
|
}
|
|
|
|
type State struct {
|
|
LastMode string `toml:"last-mode"`
|
|
Updater UpdaterState `toml:"updater"`
|
|
}
|
|
|
|
func LoadState() *State {
|
|
s := DefaultState()
|
|
|
|
path, err := StatePath()
|
|
if err != nil {
|
|
return s
|
|
}
|
|
|
|
if _, statErr := os.Stat(path); os.IsNotExist(statErr) {
|
|
return s
|
|
}
|
|
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return s
|
|
}
|
|
|
|
if _, err := toml.Decode(string(data), s); err != nil {
|
|
return s
|
|
}
|
|
|
|
return s
|
|
}
|
|
|
|
func SaveState(s *State) error {
|
|
path, err := StatePath()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = os.MkdirAll(filepath.Dir(path), 0755)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer file.Close()
|
|
|
|
enc := toml.NewEncoder(file)
|
|
if err := enc.Encode(s); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|