Пример #1
0
func main() {
	if len(os.Args) != 3 {
		fmt.Println("Usage:\n\tgo run main.go ./udgerdb.dat \"Opera/9.50 (Nintendo DSi; Opera/507; U; en-US)\"")
		os.Exit(0)
	}

	u, err := udger.New(os.Args[1])
	if err != nil {
		fmt.Println("error: ", err)
		os.Exit(-1)
	}

	fmt.Println(len(u.Browsers), "browsers loaded")
	fmt.Println(len(u.OS), "OS loaded")
	fmt.Println(len(u.Devices), "device types loaded")
	fmt.Println("")

	ua, err := u.Lookup(os.Args[2])
	if err != nil {
		fmt.Println("error: ", err)
		os.Exit(-1)
	}

	fmt.Printf("%+v\n", ua)
}
Пример #2
0
func main() {
	var err error
	t := time.Now()
	logfile, err := os.Create(t.Format("02 Jan 06 15:04:05") + ".log")
	log.SetOutput(logfile)
	port := flag.Int("p", 8080, "server port")
	flag.Parse()
	handler := new(MyHandler)
	handler.u, err = udger.New("udgerdb.dat")
	if err == nil {
		log.Println("UdgerDB loaded successfully")
	} else {
		log.Fatal(err)
	}
	http.Handle("/", handler)
	if err = http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
		log.Fatal(err)
	}
}