-
Notifications
You must be signed in to change notification settings - Fork 0
/
league_mapper.go
63 lines (51 loc) · 1.48 KB
/
league_mapper.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
package app
import (
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
)
const (
//SourceLiveScore represent livescore source
SourceLiveScore = "livescore"
)
//LeagueMapper represent league mapper
type LeagueMapper struct {
ID string `json:"id" bson:"_id"`
Key string `json:"key" bson:"key"`
URL string `json:"url" bson:"url"`
SourceKey string `json:"source_key" bson:"source_key"`
}
//NewLeagueMapper handle create new league mapper
func NewLeagueMapper(session *mgo.Session, key string, url string, sourceKey string) (*LeagueMapper, error) {
l := new(LeagueMapper)
l.ID = bson.NewObjectId().Hex()
l.Key = key
l.URL = url
l.SourceKey = sourceKey
if err := LeagueMappers(session).Insert(l); err != nil {
return nil, err
}
return l, nil
}
//LeagueList get league list
func LeagueList(session *mgo.Session) ([]LeagueMapper, error) {
ll := []LeagueMapper{}
if err := LeagueMappers(session).Find(bson.M{}).Sort("key").All(&ll); err != nil {
return nil, err
}
return ll, nil
}
//RemoveLeagueMappersByID remove leagueMappersByID
func RemoveLeagueMappersByID(session *mgo.Session, ID string) error {
if err := LeagueMappers(session).RemoveId(ID); err != nil {
return err
}
return nil
}
//GetLeagueMapperByKey get league mapper by specific key
func GetLeagueMapperByKey(session *mgo.Session, key string) (LeagueMapper, error) {
l := LeagueMapper{}
if err := LeagueMappers(session).Find(bson.M{"key": key}).One(&l); err != nil {
return l, err
}
return l, nil
}