You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
508 B

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