Пример #1
0
func main() {
	flags := flag.NewFlagSet("tracklog-control", flag.ExitOnError)
	flags.Usage = usage
	configFile := flags.String("config", "config.toml", "path to config file")
	flags.Parse(os.Args[1:])
	if flags.NArg() == 0 {
		usage()
	}

	cnf, err := readConfig(*configFile)
	if err != nil {
		log.Fatalln(err)
	}
	conf = cnf

	dbase := db.Driver(conf.DB.Driver)
	if dbase == nil {
		log.Fatalf("unknown database driver %s\n", conf.DB.Driver)
	}
	if err := dbase.Open(conf.DB.DSN); err != nil {
		log.Fatalf("cannot open database: %s\n", err)
	}
	database = dbase

	args := flags.Args()
	switch args[0] {
	case "user":
		userCmd(args[1:])
	case "import":
		importCmd(args[1:])
	default:
		usage()
	}
}
Пример #2
0
func main() {
	flag.Parse()

	f, err := os.Open(*configFile)
	if err != nil {
		die("cannot open config file: %s", err)
	}
	defer f.Close()
	conf, err := config.Read(f)
	if err != nil {
		die("cannot read config file: %s", err)
	}
	if err := config.Check(conf); err != nil {
		die("invalid config file: %s", err)
	}

	DB := db.Driver(conf.DB.Driver)
	if DB == nil {
		die("unknown database driver %s", conf.DB.Driver)
	}
	if err := DB.Open(conf.DB.DSN); err != nil {
		die("cannot open database: %s", err)
	}

	s, err := server.New(conf, DB)
	if err != nil {
		die("%s", err)
	}

	log.Fatalln(http.ListenAndServe(conf.Server.ListenAddress, s))
}