form

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(vs url.Values, v any) error

func DecodeValues

func DecodeValues(msg proto.Message, values url.Values) error

DecodeValues decode url value into proto message.

func Encode

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

func EncodeField

func EncodeField(fieldDescriptor protoreflect.FieldDescriptor, value protoreflect.Value) (string, error)

EncodeField encode proto message filed

func EncodeURL

func EncodeURL(pathTemplate string, msg any, needQuery bool) string

func EncodeValues

func EncodeValues(msg proto.Message) (url.Values, error)

EncodeValues encode a message into url values.

func Marshal

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

func Name

func Name() string

func ReplaceDefaultCodec

func ReplaceDefaultCodec(codec Codec)

func Unmarshal

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

Types

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) Codec

New returns a new Codec, default tag name is "json", proto use protoJSON tag

func (Codec) Decode

func (c Codec) Decode(vs url.Values, v any) error

func (Codec) Encode

func (c Codec) Encode(v any) (url.Values, error)

func (Codec) EncodeURL

func (c Codec) EncodeURL(pathTemplate string, msg any, needQuery bool) string

EncodeURL encode msg to url path. pathTemplate is a template of url path like http://helloworld.dev/{name}/sub/{sub.name},

func (Codec) Marshal

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

func (Codec) Name

func (Codec) Name() string

func (Codec) Unmarshal

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

type Option

type Option func(*Codec)

func WithDecoder

func WithDecoder(decoder *form.Decoder) Option

func WithDisableProto

func WithDisableProto() Option

func WithEncoder

func WithEncoder(encoder *form.Encoder) Option

func WithTagName

func WithTagName(tagName string) Option

Jump to

Keyboard shortcuts

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