-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmain.go
63 lines (59 loc) · 1.65 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 (
"encoding/json"
"github.com/chuccp/utils/log"
core "github.com/v2fly/v2ray-core/v5"
_ "github.com/v2fly/v2ray-core/v5/app/proxyman/inbound"
_ "github.com/v2fly/v2ray-core/v5/app/proxyman/outbound"
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
v4 "github.com/v2fly/v2ray-core/v5/infra/conf/v4"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
)
func main() {
export := os.Getenv("PORT")
if export ==""{
export = "9096"
}
uuid := os.Getenv("UUID")
path := os.Getenv("WSPATH")
alterId := os.Getenv("alterId")
Security := os.Getenv("Security")
if !strings.HasPrefix(path,"/"){
path = "/"+path
}
port,_:=strconv.ParseUint(export,10,32)
var settingsJson = `{
"udp": false,
"clients": [
{
"id": "`+uuid+`",
"alterId": `+alterId+`,
"email": "[email protected]"
}
],
"allowTransparent": false
}`
settingsData := json.RawMessage(settingsJson)
ws:=v4.TransportProtocol("ws")
streamConfig:=v4.StreamConfig{Network:&ws,Security: Security,WSSettings:&v4.WebSocketConfig{Path: path}}
inboundV4:=&v4.InboundDetourConfig{Protocol: "vmess",PortRange:&cfgcommon.PortRange{From: uint32(port), To: uint32(port)},Settings:&settingsData,StreamSetting: &streamConfig}
vc:=&v4.Config{InboundConfigs:[]v4.InboundDetourConfig{*inboundV4},OutboundConfigs:[]v4.OutboundDetourConfig{{
Protocol:"freedom",
}}}
cfg,_:=vc.Build()
install, err := core.New(cfg)
if err == nil {
err = install.Start()
log.Info("121212", err)
} else {
log.Info("5345345", err)
}
log.Info("!!!!!!", err)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGBUS)
<-sig
}