1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

67 lines
1.2 KiB
Go
Raw Normal View History

2017-05-16 13:39:59 +02:00
package main
2017-05-16 15:22:40 +02:00
import (
2017-05-19 16:16:14 +02:00
"flag"
2017-05-16 15:22:40 +02:00
"log"
"net/http"
2017-05-16 17:24:08 +02:00
"github.com/julienschmidt/httprouter"
2017-05-16 15:22:40 +02:00
)
2017-05-16 13:39:59 +02:00
2017-05-18 15:23:36 +02:00
var AliceConfig *Config
2017-06-23 16:11:47 +02:00
var AliceRoutesStore *RoutesStore
2017-06-23 17:40:19 +02:00
var AliceNeighboursStore *NeighboursStore
2017-05-18 15:23:36 +02:00
2017-05-16 13:39:59 +02:00
func main() {
2017-05-18 15:23:36 +02:00
var err error
2017-05-19 16:16:14 +02:00
// Handle commandline parameters
configFilenameFlag := flag.String(
"config", "/etc/alicelg/alice.conf",
"Alice looking glass configuration file",
)
flag.Parse()
2017-05-16 15:22:40 +02:00
// Load configuration
2017-05-19 16:16:14 +02:00
AliceConfig, err = loadConfig(*configFilenameFlag)
if err != nil {
log.Fatal(err)
}
// Say hi
printBanner()
log.Println("Using configuration:", AliceConfig.File)
2017-05-16 15:22:40 +02:00
2017-06-23 12:36:32 +02:00
// Setup local routes store
2017-06-23 16:11:47 +02:00
AliceRoutesStore = NewRoutesStore(AliceConfig)
2017-07-04 12:36:48 +02:00
if AliceConfig.Server.EnablePrefixLookup == true {
AliceRoutesStore.Start()
}
2017-06-23 12:36:32 +02:00
2017-06-23 17:40:19 +02:00
// Setup local neighbours store
AliceNeighboursStore = NewNeighboursStore(AliceConfig)
2017-07-04 12:36:48 +02:00
if AliceConfig.Server.EnablePrefixLookup == true {
AliceNeighboursStore.Start()
}
2017-06-23 17:40:19 +02:00
2017-05-16 17:24:08 +02:00
// Setup request routing
router := httprouter.New()
2017-05-16 16:00:01 +02:00
// Serve static content
2018-06-20 12:03:23 +02:00
err = webRegisterAssets(AliceConfig.Ui, router)
2017-05-16 17:24:08 +02:00
if err != nil {
log.Fatal(err)
}
2017-05-16 15:22:40 +02:00
2017-05-18 15:23:36 +02:00
err = apiRegisterEndpoints(router)
2017-05-18 14:44:50 +02:00
if err != nil {
log.Fatal(err)
}
2017-05-16 15:22:40 +02:00
// Start http server
2017-05-22 10:27:19 +02:00
log.Fatal(http.ListenAndServe(AliceConfig.Server.Listen, router))
2017-05-16 13:39:59 +02:00
}