proxyclient

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 16 Imported by: 0

README

ProxyClient

Enhanced HTTP Client with Multi-Proxy Support for Go

ProxyClient is a Go package that extends the standard http.Client to seamlessly support multiple proxy protocols, including HTTP/HTTPS, SOCKS4, SOCKS5, SSL, V2Ray, SSR/SS, and MTProto. It provides a unified interface for developers to interact with diverse proxy types without manual low-level configurations.

Tests Codecov Go Report Card Go Reference GitHub Release License PRs welcome

Features

Multi-Protocol Support:
HTTP/HTTPS Proxy: Direct and authenticated connections.
SOCKS4/SOCKS5: Full support for SOCKS protocols (IPv4/IPv6).
SSL/TLS Tunneling: Secure proxy tunneling for encrypted traffic.
V2Ray/SSR/SS: Integration with popular proxy tools (Shadowsocks, V2Ray core).
MTProto: Native support for Telegram’s MTProto protocol.

Simplified API: Create a proxy-enabled client with a single function call.
Authentication: Built-in handling for username/password, encryption keys, and token-based auth.
Compatibility: Fully compatible with Go’s standard http.Client methods (Get, Post, etc.).

Quick Start
Installation
go get github.com/cnlangzi/proxyclient
Usage Example
package main

import (
    "fmt"
    "github.com/cnlangzi/proxyclient"
    // import v5 vmess/vless/trojan/ssr (via xray)
    _ "github.com/cnlangzi/proxyclient/xray"
    // import ss
    _ "github.com/cnlangzi/proxyclient/ss"
)

func main() {
    // Create a client with SOCKS5 proxy
    client, err := proxyclient.New("socks5://user:pass@127.0.0.1:1080")
    
    if err != nil {
        panic(err)
    }

    // Use like a standard http.Client
    resp, err := client.Get("https://example.com")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("Response status:", resp.Status)
}

Supported Proxy Types
Protocol Example Config
http http://user:pass@127.0.0.1:8080
https https://user:pass@127.0.0.1:8080
socks4 socks4://user:pass@127.0.0.1:1080
socks5 socks5://user:pass@127.0.0.1:1080
trojan trojan://pass@host:40021?allowInsecure=0&sni=&type=ws
vmess(v5) vmess://eyJ2IjogIjIiLCAicHMiOiAiXHU1Yz...
vless(v5) vless://uuid@host:port?allowInsecure=false&security=tls...
ss ss://user:pass@127.0.0.1:8080
ssr ssr://user:pass@127.0.0.1:8080
ssh ssh://user:pass@127.0.0.1:2222
MTProto mtproto://user:pass@127.0.0.1:8080

Why Use proxyclient?

Unified Interface: Simplify code for multi-proxy environments.
Extensible: Easily add new proxy protocols via modular design.


Contributions welcome! 🚀

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownProtocol = errors.New("proxyclient: unknown proxy protocol")
	ErrInvalidHost     = errors.New("proxyclient: invalid proxy host")
)

Functions

func CreateTransport added in v0.0.2

func CreateTransport(o *Options) *http.Transport

func GetFreePort added in v0.0.2

func GetFreePort() (int, error)

func IsDomain added in v0.0.5

func IsDomain(s string) bool

func IsHost added in v0.0.5

func IsHost(s string) bool

func IsIP added in v0.0.5

func IsIP(s string) bool

func New

func New(proxyURL string, options ...Option) (*http.Client, error)

func Ping added in v0.0.2

func Ping(host string, port string, timeout time.Duration) bool

Ping performs a TCP fast-fail dial to host:port and reports whether the remote accepted the SYN within the (capped) timeout. It is intentionally limited to TCP: hysteria2 / hy2 use UDP, and a successful TCP dial against a UDP-only endpoint is meaningless. Use PingWithScheme for protocol-aware dispatch.

The returned bool is best-effort: even if the kernel returns a SYN-ACK, the remote service may still be dead. The caller is expected to run a full status probe afterwards; Ping is only a cheap pre-filter.

func PingWithScheme added in v0.1.1

func PingWithScheme(host string, port string, scheme string, timeout time.Duration) bool

PingWithScheme dispatches to TCP or UDP fast-fail based on the proxy scheme. Unknown schemes fall back to TCP. scheme matching is case-insensitive and supports the short alias "hy2" alongside "hysteria2".

UDP fast-fail: dial the UDP socket, send a 0-byte datagram, then attempt a short read. A successful dial + write implies the port is open; ICMP "port unreachable" or a read error from a half-open socket is treated as still-alive for hysteresis reasons (UDP is unreliable and a single probe is not authoritative).

func ProxyHTTP

func ProxyHTTP(u *url.URL, o *Options) (http.RoundTripper, error)

func ProxySocks4

func ProxySocks4(u *url.URL, o *Options) (http.RoundTripper, error)

func ProxySocks5

func ProxySocks5(u *url.URL, o *Options) (http.RoundTripper, error)

func RegisterParser added in v0.0.3

func RegisterParser(proto string, f FuncParser)

func RegisterProxy

func RegisterProxy(proto string, f ProxyFunc)

func SchemeOfURL added in v0.1.1

func SchemeOfURL(rawURL string) string

SchemeOfURL extracts the scheme from a raw proxy URL string. It tolerates whitespace and an empty input. An unparsable URL returns "".

This is a lightweight parser used by callers that already have a raw URL string (e.g. the SQLite-backed proxy table) and don't want to pay the cost of a full url.Parse round-trip into the proxyclient URL registry.

func SetDeadline added in v0.0.8

func SetDeadline(conn net.Conn, timeout time.Duration, disableKeepAlives bool) (net.Conn, error)

func WithRecover added in v0.0.5

func WithRecover(dial func() (net.Conn, error)) (conn net.Conn, err error)

Types

type Bool added in v0.0.5

type Bool struct {
	// contains filtered or unexported fields
}

func (*Bool) MarshalJSON added in v0.0.5

func (i *Bool) MarshalJSON() ([]byte, error)

func (*Bool) UnmarshalJSON added in v0.0.5

func (i *Bool) UnmarshalJSON(data []byte) error

func (Bool) Value added in v0.0.5

func (i Bool) Value() bool

Add a getter method to retrieve the value

type Dialer added in v0.0.2

type Dialer func(ctx context.Context, network string, address string) (net.Conn, error)

type FuncParser added in v0.0.3

type FuncParser func(u *url.URL) (URL, error)

type Int added in v0.0.3

type Int struct {
	// contains filtered or unexported fields
}

func (*Int) MarshalJSON added in v0.0.3

func (i *Int) MarshalJSON() ([]byte, error)

func (*Int) UnmarshalJSON added in v0.0.3

func (i *Int) UnmarshalJSON(data []byte) error

func (Int) Value added in v0.0.3

func (i Int) Value() int

Add a getter method to retrieve the value

type Option

type Option func(*Options)

func WithClient

func WithClient(c *http.Client) Option

func WithTimeout

func WithTimeout(d time.Duration) Option

func WithTransport

func WithTransport(tr *http.Transport) Option

type Options

type Options struct {
	Timeout   time.Duration
	Client    *http.Client
	Transport *http.Transport
}

type ProxyFunc

type ProxyFunc func(*url.URL, *Options) (http.RoundTripper, error)

type String added in v0.0.5

type String struct {
	// contains filtered or unexported fields
}

func (*String) MarshalJSON added in v0.0.5

func (i *String) MarshalJSON() ([]byte, error)

func (*String) UnmarshalJSON added in v0.0.5

func (i *String) UnmarshalJSON(data []byte) error

func (String) Value added in v0.0.5

func (i String) Value() string

Add a getter method to retrieve the value

type URL added in v0.0.3

type URL interface {
	Raw() *url.URL
	Opaque() string
	Protocol() string
	Host() string
	Port() string
	User() string
	Password() string
	Name() string
}

func ParseURL added in v0.0.3

func ParseURL(u string) (URL, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL