更改实现模式采用go 协程

This commit is contained in:
giaogiao 2023-07-31 17:46:59 +08:00
parent 2b7462c2fe
commit 4b25cd5c1b
1 changed files with 9 additions and 3 deletions

12
main.go
View File

@ -2,7 +2,7 @@
* @Author: giaogiao giaogiao * @Author: giaogiao giaogiao
* @Date: 2023-07-28 08:53:13 * @Date: 2023-07-28 08:53:13
* @LastEditors: giaogiao giaogiao * @LastEditors: giaogiao giaogiao
* @LastEditTime: 2023-07-31 16:50:10 * @LastEditTime: 2023-07-31 17:32:36
* @FilePath: \go\main.go * @FilePath: \go\main.go
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
@ -17,6 +17,7 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"github.com/parnurzeal/gorequest" "github.com/parnurzeal/gorequest"
@ -53,15 +54,20 @@ func read_configuration_file() {
fmt.Println(err) fmt.Println(err)
return return
} }
//fmt.Println(len(tooltt.Node))求结构体数组大小
} }
func read_a_file(node *[]Node) { func read_a_file(node *[]Node) {
var wg sync.WaitGroup
wg.Add(len(*node))
for _, item := range *node { for _, item := range *node {
// fmt.Println(item.Remarks, item.Country, item.Port) // fmt.Println(item.Remarks, item.Country, item.Port)
text_url(item.Remarks, item.Country, item.Port) go text_url(item.Remarks, item.Country, item.Port, wg.Done)
} }
wg.Wait()
} }
func text_url(remarks string, country string, port int) { func text_url(remarks string, country string, port int, done func()) {
defer done()
var port_string string = strconv.Itoa(port) var port_string string = strconv.Itoa(port)
setup.CwLog().Infof("start_testing country:%s,port:%d", country, port) setup.CwLog().Infof("start_testing country:%s,port:%d", country, port)
request := gorequest.New().Proxy("socks5://127.0.0.1:" + port_string) request := gorequest.New().Proxy("socks5://127.0.0.1:" + port_string)