go - How to set which IP to use for a HTTP request? -


i dont know if it's possible std lib not state current address being used:

http://golang.org/pkg/net/http/

resp, err := http.get("http://example.com/") if err != nil {     // handle error } defer resp.body.close() body, err := ioutil.readall(resp.body) 

what i'm trying set source address http request, why? because don't want use primary ip address kind of stuff...

you can set custom dialer in client's transport.

// create transport http.defaulttransport, specified localaddr transport := &http.transport{     proxy: http.proxyfromenvironment,     dialcontext: (&net.dialer{         timeout:   30 * time.second,         keepalive: 30 * time.second,         localaddr: localaddr,         dualstack: true,     }).dialcontext,     maxidleconns:          100,     idleconntimeout:       90 * time.second,     tlshandshaketimeout:   10 * time.second,     expectcontinuetimeout: 1 * time.second, }  client := &http.client{     transport: transport, } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -