forked from yirenchengfeng/LiteSpeedTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (81 loc) · 1.77 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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
grpcServer "github.com/xxf098/lite-proxy/api/rpc/liteserver"
C "github.com/xxf098/lite-proxy/constant"
"github.com/xxf098/lite-proxy/core"
"github.com/xxf098/lite-proxy/utils"
webServer "github.com/xxf098/lite-proxy/web"
)
var (
port = flag.Int("p", 8090, "set port")
test = flag.String("test", "", "test from command line with subscription link or file")
conf = flag.String("config", "", "command line options")
ping = flag.Int("ping", 2, "retry times to ping link on startup")
grpc = flag.Bool("grpc", false, "start grpc server")
version = flag.Bool("v", false, "show current version of clash")
)
func main() {
flag.Parse()
if *version {
fmt.Printf("LiteSpeedTest %s %s %s with %s %s\n", C.Version, runtime.GOOS, runtime.GOARCH, runtime.Version(), C.BuildTime)
return
}
link := ""
for _, arg := range os.Args {
if strings.HasPrefix(arg, "-") {
continue
}
if _, err := utils.CheckLink(arg); err == nil {
link = arg
break
}
}
if *test != "" {
if err := webServer.TestFromCMD(*test, conf); err != nil {
log.Fatal(err)
}
return
}
// start grpc server
if *grpc {
if err := grpcServer.StartServer(uint16(*port)); err != nil {
log.Fatalln(err)
}
return
}
if link == "" {
if len(os.Args) < 2 {
*port = 10888
}
if err := webServer.ServeFile(*port); err != nil {
log.Fatalln(err)
}
return
}
c := core.Config{
LocalHost: "0.0.0.0",
LocalPort: *port,
Link: link,
Ping: *ping,
}
p, err := core.StartInstance(c)
if err != nil {
log.Fatalln(err)
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigs)
go func() {
<-sigs
p.Close()
}()
p.Run()
}