-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-example-mp.go
54 lines (46 loc) · 1.22 KB
/
go-example-mp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
)
func main() {
// Get proxy credentials from environment variables
proxyUsername := os.Getenv("proxy_username")
proxyPassword := os.Getenv("proxy_password")
if proxyUsername == "" || proxyPassword == "" {
fmt.Println("Error: Proxy credentials not set. Please set proxy_username and proxy_password.")
fmt.Println("Example:")
fmt.Println("export proxy_username=your_username")
fmt.Println("export proxy_password=your_password")
os.Exit(1)
}
// Set up the proxy URL
proxyURL, err := url.Parse(fmt.Sprintf("http://customer-%s:%s@mp.evomi.com:3000", proxyUsername, proxyPassword))
if err != nil {
fmt.Println("Error parsing proxy URL:", err)
return
}
// Create a new HTTP client with the proxy
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyURL),
},
}
// Make a request through the proxy
resp, err := client.Get("https://ip.evomi.com/")
if err != nil {
fmt.Println("Error making request:", err)
return
}
defer resp.Body.Close()
// Read and print the response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println(string(body))
}