2019-08-19 23:30:59 +00:00
|
|
|
package main
|
|
|
|
|
2019-08-21 08:31:57 +00:00
|
|
|
import "os"
|
2019-08-21 08:15:45 +00:00
|
|
|
import "fmt"
|
2019-08-20 02:15:56 +00:00
|
|
|
import "github.com/sirupsen/logrus"
|
|
|
|
import "github.com/sneak/sircd/sircd"
|
2019-08-21 08:15:45 +00:00
|
|
|
import "github.com/spf13/viper"
|
|
|
|
|
|
|
|
var Version string
|
|
|
|
var Buildtime string
|
2019-08-21 08:31:57 +00:00
|
|
|
var Builduser string
|
|
|
|
var Buildarch string
|
2019-08-19 23:30:59 +00:00
|
|
|
|
|
|
|
func main() {
|
2019-08-21 08:15:45 +00:00
|
|
|
|
2019-08-21 08:18:10 +00:00
|
|
|
c := viper.New()
|
|
|
|
// default config variables
|
|
|
|
c.SetDefault("myhostname", "irc.example.com")
|
|
|
|
c.SetDefault("network", "ExampleNet")
|
|
|
|
c.SetDefault("admin", "webmaster@example.com")
|
2019-08-21 08:31:57 +00:00
|
|
|
c.SetDefault("loglevel", "info")
|
2019-08-21 08:18:10 +00:00
|
|
|
c.SetDefault("version", Version)
|
|
|
|
c.SetDefault("buildtime", Buildtime)
|
2019-08-21 08:31:57 +00:00
|
|
|
c.SetDefault("builduser", Builduser)
|
|
|
|
c.SetDefault("buildarch", Buildarch)
|
2019-08-21 08:18:10 +00:00
|
|
|
|
|
|
|
// read config file
|
|
|
|
c.SetConfigName("sircd") // name of config file (without extension)
|
|
|
|
c.AddConfigPath("/etc/sircd/") // path to look for the config file in
|
|
|
|
c.AddConfigPath("$HOME/.config/sircd") // call multiple times to add many search paths
|
|
|
|
c.AddConfigPath(".") // optionally look for config in the working directory
|
|
|
|
err := c.ReadInConfig() // Find and read the config file
|
|
|
|
if err != nil { // Handle errors reading the config file
|
|
|
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
|
|
|
}
|
|
|
|
|
2019-08-21 19:07:47 +00:00
|
|
|
// this is the only config settable by env var by design
|
|
|
|
// do everything else in the config file
|
|
|
|
if os.Getenv("DEBUG") != "" {
|
|
|
|
c.Set("loglevel", "debug")
|
|
|
|
}
|
2019-08-21 08:31:57 +00:00
|
|
|
|
|
|
|
// set up logging
|
|
|
|
log := logrus.New()
|
2019-08-21 19:07:47 +00:00
|
|
|
log.SetReportCaller(false)
|
|
|
|
switch c.GetString("loglevel") {
|
|
|
|
case "error":
|
|
|
|
log.SetLevel(logrus.ErrorLevel)
|
|
|
|
case "info":
|
|
|
|
log.SetLevel(logrus.InfoLevel)
|
|
|
|
default:
|
|
|
|
log.SetLevel(logrus.DebugLevel)
|
|
|
|
log.SetReportCaller(true)
|
|
|
|
}
|
2019-08-21 08:18:10 +00:00
|
|
|
// instantiate server
|
|
|
|
s := sircd.New(c)
|
|
|
|
// give it our logger
|
|
|
|
s.SetLogger(log)
|
|
|
|
|
|
|
|
// run it
|
2019-08-21 08:15:45 +00:00
|
|
|
s.Start()
|
2019-08-19 23:30:59 +00:00
|
|
|
}
|