Documentation ¶
Index ¶
- func CommaSeperatedList(s string) []string
- func Convert(src reflect.Value, dst reflect.Value) E.NestedError
- func ConvertString(src string, dst reflect.Value) (convertible bool, convErr E.NestedError)
- func Copy(dst *ContextWriter, src *ContextReader) error
- func Copy2(ctx context.Context, dst io.Writer, src io.Reader) error
- func Deserialize(src SerializedObject, dst any) E.NestedError
- func DeserializeJSON(j map[string]string, target any) E.NestedError
- func ExtractPort(fullURL string) (int, error)
- func FormatDuration(d time.Duration) string
- func FormatTime(t time.Time) string
- func GetSchema(path string) *jsonschema.Schema
- func ListFiles(dir string, maxDepth int) ([]string, error)
- func LoadJSON[T any](path string, pointer *T) E.NestedError
- func ParseBool(s string) bool
- func PortString(port uint16) string
- func SaveJSON[T any](path string, pointer *T, perm os.FileMode) E.NestedError
- func Title(s string) string
- func ToLowerNoSnake(s string) string
- func ValidateYaml(schema *jsonschema.Schema, data []byte) E.NestedError
- type BidirectionalPipe
- type ContextReader
- type ContextWriter
- type Converter
- type FileReader
- type NoCopy
- type Pipe
- type SerializedObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommaSeperatedList ¶
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) error
func Deserialize ¶
func Deserialize(src SerializedObject, dst any) E.NestedError
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, the SerializedObject will be deserialized into the struct fields. 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 DeserializeJSON ¶
func DeserializeJSON(j map[string]string, target any) E.NestedError
func ExtractPort ¶
func FormatDuration ¶
func FormatTime ¶
func GetSchema ¶
func GetSchema(path string) *jsonschema.Schema
func ListFiles ¶
Recursively lists all files in a directory until `maxDepth` is reached Returns a slice of file paths relative to `dir`.
func PortString ¶
func ToLowerNoSnake ¶
func ValidateYaml ¶
func ValidateYaml(schema *jsonschema.Schema, data []byte) E.NestedError
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() error
type ContextReader ¶
TODO: move to "utils/io".
type ContextWriter ¶
TODO: move to "utils/io".
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 SerializedObject ¶
func Serialize ¶
func Serialize(data any) (SerializedObject, E.NestedError)
Serialize converts the given data into a map[string]any representation.
It uses reflection to inspect the data type and handle different kinds of data. For a struct, it extracts the fields using the json tag if present, or the field name if not. For an embedded struct, it recursively converts its fields into the result map. For any other type, it returns an error.
Parameters: - data: The data to be converted into a map.
Returns: - result: The resulting map[string]any representation of the data. - error: An error if the data type is unsupported or if there is an error during conversion.