jx/internal/resource/types.go

30 lines
695 B
Go
Raw Permalink Normal View History

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"
_ "net/url"
"strings"
"decl/internal/types"
"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")
ResourceTypes *types.Types[data.Resource] = folio.DocumentRegistry.ResourceTypes
2024-03-20 16:15:27 +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)
}