Documentation
¶
Index ¶
- Variables
- type ReadValueError
- type StructDecoder
- type StructEncoder
- type StructEncoderCombiner
- type StructTagCommand
- type StructTagHandler
- type StructTagHandlerExecutionError
- type StructTagHandlerUnsupportedFieldError
- type StructTagValueReader
- type StructTagValueWriter
- type TagValueHandlerConfigError
- type ValueReaderFunc
- type ValueWriterFunc
- type WriteValueError
Constants ¶
This section is empty.
Variables ¶
var ErrNotAStruct = fmt.Errorf("type is not a struct")
An error that says that the type where the tags should be read is not a struct.
Functions ¶
This section is empty.
Types ¶
type ReadValueError ¶
type ReadValueError struct {
// contains filtered or unexported fields
}
An error that wraps the underlying value write error.
func NewReadValueError ¶
func NewReadValueError[T any](valueType reflect.Type, cause error) *ReadValueError
Creates a new gotag.ReadValueError.
func (*ReadValueError) Unwrap ¶
func (e *ReadValueError) Unwrap() error
Returns the cause of the the read error.
type StructDecoder ¶
type StructDecoder[T any, S any] interface { // Create a new instance based on the source. Decode(s S) (T, error) }
Decoder that creates new instaces of structs that have struct tags.
func NewDecoder ¶
func NewDecoder[T any, S any](writers ...StructTagValueWriter[S]) StructDecoder[T, S]
Creates a default gotag.StructDecoder.
type StructEncoder ¶
type StructEncoder[T any, R any] interface { // Create a new instance based on the source. Encode(t T, defaultValue R) (R, error) }
Decoder that creates new instaces of structs that have struct tags.
func NewEncoder ¶
func NewEncoder[T any, R any](readers ...StructTagValueReader[R]) StructEncoder[T, R]
Creates a default gotag.StructEncoder.
type StructEncoderCombiner ¶
type StructTagCommand ¶
type StructTagCommand struct {
// contains filtered or unexported fields
}
Allows accessing the value without exposing the reflect.Value.
func (*StructTagCommand) Tag ¶
func (c *StructTagCommand) Tag() string
Tag implements StructTagHandler.
func (*StructTagCommand) TagValues ¶
func (c *StructTagCommand) TagValues() []string
type StructTagHandler ¶
type StructTagHandler interface {
Tag() string
}
Interface for struct tag handlers.
type StructTagHandlerExecutionError ¶
type StructTagHandlerExecutionError struct {
// contains filtered or unexported fields
}
An error that wraps the underlying value tag processing error.
func NewStructTagHandlerExecutionError ¶
func NewStructTagHandlerExecutionError(command *StructTagCommand, cause error) *StructTagHandlerExecutionError
Creates a new gotag.StructTagHandlerExecutionError.
func (*StructTagHandlerExecutionError) Error ¶
func (e *StructTagHandlerExecutionError) Error() string
Error implements error.
func (*StructTagHandlerExecutionError) Unwrap ¶
func (e *StructTagHandlerExecutionError) Unwrap() error
Returns the cause of the the write error.
type StructTagHandlerUnsupportedFieldError ¶
type StructTagHandlerUnsupportedFieldError struct {
// contains filtered or unexported fields
}
An error for a not supported field.
func NewStructTagHandlerUnsupportedFieldError ¶
func NewStructTagHandlerUnsupportedFieldError(command *StructTagCommand) *StructTagHandlerUnsupportedFieldError
Creates a new gotag.StructTagHandlerUnsupportedFieldError.
func (*StructTagHandlerUnsupportedFieldError) Error ¶
func (e *StructTagHandlerUnsupportedFieldError) Error() string
Error implements error.
type StructTagValueReader ¶
type StructTagValueReader[R any] interface { StructTagHandler // Processes the struct tag and sets the value. Read(cmd *StructTagCommand, result R) (R, error) }
Interface for struct tag based value writers.
type StructTagValueWriter ¶
type StructTagValueWriter[S any] interface { StructTagHandler // Processes the struct tag and sets the value. Write(cmd *StructTagCommand, source S) error }
Interface for struct tag based value writers.
type TagValueHandlerConfigError ¶
type TagValueHandlerConfigError struct {
// contains filtered or unexported fields
}
An error for a invalid handler configuration.
func NewTagValueHandlerConfigError ¶
func NewTagValueHandlerConfigError(command *StructTagCommand, message string) *TagValueHandlerConfigError
Creates a new gotag.TagValueHandlerConfigError.
func (*TagValueHandlerConfigError) Error ¶
func (e *TagValueHandlerConfigError) Error() string
Error implements error.
type ValueReaderFunc ¶
Function that transforms the reflect.Value. Returns value, true and nil error, if the execution has succeeded. Returns default value, true and non-nil error, if the execution has failed. Returns default value, false and nil error, if the value is not supported.
func NewFirstSucceedValueReader ¶ added in v1.1.0
func NewFirstSucceedValueReader[R any](readers ...ValueReaderFunc[R]) ValueReaderFunc[R]
Combines multiple gotag.ValueReaderFunc into a single one. Each function is executed in natural order. Returns the result from the first supported function. Return default value, false and nil error, if no function supports the value or all supported functions fail.
func NewFirstSupportedValueReader ¶ added in v1.1.0
func NewFirstSupportedValueReader[R any](readers ...ValueReaderFunc[R]) ValueReaderFunc[R]
Combines multiple gotag.ValueReaderFunc into a single one. Each function is executed in natural order. Returns the result from the first supported function. Return default value, false and nil error, if no function supports the value.
func (ValueReaderFunc[R]) ReadValue ¶
func (f ValueReaderFunc[R]) ReadValue(c *StructTagCommand) (R, error)
Reads the value without exposing the reflect.Value.
type ValueWriterFunc ¶
Function that transforms the source value, and writes it to the reflect.Value. Returns true and nil error, if the execution has succeeded. Returns true and non-nil error, if the execution has failed. Returns false and nil error, if the value is not supported.
func NewFirstSucceedValueWriter ¶ added in v1.1.0
func NewFirstSucceedValueWriter[S any](writers ...ValueWriterFunc[S]) ValueWriterFunc[S]
Combines multiple gotag.ValueWriterFunc into a single one. Each function is executed in natural order. Returns the result from the first supported function which executes without errors. Return false and nil error, if no function supports the value or all supported functions fail.
func NewFirstSupportedValueWriter ¶ added in v1.1.0
func NewFirstSupportedValueWriter[S any](writers ...ValueWriterFunc[S]) ValueWriterFunc[S]
Combines multiple gotag.ValueWriterFunc into a single one. Each function is executed in natural order. Returns the result from the first supported function. Return false and nil error, if no function supports the value.
func (ValueWriterFunc[S]) WriteValue ¶
func (f ValueWriterFunc[S]) WriteValue(c *StructTagCommand, source S) error
Writes the value without exposing the reflect.Value.
type WriteValueError ¶
type WriteValueError struct {
// contains filtered or unexported fields
}
An error that wraps the underlying value write error.
func NewWriteValueError ¶
func NewWriteValueError(newValue any, valueType reflect.Type, cause error) *WriteValueError
Creates a new gotag.WriteValueError.
func (*WriteValueError) Unwrap ¶
func (e *WriteValueError) Unwrap() error
Returns the cause of the the write error.