-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (50 loc) · 1.1 KB
/
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
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"path"
"path/filepath"
"qingchoulove.github.com/bifrost/server"
"syscall"
)
var (
cliPwd = flag.String("pwd", "password", "Input Basic Auth Password")
cliUser = flag.String("user", "user", "Input Basic Auth Username")
cliPort = flag.Int("port", 8080, "Input web server port")
)
func main() {
flag.Parse()
cancel, cancelFunc := context.WithCancel(context.Background())
// graceful shutdown
signals := make(chan os.Signal)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
go func() {
s := <-signals
log.Println("Caught signal:", s)
cancelFunc()
}()
// run server
serve, err := server.NewServer(cancel,
server.OptionStaticPath(getCurrPath()),
server.OptionUserName(*cliUser),
server.OptionPassword(*cliPwd),
server.OptionPort(*cliPort))
if err != nil {
log.Println("NewServer Server:", err)
return
}
err = serve.Run()
if err != nil {
log.Println("Server Stop:", err)
}
}
func getCurrPath() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return path.Dir("")
}
return dir
}