arnaucube
arnaucube/goBlockchainDataAnalysisPublic Self-hosted repository
goBlockchainDataAnalysis/stats.go
stats.goRaw
 1package main
 2
 3import "gopkg.in/mgo.v2/bson"
 4
 5func getStats() StatsModel {
 6	var stats StatsModel
 7	err := statsCollection.Find(bson.M{"title": "stats"}).One(&stats)
 8	check(err)
 9	stats.Title = "stats"
10	return stats
11}
12
13func updateStats(stats StatsModel) {
14	var oldStats StatsModel
15	err := statsCollection.Find(bson.M{"title": "stats"}).One(&oldStats)
16	if err != nil {
17		err = statsCollection.Insert(stats)
18		check(err)
19	} else {
20		err = statsCollection.Update(bson.M{"title": "stats"}, &stats)
21		check(err)
22	}
23}