utils

package
v0.0.0-...-b02a79d Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReCaptchaURL = "https://www.google.com/recaptcha/api/siteverify"
	TurnstileURL = "https://challenges.cloudflare.com/turnstile/v0/siteverify"
)

Variables

View Source
var DefaultJSONLogHandler = NewJSONLogHandler(os.Stderr)
View Source
var ErrNeverTried = errors.New("never tried")
View Source
var RequestCtxKey = &ContextKey{name: "RequestContext"}

Functions

func CORSMiddleware

func CORSMiddleware(next http.HandlerFunc) http.HandlerFunc

func LogAndRecoverMiddleware

func LogAndRecoverMiddleware(next http.HandlerFunc) http.HandlerFunc

func MiddlewareWrap

func MiddlewareWrap(handler http.HandlerFunc, middlewares ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc

func Retry

func Retry(retries int, backOff time.Duration, fn func() error) error

Types

type ContextKey

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

func (ContextKey) String

func (key ContextKey) String() string

type Entry

type Entry struct {
	log.Entry
	Level log.Level `json:"severity"` // GCP expects a "severity" field
}

type HttpRequestLog

type HttpRequestLog struct {
	Timestamp     time.Time `json:"-"`
	Latency       string    `json:"latency,omitempty"`
	Protocol      string    `json:"protocol,omitempty"`
	Referer       string    `json:"referer,omitempty"`
	RemoteIp      string    `json:"remoteIp,omitempty"`
	RequestMethod string    `json:"requestMethod,omitempty"`
	RequestUrl    string    `json:"requestUrl,omitempty"`
	UserAgent     string    `json:"userAgent,omitempty"`
	ServerIp      string    `json:"serverIp,omitempty"`
}

func (*HttpRequestLog) Finalize

func (reqLog *HttpRequestLog) Finalize()

type JSONLogHandler

type JSONLogHandler struct {
	*json.Encoder
	// contains filtered or unexported fields
}

func NewJSONLogHandler

func NewJSONLogHandler(w io.Writer) *JSONLogHandler

func (*JSONLogHandler) HandleLog

func (h *JSONLogHandler) HandleLog(e *log.Entry) error

type ReCaptcha

type ReCaptcha struct {
	Client  http.Client
	Secret  string
	Version RecaptchaVersion
}

func (*ReCaptcha) Verify

func (c *ReCaptcha) Verify(response string, opts VerifyOptions) error

Verify the provided reCaptcha token depending on version.

type RecaptchaVersion

type RecaptchaVersion string
const (
	ReCaptchaV2 RecaptchaVersion = "v2"
	ReCaptchaV3 RecaptchaVersion = "v3"
	ReCaptchaCf RecaptchaVersion = "cf"
)

type RequestContext

type RequestContext struct {
	RequestLog *HttpRequestLog
	LogEntry   *log.Entry
}

type SiteVerifyResponse

type SiteVerifyResponse struct {
	Success     bool      `json:"success"`
	Score       float64   `json:"score"`
	Action      string    `json:"action"`
	ChallengeTS time.Time `json:"challenge_ts"`
	Hostname    string    `json:"hostname"`
	ErrorCodes  []string  `json:"error-codes"`
}

type VerifyError

type VerifyError struct {
	IsHttpError bool
	Err         error
}

func (VerifyError) Error

func (err VerifyError) Error() string

type VerifyOptions

type VerifyOptions struct {
	RemoteIp       string
	Action         string
	ScoreThreshold float64
}

Jump to

Keyboard shortcuts

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