httpext

package
v2.0.0-...-1fe9aa2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Platform             = "HTTP"
	ContentTypeHeader    = "Content-Type"
	CharsetHeader        = "Accept-Charset"
	AcceptHeader         = "Accept"
	AuthorizationHeader  = "Authorization"
	RealIPHeader         = "X-Real-IP"
	AcceptLanguageHeader = "Accept-Language"
	SessionIDHeader      = "session-id"
	ContentDisposition   = "Content-Disposition"
)

Variables

View Source
var (
	DefaultCors = cors.New(cors.Options{
		AllowedOrigins: []string{"*"},
		AllowedMethods: []string{
			http.MethodGet,
			http.MethodPost,
			http.MethodPut,
			http.MethodPatch,
			http.MethodDelete,
			http.MethodOptions,
		},
		AllowedHeaders: []string{"*"},
	})
)
View Source
var (
	ErrInvalidToken = errors.New(codes.Unauthenticated).WithDetails("invalid Authenticate")
)

Functions

func AuthHeader

func AuthHeader(req *http.Request) (authenticate.Authenticate, error)

func BindRequestModel

func BindRequestModel(req *http.Request, model any) error

func BindResponseModel

func BindResponseModel(res *http.Response, model any) ([]byte, error)

func GetContentMIME

func GetContentMIME(header http.Header) string
func Header(req *http.Request, key string) string

func ParseHeader

func ParseHeader[T any](req *http.Request, key string, parse func(str string) (T, error)) (T, error)

func RequestPayload

func RequestPayload(req *http.Request) ([]byte, error)

func ResponsePayload

func ResponsePayload(res *http.Response) ([]byte, error)

func Send

func Send(res http.ResponseWriter, _ *http.Request, code int, mime string, data []byte)

func SendCode

func SendCode(res http.ResponseWriter, _ *http.Request, code int)

func SendError

func SendError(res http.ResponseWriter, req *http.Request, err error)

func SendModel

func SendModel(res http.ResponseWriter, req *http.Request, code int, model any)

Types

type Configs

type Configs struct {
	HttpPort netext.Port `env:"HTTP_PORT" envDefault:"8080"`
}

Jump to

Keyboard shortcuts

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