2024-03-20 19:23:31 +00:00
|
|
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
2024-03-22 17:39:06 +00:00
|
|
|
|
2024-03-20 16:15:27 +00:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
2024-03-25 20:31:06 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-07-01 21:54:18 +00:00
|
|
|
_ "net/url"
|
2024-04-03 16:54:50 +00:00
|
|
|
"strings"
|
2024-07-01 21:54:18 +00:00
|
|
|
"decl/internal/types"
|
2024-09-19 08:11:57 +00:00
|
|
|
"decl/internal/data"
|
|
|
|
"decl/internal/folio"
|
2024-03-20 16:15:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-03-25 20:31:06 +00:00
|
|
|
ErrUnknownResourceType = errors.New("Unknown resource type")
|
2024-09-19 08:11:57 +00:00
|
|
|
ResourceTypes *types.Types[data.Resource] = folio.DocumentRegistry.ResourceTypes
|
2024-03-20 16:15:27 +00:00
|
|
|
)
|
|
|
|
|
2024-04-03 16:54:50 +00:00
|
|
|
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)
|
|
|
|
}
|