Ejemplo n.º 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU()*2 + 1)

	flag.Parse()
	os.Chdir(filepath.Dir(os.Args[0]))
	fmt.Println("Listen server address: " + *addr)
	fmt.Println("Read configuration file success, fithpath: " + filepath.Join(filepath.Dir(os.Args[0]), *configPath))

	App.Load(*configPath)

	if sqliteDns, ok := App.Database["Sqlite"]; ok && sqliteDns != "" {
		sqlite, err := utils.NewSqlite(sqliteDns)
		if err != nil {
			fmt.Println(err)
			os.Exit(-1)
		}

		defer sqlite.Close()
		orm := NewActiveRecord(sqlite)
		Middleware.Add("orm", orm)
		Middleware.Add("db", sqlite)
	}

	App.HandleFavicon()
	App.HandleStatic()
	App.ListenAndServe(*addr)
}
Ejemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU()*2 + 1)

	flag.Parse()
	os.Chdir(filepath.Dir(os.Args[0]))
	fmt.Println("Listen server address: " + *addr)
	fmt.Println("Read configuration file success, fithpath: " + filepath.Join(filepath.Dir(os.Args[0]), *configPath))

	App.Load(*configPath)

	sqlite, err := utils.NewSqlite("./data/todo.db")
	if err != nil {
		fmt.Println(err)
		os.Exit(-1)
	}

	defer sqlite.Close()
	Middleware.Add("db", sqlite)

	App.HandleFavicon()
	App.HandleStatic()
	App.ListenAndServe(*addr)
}