Back to godoc.org
github.com/sj14/recaptcha

package recaptcha

v0.1.0
Latest Go to latest
Published: Mar 21, 2020 | License: MIT | Module: github.com/sj14/recaptcha

Overview

based on https://www.socketloop.com/tutorials/golang-recaptcha-example

Index

Variables

var (
	// ErrNoCaptcha is returned when the form value 'g-recaptcha-response' is empty
	ErrNoCaptcha = errors.New("missing recaptcha response in request")
	// ErrNoSuccess is returned when the recaptcha request was not successful.
	ErrNoSuccess = errors.New("request was not successful")
	// ErrScore is returned when the calculated score is below the required score (V3 only).
	ErrScore = errors.New("request was below the required score")
	// ErrAction is returned when the action is not the required one (V3 only).
	ErrAction = errors.New("wrong action")
)

type OptionV3

type OptionV3 func(*optionsV3)

OptionV3 are optional settings for reCAPTCHA V3 validations.

func Action

func Action(action string) OptionV3

Action sets the required action for a successful validation (default is empty).

func MinScore

func MinScore(min float64) OptionV3

MinScore sets the minimum required score for a successful validation (default: 0.5).

type ResponseV2

type ResponseV2 struct {
	Success     bool      `json:"success"`
	ChallengeTS time.Time `json:"challenge_ts"` // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
	Hostname    string    `json:"hostname"`     // the hostname of the site where the reCAPTCHA was solved
	ErrorCodes  []string  `json:"error-codes"`  // optional
}

ResponseV2 is a reCAPTCHA v2 response.

func VerifyV2

func VerifyV2(secret string, r *http.Request) (*ResponseV2, error)

VerifyV2 verifies a reCAPTCHA v2 request.

type ResponseV3

type ResponseV3 struct {
	Score  float64 `json:"score"`
	Action string  `json:"action"`
	ResponseV2
}

ResponseV3 is a reCAPTCHA v3 response.

func VerifyV3

func VerifyV3(secret string, r *http.Request, opts ...OptionV3) (*ResponseV3, error)

VerifyV3 verifies a reCAPTCHA v3 request.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier