28 lines
793 B
Go
28 lines
793 B
Go
|
|
// 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
|
||
|
|
}
|