wwhttp

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuthOptionalMiddleware added in v0.14.7

func BasicAuthOptionalMiddleware(next http.Handler) http.Handler

func CloudflareMiddleware added in v0.12.0

func CloudflareMiddleware(log zerolog.Logger) func(next http.Handler) http.Handler

func ContextWithBasicAuth added in v0.14.7

func ContextWithBasicAuth(ctx context.Context, basicAuth *BasicAuth) context.Context

func ContextWithUserAgent added in v0.14.7

func ContextWithUserAgent(ctx context.Context, userAgent string) context.Context

func CorsMiddleware

func CorsMiddleware(allowedOrigins []string) func(next http.Handler) http.Handler

func IpContextMiddleware

func IpContextMiddleware(next http.Handler) http.Handler

func IpForContext

func IpForContext(ctx context.Context) net.IP

func LoggerMiddleware added in v0.12.0

func LoggerMiddleware(logger zerolog.Logger, cloudflare bool, optSkipPaths ...[]string) func(next http.Handler) http.Handler

LoggerMiddleware is a copy of httplog.RequestLogger, but with Cloudflare header support.

func NewRouter

func NewRouter(logger zerolog.Logger, serviceName string, cloudflare bool) *chi.Mux

func RequestIDHeaderMiddleware

func RequestIDHeaderMiddleware(next http.Handler) http.Handler

func RequireCloudflareMiddleware added in v0.12.0

func RequireCloudflareMiddleware(log zerolog.Logger) func(next http.Handler) http.Handler

func ServerWithAutoCert

func ServerWithAutoCert(
	domain string,
	httpServer *http.Server,
	httpsServer *http.Server,
)

func UserAgentFromContext added in v0.14.7

func UserAgentFromContext(ctx context.Context) string

func UserAgentMiddleware added in v0.14.7

func UserAgentMiddleware(next http.Handler) http.Handler

Types

type BasicAuth added in v0.14.7

type BasicAuth struct {
	Username string
	Password string
}

func BasicAuthFromContext added in v0.14.7

func BasicAuthFromContext(ctx context.Context) *BasicAuth

type CloudflareContext added in v0.12.0

type CloudflareContext struct {
	ClientIp         net.IP
	IsFromCloudflare bool
}

func CloudflareFromContext added in v0.12.0

func CloudflareFromContext(ctx context.Context) CloudflareContext

type Daemon

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

func RunDaemon

func RunDaemon(ctx context.Context, srv DaemonServer) *Daemon

RunDaemon runs the given server in the background and automatically attempts graceful shutdown on interrupt.

func (*Daemon) Wait

func (d *Daemon) Wait()

Wait will block until the context is cancelled and will exit/panic or return.

type DaemonServer added in v0.0.13

type DaemonServer interface {
	Start(ctx context.Context) error
}

type FcgiServer added in v0.0.13

type FcgiServer struct {
	Router     http.Handler
	SocketPath string
	// Dev only, should not be used in production.
	GlobalRwx bool
}

func NewFcgiServerFromEnv added in v0.0.13

func NewFcgiServerFromEnv(router http.Handler) *FcgiServer

func (*FcgiServer) Start added in v0.0.13

func (srv *FcgiServer) Start(ctx context.Context) error

type Getter added in v0.12.0

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

Getter is a helper for retrieving & caching an ETagged http response.

func NewGetter added in v0.12.0

func NewGetter(config GetterConfig) *Getter

func (*Getter) GetJson added in v0.12.0

func (pg *Getter) GetJson(ctx context.Context, v interface{}) error

type GetterConfig added in v0.12.0

type GetterConfig struct {
	Log           zerolog.Logger
	Url           string
	CheckInterval time.Duration
}

type ReCaptcha added in v0.1.0

type ReCaptcha struct {
	Log         zerolog.Logger
	SecretKeyV2 string
	SiteKeyV2   string
	SecretKeyV3 string
	SiteKeyV3   string
	MinScoreV3  float32
}

func NewReCaptchaFromEnv added in v0.1.0

func NewReCaptchaFromEnv(log zerolog.Logger) ReCaptcha

func (ReCaptcha) PublicSettings added in v0.1.0

func (r ReCaptcha) PublicSettings() ReCaptchaPublicSettings

func (ReCaptcha) ReCaptchaV2Verify added in v0.1.0

func (r ReCaptcha) ReCaptchaV2Verify(ctx context.Context, token string) (*ReCaptchaV2Response, error)

func (ReCaptcha) ReCaptchaV3Verify added in v0.1.0

func (r ReCaptcha) ReCaptchaV3Verify(ctx context.Context, token string) (*ReCaptchaV3Response, error)

func (ReCaptcha) VerifyReCaptchaTokensFromContext added in v0.1.0

func (r ReCaptcha) VerifyReCaptchaTokensFromContext(ctx context.Context, action string, tokens ReCaptchaTokens) error

type ReCaptchaPublicSettings added in v0.1.0

type ReCaptchaPublicSettings struct {
	SiteKeyV2 string `json:"siteKeyV2"`
	SiteKeyV3 string `json:"siteKeyV3"`
}

type ReCaptchaTokens added in v0.1.0

type ReCaptchaTokens struct {
	ReCaptchaV3token *string
	ReCaptchaV2token *string
}

type ReCaptchaV2Response added in v0.1.0

type ReCaptchaV2Response struct {
	Success     bool     `json:"success"`
	ChallengeTs string   `json:"challenge_ts"`
	Hostname    string   `json:"hostname"`
	ErrorCodes  []string `json:"error-codes"`
}

type ReCaptchaV3Response added in v0.1.0

type ReCaptchaV3Response struct {
	Success     bool     `json:"success"`
	Score       float32  `json:"score"`
	Action      string   `json:"action"`
	ChallengeTs string   `json:"challenge_ts"`
	Hostname    string   `json:"hostname"`
	ErrorCodes  []string `json:"error-codes"`
}

type Server

type Server struct {
	Domain    string
	Router    http.Handler
	AutoCert  bool
	CertFile  string
	CertKey   string
	HttpPort  string
	HttpsPort string
}

func (*Server) Start

func (srv *Server) Start(ctx context.Context) error

type Turnstile added in v0.15.7

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

func NewTurnstileFromEnv added in v0.15.7

func NewTurnstileFromEnv(log zerolog.Logger) *Turnstile

func (*Turnstile) SiteKey added in v0.15.7

func (t *Turnstile) SiteKey() string

func (*Turnstile) VerifyToken added in v0.15.7

func (t *Turnstile) VerifyToken(ctx context.Context, token string, expectedAction string) (bool, error)

type TurnstileVerifyResponse added in v0.15.7

type TurnstileVerifyResponse struct {
	Success     bool       `json:"success"`
	ChallengeTs *time.Time `json:"challenge_ts"`
	Hostname    *string    `json:"hostname"`
	ErrorCodes  []string   `json:"error-codes"`
	Action      *string    `json:"action"`
	CData       *string    `json:"cdata"`
}

Jump to

Keyboard shortcuts

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