47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package sinks
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/config"
|
|
)
|
|
|
|
// requireStringParam returns a non-empty string sink param.
|
|
//
|
|
// This helper is intentionally local to sinks rather than config so
|
|
// driver-specific validation stays close to the adapters that use it.
|
|
func requireStringParam(cfg config.SinkConfig, key string) (string, error) {
|
|
v, ok := cfg.Params[key]
|
|
if !ok {
|
|
return "", fmt.Errorf("sink %q: params.%s is required", cfg.Name, key)
|
|
}
|
|
s, ok := v.(string)
|
|
if !ok {
|
|
return "", fmt.Errorf("sink %q: params.%s must be a string", cfg.Name, key)
|
|
}
|
|
if strings.TrimSpace(s) == "" {
|
|
return "", fmt.Errorf("sink %q: params.%s cannot be empty", cfg.Name, key)
|
|
}
|
|
return s, nil
|
|
}
|
|
|
|
// RegisterPostgresSchemaForConfiguredSinks registers one Postgres schema for each
|
|
// configured sink using driver=postgres.
|
|
func RegisterPostgresSchemaForConfiguredSinks(cfg *config.Config, schema PostgresSchema) error {
|
|
if cfg == nil {
|
|
return fmt.Errorf("register postgres schemas: config is nil")
|
|
}
|
|
|
|
for i, sk := range cfg.Sinks {
|
|
if !strings.EqualFold(strings.TrimSpace(sk.Driver), "postgres") {
|
|
continue
|
|
}
|
|
if err := RegisterPostgresSchema(sk.Name, schema); err != nil {
|
|
return fmt.Errorf("register postgres schema for sinks[%d] name=%q: %w", i, sk.Name, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|