proxyclient

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 15 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
    _ "github.com/cnlangzi/proxyclient/v2ray"
)

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

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 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