Add mode that prints multiple worker status in console
This commit is contained in:
@@ -18,6 +18,7 @@ const (
|
|||||||
EnvPanicOnUnexpectedError = "PANIC_ON_UNEXPECTED_ERROR"
|
EnvPanicOnUnexpectedError = "PANIC_ON_UNEXPECTED_ERROR"
|
||||||
EnvBlacklistPath = "BLACKLIST_PATH"
|
EnvBlacklistPath = "BLACKLIST_PATH"
|
||||||
EnvDryRun = "DRY_RUN"
|
EnvDryRun = "DRY_RUN"
|
||||||
|
EnvPrintWorkerStatus = "PRINT_WORKER_STATUS"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config holds the application configuration loaded from environment variables.
|
// Config holds the application configuration loaded from environment variables.
|
||||||
@@ -30,6 +31,7 @@ type Config struct {
|
|||||||
PanicOnUnexpectedError bool // Panic on unexpected errors when visiting a URL
|
PanicOnUnexpectedError bool // Panic on unexpected errors when visiting a URL
|
||||||
BlacklistPath string // File that has blacklisted strings of "host:port"
|
BlacklistPath string // File that has blacklisted strings of "host:port"
|
||||||
DryRun bool // If false, don't write to disk
|
DryRun bool // If false, don't write to disk
|
||||||
|
PrintWorkerStatus bool // If false, don't print worker status table
|
||||||
}
|
}
|
||||||
|
|
||||||
var CONFIG Config //nolint:gochecknoglobals
|
var CONFIG Config //nolint:gochecknoglobals
|
||||||
@@ -136,6 +138,14 @@ func GetConfig() *Config {
|
|||||||
config.DryRun = val
|
config.DryRun = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
EnvPrintWorkerStatus: func(v string) error {
|
||||||
|
val, err := parseBool(EnvPrintWorkerStatus, v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
config.PrintWorkerStatus = val
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process each environment variable
|
// Process each environment variable
|
||||||
|
|||||||
32
hostPool/hostPool.go
Normal file
32
hostPool/hostPool.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package gemini
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ipPool = IpAddressPool{IPs: make(map[string]int)} //nolint:gochecknoglobals
|
||||||
|
var hostPool = HostPool{hostnames: make(map[string]struct{})} //nolint:gochecknoglobals
|
||||||
|
|
||||||
|
type HostPool struct {
|
||||||
|
hostnames map[string]struct{}
|
||||||
|
Lock sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *HostPool) Add(key string) {
|
||||||
|
p.Lock.Lock()
|
||||||
|
defer p.Lock.Unlock()
|
||||||
|
p.hostnames[key] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *HostPool) Get(key string) bool {
|
||||||
|
p.Lock.RLock()
|
||||||
|
defer p.Lock.RUnlock()
|
||||||
|
_, ok := p.hostnames[key]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *HostPool) Delete(key string) {
|
||||||
|
p.Lock.Lock()
|
||||||
|
defer p.Lock.Unlock()
|
||||||
|
delete(p.hostnames, key)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user