-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (45 loc) · 959 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
51
52
53
54
55
package main
import (
"log"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"sangjihaksik/share"
_ "sangjihaksik/srv-bus"
_ "sangjihaksik/srv-menu"
_ "sangjihaksik/srv-notice"
_ "sangjihaksik/static"
)
func main() {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
var l net.Listener
var err error
if _, err = net.ResolveTCPAddr("tcp", share.ListenAddr); err == nil {
l, err = net.Listen("tcp", share.ListenAddr)
} else {
if _, err = os.Stat(share.ListenAddr); !os.IsNotExist(err) {
err := os.Remove(share.ListenAddr)
if err != nil {
panic(err)
}
}
l, err = net.Listen("unix", share.ListenAddr)
if err != nil {
panic(err)
}
err = os.Chmod(share.ListenAddr, 0o777)
}
if err != nil {
panic(err)
}
server := http.Server{
Handler: share.HttpMux,
}
log.Println("Serve")
go server.Serve(l)
<-sig
log.Println("Exit")
}