-
-
Notifications
You must be signed in to change notification settings - Fork 292
/
main.go
50 lines (40 loc) · 822 Bytes
/
main.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
package netenv
import (
"github.com/safing/portbase/modules"
)
// Event Names
const (
ModuleName = "netenv"
NetworkChangedEvent = "network changed"
OnlineStatusChangedEvent = "online status changed"
)
var (
module *modules.Module
)
func init() {
module = modules.Register(ModuleName, prep, start, nil)
module.RegisterEvent(NetworkChangedEvent, true)
module.RegisterEvent(OnlineStatusChangedEvent, true)
}
func prep() error {
if err := registerAPIEndpoints(); err != nil {
return err
}
if err := prepOnlineStatus(); err != nil {
return err
}
return prepLocation()
}
func start() error {
module.StartServiceWorker(
"monitor network changes",
0,
monitorNetworkChanges,
)
module.StartServiceWorker(
"monitor online status",
0,
monitorOnlineStatus,
)
return nil
}