gocart

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryConverter

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

func (*BinaryConverter) Deserialize

func (receiver *BinaryConverter) Deserialize(data []byte, headers http.Header) (*[]byte, error)

func (*BinaryConverter) Serialize

func (receiver *BinaryConverter) Serialize(body *[]byte, headers http.Header) ([]byte, error)

func (*BinaryConverter) Type

func (receiver *BinaryConverter) Type() *gotrac.HandlerType

type Converter

type Converter[T any] interface {
	Serialize(body *T, headers http.Header) ([]byte, error)
	Deserialize(data []byte, headers http.Header) (*T, error)
	Type() *gotrac.HandlerType
}

func Binary

func Binary(contentType ...string) Converter[[]byte]

func Json

func Json[T any]() Converter[T]

func None

func None() Converter[Empty]

type Empty

type Empty struct{}

type EmptyConverter

type EmptyConverter struct{}

func (EmptyConverter) Deserialize

func (e EmptyConverter) Deserialize(data []byte, headers http.Header) (*Empty, error)

func (EmptyConverter) Serialize

func (e EmptyConverter) Serialize(body *Empty, headers http.Header) ([]byte, error)

func (EmptyConverter) Type

func (e EmptyConverter) Type() *gotrac.HandlerType

type HandlerFunc

type HandlerFunc[TInput any, TOutput any] func(request *Request[TInput], writer HeaderWriter) (*TOutput, error)

type HandlerWithConversion

type HandlerWithConversion interface {
	gotrac.Handler
	WithSummary(summary string) HandlerWithConversion
	WithDescription(description string) HandlerWithConversion
	WithHidden(hidden bool) HandlerWithConversion
}

func WithConversion

func WithConversion[TInput any, TOutput any](input Converter[TInput], output Converter[TOutput], h HandlerFunc[TInput, TOutput]) HandlerWithConversion

type HeaderWriter

type HeaderWriter interface {
	// Header returns the header map that will be sent by
	// [ResponseWriter.WriteHeader]. The [Header] map also is the mechanism with which
	// [Handler] implementations can set HTTP trailers.
	//
	// Changing the header map after a call to [ResponseWriter.WriteHeader] (or
	// [ResponseWriter.Write]) has no effect unless the HTTP status code was of the
	// 1xx class or the modified headers are trailers.
	//
	// There are two ways to set Trailers. The preferred way is to
	// predeclare in the headers which trailers you will later
	// send by setting the "Trailer" header to the names of the
	// trailer keys which will come later. In This case, those
	// keys of the Header map are treated as if they were
	// trailers. See the example. The second way, for trailer
	// keys not known to the [Handler] until after the first [ResponseWriter.Write],
	// is to prefix the [Header] map keys with the [TrailerPrefix]
	// constant value.
	//
	// To suppress automatic response headers (such as "Date"), set
	// their value to nil.
	Header() http.Header

	// WriteHeader sends an HTTP response header with the provided
	// status code.
	//
	// If WriteHeader is not called explicitly, the first call to Write
	// will trigger an implicit WriteHeader(gocart.StatusOK).
	// Thus explicit calls to WriteHeader are mainly used to
	// send error codes or 1xx informational responses.
	//
	// The provided code must be a valid HTTP 1xx-5xx status code.
	// Any number of 1xx headers may be written, followed by at most
	// one 2xx-5xx header. 1xx headers are sent immediately, but 2xx-5xx
	// headers may be buffered. Use the Flusher interface to send
	// buffered data. The header map is cleared when 2xx-5xx headers are
	// sent, but not with 1xx headers.
	//
	// The server will automatically send a 100 (Continue) header
	// on the first read from the request body if the request has
	// an "Expect: 100-continue" header.
	WriteHeader(statusCode int)
}

type JsonConverter

type JsonConverter[T any] struct {
}

func (JsonConverter[T]) Deserialize

func (j JsonConverter[T]) Deserialize(data []byte, headers http.Header) (*T, error)

func (JsonConverter[T]) Serialize

func (j JsonConverter[T]) Serialize(body *T, headers http.Header) ([]byte, error)

func (JsonConverter[T]) Type

func (j JsonConverter[T]) Type() *gotrac.HandlerType

type Request

type Request[TBody any] struct {
	http.Request
	// contains filtered or unexported fields
}

func ConvertRequest

func ConvertRequest[TBody any](request *http.Request, body *TBody) *Request[TBody]

func (*Request[TBody]) Body

func (r *Request[TBody]) Body() *TBody

Jump to

Keyboard shortcuts

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