client

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 20 Imported by: 1

README

Contributors Forks Stargazers Issues MIT License


InstantProxy API Client

An unofficial go client for Instant Proxy API

Installation

go get github.com/dthung1602/instant-proxy-api-client

Usage

Make API calls

import (
    "net"
    ipac "github.com/dthung1602/instant-proxy-api-client"
)

// create client
endpoint := ""
client := ipac.NewClient("username", "password", endpoint)

// If endpoint is empty sting, the client make http call
// to the real instant proxy server at https://admin.instantproxies.com
// For testing, start a fake server and pass endpoint = "http://localhost:3000"
// See "Fake server" section

// You don't need to explicitly call Authenticate() before making API calls
// The client will do that automatically
// However, you can call Authenticate to check if the logins is correct 
err := client.Authenticate()

// Read API
proxies, err := client.GetProxies()
ips, err := client.GetAuthorizedIPs()

// Write API
err := client.AddAuthorizedIP(net.ParseIP("127.0.0.1"))
err := client.AddAuthorizedIPs([]net.IP{
    net.ParseIP("132.4.4.6"),
    net.ParseIP("56.77.3.2"),
})

err = client.RemoveAuthorizedIP(net.ParseIP("127.0.0.1"))
err = client.RemoveAuthorizedIPs([]net.IP{
    net.ParseIP("132.4.4.6"),
    net.ParseIP("56.77.3.2"),
})

err = client.SetAuthorizedIPs([]net.IP{
    net.ParseIP("8.8.8.8"),
    net.ParseIP("4.4.4.4"),
})

// Other
myIP, err := client.GetOwnedPublicIP()

proxy, err := ipac.MakeProxy("123.21.1.1:3000")

testProxies, err := ipac.MakeProxies([]string{
    "154.38.148.102:8800",
    "154.37.249.170:8800",
    "87.101.80.161:8800",
})
result := client.TestProxies(testProxies)

Fake server

This module also includes a dead simple replica of InstantProxy server. Login credential:

  • Username: username
  • Password: password
import (
    ipac "github.com/dthung1602/instant-proxy-api-client"
)

port := 3000
authProxies := []net.IP{  // can be nil
    net.ParseIP("123.1.1.1"),
    net.ParseIP("123.1.1.2"),
}
server := ipac.NewFakeServer(port, authProxies)


// run in background, returns immediately
server.StartServing() 
client := ipac.NewClient("username", "password", "http://localhost:3000")
proxies, err := client.GetProxies()
server.Stop()

// run in foreground forever
// only stops on Ctrl+C signal
// page can be in browser at http://localhost:3000
server.ServeForever()

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Duong Thanh Hung - dthung1602@gmail.com

Project Link: https://github.com/dthung1602/instant-proxy-api-client

Acknowledgements

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	UserName string
	Password string
	Endpoint string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(username string, password string, endpoint string) *Client

func (*Client) AddAuthorizedIP

func (client *Client) AddAuthorizedIP(ip net.IP) error

func (*Client) AddAuthorizedIPs

func (client *Client) AddAuthorizedIPs(ips []net.IP) error

func (*Client) Authenticate

func (client *Client) Authenticate() error

func (*Client) GetAuthorizedIPs

func (client *Client) GetAuthorizedIPs() ([]net.IP, error)

func (*Client) GetOwnedPublicIP

func (client *Client) GetOwnedPublicIP() (net.IP, error)

func (*Client) GetProxies

func (client *Client) GetProxies() ([]*Proxy, error)

func (*Client) RemoveAuthorizedIP

func (client *Client) RemoveAuthorizedIP(ip net.IP) error

func (*Client) RemoveAuthorizedIPs

func (client *Client) RemoveAuthorizedIPs(ips []net.IP) error

func (*Client) SetAuthorizedIPs

func (client *Client) SetAuthorizedIPs(ips []net.IP) error

func (*Client) TestOwnedProxies

func (client *Client) TestOwnedProxies() ([]bool, error)

func (*Client) TestProxies

func (client *Client) TestProxies(proxies []*Proxy) []bool

type FakeServer

type FakeServer struct {
	AuthIPs []net.IP
	Port    int
	// contains filtered or unexported fields
}

func NewFakeServer

func NewFakeServer(port int, authIPs []net.IP) *FakeServer

func (*FakeServer) ServeForever

func (server *FakeServer) ServeForever()

ServeForever starts the server in the caller routine and blocks until Stop is called

func (*FakeServer) StartServing

func (server *FakeServer) StartServing()

StartServing starts the server in another go routine and return immediately

func (*FakeServer) Stop

func (server *FakeServer) Stop()

Stop the server

type MockHTTPClient

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

func (*MockHTTPClient) Get

func (mock *MockHTTPClient) Get(url string) (resp *http.Response, err error)

func (*MockHTTPClient) PostForm

func (mock *MockHTTPClient) PostForm(url string, data url.Values) (resp *http.Response, err error)

type Proxy

type Proxy struct {
	IP   net.IP
	Port uint16
}

func MakeProxies

func MakeProxies(strings []string) ([]*Proxy, error)

func MakeProxy

func MakeProxy(str string) (*Proxy, error)

func (*Proxy) String

func (proxy *Proxy) String() string

type Result

type Result[T any] struct {
	Idx int64
	Val T
	Err error
}

type SimpleHTTPClient

type SimpleHTTPClient interface {
	Get(url string) (resp *http.Response, err error)
	PostForm(url string, data url.Values) (resp *http.Response, err error)
}

type Task

type Task[T any] struct {
	Idx int64
	Fnc func() (T, error)
}

type WorkerPool

type WorkerPool[T any] struct {
	// contains filtered or unexported fields
}

func NewWorkerPool

func NewWorkerPool[T any](count int) *WorkerPool[T]

func (*WorkerPool[T]) Close

func (pool *WorkerPool[T]) Close()

Close the worker pool Tasks can no longer be submitted This function must be explicitly called before Wait

func (WorkerPool[T]) ResultErrors

func (pool WorkerPool[T]) ResultErrors() []error

func (WorkerPool[T]) ResultValues

func (pool WorkerPool[T]) ResultValues() []T

func (WorkerPool[T]) Results

func (pool WorkerPool[T]) Results() []*Result[T]

Results prevents accessing to the underlying result array while it still not completed

func (*WorkerPool[T]) Submit

func (pool *WorkerPool[T]) Submit(f func() (T, error))

Submit a new task for execution

func (*WorkerPool[T]) Wait

func (pool *WorkerPool[T]) Wait() []*Result[T]

Wait blocks until all tasks are finished and the results are collected

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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