Giter Site home page Giter Site logo

goproxy's Introduction

Goproxy


介绍

Goproxy Pool Golang 代理池系统,自动抓取代理,检测代理


启动:

go run main.go


编译:

go build main.go


监听:0.0.0.0:5010

访问:http://127.0.0.1:5010

配置文件

cache:
  key: "proxies"                #Redis队列的KEY
  redis: 192.168.0.224:6379      #Redis连接地址

check:
  time: "*/10 * * * * ?"        #校验周期10秒
  http: http://www.166.com      #http效验地址
  https: https://www.baidu.com  #https效验地址
  lowest: 30                    #代理池伐值,少于30个
  timeout: 3                    #代理检测超时

logger:
  dir: ./logs                   #Log存储路径
  file: "%Y%m%d.log"              #Log文件名


server:
  addr: 0.0.0.0:5010            #WEB服务监听地址:端口      

目录说明

├── app
│   ├── apis
│   │   └── api.go
│   └── jobs
│       ├── example.go
│       └── jobs.go
├── config
│   └── config.yaml
├── go.mod
├── LICENSE
├── main.go
├── pkg
│   ├── cache
│   │   └── redis.go
│   └── config
│       └── config.go
└── README.md

JOBS目录说明

  • jobs.go >核心调度文件不建议修改
  • example.go >任务抓取示例文件:
//初始化任务
func init(){
	//增加计划任务,5秒种获取一次IP代理
	Cron("*/5 * * * * ?", Example)
}


//获取IP列表方法
func Example() {
	url := "http://www.example.com/getProxy.json"	
	
	if Count() < config.GetInt64("check.lowest") {
		resp := Http("Get", url, nil)

		if gjson.ValidBytes(resp) && gjson.GetBytes(resp, "code").Int() == 10001 {
			data := gjson.GetBytes(resp, "data.proxy_list")
			data.ForEach(func(key, value gjson.Result) bool {
				println(value.Get("ip").String()) 
				Save(value.Get("ip").String() +":"+ value.Get("port").String(), value.String(), value.Get("timeout").Int())
				return true
			})
		}
	}	
}

APIs目录说明

Web APIs的访问控制器,用户通过http获取代理,包含以下几个方法:

GET    /                         --> Goproxy 代理池 Welcome 检测路径
GET    /get                      --> Goproxy/app/apis.Get 随机获取代理
GET    /pop                      --> Goproxy/app/apis.Pop 随机获取代理(并删除)
GET    /all                      --> Goproxy/app/apis.All 获取全部代理
GET    /raw                      --> Goproxy/app/apis.Raw 获取代理数据

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.