update go/l15.go added new function for proxy get env file

This commit is contained in:
hhu67 2026-06-10 01:20:15 +03:00
parent 96a7ebccde
commit 2deb237e98
2 changed files with 33 additions and 4 deletions

View file

@ -6,22 +6,51 @@ import (
"log"
"time"
"encoding/json"
"github.com/joho/godotenv"
"os"
"net/url"
"crypto/tls"
)
type MyIpData struct{
YourIP string `json:"ip"`
YourIP string `json:"query"`
City string `json:"city"`
Country string `json:"country"`
ISP string `json:"org"`
ISP string `json:"isp"`
}
type UA struct{
UserAgent string `json:"user-agent"`
}
func proxy() (bool, string) {
err := godotenv.Load()
if err != nil {
return false, ""
}
proxy := os.Getenv("proxy")
if proxy == "" {
return false, ""
}
return true, proxy
}
func main() {
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
er, proxis := proxy()
if er {
proxyURL, err := url.Parse(proxis)
if err != nil {
return
}
transport.Proxy = http.ProxyURL(proxyURL)
}
fmt.Println("Введите какой хотите user-agent")
var polz string
fmt.Scanln(&polz)
client := &http.Client{
Timeout: 10 * time.Second,
Timeout: 20 * time.Second,
Transport: transport,
}
req, err := http.NewRequest("GET", "https://httpbin.org/user-agent", nil)
if err != nil {
@ -32,7 +61,7 @@ func main() {
if err != nil {
log.Fatalf("%v\n", err)
}
req2, err := http.NewRequest("GET", "https://ipinfo.io", nil)
req2, err := http.NewRequest("GET", "http://ip-api.com/json", nil)
if err != nil {
log.Fatalf("%v\n", err)
}

Binary file not shown.