/
decoder.go
120 lines (108 loc) · 2.52 KB
/
decoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package db
import (
"context"
"encoding/json"
"github.com/atulanand206/find/server/core/models"
"go.mongodb.org/mongo-driver/bson"
mg "go.mongodb.org/mongo-driver/mongo"
)
func DecodePlayerJsonString(content string) (player models.Player, err error) {
if err = json.Unmarshal([]byte(content), &player); err != nil {
return
}
return
}
func DecodePermissions(cursor []bson.Raw) (scopes []models.Permission, err error) {
for _, doc := range cursor {
var scope models.Permission
err = bson.Unmarshal(doc, &scope)
if err != nil {
return
}
scopes = append(scopes, scope)
}
return
}
func DecodeMatches(cursor []bson.Raw) (games []models.Game, err error) {
for _, doc := range cursor {
var game models.Game
err = bson.Unmarshal(doc, &game)
if err != nil {
return
}
games = append(games, game)
}
return
}
func DecodeIndexes(cursor []bson.Raw) (indexes []models.Index, err error) {
for _, doc := range cursor {
var index models.Index
err = bson.Unmarshal(doc, &index)
if err != nil {
return
}
indexes = append(indexes, index)
}
return
}
func DecodeQuestions(cursor []bson.Raw) (questions []models.Question, err error) {
for _, doc := range cursor {
var question models.Question
err = bson.Unmarshal(doc, &question)
if err != nil {
return
}
questions = append(questions, question)
}
return
}
func DecodeSnapshots(cursor []bson.Raw) (snapshots []models.Snapshot, err error) {
for _, doc := range cursor {
var snapshot models.Snapshot
err = bson.Unmarshal(doc, &snapshot)
if err != nil {
return
}
snapshots = append(snapshots, snapshot)
}
return
}
func DecodeSubscribers(cursor []bson.Raw) (subscribers []models.Subscriber, err error) {
for _, doc := range cursor {
var subscriber models.Subscriber
err = bson.Unmarshal(doc, &subscriber)
if err != nil {
return
}
subscribers = append(subscribers, subscriber)
}
return
}
func DecodeTeams(cursor []bson.Raw) (teams []models.Team, err error) {
for _, doc := range cursor {
var team models.Team
err = bson.Unmarshal(doc, &team)
if err != nil {
return
}
teams = append(teams, team)
}
return
}
func DecodePlayers(cursor []bson.Raw) (players []models.Player, err error) {
for _, doc := range cursor {
var player models.Player
err = bson.Unmarshal(doc, &player)
if err != nil {
return
}
players = append(players, player)
}
return
}
func DecodeRaw(cursor *mg.Cursor) (documents []bson.Raw, err error) {
for cursor.Next(context.Background()) {
documents = append(documents, cursor.Current)
}
return
}