init
This commit is contained in:
commit
2586161abd
49 changed files with 4171 additions and 0 deletions
19
config/config.go
Normal file
19
config/config.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package config
|
||||
|
||||
type Config struct {
|
||||
Core CoreConfig `toml:"core"`
|
||||
Web WebConfig `toml:"web"`
|
||||
}
|
||||
|
||||
type WebConfig struct {
|
||||
// Domain should be the instance's full domain, including https:// but without the trailing slash.
|
||||
Domain string `toml:"domain"`
|
||||
|
||||
// Port is the port the server should listen on.
|
||||
Port int `toml:"port"`
|
||||
}
|
||||
|
||||
type CoreConfig struct {
|
||||
Postgres string `toml:"postgres"`
|
||||
Dev bool `toml:"dev"`
|
||||
}
|
22
config/parse.go
Normal file
22
config/parse.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"emperror.dev/errors"
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
func Parse(filename string) (Config, error) {
|
||||
var c Config
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return Config{}, errors.Wrap(err, "reading config file")
|
||||
}
|
||||
|
||||
err = toml.Unmarshal(b, &c)
|
||||
if err != nil {
|
||||
return c, errors.Wrap(err, "unmarshaling config file")
|
||||
}
|
||||
return c, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue