textx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 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 NewEcodeError added in v0.2.0

func NewEcodeError(code Ecode) error

func NewEcodeErrorWrap added in v0.2.0

func NewEcodeErrorWrap(code Ecode, cause error) error

func NewEcodeErrorWrapf added in v0.2.0

func NewEcodeErrorWrapf(code Ecode, cause error, msg string, args ...any) error

func NewEcodeErrorf added in v0.2.0

func NewEcodeErrorf(code Ecode, msg string, args ...any) error

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

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

Jump to

Keyboard shortcuts

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