jx/internal/folio/types.go
Matthew Rich 04b27dc5df
Some checks failed
Lint / golangci-lint (push) Has been cancelled
Declarative Tests / test (push) Has been cancelled
Declarative Tests / build-fedora (push) Has been cancelled
Declarative Tests / build-ubuntu-focal (push) Has been cancelled
add folio package
2024-08-17 18:19:56 -07:00

30 lines
727 B
Go

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