-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (60 loc) · 1.24 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
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall" //nolint:gci
)
var (
Version = "undefined"
LastCommit = "undefined"
)
var (
root, ip, port string
)
func init() {
fmt.Println("version:", Version)
fmt.Println("last_commit:", LastCommit)
p := flag.String("p", "10000", "-p 8888 prot default 10000")
dir := flag.String("d", "./", "-d /opt dir default ./")
flag.Parse()
port = ":" + *p
root = *dir
// ip addr
ips := getIps()
for {
ipnum := 0
fmt.Println("Enter select ip number")
_, _ = fmt.Scanln(&ipnum)
if ipnum >= 0 && ipnum < len(ips) {
ip = "http://" + ips[ipnum]
break
}
fmt.Println("Enter select ip number err")
}
}
func main() {
files := map[string]string{}
getAllFile(root, files)
ctx := context.Background()
ctx, cancelFunc := context.WithCancel(ctx)
go GinServer(ctx)
sigChan := make(chan os.Signal, 1)
go scanCmd(ctx, files, sigChan)
signal.Notify(sigChan, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-sigChan
log.Printf("get a signal %s\n", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
cancelFunc()
log.Println("upftp server exit now...")
return
case syscall.SIGHUP:
default:
}
}
}