找不到用golang调用xray的文档 #4280
Unanswered
kokocooler2020
asked this question in
Q&A
Replies: 5 comments 1 reply
-
比如这段代码, 报错: panic: interface conversion: interface is nil, not inbound.Manager |
Beta Was this translation helpful? Give feedback.
0 replies
-
难以置信 26Kstart的项目 找不到文档... |
Beta Was this translation helpful? Give feedback.
0 replies
-
package main
import (
"context"
"fmt"
"os"
"github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/app/log"
"github.com/xtls/xray-core/app/proxyman"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/proxy/dokodemo"
"github.com/xtls/xray-core/proxy/freedom"
)
func main() {
c := core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{}), // Add the log app
serial.ToTypedMessage(&dispatcher.Config{}), // Add the dispatcher app
serial.ToTypedMessage(&proxyman.InboundConfig{}),
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
},
Inbound: []*core.InboundHandlerConfig{
generateInboundConfig(),
},
Outbound: []*core.OutboundHandlerConfig{
generateOutboundConfig(),
},
}
instance, err := core.New(&c)
if err != nil {
panic(err)
}
if err := instance.Start(); err != nil {
panic(err)
}
// Keep the program running until interrupted
<-make(chan struct{})
}
func generateInboundConfig() *core.InboundHandlerConfig {
return &core.InboundHandlerConfig{
Tag: "inbound",
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(1080)}},
Listen: net.NewIPOrDomain(net.ParseAddress("127.0.0.1")),
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(net.ParseAddress("127.0.0.1")),
Port: 1080,
Networks: []net.Network{
net.Network_TCP,
net.Network_UDP,
},
FollowRedirect: true,
}),
}
}
func generateOutboundConfig() *core.OutboundHandlerConfig {
return &core.OutboundHandlerConfig{
Tag: "outbound1",
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
StreamSettings: &internet.StreamConfig{
Protocol: internet.TransportProtocol_TCP,
TransportSettings: []*internet.TransportConfig{
{
Protocol: internet.TransportProtocol_TCP,
Settings: serial.ToTypedMessage(&tcp.Config{}),
},
},
SecurityType: "none",
},
}),
ProxySettings: serial.ToTypedMessage(&freedom.Config{
DestinationOverride: &freedom.DestinationOverride{
Server: &protocol.ServerEndpoint{
Address: net.NewIPOrDomain(net.ParseAddress("127.0.0.1")),
Port: 80,
},
},
}),
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you very much for your help |
Beta Was this translation helpful? Give feedback.
1 reply
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
实在是找不到用golang调用xray的文档, 对xray并不熟悉, 使用golang调用xray代码很晕, 完全不知道该做什么, 也不太理解设置项的具体含义.
Beta Was this translation helpful? Give feedback.
All reactions