Adding feature selection to cfg
This commit is contained in:
parent
a7b4e31bec
commit
9730d63e58
|
@ -21,13 +21,26 @@ func main() {
|
|||
|
||||
config.LoadConfig(*cfg)
|
||||
database.Init()
|
||||
if config.C.Features.Bot {
|
||||
bot.Init()
|
||||
} else {
|
||||
log.Print("[BOTS] Feature disabled in config!")
|
||||
}
|
||||
|
||||
if config.C.Features.Web {
|
||||
web.Init()
|
||||
} else {
|
||||
log.Print("[WEB] Feature disabled in config!")
|
||||
}
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
<-c
|
||||
|
||||
if config.C.Features.Bot {
|
||||
bot.DeInit()
|
||||
}
|
||||
|
||||
database.Close()
|
||||
config.WriteConfig(*cfg)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ func Init() {
|
|||
func DeInit() {
|
||||
stream.Stop()
|
||||
telegram.DeInit()
|
||||
database.Close()
|
||||
}
|
||||
|
||||
func handleHashtagTweet(tweet *twitter.Tweet) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
// Config main type
|
||||
type Config struct {
|
||||
Features Features
|
||||
Web Web
|
||||
Twitter Twitter
|
||||
Telegram Telegram
|
||||
|
@ -45,11 +46,20 @@ type Web struct {
|
|||
WebDir string
|
||||
}
|
||||
|
||||
// Features related config
|
||||
type Features struct {
|
||||
Bot bool
|
||||
Web bool
|
||||
}
|
||||
|
||||
// C holds the loaded configuration
|
||||
var C Config
|
||||
|
||||
// LoadDefaults puts default values into C
|
||||
func LoadDefaults() {
|
||||
C.Features.Bot = true
|
||||
C.Features.Web = true
|
||||
|
||||
C.Web.BindUnix = false
|
||||
C.Web.Bind = ":8080"
|
||||
C.Web.WebDir = "./web"
|
||||
|
@ -68,6 +78,7 @@ func LoadDefaults() {
|
|||
|
||||
// LoadConfig loads the configuration from given path
|
||||
func LoadConfig(path string) error {
|
||||
LoadDefaults()
|
||||
_, err := toml.DecodeFile(path, &C)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
log.Printf("Could not find file \"%s\", using defaults!", path)
|
||||
|
|
|
@ -19,8 +19,8 @@ func Init() {
|
|||
r.GET("/betriebsstellen/:code", getBetriebsstelleByCode)
|
||||
|
||||
if config.C.Web.BindUnix {
|
||||
r.RunUnix(config.C.Web.Bind)
|
||||
go r.RunUnix(config.C.Web.Bind)
|
||||
} else {
|
||||
r.Run(config.C.Web.Bind)
|
||||
go r.Run(config.C.Web.Bind)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue