Documentation
¶
Overview ¶
Package textx GENERATED BY code_error DO NOT EDIT
Index ¶
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
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 )
Click to show internal directories.
Click to hide internal directories.