-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsmsc3.go
52 lines (43 loc) · 1004 Bytes
/
smsc3.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
package main
import (
"os"
"os/signal"
"regexp"
"github.com/mdouchement/logger"
"github.com/mdouchement/smsc3/smsc"
"github.com/sirupsen/logrus"
)
// https://gist.github.com/adothompson/1737188
func main() {
l := logrus.New()
l.SetFormatter(&logger.LogrusTextFormatter{
DisableColors: false,
ForceColors: true,
ForceFormatting: true,
PrefixRE: regexp.MustCompile(`^(\[.*?\])\s`),
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
s := &smsc.SMSC{
SMPPaddr: os.Getenv("SMSC3_SMPP_ADDR"),
Username: os.Getenv("SMSC3_USERNAME"),
Password: os.Getenv("SMSC3_PASSWORD"),
HTTPaddr: os.Getenv("SMSC3_HTTP_ADDR"),
}
if s.SMPPaddr == "" {
s.SMPPaddr = ":20001"
}
if s.HTTPaddr == "" {
s.HTTPaddr = ":6000"
}
smsc.Initialize(logger.WrapLogrus(l), s)
go func() {
if err := s.Listen(); err != nil {
l.Fatal(err)
}
}()
defer s.Stop()
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, os.Kill)
<-signals
}