Documentation
¶
Index ¶
- Variables
- func Convert(src reflect.Value, dst reflect.Value) E.Error
- func ConvertString(src string, dst reflect.Value) (convertible bool, convErr E.Error)
- func Copy(dst *ContextWriter, src *ContextReader) (err error)
- func Copy2(ctx context.Context, dst io.Writer, src io.Reader) error
- func Deserialize(src SerializedObject, dst any) (err E.Error)
- func DeserializeYAML[T any](data []byte, target *T) E.Error
- func DeserializeYAMLMap[V any](data []byte) (_ functional.Map[string, V], err E.Error)
- func Intersect[T comparable, Slice ~[]T](slice1 Slice, slice2 Slice) Slice
- func ListFiles(dir string, maxDepth int, hideHidden ...bool) ([]string, error)
- func LoadJSONIfExist[T any](path string, dst *T) error
- func MustRegisterValidation(tag string, fn validator.Func)
- func NearestField(input string, s any) string
- func New(t reflect.Type) reflect.Value
- func RegisterDefaultValueFactory[T any](factory func() *T)
- func SaveJSON[T any](path string, src *T, perm os.FileMode) error
- func Slice[T any](slice []T, n int) []T
- func ValidateWithCustomValidator(v reflect.Value) E.Error
- func ValidateWithFieldTags(s any) E.Error
- func Validator() *validator.Validate
- type BidirectionalPipe
- type ContextReader
- type ContextWriter
- type CustomValidator
- type FileReader
- type MapUnmarshaller
- type NoCopy
- type Pipe
- type RefCount
- type SerializedObject
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidType = E.New("invalid type") ErrNilValue = E.New("nil") ErrUnsettable = E.New("unsettable") ErrUnsupportedConversion = E.New("unsupported conversion") ErrUnknownField = E.New("unknown field") )
var ErrValidationError = E.New("validation error")
Functions ¶
func Convert ¶
Convert attempts to convert the src to dst.
If src is a map, it is deserialized into dst. If src is a slice, each of its elements are converted and stored in dst. For any other type, it is converted using the reflect.Value.Convert function (if possible).
If dst is not settable, an error is returned. If src cannot be converted to dst, an error is returned. If any error occurs during conversion (e.g. deserialization), it is returned.
Returns:
- error: the error occurred during conversion, or nil if no error occurred.
func ConvertString ¶
func Copy ¶
func Copy(dst *ContextWriter, src *ContextReader) (err error)
Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style This is a copy of io.Copy with context handling Author: yusing <yusing@6uo.me>.
func Deserialize ¶
func Deserialize(src SerializedObject, dst any) (err E.Error)
Deserialize takes a SerializedObject and a target value, and assigns the values in the SerializedObject to the target value. Deserialize ignores case differences between the field names in the SerializedObject and the target.
The target value must be a struct or a map[string]any. If the target value is a struct , and implements the MapUnmarshaller interface, the UnmarshalMap method will be called.
If the target value is a struct, but does not implements the MapUnmarshaller interface, the SerializedObject will be deserialized into the struct fields and validate if needed.
If the target value is a map[string]any the SerializedObject will be deserialized into the map.
The function returns an error if the target value is not a struct or a map[string]any, or if there is an error during deserialization.
func DeserializeYAMLMap ¶
func Intersect ¶
func Intersect[T comparable, Slice ~[]T](slice1 Slice, slice2 Slice) Slice
Intersect returns a new slice containing the elements that are present in both input slices. This provides a more efficient solution than using two nested loops.
func ListFiles ¶
Recursively lists all files in a directory until `maxDepth` is reached Returns a slice of file paths relative to `dir`.
func LoadJSONIfExist ¶
func MustRegisterValidation ¶
func MustRegisterValidation(tag string, fn validator.Func)
func NearestField ¶
func RegisterDefaultValueFactory ¶
func RegisterDefaultValueFactory[T any](factory func() *T)
func ValidateWithFieldTags ¶
Types ¶
type BidirectionalPipe ¶
type BidirectionalPipe struct {
// contains filtered or unexported fields
}
TODO: move to "utils/io".
func NewBidirectionalPipe ¶
func NewBidirectionalPipe(ctx context.Context, rw1 io.ReadWriteCloser, rw2 io.ReadWriteCloser) BidirectionalPipe
func (BidirectionalPipe) Start ¶
func (p BidirectionalPipe) Start() E.Error
type ContextReader ¶
TODO: move to "utils/io".
type ContextWriter ¶
TODO: move to "utils/io".
type CustomValidator ¶
type NoCopy ¶
type NoCopy struct{}
empty struct that implements Locker interface for hinting that no copy should be performed.
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
TODO: move to "utils/io".
func NewPipe ¶
func NewPipe(ctx context.Context, r io.ReadCloser, w io.WriteCloser) *Pipe
type RefCount ¶
type RefCount struct {
// contains filtered or unexported fields
}
func NewRefCounter ¶
func NewRefCounter() *RefCount