类似httpx的无状态, 无scope, 无并发池的检测模式
(ctx context.Context, config *Config)
| 17 | |
| 18 | // 类似httpx的无状态, 无scope, 无并发池的检测模式 |
| 19 | func NewCheckPool(ctx context.Context, config *Config) (*CheckPool, error) { |
| 20 | pctx, cancel := context.WithCancel(ctx) |
| 21 | config.ClientType = ihttp.STANDARD |
| 22 | pool := &CheckPool{ |
| 23 | BasePool: &BasePool{ |
| 24 | Config: config, |
| 25 | Statistor: pkg.NewStatistor(""), |
| 26 | ctx: pctx, |
| 27 | Cancel: cancel, |
| 28 | client: ihttp.NewClient(&ihttp.ClientConfig{ |
| 29 | Thread: config.Thread, |
| 30 | Type: config.ClientType, |
| 31 | Timeout: config.Timeout, |
| 32 | ProxyClient: config.ProxyClient, |
| 33 | }), |
| 34 | wg: &sync.WaitGroup{}, |
| 35 | additionCh: make(chan *Unit, config.Thread*10), |
| 36 | closeCh: make(chan struct{}), |
| 37 | processCh: make(chan *baseline.Baseline, config.Thread*2), |
| 38 | handlerDone: make(chan struct{}), |
| 39 | }, |
| 40 | } |
| 41 | pool.Request.Headers.Set("Connection", "close") |
| 42 | p, err := ants.NewPoolWithFunc(config.Thread, pool.Invoke) |
| 43 | if err != nil { |
| 44 | cancel() |
| 45 | return nil, fmt.Errorf("create check pool: %w", err) |
| 46 | } |
| 47 | |
| 48 | pool.Pool = p |
| 49 | go pool.Handler() |
| 50 | return pool, nil |
| 51 | } |
| 52 | |
| 53 | type CheckPool struct { |
| 54 | *BasePool |
no test coverage detected