-
Notifications
You must be signed in to change notification settings - Fork 0
/
mon.go
54 lines (46 loc) · 1.07 KB
/
mon.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
package main
import (
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
type ASN struct {
Id bson.ObjectId `bson:"_id,omitempty"`
Number int `bson:"number"`
Name string `bson:"name"`
Descr string `bson:"descr"`
}
type IPAddr struct {
AsnId bson.ObjectId `bson:"asn_id,omitempty"`
Address string `bson:"address"`
Reverse string `bson:"reverse"`
}
func Collection(server string) (session *mgo.Session, c *mgo.Collection, err error) {
session, err = mgo.Dial(server)
if err != nil {
panic(err)
}
// Optional. Switch the session to a monotonic behavior.
session.SetMode(mgo.Monotonic, true)
c = session.DB("asn-lookup").C("asns")
c.EnsureIndex(mgo.Index{
Key: []string{"number"},
Unique: true,
DropDups: true,
Sparse: true,
})
c.EnsureIndex(mgo.Index{
Key: []string{"address"},
Unique: true,
DropDups: true,
Sparse: true,
})
return session, c, err
}
/*
result := ASN{}
err = c.Find(bson.M{"number": 15169}).One(&result)
if err != nil {
log.Fatal(err)
}
fmt.Println("ASN:", result.Name)
*/