Load shared references with ConfigKit
This commit is contained in:
27
internal/integrations/domainrefs/load.go
Normal file
27
internal/integrations/domainrefs/load.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Package domainrefs loads shared domain reference documents.
|
||||
package domainrefs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// Load resolves a materialized shared reference using ConfigKit's native rules.
|
||||
func Load(label, mediaType string, content []byte) (map[string]any, error) {
|
||||
switch mediaType {
|
||||
case "application/json":
|
||||
if !json.Valid(content) {
|
||||
return nil, fmt.Errorf("reference %q: invalid JSON syntax", label)
|
||||
}
|
||||
case "application/yaml", "application/x-yaml":
|
||||
default:
|
||||
return nil, fmt.Errorf("reference %q: unsupported media type %q", label, mediaType)
|
||||
}
|
||||
result, err := configkit.Load[map[string]any](configkit.Bytes(label, content))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reference %q: %w", label, err)
|
||||
}
|
||||
return result.Config, nil
|
||||
}
|
||||
Reference in New Issue
Block a user