From 41b54ff61e6eb8d559e1f6695c42387f8ccc64ce Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sat, 19 Jun 2021 13:04:50 +0100 Subject: [PATCH] move buildable to cfg common --- infra/conf/blackhole.go | 3 ++- infra/conf/blackhole_test.go | 3 ++- infra/conf/{ => cfgcommon}/buildable.go | 2 +- infra/conf/dns_proxy_test.go | 3 ++- infra/conf/dokodemo_test.go | 3 ++- infra/conf/freedom_test.go | 3 ++- infra/conf/general_test.go | 4 ++-- infra/conf/http_test.go | 3 ++- infra/conf/reverse_test.go | 3 ++- infra/conf/router.go | 2 +- infra/conf/shadowsocks_test.go | 3 ++- infra/conf/socks_test.go | 5 +++-- infra/conf/transport_internet.go | 6 +++--- infra/conf/v2ray.go | 4 ++-- infra/conf/vless_test.go | 5 +++-- infra/conf/vmess_test.go | 5 +++-- 16 files changed, 34 insertions(+), 23 deletions(-) rename infra/conf/{ => cfgcommon}/buildable.go (85%) diff --git a/infra/conf/blackhole.go b/infra/conf/blackhole.go index 12223cdcc..3b4380ace 100644 --- a/infra/conf/blackhole.go +++ b/infra/conf/blackhole.go @@ -2,6 +2,7 @@ package conf import ( "encoding/json" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/golang/protobuf/proto" @@ -32,7 +33,7 @@ func (v *BlackholeConfig) Build() (proto.Message, error) { if err != nil { return nil, newError("Config: Failed to parse Blackhole response config.").Base(err) } - responseSettings, err := response.(Buildable).Build() + responseSettings, err := response.(cfgcommon.Buildable).Build() if err != nil { return nil, err } diff --git a/infra/conf/blackhole_test.go b/infra/conf/blackhole_test.go index 72e3ad395..56583071a 100644 --- a/infra/conf/blackhole_test.go +++ b/infra/conf/blackhole_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/serial" @@ -9,7 +10,7 @@ import ( ) func TestHTTPResponseJSON(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(BlackholeConfig) } diff --git a/infra/conf/buildable.go b/infra/conf/cfgcommon/buildable.go similarity index 85% rename from infra/conf/buildable.go rename to infra/conf/cfgcommon/buildable.go index 1d01cd66a..1c6ae0b47 100644 --- a/infra/conf/buildable.go +++ b/infra/conf/cfgcommon/buildable.go @@ -1,4 +1,4 @@ -package conf +package cfgcommon import "github.com/golang/protobuf/proto" diff --git a/infra/conf/dns_proxy_test.go b/infra/conf/dns_proxy_test.go index 1d4057133..0d1d1d6f0 100644 --- a/infra/conf/dns_proxy_test.go +++ b/infra/conf/dns_proxy_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -9,7 +10,7 @@ import ( ) func TestDnsProxyConfig(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(DNSOutboundConfig) } diff --git a/infra/conf/dokodemo_test.go b/infra/conf/dokodemo_test.go index c27e6f2a2..d5e945c56 100644 --- a/infra/conf/dokodemo_test.go +++ b/infra/conf/dokodemo_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -9,7 +10,7 @@ import ( ) func TestDokodemoConfig(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(DokodemoConfig) } diff --git a/infra/conf/freedom_test.go b/infra/conf/freedom_test.go index d2ae5d09f..3ce74ef35 100644 --- a/infra/conf/freedom_test.go +++ b/infra/conf/freedom_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -10,7 +11,7 @@ import ( ) func TestFreedomConfig(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(FreedomConfig) } diff --git a/infra/conf/general_test.go b/infra/conf/general_test.go index a6fbb372b..f9f739dd1 100644 --- a/infra/conf/general_test.go +++ b/infra/conf/general_test.go @@ -2,15 +2,15 @@ package conf_test import ( "encoding/json" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/golang/protobuf/proto" "github.com/v2fly/v2ray-core/v4/common" - . "github.com/v2fly/v2ray-core/v4/infra/conf" ) -func loadJSON(creator func() Buildable) func(string) (proto.Message, error) { +func loadJSON(creator func() cfgcommon.Buildable) func(string) (proto.Message, error) { return func(s string) (proto.Message, error) { instance := creator() if err := json.Unmarshal([]byte(s), instance); err != nil { diff --git a/infra/conf/http_test.go b/infra/conf/http_test.go index d2fd081c3..597063d9e 100644 --- a/infra/conf/http_test.go +++ b/infra/conf/http_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" . "github.com/v2fly/v2ray-core/v4/infra/conf" @@ -8,7 +9,7 @@ import ( ) func TestHTTPServerConfig(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(HTTPServerConfig) } diff --git a/infra/conf/reverse_test.go b/infra/conf/reverse_test.go index 3006ef7ff..8290e3ec3 100644 --- a/infra/conf/reverse_test.go +++ b/infra/conf/reverse_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/app/reverse" @@ -8,7 +9,7 @@ import ( ) func TestReverseConfig(t *testing.T) { - creator := func() conf.Buildable { + creator := func() cfgcommon.Buildable { return new(conf.ReverseConfig) } diff --git a/infra/conf/router.go b/infra/conf/router.go index 2ad12535c..f3be93385 100644 --- a/infra/conf/router.go +++ b/infra/conf/router.go @@ -64,7 +64,7 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) { return nil, newError("failed to parse to strategy config.").Base(err) } var ts proto.Message - if builder, ok := rawConfig.(Buildable); ok { + if builder, ok := rawConfig.(cfgcommon.Buildable); ok { ts, err = builder.Build() if err != nil { return nil, err diff --git a/infra/conf/shadowsocks_test.go b/infra/conf/shadowsocks_test.go index 743ef82e3..1d41ffca5 100644 --- a/infra/conf/shadowsocks_test.go +++ b/infra/conf/shadowsocks_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -11,7 +12,7 @@ import ( ) func TestShadowsocksServerConfigParsing(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(ShadowsocksServerConfig) } diff --git a/infra/conf/socks_test.go b/infra/conf/socks_test.go index c8a1858b0..8acb2bd24 100644 --- a/infra/conf/socks_test.go +++ b/infra/conf/socks_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -11,7 +12,7 @@ import ( ) func TestSocksInboundConfig(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(SocksServerConfig) } @@ -50,7 +51,7 @@ func TestSocksInboundConfig(t *testing.T) { } func TestSocksOutboundConfig(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(SocksClientConfig) } diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index de5470900..2440650c2 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -98,7 +98,7 @@ func (c *KCPConfig) Build() (proto.Message, error) { if err != nil { return nil, newError("invalid mKCP header config.").Base(err).AtError() } - ts, err := headerConfig.(Buildable).Build() + ts, err := headerConfig.(cfgcommon.Buildable).Build() if err != nil { return nil, newError("invalid mKCP header config").Base(err).AtError() } @@ -125,7 +125,7 @@ func (c *TCPConfig) Build() (proto.Message, error) { if err != nil { return nil, newError("invalid TCP header config").Base(err).AtError() } - ts, err := headerConfig.(Buildable).Build() + ts, err := headerConfig.(cfgcommon.Buildable).Build() if err != nil { return nil, newError("invalid TCP header config").Base(err).AtError() } @@ -221,7 +221,7 @@ func (c *QUICConfig) Build() (proto.Message, error) { if err != nil { return nil, newError("invalid QUIC header config.").Base(err).AtError() } - ts, err := headerConfig.(Buildable).Build() + ts, err := headerConfig.(cfgcommon.Buildable).Build() if err != nil { return nil, newError("invalid QUIC header config").Base(err).AtError() } diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index 8e2d61c6c..e100b0a22 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -235,7 +235,7 @@ func (c *InboundDetourConfig) Build() (*core.InboundHandlerConfig, error) { if dokodemoConfig, ok := rawConfig.(*DokodemoConfig); ok { receiverSettings.ReceiveOriginalDestination = dokodemoConfig.Redirect } - ts, err := rawConfig.(Buildable).Build() + ts, err := rawConfig.(cfgcommon.Buildable).Build() if err != nil { return nil, err } @@ -297,7 +297,7 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) { if err != nil { return nil, newError("failed to parse to outbound detour config.").Base(err) } - ts, err := rawConfig.(Buildable).Build() + ts, err := rawConfig.(cfgcommon.Buildable).Build() if err != nil { return nil, err } diff --git a/infra/conf/vless_test.go b/infra/conf/vless_test.go index 0ef1dd73e..92b7cc065 100644 --- a/infra/conf/vless_test.go +++ b/infra/conf/vless_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -13,7 +14,7 @@ import ( ) func TestVLessOutbound(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(VLessOutboundConfig) } @@ -59,7 +60,7 @@ func TestVLessOutbound(t *testing.T) { } func TestVLessInbound(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(VLessInboundConfig) } diff --git a/infra/conf/vmess_test.go b/infra/conf/vmess_test.go index 726d40df8..743f88f5a 100644 --- a/infra/conf/vmess_test.go +++ b/infra/conf/vmess_test.go @@ -1,6 +1,7 @@ package conf_test import ( + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "testing" "github.com/v2fly/v2ray-core/v4/common/net" @@ -13,7 +14,7 @@ import ( ) func TestVMessOutbound(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(VMessOutboundConfig) } @@ -63,7 +64,7 @@ func TestVMessOutbound(t *testing.T) { } func TestVMessInbound(t *testing.T) { - creator := func() Buildable { + creator := func() cfgcommon.Buildable { return new(VMessInboundConfig) }