Compare commits
No commits in common. "b8fc87385065f3a625853130ac2cfab243c91c30" and "e7b88bcc09ae5046378ef0341f943227488d6b01" have entirely different histories.
b8fc873850
...
e7b88bcc09
6 changed files with 20 additions and 78 deletions
|
|
@ -4,7 +4,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
"codeberg.org/danjones000/lenore"
|
"codeberg.org/danjones000/lenore"
|
||||||
"codeberg.org/danjones000/lenore/config"
|
"codeberg.org/danjones000/lenore/config"
|
||||||
|
|
@ -12,15 +11,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
conf, err := config.LoadFromToml(getTomlFile())
|
conf := config.Config{
|
||||||
quitErr(err)
|
BaseURL: "http://localhost:4523/",
|
||||||
fmt.Printf("%+v\n", conf)
|
Conn: config.ConnSettings{
|
||||||
|
Store: "sqlite",
|
||||||
|
DSN: "storage",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
db, err := store.MakeStore(conf.Conn.Store, conf)
|
db, err := store.MakeStore(conf.Conn.Store, conf)
|
||||||
quitErr(err)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
app, err := lenore.NewApp(config.Version, conf, db)
|
app, err := lenore.NewApp(config.Version, conf, db)
|
||||||
quitErr(err)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(app)
|
fmt.Println(app)
|
||||||
serv := app.Service()
|
serv := app.Service()
|
||||||
|
|
@ -28,28 +35,3 @@ func main() {
|
||||||
fmt.Println(string(out))
|
fmt.Println(string(out))
|
||||||
fmt.Println(serv.ID)
|
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"
|
|
||||||
`
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `toml:"name"`
|
Name string
|
||||||
Env Env `toml:"env"`
|
Env Env
|
||||||
BaseURL string `toml:"base_url"`
|
BaseURL string
|
||||||
Conn ConnSettings `toml:"conn"`
|
Conn ConnSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnSettings struct {
|
type ConnSettings struct {
|
||||||
Store string `toml:"store"`
|
Store string
|
||||||
DSN string `toml:"dsn"`
|
DSN string
|
||||||
Settings map[string]any `toml:"settings"`
|
AdditionalSettings map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) Environment() Env {
|
func (c Config) Environment() Env {
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
1
go.mod
|
|
@ -3,7 +3,6 @@ module codeberg.org/danjones000/lenore
|
||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.4.0
|
|
||||||
github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c
|
github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c
|
||||||
github.com/go-ap/client v0.0.0-20240910141951-13a4f3c4fd53
|
github.com/go-ap/client v0.0.0-20240910141951-13a4f3c4fd53
|
||||||
github.com/go-ap/fedbox v0.0.0-20240910163620-7bcedb2eb399
|
github.com/go-ap/fedbox v0.0.0-20240910163620-7bcedb2eb399
|
||||||
|
|
|
||||||
2
go.sum
2
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/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 h1:bCGvett+MiEDc5L+T9jByp671KnKRG/iJCCm0fc+21s=
|
||||||
git.sr.ht/~mariusor/ssm v0.0.0-20240811085540-34f24cac52b7/go.mod h1:VApG24PG5Ij+tw5zpN5O61FSQU9gJK/cYQwFYM+kkwA=
|
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 h1:1QjPnPJhwGUjsD9+7h98EQlKsxnG5TV+nnEvk0wnkls=
|
||||||
github.com/carlmjohnson/be v0.23.2/go.mod h1:KAgPUh0HpzWYZZI+IABdo80wTgY43YhbdsiLYAaSI/Q=
|
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=
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
|
|
|
||||||
Reference in a new issue