30 lines
695 B
Go
30 lines
695 B
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package resource
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
_ "net/url"
|
|
"strings"
|
|
"decl/internal/types"
|
|
"decl/internal/data"
|
|
"decl/internal/folio"
|
|
)
|
|
|
|
var (
|
|
ErrUnknownResourceType = errors.New("Unknown resource type")
|
|
ResourceTypes *types.Types[data.Resource] = folio.DocumentRegistry.ResourceTypes
|
|
)
|
|
|
|
type TypeName string //`json:"type"`
|
|
|
|
func (n *TypeName) UnmarshalJSON(b []byte) error {
|
|
ResourceTypeName := strings.Trim(string(b), "\"")
|
|
if ResourceTypes.Has(ResourceTypeName) {
|
|
*n = TypeName(ResourceTypeName)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("%w: %s", ErrUnknownResourceType, ResourceTypeName)
|
|
}
|