first commit
This commit is contained in:
commit
7181502a64
11 changed files with 770 additions and 0 deletions
38
main.go
Normal file
38
main.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfgPath := flag.String("c", "nutils.toml", "config file path")
|
||||
flag.Parse()
|
||||
|
||||
cfg, err := LoadConfig(*cfgPath)
|
||||
if err != nil {
|
||||
log.Fatalf("config: %v", err)
|
||||
}
|
||||
|
||||
geo, err := InitGeo(&GeoConfig{
|
||||
AsnURL: cfg.Geo.DownloadURLAsn,
|
||||
CityURL: cfg.Geo.DownloadURLCity,
|
||||
AsnPath: filepath.Join(cfg.Geo.CacheDir, filepath.Base(cfg.Geo.AsnDB)),
|
||||
CityPath: filepath.Join(cfg.Geo.CacheDir, filepath.Base(cfg.Geo.CityDB)),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("geo init: %v", err)
|
||||
}
|
||||
defer geo.Close()
|
||||
|
||||
services := BuildServices(cfg)
|
||||
if len(services) == 0 {
|
||||
log.Fatal("no services enabled")
|
||||
}
|
||||
|
||||
fmt.Printf("nutils listening on %s with %d services\n", cfg.Server.Listen, len(services))
|
||||
log.Fatal(http.ListenAndServe(cfg.Server.Listen, Handle(services, geo)))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue