form

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeValues

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

DecodeValues decode url value into proto message.

func EncodeField

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

EncodeField encode proto message filed

func EncodeFieldMask

func EncodeFieldMask(m protoreflect.Message, useProtoNames bool) (query string)

EncodeFieldMask return field mask name=paths

func EncodeValues

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

EncodeValues encode a message into url values.

Types

type Codec

type Codec struct {
	Encoder *form.Encoder
	Decoder *form.Decoder
	TagName string
	// UseProtoNames uses proto field name instead of
	// lowerCamelCase name in JSON field names.
	UseProtoNames bool
	// UseEnumNumbers emits enum values as numbers.
	UseEnumNumbers bool
}

func New

func New(tagName string) *Codec

New returns a new Codec,

UseProtoNames: true
UseEnumNumbers: true

func (*Codec) ContentType

func (*Codec) ContentType(_ any) string

ContentType always Returns "application/x-www-form-urlencoded; charset=utf-8"

func (*Codec) Decode

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

func (*Codec) DisableUseEnumNumbers

func (c *Codec) DisableUseEnumNumbers() *Codec

DisableUseProtoNames disable emits enum values as numbers.

func (*Codec) DisableUseProtoNames

func (c *Codec) DisableUseProtoNames() *Codec

DisableUseProtoNames disable proto field name, use lowerCamelCase name in JSON field names.

func (*Codec) Encode

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

func (*Codec) EncodeFieldMask

func (c *Codec) EncodeFieldMask(m protoreflect.Message) string

EncodeFieldMask return field mask name=paths

func (*Codec) EncodeURL

func (c *Codec) EncodeURL(pathTemplate string, v 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) NewDecoder

func (c *Codec) NewDecoder(r io.Reader) codec.Decoder

func (*Codec) NewEncoder

func (c *Codec) NewEncoder(w io.Writer) codec.Encoder

func (*Codec) Unmarshal

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

type MultipartCodec

type MultipartCodec struct {
	*Codec
}

func (*MultipartCodec) ContentType

func (*MultipartCodec) ContentType(_ any) string

type QueryCodec

type QueryCodec struct {
	*Codec
}

func (*QueryCodec) ContentType

func (*QueryCodec) ContentType(_ any) string

type UriCodec

type UriCodec struct {
	*Codec
}

func (*UriCodec) ContentType

func (*UriCodec) ContentType(_ any) string

Jump to

Keyboard shortcuts

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