Compare commits

..

No commits in common. "b8fc87385065f3a625853130ac2cfab243c91c30" and "e7b88bcc09ae5046378ef0341f943227488d6b01" have entirely different histories.

6 changed files with 20 additions and 78 deletions

View file

@ -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"
`

View file

@ -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 {

View file

@ -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
}

View file

@ -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"])
}

1
go.mod
View file

@ -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

2
go.sum
View file

@ -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=