diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-09-24 23:36:00 +0200 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-09-24 23:36:00 +0200 |
| commit | bd9e7f7acfd855d4685aa4544169c0e29cdbf205 (patch) | |
| tree | c5218c65359c0c2dee5a8db2670f30db677f068a /module.go | |
| parent | 08df9258a532b653c243e077e82491dbe62ad854 (diff) | |
clean up modules
Diffstat (limited to 'module.go')
| -rw-r--r-- | module.go | 33 |
1 files changed, 6 insertions, 27 deletions
@@ -2,14 +2,10 @@ package flyscrape import ( "encoding/json" - "fmt" "net/http" - "sync" ) -type Module interface { - ID() string -} +type Module any type Transport interface { Transport(*http.Request) (*http.Response, error) @@ -34,32 +30,15 @@ type OnComplete interface { OnComplete() } -func RegisterModule(m Module) { - id := m.ID() - if id == "" { - panic("module id is missing") - } - - globalModulesMu.Lock() - defer globalModulesMu.Unlock() - - if _, ok := globalModules[id]; ok { - panic(fmt.Sprintf("module %s already registered", id)) - } - globalModules[id] = m +func RegisterModule(mod Module) { + globalModules = append(globalModules, mod) } -func LoadModules(s *Scraper, opts Options) { - globalModulesMu.RLock() - defer globalModulesMu.RUnlock() - +func LoadModules(s *Scraper, cfg Config) { for _, mod := range globalModules { - json.Unmarshal(opts, mod) + json.Unmarshal(cfg, mod) s.LoadModule(mod) } } -var ( - globalModules = map[string]Module{} - globalModulesMu sync.RWMutex -) +var globalModules = []Module{} |