Documentation
¶
Overview ¶
Package textx GENERATED BY code_error DO NOT EDIT
Index ¶
- Constants
- Variables
- func Marshal(v any) ([]byte, error)
- func MarshalURL(v any) (url.Values, error)
- func NewEcodeError(code Ecode) error
- func NewEcodeErrorWrap(code Ecode, cause error) error
- func NewEcodeErrorWrapf(code Ecode, cause error, msg string, args ...any) error
- func NewEcodeErrorf(code Ecode, msg string, args ...any) error
- func Unmarshal(data []byte, v any) error
- func UnmarshalURL(u url.Values, v any) error
- type Ecode
- type EcodeError
Examples ¶
Constants ¶
View Source
const URLTag = "url"
URLTag describes url parameter in struct tag
Variables ¶
View Source
var ( TextMarshaler = reflect.TypeFor[encoding.TextMarshaler]() TextUnmarshaler = reflect.TypeFor[encoding.TextUnmarshaler]() )
Functions ¶
func MarshalURL ¶ added in v0.1.0
MarshalURL encodes a struct value into url.Values. It supports struct tags `name:"customName" as the URL parameter name; It will skip unexported fields and fields with name tag "-". By default, the URL parameter names are converted to lowerCamelCase.
Example ¶
u, err := MarshalURL(struct {
Name string `url:"id"`
Age int
Gender int8
Country string `url:"country,default='cn'"`
Codes []string
}{
Name: "Alex",
Age: 30,
Codes: []string{"a", "b", "c"},
})
if err != nil {
panic(err)
}
fmt.Println(u.Encode())
Output: age=30&codes=a&codes=b&codes=c&country=cn&id=Alex
func NewEcodeError ¶ added in v0.2.0
func NewEcodeErrorWrap ¶ added in v0.2.0
func NewEcodeErrorWrapf ¶ added in v0.2.0
func NewEcodeErrorf ¶ added in v0.2.0
Types ¶
type Ecode ¶ added in v0.2.0
type Ecode int8
Ecode defines error code when Marshal/Unmarshal +genx:code_error @def textx
const ( ECODE_UNDEFINED Ecode = iota ECODE__MARSHAL_TEXT_INVALID_INPUT // marshal text got invalid input ECODE__MARSHAL_TEXT_FAILED // failed to marshal text ECODE__MARSHAL_URL_INVALID_INPUT // marshal url got invalid input ECODE__MARSHAL_URL_FAILED // failed to marshal url ECODE__UNMARSHAL_TEXT_INVALID_INPUT // unmarshal text got invalid input ECODE__UNMARSHAL_TEXT_FAILED // failed to unmarshal text ECODE__UNMARSHAL_URL_INVALID_INPUT // unmarshal url got invalid input ECODE__UNMARSHAL_URL_FAILED // failed to unmarshal url )
type EcodeError ¶ added in v0.2.0
type EcodeError struct {
// contains filtered or unexported fields
}
func (*EcodeError) Code ¶ added in v0.2.0
func (e *EcodeError) Code() Ecode
func (*EcodeError) Error ¶ added in v0.2.0
func (e *EcodeError) Error() string
func (*EcodeError) Is ¶ added in v0.2.0
func (e *EcodeError) Is(err error) bool
func (*EcodeError) Unwrap ¶ added in v0.2.0
func (e *EcodeError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.