-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (36 loc) · 833 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
package main
import (
"github.com/codemodus/freenet/coms"
"github.com/codemodus/sigmon/v2"
"github.com/sirupsen/logrus"
)
func main() {
// Wire into and ignore common system signals.
sm := sigmon.New(nil)
sm.Start()
// coms provides info/error logging, done signaling, and a WaitGroup.
c := coms.New(logrus.New())
// setup iptables
closeIptables, err := setupIptables()
if err != nil {
c.Error(err)
return
}
defer closeIptables()
// Conc wraps a lambda in a go routine and handles WaitGroup accounting.
c.Conc(func() {
listenTCP(c, 80, false)
})
c.Conc(func() {
listenTCP(c, 443, true)
})
// Setup system signal behavior (die on all sigs).
sm.Set(func(s *sigmon.State) {
c.Info("goodbye")
c.Close()
})
// Wait for WaitGroup resolution.
c.Wait()
// Remove system signal wiring.
sm.Stop()
}