Beispiel #1
0
func TestMain(m *testing.M) {

	// testG = gas.New()
	// testG.LoadConfig("../testfiles/config_test.yaml")

	//var md ModelInterface

	cfg := config.New(map[interface{}]interface{}{"Db": testConfig})
	testM = New(cfg).(*MySQLModel)
	// switch strings.ToLower(c.Db.SQLDriver) {
	//     case "mysql":

	//     default:
	//         panic("Unknow Database Driver: " + g.Config.Db.SQLDriver)

	// }

	//err := db.ConnectWithDefault(testConfig["username"], testConfig["password"], testConfig["dbname"])
	//if err != nil {
	//	panic(err.Error())
	//}
	//md.SetDB(db)
	//builder.SetDB(db)
	//md.SetBuilder(builder)
	//
	//testM = md

	code := m.Run()
	// shutdown()
	os.Exit(code)
}
Beispiel #2
0
// New gas Object
//
// Ex:
//  g := New()
//  g.Run()
func New(configPath ...string) *Engine {
	g := &Engine{}

	// init logger
	if _, err := os.Stat("log/system.log"); os.IsNotExist(err) {
		os.Mkdir("log", 0700)
	}

	g.Logger = logger.New("log/system.log")

	// init pool
	g.pool.New = func() interface{} {
		c := createContext(nil, g)

		return c
	}

	// load config
	g.Config = config.New(defaultConfig)
	if len(configPath) != 0 {
		for _, path := range configPath {
			g.Config.Load(path)
		}
	}

	// set router
	g.Router = newRouter(g) //&Router{g: g}

	// set default not found handler
	g.Router.SetNotFoundHandler(defaultNotFoundHandler)

	// set default panic handler
	g.Router.SetPanicHandler(defaultPanicHandler)

	// set static file path
	g.Router.StaticPath(g.Config.GetString("PubDir"))

	// add Log middleware
	// g.Router.Use(middleware.LogMiddleware)

	return g
}