utils

package
v0.0.0-...-3d7ecd4 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

This is a changed version of https://github.com/ezzarghili/recaptcha-go

Index

Constants

View Source
const (
	XForwardedFor = "X-Forwarded-For"
	XRealIP       = "X-Real-IP"
)
View Source
const (
	// V2 recaptcha api v2
	RecaptchaV2 VERSION = iota
	// V3 recaptcha api v3, more details can be found here : https://developers.google.com/recaptcha/docs/v3
	RecaptchaV3
	// DefaultThreshold Default minimin score when using V3 api
	DefaultThreshold float32 = 0.5
)

Variables

This section is empty.

Functions

func CheckFileExistance

func CheckFileExistance(filepath string) bool

func DoMD5

func DoMD5(input string) string

func ErrorHandler

func ErrorHandler(err error) bool

func PasswordCrypto

func PasswordCrypto(pwd string) string

func RemoteIp

func RemoteIp(req *http.Request) string

Types

type Error

type Error struct {

	// ErrorCodes contains any error codes from the recaptcha response.
	ErrorCodes []string
	// RequestError is true if the verify request to recaptcha failed.
	RequestError bool
	// contains filtered or unexported fields
}

Error custom error to pass ErrorCodes and RequestError to user.

func (*Error) Error

func (e *Error) Error() string

type ReCAPTCHA

type ReCAPTCHA struct {
	Secret        string
	ReCAPTCHALink string
	Version       VERSION
	Timeout       time.Duration
	// contains filtered or unexported fields
}

ReCAPTCHA recpatcha holder struct, make adding mocking code simpler.

func NewReCAPTCHA

func NewReCAPTCHA(ReCAPTCHASecret string, version VERSION, timeout time.Duration) (ReCAPTCHA, error)

NewReCAPTCHA new ReCAPTCHA instance if version is set to V2 uses recatpcha v2 API, get your secret from https://www.google.com/recaptcha/admin

if version is set to V2 uses recatpcha v2 API, get your secret from https://g.co/recaptcha/v3

func (*ReCAPTCHA) Verify

func (r *ReCAPTCHA) Verify(challengeResponse string) error

Verify returns `nil` if no error and the client solved the challenge correctly

func (*ReCAPTCHA) VerifyWithOptions

func (r *ReCAPTCHA) VerifyWithOptions(challengeResponse string, options VerifyOption) error

VerifyWithOptions returns `nil` if no error and the client solved the challenge correctly and all options are matching `Threshold` and `Action` are ignored when using V2 version

type VERSION

type VERSION int8

VERSION the recaptcha api version

type VerifyOption

type VerifyOption struct {
	Threshold      float32 // ignored in v2 recaptcha
	Action         string  // ignored in v2 recaptcha
	Hostname       string
	ApkPackageName string
	ResponseTime   time.Duration
	RemoteIP       string
}

VerifyOption verification options expected for the challenge

Jump to

Keyboard shortcuts

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