23 lines
384 B
Go
23 lines
384 B
Go
|
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
|
||
|
}
|