jx/internal/resource/types.go
Matthew Rich 1460d2285b
Some checks failed
Declarative Tests / build-ubuntu-focal (push) Waiting to run
Lint / golangci-lint (push) Failing after 15s
Declarative Tests / test (push) Failing after 5s
Declarative Tests / build-fedora (push) Has been cancelled
add support for configuration documents
2024-07-01 14:54:18 -07:00

28 lines
630 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
"errors"
"fmt"
_ "net/url"
"strings"
"decl/internal/types"
)
var (
ErrUnknownResourceType = errors.New("Unknown resource type")
ResourceTypes *types.Types[Resource] = types.New[Resource]()
)
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)
}