Exemple #1
0
//create a new connector
func NewSimpleConnector(driverName, driverSource string,
	l log.ILogger, maxConn int, debug bool) Connector {
	db, err := sql.Open(driverName, driverSource)

	if err == nil {
		err = db.Ping()
	}

	if err != nil {
		defer db.Close()
		//如果异常,则显示并退出
		log.Fatalln("[ DBC][ " + driverName + "] " + err.Error())
		return nil
	}

	// 设置最大连接数
	if maxConn > 0 {
		db.SetMaxOpenConns(maxConn)
	}

	return &SimpleDbConnector{
		_db:          db,
		_orm:         orm.NewOrm(db),
		driverName:   driverName,
		driverSource: driverName,
		logger:       l,
	}
}
Exemple #2
0
func (this *Interceptor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if this._app == nil {
		log.Fatalln("Please use web.NewInterceptor(gof.App) to initialize!")
		os.Exit(1)
	}
	this.handle(this._app, w, r, this._execute)
}
Exemple #3
0
func (this *MainApp) Config() *gof.Config {
	if this._config == nil {
		if cfg, err := gof.LoadConfig(this._confFilePath); err == nil {
			this._config = cfg
			cfg.Set("exp_fee_bit", float64(1))
		} else {
			log.Fatalln(err)
		}
	}
	return this._config
}