textx

package
v0.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 9 Imported by: 3

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 Marshal added in v0.1.0

func Marshal(v any) ([]byte, error)

func MarshalURL added in v0.1.0

func MarshalURL(v any) (url.Values, error)

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 Unmarshal added in v0.1.0

func Unmarshal(data []byte, v any) error

func UnmarshalURL added in v0.1.0

func UnmarshalURL(u url.Values, v any) error

UnmarshalURL decodes values from url.Values into a struct. The input MUST be a pointer to a struct or reflect.Value of a struct.

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
)

func (Ecode) Message added in v0.2.0

func (e Ecode) Message() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL