Add toml config file
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
96a6360629
commit
c68fcfe439
|
@ -1,2 +1,3 @@
|
|||
/dist/
|
||||
/owobot
|
||||
/owobot.db
|
||||
/owobot.db
|
||||
|
|
|
@ -17,6 +17,7 @@ builds:
|
|||
archives:
|
||||
- files:
|
||||
- owobot.service
|
||||
- owobot.toml
|
||||
nfpms:
|
||||
- id: owobot
|
||||
description: "Your server's guardian and entertainer"
|
||||
|
@ -34,6 +35,9 @@ nfpms:
|
|||
contents:
|
||||
- src: owobot.service
|
||||
dst: /etc/systemd/system/owobot.service
|
||||
- src: owobot.toml
|
||||
dst: /etc/owobot/config.toml
|
||||
type: "config|noreplace"
|
||||
aurs:
|
||||
- name: owobot-bin
|
||||
homepage: 'https://gitea.elara.ws/owobot/owobot'
|
||||
|
@ -47,10 +51,15 @@ aurs:
|
|||
- owobot
|
||||
conflicts:
|
||||
- owobot
|
||||
backup:
|
||||
- etc/owobot/config.toml
|
||||
package: |-
|
||||
# binaries
|
||||
install -Dm755 ./owobot "${pkgdir}/usr/bin/owobot"
|
||||
|
||||
# configs
|
||||
install -Dm644 ./owobot.toml "${pkgdir}/etc/owobot/config.toml"
|
||||
|
||||
# services
|
||||
install -Dm644 ./owobot.service "${pkgdir}/etc/systemd/system/owobot.service"
|
||||
release:
|
||||
|
|
27
config.go
27
config.go
|
@ -27,20 +27,33 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
Token string `env:"TOKEN,notEmpty" toml:"token"`
|
||||
DBPath string `env:"DB_PATH" envDefault:"owobot.db" toml:"db_path"`
|
||||
Token string `env:"TOKEN" toml:"token"`
|
||||
DBPath string `env:"DB_PATH" toml:"db_path"`
|
||||
Activity Activity `envPrefix:"ACTIVITY_" toml:"activity"`
|
||||
}
|
||||
|
||||
type Activity struct {
|
||||
Type discordgo.ActivityType `env:"TYPE" envDefault:"-1" toml:"type"`
|
||||
Name string `env:"NAME" envDefault:"" toml:"name"`
|
||||
Type discordgo.ActivityType `env:"TYPE" toml:"type"`
|
||||
Name string `env:"NAME" toml:"name"`
|
||||
}
|
||||
|
||||
func loadConfig() (*Config, error) {
|
||||
cfg := &Config{}
|
||||
// Create a new config struct with default values
|
||||
cfg := &Config{
|
||||
Token: "",
|
||||
DBPath: "owobot.db",
|
||||
Activity: Activity{
|
||||
Type: -1,
|
||||
Name: "",
|
||||
},
|
||||
}
|
||||
|
||||
fl, err := os.Open("/etc/owobot.toml")
|
||||
configPath := os.Getenv("OWOBOT_CONFIG_PATH")
|
||||
if configPath == "" {
|
||||
configPath = "/etc/owobot/config.toml"
|
||||
}
|
||||
|
||||
fl, err := os.Open(configPath)
|
||||
if err == nil {
|
||||
err = toml.NewDecoder(fl).Decode(cfg)
|
||||
if err != nil {
|
||||
|
@ -49,5 +62,7 @@ func loadConfig() (*Config, error) {
|
|||
fl.Close()
|
||||
}
|
||||
|
||||
println(cfg.Activity.Type, cfg.Activity.Name)
|
||||
|
||||
return cfg, env.ParseWithOptions(cfg, env.Options{Prefix: "OWOBOT_"})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
token = "CHANGE ME"
|
||||
db_path = "/etc/owobot/owobot.db"
|
||||
|
||||
[activity]
|
||||
type = -1
|
||||
name = ""
|
Loading…
Reference in New Issue