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