29 lines
637 B
Go
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)
|
|
}
|