2015-09-17 20:57:27 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
flags "github.com/jessevdk/go-flags"
|
|
|
|
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/martinp/ifconfigd/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var opts struct {
|
|
|
|
DBPath string `short:"f" long:"file" description:"Path to GeoIP database" value-name:"FILE" default:""`
|
|
|
|
Listen string `short:"l" long:"listen" description:"Listening address" value-name:"ADDR" default:":8080"`
|
|
|
|
CORS bool `short:"x" long:"cors" description:"Allow requests from other domains" default:"false"`
|
|
|
|
Template string `short:"t" long:"template" description:"Path to template" default:"index.html"`
|
|
|
|
}
|
|
|
|
_, err := flags.ParseArgs(&opts, os.Args)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
var a *api.API
|
|
|
|
if opts.DBPath == "" {
|
|
|
|
a = api.New()
|
|
|
|
} else {
|
|
|
|
a, err = api.NewWithGeoIP(opts.DBPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2015-09-17 22:09:50 +02:00
|
|
|
|
2015-09-17 20:57:27 +02:00
|
|
|
a.CORS = opts.CORS
|
|
|
|
a.Template = opts.Template
|
|
|
|
|
2015-09-18 17:13:14 +02:00
|
|
|
log.Printf("Listening on %s", opts.Listen)
|
2015-09-17 20:57:27 +02:00
|
|
|
if err := a.ListenAndServe(opts.Listen); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|