core

package
v0.0.0-...-58f8293 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

+gengo:runtimedoc=false

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithMgr

func ContextWithMgr(ctx context.Context, mgr Mgr) context.Context

func ContextWithStatusCode

func ContextWithStatusCode(ctx context.Context, statusCode int) context.Context

func EachParameter

func EachParameter(ctx context.Context, tpe typesx.Type, each func(p *Parameter) bool)

func EachRequestParameter

func EachRequestParameter(ctx context.Context, tpe typesx.Type, each func(rp *RequestParameter)) error

func GroupedParametersSetFromContext

func GroupedParametersSetFromContext(ctx context.Context) *sync.Map

func MIMEHeader

func MIMEHeader(headers ...textproto.MIMEHeader) textproto.MIMEHeader

func NewValidator

func NewValidator(ctx context.Context, fieldType typex.Type, tags map[string]Tag, omitempty bool, transformer Transformer) (validator.Validator, error)

func ParseTags

func ParseTags(tag string) map[string]Tag

func Register

func Register(transformers ...Transformer)

func StatusCodeFromContext

func StatusCodeFromContext(ctx context.Context) int

func StringifyPath

func StringifyPath(path string, params map[string]string) string

func WithGroupedParametersSet

func WithGroupedParametersSet(ctx context.Context, m *sync.Map) context.Context

func Wrap

func WriteHeader

func WriteHeader(ctx context.Context, w io.Writer, contentType string, param map[string]string)

Types

type CanInterface

type CanInterface interface {
	Interface() any
}

type CanNextReader

type CanNextReader interface {
	NextReader() io.ReadCloser
}

type CanNextWriter

type CanNextWriter interface {
	NextWriter() io.Writer
}

type CanString

type CanString interface {
	String() string
}

type CommonOption

type CommonOption struct {
	// when enable
	// should ignore value when value is empty
	Omitempty bool
	Explode   bool
}

type FlattenParams

type FlattenParams struct {
	Parameters []RequestParameter
}

func (*FlattenParams) CollectParams

func (params *FlattenParams) CollectParams(ctx context.Context, typ typesx.Type) error

func (FlattenParams) NewValidator

func (FlattenParams) NewValidator(ctx context.Context, typ typesx.Type) (validator.Validator, error)

func (FlattenParams) String

func (FlattenParams) String() string

func (*FlattenParams) Validate

func (params *FlattenParams) Validate(v any) error

type GroupedParameters

type GroupedParameters = map[string][]Parameter

func CollectGroupedParameters

func CollectGroupedParameters(ctx context.Context, tpe typesx.Type) GroupedParameters

type HeaderWriter

type HeaderWriter interface {
	WithHeader
	io.Writer
}

func WriterWithHeader

func WriterWithHeader(w io.Writer, header http.Header) HeaderWriter

type MayValidator

type MayValidator interface {
	NewValidator(ctx context.Context, typ typex.Type) (validator.Validator, error)
}

type Mgr

type Mgr interface {
	NewTransformer(context.Context, typesx.Type, Option) (Transformer, error)
	GetTransformerNames(name string) []string
}

func MgrFromContext

func MgrFromContext(ctx context.Context) Mgr

type Option

type Option struct {
	Name   string
	MIME   string
	Strict bool
	CommonOption
}

func (Option) String

func (op Option) String() string

type Parameter

type Parameter struct {
	In    string
	Name  string
	Field typesx.StructField
	Type  typesx.Type
	Tags  map[string]Tag
	Loc   []int
}

func (*Parameter) FieldValue

func (p *Parameter) FieldValue(structReflectValue reflect.Value) reflect.Value

type ParameterValue

type ParameterValue struct {
	Parameter
	Value reflect.Value
}

type RequestParameter

type RequestParameter struct {
	Parameter
	TransformerOption Option
	Transformer       Transformer
	Validator         validator.Validator
}

type StringBuilders

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

func NewStringBuilders

func NewStringBuilders() *StringBuilders

func (*StringBuilders) NextWriter

func (v *StringBuilders) NextWriter() io.Writer

func (*StringBuilders) SetN

func (v *StringBuilders) SetN(n int)

func (*StringBuilders) StringSlice

func (v *StringBuilders) StringSlice() []string

func (*StringBuilders) Write

func (v *StringBuilders) Write(p []byte) (n int, err error)

type StringReader

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

func NewStringReader

func NewStringReader(v string) *StringReader

func (*StringReader) Close

func (r *StringReader) Close() error

func (*StringReader) Interface

func (r *StringReader) Interface() any

func (*StringReader) Read

func (r *StringReader) Read(p []byte) (n int, err error)

func (*StringReader) String

func (r *StringReader) String() string

type StringReaders

type StringReaders struct {
	Readers []io.ReadCloser
	// contains filtered or unexported fields
}

func NewStringReaders

func NewStringReaders(values []string) *StringReaders

func (*StringReaders) Close

func (v *StringReaders) Close() error

func (*StringReaders) Interface

func (v *StringReaders) Interface() any

func (*StringReaders) Len

func (v *StringReaders) Len() int

func (*StringReaders) NextReader

func (v *StringReaders) NextReader() io.ReadCloser

func (*StringReaders) Read

func (v *StringReaders) Read(p []byte) (n int, err error)

type Tag

type Tag string

func (Tag) HasFlag

func (t Tag) HasFlag(flag string) bool

func (Tag) Name

func (t Tag) Name() string

type Transformer

type Transformer interface {
	// Names should include name or alias of transformer
	// prefer using some keyword about content-type
	// first must validate content-type
	Names() []string
	// New will create transformer new transformer instance by type
	// in this step will to check transformer is valid for type
	New(context.Context, typesx.Type) (Transformer, error)

	TransformerEncoder
	TransformerDecoder
}

func NewTransformer

func NewTransformer(ctx context.Context, tpe typesx.Type, opt Option) (Transformer, error)

type TransformerAndOption

type TransformerAndOption struct {
	Transformer
	Option Option
}

type TransformerDecoder

type TransformerDecoder interface {
	// DecodeFrom
	// will unmarshal data from read into some struct
	DecodeFrom(ctx context.Context, r io.ReadCloser, v any, headers ...textproto.MIMEHeader) error
}

type TransformerEncoder

type TransformerEncoder interface {
	// EncodeTo
	// if w implement interface { Header() http.Header }
	// Content-Type will be set
	EncodeTo(ctx context.Context, w io.Writer, v any) (err error)
}

type WithHeader

type WithHeader interface {
	Header() http.Header
}

type WithNamedByTag

type WithNamedByTag interface {
	NamedByTag() string
}

Jump to

Keyboard shortcuts

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