forked from magoo/AuthTables
-
Notifications
You must be signed in to change notification settings - Fork 1
/
datastore.go
51 lines (41 loc) · 1.08 KB
/
datastore.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
package main
import (
"encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/willf/bloom"
"gopkg.in/redis.v4"
)
// Bloom Filter
var filter = bloom.NewWithEstimates(c.BloomSize, 1e-3) // Configurable in environment var.
// Record is the main struct that is passed from applications to AuthTables as JSON.
// Applications send us these, and AuthTables responds with `OK`s or `BAD`.
type Record struct {
UID string `json:"uid"`
IP string `json:"ip"`
Mid string `json:"mid"`
}
// Marshaler returns the input data jsonified.
func (r Record) Marshaler() []byte {
json, err := json.Marshal(r)
if err != nil {
log.Error("Issue marshal'ing json")
}
fmt.Println(string(json))
return json
}
// RecordHashes is a struct ready for use in the bloom filter or redis.
type RecordHashes struct {
uid []byte
uidMID []byte
uidIP []byte
uidALL []byte
ipMID []byte
midIP []byte
}
// Take us online to Redis
var client = redis.NewClient(&redis.Options{
Addr: c.Host + ":" + c.Port,
Password: c.Password, // no password set
DB: 0, // use default DB
})