-
Notifications
You must be signed in to change notification settings - Fork 0
/
gost.go
51 lines (43 loc) · 1.1 KB
/
gost.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
package main
import (
"github.com/robmcl4/gost/storage"
"github.com/robmcl4/gost/config"
"github.com/robmcl4/gost/config/shutdown"
"github.com/robmcl4/gost/email"
"github.com/robmcl4/gost/smtp_server"
log "github.com/Sirupsen/logrus"
)
func main() {
log.SetLevel(log.DebugLevel)
log.Info("Starting gost server")
if err := config.LoadConfigFromFile(); err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Warning("could not load config, using default")
}
backend, err := storage.GetBackend()
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Error("could not initialize backend")
return
}
emch := make(chan *email.SMTPEmail, 64)
go intercept(backend, emch)
go runServer(emch)
shutdown.ShutdownOnSigint()
}
func runServer(emch chan *email.SMTPEmail) {
err := smtp_server.ReceiveEmail(emch)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Error("could not start connection")
return
}
}
func intercept(b storage.Backend, ch chan *email.SMTPEmail) {
for {
b.PutEmail(<- ch)
}
}