binder

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2025 License: Apache-2.0 Imports: 12 Imported by: 11

Documentation

Index

Constants

View Source
const (
	HeaderAccept      = "Accept"
	HeaderContentType = "Content-Type"
)
View Source
const (
	MIMEJSON              string = "application/json"
	MIMEXML                      = "application/xml"
	MIMEXML2                     = "text/xml"
	MIMEPOSTForm                 = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTForm        = "multipart/form-data"
	MIMEPROTOBUF                 = "application/x-protobuf"
	MIMEMSGPACK                  = "application/x-msgpack"
	MIMEMSGPACK2                 = "application/msgpack"
	MIMEYAML                     = "application/x-yaml"
)

Content-Type MIME of the most common data formats.

Variables

View Source
var Form = &formBinding{}
View Source
var Json = jsonBinding{}
View Source
var Protobuf = &protobufBinding{}
View Source
var Xml = &xmlBinding{}

Functions

func ContentTypeFormat added in v1.2.0

func ContentTypeFormat(c string) string

func Decode

func Decode(r io.Reader, i any, t any) error

func Encode

func Encode(w io.Writer, i any, t any) error

func Marshal

func Marshal(i any, t any) ([]byte, error)

func Register

func Register(t string, handle Binder) error

func SetMimeType added in v1.2.0

func SetMimeType(id uint8, name string, typ string)

func Unmarshal

func Unmarshal(b []byte, i any, t any) error

Types

type Binder

type Binder interface {
	Id() uint8                           // 1
	Name() string                        //JSON
	String() string                      //application/json
	Encode(io.Writer, interface{}) error //同Marshal
	Decode(io.Reader, interface{}) error //同Unmarshal
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}
var Default Binder = Json

func Get added in v1.1.0

func Get(i any) (h Binder)

Get 获取 string(name/type) uint8(id)

func GetContentType added in v1.2.0

func GetContentType(meta map[string]string, mod ContentTypeMod) (r Binder)

func New

func New(t string) (b Binder)

type ContentTypeMod added in v1.2.0

type ContentTypeMod int8
const (
	ContentTypeModReq ContentTypeMod = iota
	ContentTypeModRes
)

type T added in v1.2.0

type T struct {
	Id   uint8
	Name string
	Type string
}

func Type added in v1.2.0

func Type(i any) (r *T)

Jump to

Keyboard shortcuts

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