Beispiel #1
0
func (this *Cache) Delete(key string) {
	this.client.Delete(key)

	if conf.IsDev() {
		log.Println("cache delete:", key)
	}
}
Beispiel #2
0
func init() {
	dataSource := conf.Config.Datasource
	maxIdleConns := conf.Config.MaxIdleConns
	maxOpenConns := conf.Config.MaxOpenConns

	log.Println("mysql datasource:", dataSource, ", maxIdleConns", maxIdleConns, ", maxOpenConns", maxOpenConns)

	db, err := sql.Open("mysql", dataSource)
	utils.HandleError(err)

	db.SetMaxIdleConns(maxIdleConns)
	db.SetMaxOpenConns(maxOpenConns)

	DbMap = &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}}

	// Trace query log
	if conf.IsDev() {
		DbMap.TraceOn("", log.New(os.Stdout, "", log.Lmicroseconds))
	}

	// Define table metadata
	new(UserManager).AddTable()
	new(ChatroomManager).AddTable()

	utils.HandleError(DbMap.CreateTablesIfNotExists())
}
Beispiel #3
0
func (this *Cache) Put(key string, value []byte) {
	item := memcache.Item{Key: key, Value: value}
	this.client.Set(&item)

	if conf.IsDev() {
		log.Println("cache put:", key)
	}
}
Beispiel #4
0
func (this *Cache) Increment(key string, delta uint64) uint64 {
	newValue, err := this.client.Increment(key, delta)
	utils.HandleError(err)

	if conf.IsDev() {
		log.Println("cache increment:", key, delta)
	}

	return newValue
}
Beispiel #5
0
func (this *Cache) Get(key string) []byte {
	item, err := this.client.Get(key)
	if conf.IsDev() {
		utils.HandleError(err)
	}

	if item == nil {
		if conf.IsDev() {
			log.Println("cache not hit:", key)
		}
		return nil
	}

	if conf.IsDev() {
		log.Println("cache hit:", key)
	}

	return item.Value
}
Beispiel #6
0
func initGorelic() {
	if !conf.IsDev() {
		return
	}

	agent = gorelic.NewAgent()
	agent.NewrelicName = "go-gamereviews"
	agent.Verbose = true
	agent.NewrelicLicense = conf.Config.NewrelicLicense
	agent.CollectHTTPStat = true
	agent.HTTPTimer = metrics.NewTimer()
	agent.Run()
}