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