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
|
||||||
/owobot.db
|
/owobot.db
|
||||||
|
|
|
@ -17,6 +17,7 @@ builds:
|
||||||
archives:
|
archives:
|
||||||
- files:
|
- files:
|
||||||
- owobot.service
|
- owobot.service
|
||||||
|
- owobot.toml
|
||||||
nfpms:
|
nfpms:
|
||||||
- id: owobot
|
- id: owobot
|
||||||
description: "Your server's guardian and entertainer"
|
description: "Your server's guardian and entertainer"
|
||||||
|
@ -34,6 +35,9 @@ nfpms:
|
||||||
contents:
|
contents:
|
||||||
- src: owobot.service
|
- src: owobot.service
|
||||||
dst: /etc/systemd/system/owobot.service
|
dst: /etc/systemd/system/owobot.service
|
||||||
|
- src: owobot.toml
|
||||||
|
dst: /etc/owobot/config.toml
|
||||||
|
type: "config|noreplace"
|
||||||
aurs:
|
aurs:
|
||||||
- name: owobot-bin
|
- name: owobot-bin
|
||||||
homepage: 'https://gitea.elara.ws/owobot/owobot'
|
homepage: 'https://gitea.elara.ws/owobot/owobot'
|
||||||
|
@ -47,10 +51,15 @@ aurs:
|
||||||
- owobot
|
- owobot
|
||||||
conflicts:
|
conflicts:
|
||||||
- owobot
|
- owobot
|
||||||
|
backup:
|
||||||
|
- etc/owobot/config.toml
|
||||||
package: |-
|
package: |-
|
||||||
# binaries
|
# binaries
|
||||||
install -Dm755 ./owobot "${pkgdir}/usr/bin/owobot"
|
install -Dm755 ./owobot "${pkgdir}/usr/bin/owobot"
|
||||||
|
|
||||||
|
# configs
|
||||||
|
install -Dm644 ./owobot.toml "${pkgdir}/etc/owobot/config.toml"
|
||||||
|
|
||||||
# services
|
# services
|
||||||
install -Dm644 ./owobot.service "${pkgdir}/etc/systemd/system/owobot.service"
|
install -Dm644 ./owobot.service "${pkgdir}/etc/systemd/system/owobot.service"
|
||||||
release:
|
release:
|
||||||
|
|
27
config.go
27
config.go
|
@ -27,20 +27,33 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Token string `env:"TOKEN,notEmpty" toml:"token"`
|
Token string `env:"TOKEN" toml:"token"`
|
||||||
DBPath string `env:"DB_PATH" envDefault:"owobot.db" toml:"db_path"`
|
DBPath string `env:"DB_PATH" toml:"db_path"`
|
||||||
Activity Activity `envPrefix:"ACTIVITY_" toml:"activity"`
|
Activity Activity `envPrefix:"ACTIVITY_" toml:"activity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Activity struct {
|
type Activity struct {
|
||||||
Type discordgo.ActivityType `env:"TYPE" envDefault:"-1" toml:"type"`
|
Type discordgo.ActivityType `env:"TYPE" toml:"type"`
|
||||||
Name string `env:"NAME" envDefault:"" toml:"name"`
|
Name string `env:"NAME" toml:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() (*Config, error) {
|
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 {
|
if err == nil {
|
||||||
err = toml.NewDecoder(fl).Decode(cfg)
|
err = toml.NewDecoder(fl).Decode(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -49,5 +62,7 @@ func loadConfig() (*Config, error) {
|
||||||
fl.Close()
|
fl.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println(cfg.Activity.Type, cfg.Activity.Name)
|
||||||
|
|
||||||
return cfg, env.ParseWithOptions(cfg, env.Options{Prefix: "OWOBOT_"})
|
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