mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Style: format code by gofumpt (#761)
This commit is contained in:
parent
d77be80b40
commit
e286cdcaa8
111 changed files with 293 additions and 291 deletions
|
@ -42,12 +42,10 @@ func (v *BlackholeConfig) Build() (proto.Message, error) {
|
|||
return config, nil
|
||||
}
|
||||
|
||||
var (
|
||||
configLoader = NewJSONConfigLoader(
|
||||
ConfigCreatorCache{
|
||||
"none": func() interface{} { return new(NoneResponse) },
|
||||
"http": func() interface{} { return new(HTTPResponse) },
|
||||
},
|
||||
"type",
|
||||
"")
|
||||
)
|
||||
var configLoader = NewJSONConfigLoader(
|
||||
ConfigCreatorCache{
|
||||
"none": func() interface{} { return new(NoneResponse) },
|
||||
"http": func() interface{} { return new(HTTPResponse) },
|
||||
},
|
||||
"type",
|
||||
"")
|
||||
|
|
|
@ -27,7 +27,7 @@ func init() {
|
|||
|
||||
geositeFilePath := filepath.Join(wd, "geosite.dat")
|
||||
os.Setenv("xray.location.asset", wd)
|
||||
geositeFile, err := os.OpenFile(geositeFilePath, os.O_CREATE|os.O_WRONLY, 0600)
|
||||
geositeFile, err := os.OpenFile(geositeFilePath, os.O_CREATE|os.O_WRONLY, 0o600)
|
||||
common.Must(err)
|
||||
defer geositeFile.Close()
|
||||
|
||||
|
@ -46,6 +46,7 @@ func init() {
|
|||
common.Must(err)
|
||||
common.Must2(geositeFile.Write(listBytes))
|
||||
}
|
||||
|
||||
func TestDNSConfigParsing(t *testing.T) {
|
||||
geositePath := platform.GetAssetLocation("geosite.dat")
|
||||
defer func() {
|
||||
|
|
|
@ -51,6 +51,7 @@ type HTTPRemoteConfig struct {
|
|||
Port uint16 `json:"port"`
|
||||
Users []json.RawMessage `json:"users"`
|
||||
}
|
||||
|
||||
type HTTPClientConfig struct {
|
||||
Servers []*HTTPRemoteConfig `json:"servers"`
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ content 2`,
|
|||
`
|
||||
content
|
||||
|
||||
content 2`},
|
||||
content 2`,
|
||||
},
|
||||
{`content`, `content`},
|
||||
{" ", " "},
|
||||
{`con/*abcd*/tent`, "content"},
|
||||
|
|
|
@ -60,8 +60,7 @@ func (c *MTProtoServerConfig) Build() (proto.Message, error) {
|
|||
return config, nil
|
||||
}
|
||||
|
||||
type MTProtoClientConfig struct {
|
||||
}
|
||||
type MTProtoClientConfig struct{}
|
||||
|
||||
func (c *MTProtoClientConfig) Build() (proto.Message, error) {
|
||||
config := new(mtproto.ClientConfig)
|
||||
|
|
|
@ -338,7 +338,7 @@ func parseDomainRule(domain string) ([]*router.Domain, error) {
|
|||
}
|
||||
return domains, nil
|
||||
}
|
||||
var isExtDatFile = 0
|
||||
isExtDatFile := 0
|
||||
{
|
||||
const prefix = "ext:"
|
||||
if strings.HasPrefix(domain, prefix) {
|
||||
|
@ -417,7 +417,7 @@ func toCidrList(ips StringList) ([]*router.GeoIP, error) {
|
|||
})
|
||||
continue
|
||||
}
|
||||
var isExtDatFile = 0
|
||||
isExtDatFile := 0
|
||||
{
|
||||
const prefix = "ext:"
|
||||
if strings.HasPrefix(ip, prefix) {
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
)
|
||||
|
||||
func BuildConfig(files []string, formats []string) (*core.Config, error) {
|
||||
|
||||
cf := &conf.Config{}
|
||||
for i, file := range files {
|
||||
newError("Reading config: ", file).AtInfo().WriteToLog()
|
||||
|
@ -32,9 +31,7 @@ func BuildConfig(files []string, formats []string) (*core.Config, error) {
|
|||
|
||||
type readerDecoder func(io.Reader) (*conf.Config, error)
|
||||
|
||||
var (
|
||||
ReaderDecoderByFormat = make(map[string]readerDecoder)
|
||||
)
|
||||
var ReaderDecoderByFormat = make(map[string]readerDecoder)
|
||||
|
||||
func init() {
|
||||
ReaderDecoderByFormat["json"] = DecodeJSONConfig
|
||||
|
|
|
@ -70,6 +70,7 @@ type SocksRemoteConfig struct {
|
|||
Port uint16 `json:"port"`
|
||||
Users []json.RawMessage `json:"users"`
|
||||
}
|
||||
|
||||
type SocksClientConfig struct {
|
||||
Servers []*SocksRemoteConfig `json:"servers"`
|
||||
}
|
||||
|
|
|
@ -540,7 +540,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
|
|||
tproxy = internet.SocketConfig_Off
|
||||
}
|
||||
|
||||
var dStrategy = internet.DomainStrategy_AS_IS
|
||||
dStrategy := internet.DomainStrategy_AS_IS
|
||||
switch strings.ToLower(c.DomainStrategy) {
|
||||
case "useip", "use_ip":
|
||||
dStrategy = internet.DomainStrategy_USE_IP
|
||||
|
|
|
@ -127,6 +127,7 @@ type VMessOutboundTarget struct {
|
|||
Port uint16 `json:"port"`
|
||||
Users []json.RawMessage `json:"users"`
|
||||
}
|
||||
|
||||
type VMessOutboundConfig struct {
|
||||
Receivers []*VMessOutboundTarget `json:"vnext"`
|
||||
}
|
||||
|
|
|
@ -380,7 +380,8 @@ func TestConfig_Override(t *testing.T) {
|
|||
fn string
|
||||
want *Config
|
||||
}{
|
||||
{"combine/empty",
|
||||
{
|
||||
"combine/empty",
|
||||
&Config{},
|
||||
&Config{
|
||||
LogConfig: &LogConfig{},
|
||||
|
@ -404,40 +405,54 @@ func TestConfig_Override(t *testing.T) {
|
|||
Reverse: &ReverseConfig{},
|
||||
},
|
||||
},
|
||||
{"combine/newattr",
|
||||
{
|
||||
"combine/newattr",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "old"}}},
|
||||
&Config{LogConfig: &LogConfig{}}, "",
|
||||
&Config{LogConfig: &LogConfig{}, InboundConfigs: []InboundDetourConfig{{Tag: "old"}}}},
|
||||
{"replace/inbounds",
|
||||
&Config{LogConfig: &LogConfig{}, InboundConfigs: []InboundDetourConfig{{Tag: "old"}}},
|
||||
},
|
||||
{
|
||||
"replace/inbounds",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}}},
|
||||
"",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}}}},
|
||||
{"replace/inbounds-replaceall",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}}},
|
||||
},
|
||||
{
|
||||
"replace/inbounds-replaceall",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
|
||||
"",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}}},
|
||||
{"replace/notag-append",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
|
||||
},
|
||||
{
|
||||
"replace/notag-append",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{}, {Protocol: "vmess"}}},
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}}},
|
||||
"",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{}, {Protocol: "vmess"}, {Tag: "pos1", Protocol: "kcp"}}}},
|
||||
{"replace/outbounds",
|
||||
&Config{InboundConfigs: []InboundDetourConfig{{}, {Protocol: "vmess"}, {Tag: "pos1", Protocol: "kcp"}}},
|
||||
},
|
||||
{
|
||||
"replace/outbounds",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}}},
|
||||
"",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}}}},
|
||||
{"replace/outbounds-prepend",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}}},
|
||||
},
|
||||
{
|
||||
"replace/outbounds-prepend",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
|
||||
"config.json",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}}},
|
||||
{"replace/outbounds-append",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
|
||||
},
|
||||
{
|
||||
"replace/outbounds-append",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos2", Protocol: "kcp"}}},
|
||||
"config_tail.json",
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}, {Tag: "pos2", Protocol: "kcp"}}}},
|
||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}, {Tag: "pos2", Protocol: "kcp"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue