第一个可用版本

This commit is contained in:
giaogiao 2023-07-28 15:10:48 +08:00
parent 6f9075938d
commit 81cf3e7b64
4 changed files with 78 additions and 7 deletions

3
go.mod
View File

@ -5,6 +5,9 @@ go 1.20
require (
github.com/parnurzeal/gorequest v0.2.16 // indirect
github.com/pkg/errors v0.9.1 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.12.0 // indirect
moul.io/http2curl v1.0.0 // indirect
)

8
go.sum
View File

@ -1,7 +1,15 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/parnurzeal/gorequest v0.2.16 h1:T/5x+/4BT+nj+3eSknXmCTnEVGSzFzPGdpqmUVVZXHQ=
github.com/parnurzeal/gorequest v0.2.16/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
moul.io/http2curl v1.0.0 h1:6XwpyZOYsgZJrU8exnG87ncVkU1FVCcTRpwzOkTDUi8=

63
main.go
View File

@ -2,23 +2,72 @@
* @Author: giaogiao giaogiao
* @Date: 2023-07-28 08:53:13
* @LastEditors: giaogiao giaogiao
* @LastEditTime: 2023-07-28 08:54:07
* @LastEditTime: 2023-07-28 15:10:40
* @FilePath: \go\main.go
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
"time"
"github.com/parnurzeal/gorequest"
"go.uber.org/zap"
)
func myFunc() {
fmt.Println("Call myFunc")
func read_a_file() {
type Node []struct {
Remarks string `json:"remarks"`
Country string `json:"country"`
Port int `json:"port"`
}
// 打开json文件
jsonFile, err := os.Open("user.json")
// 最好要处理以下错误
if err != nil {
fmt.Println(err)
}
// 要记得关闭
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
var node Node
err = json.Unmarshal(byteValue, &node)
if err != nil {
fmt.Println(err)
}
for _, item := range node {
// fmt.Println(item.Remarks, item.Country, item.Port)
text_url(item.Remarks, item.Country, item.Port)
}
}
func text_url() {
fmt.Println("Call myFunc2")
func text_url(remarks string, country string, port int) {
sugar := zap.NewExample().Sugar()
sugar.Infof("start_testing country:%s,port:%d", country, port)
request := gorequest.New().Proxy("socks5://23.224.102.3:" + strconv.Itoa(port))
resp, body, errs := request.Get("https://ip.shagain.club/").End()
if errs != nil {
// fmt.Print(errs)
sugar.Errorf("start_testing country:%s,port:%d,error:%s", country, port, errs)
sugar.Infof("start_switching_ip country:%s,port:%d", country, port)
// resp, err := http.Get("http://127.0.0.1:9049/v1/ips?num=1&country=" + country + "&state=all&city=all&zip=all&t=txt&port=" + strconv.Itoa(port) + "&isp=all&start=&end=")
// sugar.Infof("switch_ip_to_return resp:%s,err:%s", resp, err)
}
sugar.Infof("requestToReturnTheResult resp:%s,body:%s", resp, body)
}
func main() {
fmt.Println("嗨客网(www.haicoder.net)")
text_url()
for {
time.Sleep(5000)
read_a_file()
}
}

11
user.json Normal file
View File

@ -0,0 +1,11 @@
[
{
"remarks": "giao",
"country": "UK",
"port": 30000
},{
"remarks": "giao2",
"country": "UK",
"port": 30001
}
]