Chore: rename proxy Type() to Proto()

This commit is contained in:
xjasonlyu
2021-02-07 10:38:07 +08:00
parent a3ff3a5a15
commit ee00315894
8 changed files with 38 additions and 15 deletions
+2 -2
View File
@@ -22,8 +22,8 @@ func (b *Base) Addr() string {
return b.addr
}
func (b *Base) Type() string {
return "base"
func (b *Base) Proto() string {
return ""
}
func (b *Base) DialContext(context.Context, *adapter.Metadata) (net.Conn, error) {
+2 -2
View File
@@ -20,8 +20,8 @@ func NewDirect() *Direct {
}
}
func (d *Direct) Type() string {
return "direct"
func (d *Direct) Proto() string {
return DirectProto.String()
}
func (d *Direct) DialContext(ctx context.Context, metadata *adapter.Metadata) (net.Conn, error) {
+24
View File
@@ -0,0 +1,24 @@
package proxy
import "fmt"
const (
DirectProto Proto = iota
ShadowsocksProto
Socks5Proto
)
type Proto uint8
func (proto Proto) String() string {
switch proto {
case DirectProto:
return "direct"
case ShadowsocksProto:
return "ss"
case Socks5Proto:
return "socks5"
default:
return fmt.Sprintf("proto(%d)", proto)
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ type Dialer interface {
type Proxy interface {
Dialer
Addr() string
Type() string
Proto() string
}
// SetDialer sets default Dialer.
+2 -2
View File
@@ -39,8 +39,8 @@ func NewShadowsocks(addr, method, password, obfsMode, obfsHost string) (*Shadows
}, nil
}
func (ss *Shadowsocks) Type() string {
return "ss"
func (ss *Shadowsocks) Proto() string {
return ShadowsocksProto.String()
}
func (ss *Shadowsocks) DialContext(ctx context.Context, metadata *adapter.Metadata) (c net.Conn, err error) {
+2 -2
View File
@@ -29,8 +29,8 @@ func NewSocks5(addr, user, pass string) (*Socks5, error) {
}, nil
}
func (ss *Socks5) Type() string {
return "socks5"
func (ss *Socks5) Proto() string {
return Socks5Proto.String()
}
func (ss *Socks5) DialContext(ctx context.Context, metadata *adapter.Metadata) (c net.Conn, err error) {