forked from cert-lv/graphoscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.go
45 lines (38 loc) · 1001 Bytes
/
filters.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
package main
import (
"encoding/json"
)
/*
* Structure to hold search filter's state
*/
type Filter struct {
// When filter is enabled - related request will be launched
// to retrieve the data when web page is loaded
Enabled bool `json:"enabled" bson:"enabled"`
// User's original query
Query string `json:"query" bson:"query"`
}
/*
* Handle 'filters' websocket command to save all current user's filters
*/
func (a *Account) filtersHandler(filters string) {
var list []map[string]*Filter
err := json.Unmarshal([]byte(filters), &list)
if err != nil {
a.send("error", "Can't parse filters data.", "Can't save filters!")
log.Error().
Str("ip", a.Session.IP).
Str("username", a.Username).
Msg("Can't unmarshal filters data: " + err.Error())
return
}
err = a.update("filters", list)
if err != nil {
a.send("error", err.Error(), "Can't save filters!")
return
}
log.Debug().
Str("ip", a.Session.IP).
Str("username", a.Username).
Msg("Filters are saved")
}