xbinding

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 1 Imported by: 6

README

xinding 说明

介绍

xbinding是基于gin框架的binding模块的扩展,主要从项目gin中分离处理binding的部分内容,进行改造处理适配除http以外的其他数据绑定过程。并且兼容http.request的绑定方式。

安装

使用

示例

注意事项

版本变更记录

Documentation

Index

Constants

View Source
const (
	MIMEJSON              = "application/json"
	MIMEHTML              = "text/html"
	MIMEXML               = "application/xml"
	MIMEXML2              = "text/xml"
	MIMEPlain             = "text/plain"
	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"
)
View Source
const DefaultProto = "binding"

Variables

View Source
var ErrUnsupportedContentType = fmt.Errorf("xbinding: 不支持的Content-Type")

Functions

func Register

func Register(resolver Resolver)

Types

type BytesReader added in v0.1.1

type BytesReader []byte

func (BytesReader) ReadObject added in v0.1.1

func (b BytesReader) ReadObject() (any, error)

type Codec

type Codec interface {
	ContentType() string
	Marshal(v interface{}) ([]byte, error)
	Bind(reader Reader, v interface{}) error
}

func GetCodec added in v0.1.1

func GetCodec(opts ...Option) (Codec, error)

GetCodec 根据适配器名称及参数返回配置处理器

type MapReader added in v0.1.1

type MapReader map[string][]string

func (MapReader) ReadObject added in v0.1.1

func (b MapReader) ReadObject() (any, error)

type MultipartReqestInfo added in v0.1.1

type MultipartReqestInfo struct {
	Boundary string
	Body     any
}

type Option

type Option func(o *Options)

func WithContentType added in v0.1.1

func WithContentType(contentType string) Option

func WithMethod

func WithMethod(method string) Option

func WithProto

func WithProto(proto string) Option

type Options

type Options struct {
	Proto       string
	Method      string
	ContentType string
}

func NewOptions

func NewOptions(opts ...Option) *Options

type Reader

type Reader interface {
	ReadObject() (any, error)
}

绑定数据的源reader

type ReaderWrapper added in v0.1.1

type ReaderWrapper struct {
	Data any
}

func (*ReaderWrapper) ReadObject added in v0.1.1

func (r *ReaderWrapper) ReadObject() (any, error)

type Resolver

type Resolver interface {
	Name() string
	Resolve(opts *Options) (Codec, error)
}

解析器

type SMapReader added in v0.1.1

type SMapReader map[string]string

func (SMapReader) ReadObject added in v0.1.1

func (b SMapReader) ReadObject() (any, error)

type XMapReader added in v0.1.1

type XMapReader map[string]any

func (XMapReader) ReadObject added in v0.1.1

func (b XMapReader) ReadObject() (any, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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