jx/internal/source/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

29 lines
637 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package source
import (
"errors"
"fmt"
_ "net/url"
"strings"
_ "path/filepath"
"decl/internal/types"
)
var (
ErrUnknownSourceType = errors.New("Unknown source type")
SourceTypes *types.Types[DocSource] = types.New[DocSource]()
)
type TypeName string //`json:"type"`
func (n *TypeName) UnmarshalJSON(b []byte) error {
SourceTypeName := strings.Trim(string(b), "\"")
if SourceTypes.Has(SourceTypeName) {
*n = TypeName(SourceTypeName)
return nil
}
return fmt.Errorf("%w: %s", ErrUnknownSourceType, SourceTypeName)
}