echoip/main.go

44 lines
1.1 KiB
Go
Raw Normal View History

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 {
2015-09-21 18:03:52 +02:00
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"`
ReverseLookup bool `short:"r" long:"reverselookup" description:"Perform reverse hostname lookups" default:"false"`
Template string `short:"t" long:"template" description:"Path to template" default:"index.html"`
2015-09-17 20:57:27 +02:00
}
_, 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
2015-09-21 18:03:52 +02:00
a.ReverseLookup = opts.ReverseLookup
2015-09-17 20:57:27 +02:00
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)
}
}