/
module.go
40 lines (34 loc) · 950 Bytes
/
module.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
package geoip
import (
"context"
"github.com/safing/portbase/api"
"github.com/safing/portbase/modules"
"github.com/safing/portmaster/updates"
)
var module *modules.Module
func init() {
module = modules.Register("geoip", prep, nil, nil, "base", "updates")
}
func prep() error {
if err := api.RegisterEndpoint(api.Endpoint{
Path: "intel/geoip/countries",
Read: api.PermitUser,
// Do not attach to module, as the data is always available anyway.
StructFunc: func(ar *api.Request) (i interface{}, err error) {
return countries, nil
},
Name: "Get Country Information",
Description: "Returns a map of country information centers indexed by ISO-A2 country code",
}); err != nil {
return err
}
return module.RegisterEventHook(
updates.ModuleName,
updates.ResourceUpdateEvent,
"Check for GeoIP database updates",
func(c context.Context, i interface{}) error {
worker.triggerUpdate()
return nil
},
)
}