package main

import (
	"log"
	"os/exec"

	"git.trj.tw/golang/go-geoip/module/geoip"
	"git.trj.tw/golang/go-geoip/routes/routes"
)

func main() {
	downloadGeoDB()
	// init geodb
	db, err := geoip.NewReader()
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	// init gin
	engine := routes.NewEngine()
	routes.RegRoutes(engine)
	engine.Run(":10230")
}

func downloadGeoDB() {
	log.Println("start download new geoip db")
	cmd := exec.Command("/usr/bin/download-geodb.sh")
	cmd.Start()

	err := cmd.Wait()
	if err != nil {
		log.Printf("command run fail:: %v \n", err)
	}
}
