Browse Source

move init func to separate files

Darien Raymond 6 years ago
parent
commit
3de50a6412

+ 0 - 6
app/commander/commander.go

@@ -100,9 +100,3 @@ func (c *Commander) Close() error {
 
 
 	return nil
 	return nil
 }
 }
-
-func init() {
-	common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
-		return NewCommander(ctx, cfg.(*Config))
-	}))
-}

+ 15 - 0
app/commander/init.go

@@ -0,0 +1,15 @@
+// +build !confonly
+
+package commander
+
+import (
+	"context"
+
+	"v2ray.com/core/common"
+)
+
+func init() {
+	common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
+		return NewCommander(ctx, cfg.(*Config))
+	}))
+}

+ 15 - 0
app/dns/init.go

@@ -0,0 +1,15 @@
+// +build !confonly
+
+package dns
+
+import (
+	"context"
+
+	"v2ray.com/core/common"
+)
+
+func init() {
+	common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
+		return New(ctx, config.(*Config))
+	}))
+}

+ 0 - 6
app/dns/server.go

@@ -220,9 +220,3 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err
 
 
 	return nil, newError("returning nil for domain ", domain).Base(lastErr)
 	return nil, newError("returning nil for domain ", domain).Base(lastErr)
 }
 }
-
-func init() {
-	common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
-		return New(ctx, config.(*Config))
-	}))
-}

+ 0 - 7
transport/internet/kcp/config.go

@@ -3,7 +3,6 @@ package kcp
 import (
 import (
 	"crypto/cipher"
 	"crypto/cipher"
 
 
-	"v2ray.com/core/common"
 	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/internet"
 )
 )
 
 
@@ -97,9 +96,3 @@ func (c *Config) GetReceivingInFlightSize() uint32 {
 func (c *Config) GetReceivingBufferSize() uint32 {
 func (c *Config) GetReceivingBufferSize() uint32 {
 	return c.GetReadBufferSize() / c.GetMTUValue()
 	return c.GetReadBufferSize() / c.GetMTUValue()
 }
 }
-
-func init() {
-	common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
-		return new(Config)
-	}))
-}

+ 0 - 5
transport/internet/kcp/dialer.go

@@ -6,7 +6,6 @@ import (
 	"io"
 	"io"
 	"sync/atomic"
 	"sync/atomic"
 
 
-	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/dice"
 	"v2ray.com/core/common/dice"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
@@ -92,7 +91,3 @@ func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet
 
 
 	return iConn, nil
 	return iConn, nil
 }
 }
-
-func init() {
-	common.Must(internet.RegisterTransportDialer(protocolName, DialKCP))
-}

+ 22 - 0
transport/internet/kcp/init.go

@@ -0,0 +1,22 @@
+// +build !confonly
+
+package kcp
+
+import (
+	"v2ray.com/core/common"
+	"v2ray.com/core/transport/internet"
+)
+
+func init() {
+	common.Must(internet.RegisterTransportDialer(protocolName, DialKCP))
+}
+
+func init() {
+	common.Must(internet.RegisterTransportListener(protocolName, ListenKCP))
+}
+
+func init() {
+	common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
+		return new(Config)
+	}))
+}

+ 0 - 5
transport/internet/kcp/listener.go

@@ -6,7 +6,6 @@ import (
 	"crypto/tls"
 	"crypto/tls"
 	"sync"
 	"sync"
 
 
-	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/internet"
@@ -190,7 +189,3 @@ func (w *Writer) Close() error {
 func ListenKCP(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, addConn internet.ConnHandler) (internet.Listener, error) {
 func ListenKCP(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, addConn internet.ConnHandler) (internet.Listener, error) {
 	return NewListener(ctx, address, port, streamSettings, addConn)
 	return NewListener(ctx, address, port, streamSettings, addConn)
 }
 }
-
-func init() {
-	common.Must(internet.RegisterTransportListener(protocolName, ListenKCP))
-}

+ 0 - 4
transport/internet/quic/dialer.go

@@ -210,7 +210,3 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
 
 
 	return client.openConnection(destAddr, config, tlsConfig, streamSettings.SocketSettings)
 	return client.openConnection(destAddr, config, tlsConfig, streamSettings.SocketSettings)
 }
 }
-
-func init() {
-	common.Must(internet.RegisterTransportDialer(protocolName, Dial))
-}

+ 0 - 5
transport/internet/quic/hub.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"context"
 	"time"
 	"time"
 
 
-	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/protocol/tls/cert"
 	"v2ray.com/core/common/protocol/tls/cert"
 	"v2ray.com/core/common/signal/done"
 	"v2ray.com/core/common/signal/done"
@@ -131,7 +130,3 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
 
 
 	return listener, nil
 	return listener, nil
 }
 }
-
-func init() {
-	common.Must(internet.RegisterTransportListener(protocolName, Listen))
-}

+ 22 - 0
transport/internet/quic/init.go

@@ -0,0 +1,22 @@
+// +build !confonly
+
+package quic
+
+import (
+	"v2ray.com/core/common"
+	"v2ray.com/core/transport/internet"
+)
+
+func init() {
+	common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
+		return new(Config)
+	}))
+}
+
+func init() {
+	common.Must(internet.RegisterTransportDialer(protocolName, Dial))
+}
+
+func init() {
+	common.Must(internet.RegisterTransportListener(protocolName, Listen))
+}

+ 0 - 11
transport/internet/quic/quic.go

@@ -1,10 +1,5 @@
 package quic
 package quic
 
 
-import (
-	"v2ray.com/core/common"
-	"v2ray.com/core/transport/internet"
-)
-
 //go:generate errorgen
 //go:generate errorgen
 
 
 // Here is some modification needs to be done before update quic vendor.
 // Here is some modification needs to be done before update quic vendor.
@@ -15,9 +10,3 @@ import (
 
 
 const protocolName = "quic"
 const protocolName = "quic"
 const internalDomain = "quic.internal.v2ray.com"
 const internalDomain = "quic.internal.v2ray.com"
-
-func init() {
-	common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
-		return new(Config)
-	}))
-}