在合适的地方return

This commit is contained in:
giaogiao 2023-07-28 16:11:32 +08:00
parent 67c06bdf93
commit 602e2af9c2
1 changed files with 15 additions and 4 deletions

19
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-28 15:31:25 * @LastEditTime: 2023-07-28 16:07:39
* @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
*/ */
@ -34,6 +34,7 @@ func read_a_file() {
// 最好要处理以下错误 // 最好要处理以下错误
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return
} }
// 要记得关闭 // 要记得关闭
@ -44,6 +45,7 @@ func read_a_file() {
err = json.Unmarshal(byteValue, &node) err = json.Unmarshal(byteValue, &node)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return
} }
for _, item := range node { for _, item := range node {
// fmt.Println(item.Remarks, item.Country, item.Port) // fmt.Println(item.Remarks, item.Country, item.Port)
@ -52,14 +54,20 @@ func read_a_file() {
} }
func text_url(remarks string, country string, port int) { func text_url(remarks string, country string, port int) {
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://23.224.102.3:" + strconv.Itoa(port)) request := gorequest.New().Proxy("socks5://127.0.0.1:" + strconv.Itoa(port))
resp, body, errs := request.Get("https://ip.shagain.club/").End() resp, body, errs := request.Get("https://ip.shagain.club/").End()
if errs != nil { if errs != nil {
// fmt.Print(errs) fmt.Println("发现 端口:" + strconv.Itoa(port) + "无法连接 开始切换IP")
setup.CwLog().Errorf("start_testing country:%s,port:%d,error:%s", country, port, errs) setup.CwLog().Errorf("start_testing country:%s,port:%d,error:%s", country, port, errs)
setup.CwLog().Infof("start_switching_ip country:%s,port:%d", country, port) setup.CwLog().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=") resp, err := http.Get("http://127.0.0.1:50101/api/get_ip_list?num=1&country=" + country + "&state=all&city=all&zip=all&isp=all&ip_time=1&t=1&port=" + strconv.Itoa(port))
if errs != nil {
fmt.Println("切换IP 失败 端口:" + strconv.Itoa(port))
return
}
fmt.Println("切换IP成功 端口:" + strconv.Itoa(port))
setup.CwLog().Infof("switch_ip_to_return resp:%s,err:%s", resp, err) setup.CwLog().Infof("switch_ip_to_return resp:%s,err:%s", resp, err)
return
} }
setup.CwLog().Infof("requestToReturnTheResult resp:%s,body:%s", resp, body) setup.CwLog().Infof("requestToReturnTheResult resp:%s,body:%s", resp, body)
setup.CwLog().Infof("the_current_port_is_fine port:%d", port) setup.CwLog().Infof("the_current_port_is_fine port:%d", port)
@ -69,8 +77,11 @@ func init() {
setup.InitLogger() //初始化log setup.InitLogger() //初始化log
} }
func main() { func main() {
fmt.Println("程序已经启动")
setup.CwLog().Warn("start") //测试log setup.CwLog().Warn("start") //测试log
for { for {
timeStr := time.Now().Format("2006-01-02 15:04:05") //当前时间的字符串2006-01-02 15:04:05据说是golang的诞生时间固定写法
fmt.Println("开始检测 " + timeStr) //打印结果2017-04-11 13:24:04
time.Sleep(5000) time.Sleep(5000)
read_a_file() read_a_file()
} }