recaptcha

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2019 License: MIT Imports: 6 Imported by: 0

README

Go client for Google Recaptcha V3

What is Recaptcha V3?

https://developers.google.com/recaptcha/docs/versions#v3

How to install:

go get github.com/ges-sh/recaptcha

How to use:

package main

import (
	"fmt"

	"github.com/ges-sh/recaptcha"
)

func main() {
	secret := "RECAPTCHA_SECRET"
	minScore := 0.3 // example

	captchaClient := recaptcha.New(secret, minScore)

	token := "USER_TOKEN" // generated by frontend side for every visiting user

	userValid, err := captchaClient.FetchRecaptchaV3(token, "127.0.0.1")
	if err != nil{
		log.Println(err)
		return
	}

	fmt.Println(userValid)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(secret string, score float64) Client

Returns new instance of recaptcha Client

func NewWithClient

func NewWithClient(secret string, score float64, client HTTPClient) Client

Returns new instance of recaptcha Client with custom http client

func (Client) FetchRecaptchaV3

func (c Client) FetchRecaptchaV3(token, ip string) (bool, error)

FetchRecaptchaV3 returns whether user is valid from the perspective of Recaptcha V3 and minimum required score. For more information about token visit https://developers.google.com/recaptcha/docs/v3.

type HTTPClient

type HTTPClient interface {
	PostForm(url string, query url.Values) (*http.Response, error)
}

Jump to

Keyboard shortcuts

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