set configuration for each extractor
This commit is contained in:
parent
6baa965534
commit
0a63df9ce6
19 changed files with 337 additions and 175 deletions
44
config/main.go
Normal file
44
config/main.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"govd/models"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var extractorConfigs map[string]*models.ExtractorConfig
|
||||
|
||||
func LoadExtractorConfigs() error {
|
||||
extractorConfigs = make(map[string]*models.ExtractorConfig)
|
||||
configPath := "ext-cfg.yaml"
|
||||
|
||||
_, err := os.Stat(configPath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("errore nella lettura del file di configurazione: %w", err)
|
||||
}
|
||||
|
||||
var rawConfig map[string]*models.ExtractorConfig
|
||||
|
||||
if err := yaml.Unmarshal(data, &rawConfig); err != nil {
|
||||
return fmt.Errorf("errore nella decodifica del file YAML: %w", err)
|
||||
}
|
||||
for codeName, config := range rawConfig {
|
||||
extractorConfigs[codeName] = config
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetExtractorConfig(codeName string) *models.ExtractorConfig {
|
||||
if config, exists := extractorConfigs[codeName]; exists {
|
||||
return config
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue