-
Notifications
You must be signed in to change notification settings - Fork 179
/
main.go
63 lines (52 loc) · 1.49 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
package main
import (
"context"
"fmt"
"github.com/mojocn/felix/api"
"github.com/mojocn/felix/model"
"github.com/mojocn/felix/socks5ws"
"log"
"log/slog"
"os"
"os/signal"
"syscall"
"time"
)
var (
buildTime, gitHash string
userUUID = "53881505-c10c-464a-8949-e57184a576a9"
url = "ws://demo.libragen.cn/5sdfasdf"
protocol = "socks5e" // or vless
)
func main() {
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
slog.SetLogLoggerLevel(slog.LevelDebug)
model.DB()
appCfg := model.Cfg()
app, err := socks5ws.NewClientLocalSocks5Server(fmt.Sprintf("127.0.0.1:%d", appCfg.PortSocks5), "GeoLite2-Country.mmdb")
if err != nil {
log.Fatal(err)
}
slog.With("socks5", app.AddrSocks5).Info("socks5 server listening on")
ctx, cancel := context.WithCancel(context.Background())
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGABRT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGKILL)
httpS := api.AdminServer(fmt.Sprintf("127.0.0.1:%d", appCfg.PortHttp))
go func() {
if err := httpS.ListenAndServe(); err != nil {
log.Fatal(err)
}
}()
go func() {
sig := <-signalChan
fmt.Printf("\nReceived signal: %s\n", sig)
cancel() // Cancel the context
// Shutdown the server with a timeout
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, 2*time.Second)
defer shutdownCancel()
if err := httpS.Shutdown(shutdownCtx); err != nil {
log.Fatalf("Server Shutdown Failed:%+v", err)
}
}()
app.Run(ctx)
}