Begun data module

This commit is contained in:
2025-10-23 03:11:27 +08:00
parent 37cbc78f9b
commit c52b2f7aa6
7 changed files with 120 additions and 17 deletions

View File

@@ -0,0 +1,34 @@
// Package registry ...
package registry
import (
"fmt"
"sync"
"gitlab.michelsen.id/phillmichelsen/tessera/core/data"
)
type ProcessorFactory func(string) (data.Processor, error)
type Processors struct {
mu sync.RWMutex
m map[string]ProcessorFactory
}
func NewProcessors() *Processors { return &Processors{m: make(map[string]ProcessorFactory)} }
func (r *Processors) Register(name string, f ProcessorFactory) {
r.mu.Lock()
defer r.mu.Unlock()
r.m[name] = f
}
func (r *Processors) New(name string, params string) (data.Processor, error) {
r.mu.RLock()
f, ok := r.m[name]
r.mu.RUnlock()
if !ok {
return nil, fmt.Errorf("unknown processor: %s", name)
}
return f(params)
}