diff --git a/cmd/lenore/main.go b/cmd/lenore/main.go index edc4dc8..012cada 100644 --- a/cmd/lenore/main.go +++ b/cmd/lenore/main.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "os" "codeberg.org/danjones000/lenore" "codeberg.org/danjones000/lenore/config" @@ -12,15 +11,23 @@ import ( ) func main() { - conf, err := config.LoadFromToml(getTomlFile()) - quitErr(err) - fmt.Printf("%+v\n", conf) + conf := config.Config{ + BaseURL: "http://localhost:4523/", + Conn: config.ConnSettings{ + Store: "sqlite", + DSN: "storage", + }, + } db, err := store.MakeStore(conf.Conn.Store, conf) - quitErr(err) + if err != nil { + panic(err) + } app, err := lenore.NewApp(config.Version, conf, db) - quitErr(err) + if err != nil { + panic(err) + } fmt.Println(app) serv := app.Service() @@ -28,28 +35,3 @@ func main() { fmt.Println(string(out)) fmt.Println(serv.ID) } -func quitErr(err error) { - if err != nil { - panic(err) - } -} - -func getTomlFile() string { - tmp, err := os.CreateTemp("", "*.toml") - if err != nil { - panic(err) - } - defer tmp.Close() - - p := tmp.Name() - fmt.Fprintln(tmp, confStr) - return p -} - -var confStr = ` -base_url = "http://localhost:4523/" - -[conn] -store = "sqlite" -dsn = "store" -` diff --git a/config/config.go b/config/config.go index 27102a8..953ddce 100644 --- a/config/config.go +++ b/config/config.go @@ -1,16 +1,16 @@ package config type Config struct { - Name string `toml:"name"` - Env Env `toml:"env"` - BaseURL string `toml:"base_url"` - Conn ConnSettings `toml:"conn"` + Name string + Env Env + BaseURL string + Conn ConnSettings } type ConnSettings struct { - Store string `toml:"store"` - DSN string `toml:"dsn"` - Settings map[string]any `toml:"settings"` + Store string + DSN string + AdditionalSettings map[string]any } func (c Config) Environment() Env { diff --git a/config/load.go b/config/load.go deleted file mode 100644 index 3293b65..0000000 --- a/config/load.go +++ /dev/null @@ -1,8 +0,0 @@ -package config - -import "github.com/BurntSushi/toml" - -func LoadFromToml(path string) (c Config, err error) { - _, err = toml.DecodeFile(path, &c) - return -} diff --git a/config/load_test.go b/config/load_test.go deleted file mode 100644 index b289496..0000000 --- a/config/load_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package config - -import ( - "fmt" - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestLoadTomlMissing(t *testing.T) { - _, e := LoadFromToml("not-a-real-filee") - assert.Error(t, e) -} - -func TestLoadTomlGood(t *testing.T) { - tmp, _ := os.CreateTemp("", "*.toml") - defer tmp.Close() - fmt.Fprintln(tmp, `name = "Cool"`) - fmt.Fprintln(tmp, "[conn]") - fmt.Fprintln(tmp, `store = "sqlite"`) - fmt.Fprintln(tmp, "[conn.settings]") - fmt.Fprintln(tmp, `num = 42`) - c, e := LoadFromToml(tmp.Name()) - assert.NoError(t, e) - assert.Equal(t, "Cool", c.Name) - assert.Equal(t, "sqlite", c.Conn.Store) - assert.Equal(t, int64(42), c.Conn.Settings["num"]) -} diff --git a/go.mod b/go.mod index 2226a1c..2b3ca76 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module codeberg.org/danjones000/lenore go 1.23.1 require ( - github.com/BurntSushi/toml v1.4.0 github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c github.com/go-ap/client v0.0.0-20240910141951-13a4f3c4fd53 github.com/go-ap/fedbox v0.0.0-20240910163620-7bcedb2eb399 diff --git a/go.sum b/go.sum index 4a5a48b..617a50d 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,6 @@ git.sr.ht/~mariusor/lw v0.0.0-20240906100438-00d2184b2120 h1:OLxL9lel79BV3EHu/AM git.sr.ht/~mariusor/lw v0.0.0-20240906100438-00d2184b2120/go.mod h1:kXJ4JsgGBu7IVBKlrVvGjSLJmpsAGqZwq/JU/kTUaLw= git.sr.ht/~mariusor/ssm v0.0.0-20240811085540-34f24cac52b7 h1:bCGvett+MiEDc5L+T9jByp671KnKRG/iJCCm0fc+21s= git.sr.ht/~mariusor/ssm v0.0.0-20240811085540-34f24cac52b7/go.mod h1:VApG24PG5Ij+tw5zpN5O61FSQU9gJK/cYQwFYM+kkwA= -github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= -github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/carlmjohnson/be v0.23.2 h1:1QjPnPJhwGUjsD9+7h98EQlKsxnG5TV+nnEvk0wnkls= github.com/carlmjohnson/be v0.23.2/go.mod h1:KAgPUh0HpzWYZZI+IABdo80wTgY43YhbdsiLYAaSI/Q= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=