This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
main.go
93 lines (81 loc) · 1.52 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* @Author: EagleXiang
* @Github: https://github.com/eaglexiang
* @Date: 2018-12-27 08:38:06
* @LastEditors: EagleXiang
* @LastEditTime: 2019-08-28 20:00:23
*/
package main
import (
"fmt"
"os"
"os/signal"
mycmd "github.com/eaglexiang/eagle.tunnel.go/cmd"
"github.com/eaglexiang/eagle.tunnel.go/server"
"github.com/eaglexiang/eagle.tunnel.go/server/config"
"github.com/eaglexiang/go/logger"
"github.com/eaglexiang/go/settings"
)
var service *server.Service
func main() {
args := os.Args[1:]
if len(args) == 0 {
fmt.Println("error: no arg for Eagle Tunnel")
return
}
switch args[0] {
case "check":
check(args)
default:
core(args)
}
}
func waitSig() {
fmt.Println("press Ctrl + C to quit")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
}
// Init 初始化参数系统
func Init(args []string) error {
err := mycmd.ImportArgs(args)
if err != nil {
return err
}
config.ImportConfigFiles()
return nil
}
// check check子命令
func check(args []string) {
err := Init(args[2:])
if err != nil {
logger.Error(err)
return
}
mycmd.Check(args[1])
}
func core(args []string) {
err := Init(args)
if err != nil {
if err.Error() != "no need to continue" {
logger.Error(err)
}
return
}
fmt.Println(settings.ToString())
service = server.CreateService()
defer service.Close()
go startService()
waitSig()
fmt.Println("stoping...")
stopService()
}
func startService() {
err := service.Start()
if err != nil {
logger.Error(err)
}
}
func stopService() {
service.Close()
}