Initial commit
This commit is contained in:
commit
36baaf0caf
10 changed files with 961 additions and 0 deletions
82
main.go
Normal file
82
main.go
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// External
|
||||
"git.gibonuddevalla.se/go/vlog"
|
||||
|
||||
// Standard
|
||||
"flag"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
const VERSION = "v1"
|
||||
|
||||
var (
|
||||
flagVersion bool
|
||||
flagDev bool
|
||||
flagDebug bool
|
||||
flagConfig string
|
||||
|
||||
config Config
|
||||
initLogger *slog.Logger
|
||||
logger *slog.Logger
|
||||
|
||||
device RouterosDevice
|
||||
)
|
||||
|
||||
func init() {// {{{
|
||||
initLogger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{}))
|
||||
|
||||
confDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
initLogger.Error("application", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defConfFilename := path.Join(confDir, "routeros_dns.json")
|
||||
|
||||
flag.BoolVar(&flagVersion, "version", false, "Print version and exit")
|
||||
flag.BoolVar(&flagDev, "dev", false, "Load each static file from disk")
|
||||
flag.BoolVar(&flagDebug, "debug", false, "Debugging log level")
|
||||
flag.StringVar(&flagConfig, "config", defConfFilename, "Path to filename for configuration")
|
||||
flag.Parse()
|
||||
|
||||
config, err = readConfig()
|
||||
if err != nil {
|
||||
initLogger.Error("application", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger = initLogging(config)
|
||||
}// }}}
|
||||
func initLogging(config Config) (*slog.Logger) {// {{{
|
||||
opts := slog.HandlerOptions{}
|
||||
if flagDebug {
|
||||
opts.Level = slog.LevelDebug
|
||||
}
|
||||
handler := vlog.New(
|
||||
os.Stdout,
|
||||
opts,
|
||||
config.Logging.LogDir,
|
||||
config.Logging.URL,
|
||||
"routeros-dns",
|
||||
config.Logging.System,
|
||||
config.Logging.Instance,
|
||||
)
|
||||
return slog.New(handler)
|
||||
}// }}}
|
||||
|
||||
func main() {
|
||||
initLogger.Info("application", "version", VERSION)
|
||||
|
||||
device.Host = config.Device.Address
|
||||
device.Port = config.Device.Port
|
||||
device.Username = config.Device.Username
|
||||
device.Password = config.Device.Password
|
||||
device.Timeout = config.Device.Timeout
|
||||
device.Init()
|
||||
|
||||
registerWebserverHandlers()
|
||||
startWebserver()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue