jx/internal/source/types.go

29 lines
637 B
Go
Raw Normal View History

2024-04-18 00:07:12 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package source
import (
"errors"
"fmt"
_ "net/url"
2024-04-18 00:07:12 +00:00
"strings"
_ "path/filepath"
"decl/internal/types"
2024-04-18 00:07:12 +00:00
)
var (
ErrUnknownSourceType = errors.New("Unknown source type")
SourceTypes *types.Types[DocSource] = types.New[DocSource]()
2024-04-18 00:07:12 +00:00
)
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)
}