-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-console.go
More file actions
59 lines (53 loc) · 1.06 KB
/
docker-console.go
File metadata and controls
59 lines (53 loc) · 1.06 KB
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
56
57
58
59
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
app "./console"
)
func main() {
var address *string = flag.String("Address", "", "server listen address")
var port *string = flag.String("Port", "8080", "server listen port")
var sessionKey *string = flag.String("SessionKey", "_auth_user_id", "user serssion key")
flag.Parse()
options := app.DefaultOptions
options.Address = *address
options.Port = *port
options.SessionKey = *sessionKey
app, err := app.New(nil, &options)
registerSignals(app)
err = app.Run()
if err != nil {
exit(err, 4)
}
fmt.Println("Start server on " + options.Port + " success")
}
func exit(err error, code int) {
if err != nil {
fmt.Println(err)
}
os.Exit(code)
}
func registerSignals(app *app.App) {
sigChan := make(chan os.Signal, 1)
signal.Notify(
sigChan,
syscall.SIGINT,
syscall.SIGTERM,
)
go func() {
for {
s := <-sigChan
switch s {
case syscall.SIGINT, syscall.SIGTERM:
if app.Exit() {
fmt.Println("Send ^C to force exit.")
} else {
os.Exit(5)
}
}
}
}()
}