IPMux is an open-source GoLang library that provides a simple and efficient way to multiplex HTTP clients based on source IP addresses. This library is designed to handle scenarios where you need to make HTTP requests from specific network interfaces based on the source IP.
This library could be useful to bypass rate limit errors which operate on source IPs.
- Multiplex HTTP clients based on source IP addresses.
- Customizable options for creating HTTP clients.
- Easy-to-use interface for seamless integration.
- Enabling DNS cache with a refresh interval.
go get github.com/optimus-hft/go-ipmux
package main
import (
"fmt"
"io"
"time"
"github.com/optimus-hft/go-ipmux"
)
func main() {
// both ips should be attached to your device for IPMux to operate properly
ips := []string{"192.168.0.1", "192.168.0.2"}
ipMux, err := ipmux.New(ips, ipmux.WithTimeout(10*time.Second))
if err != nil {
fmt.Println(err)
return
}
client := ipMux.Client()
response, err := client.Get("https://google.com")
if err != nil {
panic(err)
}
defer response.Body.Close()
fmt.Println(io.ReadAll(response.Body))
}
- ips: List of IP addresses to create HTTP clients for.
- options: Optional parameters to customize client creation. Returns a new IPMux instance.
Returns an HTTP client associated with one of the IPs provided in the New function. Returns http.DefaultClient
if no clients are available.
Returns a list of all clients created for the list of IPs given in New
. Returns a list containing one client (http.DefaultClient
) when there are no available clients.
Change the base client used to create clients for IPMux.
Set timeout on both client and dialer of the clients.
Set keepalive on dialer of the clients.
Change the base transport (http.RoundTripper) used to create clients for IPMux.
Change the base dialer used to create clients for IPMux.
Enable the DNS cache feature with a refresh interval.
Change the default context to control background goroutine like DNS cache refresh. The default context is context.Background()
.
Pull requests and bug reports are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.