mirror of
https://github.com/mpolden/echoip.git
synced 2024-11-14 01:12:47 +01:00
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
flags "github.com/jessevdk/go-flags"
|
|
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/martinp/ipd/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"`
|
|
ReverseLookup bool `short:"r" long:"reverse-lookup" description:"Perform reverse hostname lookups"`
|
|
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)
|
|
}
|
|
|
|
api := api.New()
|
|
api.CORS = opts.CORS
|
|
if opts.ReverseLookup {
|
|
log.Println("Enabling reverse lookup")
|
|
api.EnableReverseLookup()
|
|
}
|
|
if opts.DBPath != "" {
|
|
log.Printf("Enabling country lookup (using database: %s)\n", opts.DBPath)
|
|
if err := api.EnableCountryLookup(opts.DBPath); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
api.Template = opts.Template
|
|
|
|
log.Printf("Listening on %s", opts.Listen)
|
|
if err := api.ListenAndServe(opts.Listen); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|