Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Jul 22, 2024
1 parent bf0caca commit cd8c2f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 5 additions & 6 deletions proxy/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// ErrProtocol indicates that parsing encountered an unknown protocol.
var ErrProtocol = errors.New("proxy: unknown protocol")

// A proxy holds a proxy's protocol and how to parse it.
// A protocol holds a proxy protocol's name and how to parse it.
type protocol struct {
name string
parse func(*url.URL) (Proxy, error)
Expand Down Expand Up @@ -44,10 +44,9 @@ func pick(name string) protocol {
return protocol{}
}

// Parse parses a proxy url that has been encoded in a registered format.
// The string returned is the format name used during format registration.
// Format registration is typically done by an init function in the codec-
// specific package.
// Parse parses proxy *url.URL that holds the proxy info into Proxy.
// Protocol registration is typically done by an init function in the
// proxy-specific package.
func Parse(proxyURL *url.URL) (Proxy, error) {
if proxyURL == nil {
return nil, errors.New("proxy: nil url")
Expand All @@ -62,7 +61,7 @@ func Parse(proxyURL *url.URL) (Proxy, error) {
return p.parse(proxyURL)
}

// ParseFromURL parses a
// ParseFromURL parses url string that holds the proxy info into Proxy.
func ParseFromURL(proxy string) (Proxy, error) {
proxyURL, err := url.Parse(proxy)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ const (
var DefaultProxy Proxy = nil

type Proxy interface {
// Address returns the address of the proxy.
Address() string

// Protocol returns the protocol of the proxy.
Protocol() string

// String returns the string representation of the proxy.
String() string

// DialContext is used to dial TCP networks with context.
DialContext(context.Context, *M.Metadata) (net.Conn, error)

// DialUDP is used to to dial/listen UDP networks.
DialUDP(*M.Metadata) (net.PacketConn, error)
}

Expand Down

0 comments on commit cd8c2f5

Please sign in to comment.