-
Notifications
You must be signed in to change notification settings - Fork 2
/
listeners.go
55 lines (48 loc) · 1.02 KB
/
listeners.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
52
53
54
55
package main
import (
"net/url"
"github.com/sirupsen/logrus"
. "github.com/jaracil/nexus/log"
"golang.org/x/net/context"
)
func listen() {
if listenContext != nil {
listenCancel()
}
listenContext, listenCancel = context.WithCancel(mainContext)
listeners(listenContext)
}
func listeners(ctx context.Context) {
for _, v := range opts.Listeners {
if u, err := url.Parse(v); err == nil {
switch u.Scheme {
case "tcp":
go tcpListener(u, ctx, false)
case "tcp+proxy":
go tcpListener(u, ctx, true)
case "ssl":
go sslListener(u, ctx, false)
case "ssl+proxy":
go sslListener(u, ctx, true)
case "http":
go httpListener(u, ctx)
case "https":
go httpsListener(u, ctx)
case "health":
go healthCheckListener(u, ctx)
default:
Log.WithFields(logrus.Fields{
"listener": u,
}).Print("Unknown listener")
mainCancel()
return
}
} else {
Log.WithFields(logrus.Fields{
"listener": v,
}).Print("Couldn't parse listener")
mainCancel()
return
}
}
}