httputil

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JwtParseRSAPrivateKeyFromPEM = jwtgo.ParseRSAPrivateKeyFromPEM
	JwtNewWithClaims             = jwtgo.NewWithClaims
	JwtSigningMethodRS256        = jwtgo.SigningMethodRS256
	JwtNewNumericDate            = jwtgo.NewNumericDate
)
View Source
var (
	ErrParsingCookie = errors.New("parsing cookie")
)

Functions

func Chain

func Chain(h http.Handler, middleware ...func(http.Handler) http.Handler) http.Handler

func DevProxy

func DevProxy(mux *http.ServeMux, service http.Handler, isDev bool, proxyAddr string, exceptions []string) error

DevProxy is for serving static files in development mode. mainly used for UI development with a separate server.

func GetCookie

func GetCookie(key CookieKey, r *http.Request) (string, error)

Get tries to extract cookie by name from request object

func ReadBodyLimiter

func ReadBodyLimiter(size int64, w http.ResponseWriter, r *http.Request) ([]byte, error)

func ReadLimter

func ReadLimter(size int64, w http.ResponseWriter, r *http.Request)

func ReverseProxy

func ReverseProxy(rawURL string) (http.HandlerFunc, error)

func ServeFile

func ServeFile(fs fs.FS) http.Handler

func SetCookie

func SetCookie(w http.ResponseWriter, key CookieKey, value string, maxAge time.Duration, secure bool)

Set maxAge is in seconds, if maxAge is zero, it deletes the cookie

func WithLogging

func WithLogging(next http.Handler) http.Handler

func WithSessionContext

func WithSessionContext[T any](cookieKey CookieKey, ctxKey ContextKey, parseSession func(token string) (T, error)) func(next http.Handler) http.Handler

Types

type ContextKey

type ContextKey string

type CookieKey

type CookieKey string

type Jwt

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

func New

func New(secretKey string) *Jwt

func (*Jwt) Decode

func (j *Jwt) Decode(jwt string, claims JwtClaims) error

func (*Jwt) Encode

func (j *Jwt) Encode(claims JwtClaims) (string, error)

type JwtClaims

type JwtClaims = jwtgo.Claims

type JwtMapClaims

type JwtMapClaims = jwtgo.MapClaims

type JwtRegisteredClaims

type JwtRegisteredClaims = jwtgo.RegisteredClaims

type JwtToken

type JwtToken = jwtgo.Token

type TokenParser

type TokenParser interface {
	ParseToken(token *JwtToken) error
}

Jump to

Keyboard shortcuts

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