hcaptcha

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 License: MIT Imports: 6 Imported by: 1

README

hCaptcha

This library was based on the hCaptcha server-side verification docs.

Example

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithContext added in v0.0.2

func WithContext(ctx context.Context) func(*Client)

WithContext sets the context.Context of a Client

func WithHTTP added in v0.0.2

func WithHTTP(httpClient *http.Client) func(*Client)

WithHTTP sets the http.Client of a Client

Types

type Client

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

Client is an hCaptcha client

func New

func New(secret string, options ...ClientOption) (*Client, error)

New returns a new hCaptcha Client

func (*Client) Verify

func (c *Client) Verify(token string, opts PostOptions) (*Response, error)

Verify checks the response against the hCaptcha API

Example
// Dummy secret https://docs.hcaptcha.com/#integrationtest
client, err := New(dummySecret)
if err != nil {
	panic(err)
}

// Dummy token https://docs.hcaptcha.com/#integrationtest
resp, err := client.Verify(dummyToken, PostOptions{})
if err != nil {
	panic(err)
}

if resp.Success {
	fmt.Println("Verification succeeded")
	
Output:

Verification succeeded

type ClientOption added in v0.0.2

type ClientOption func(*Client)

ClientOption is a func to modify a new Client

type ErrorCode

type ErrorCode string

ErrorCode is any possible error from hCaptcha

const (
	ErrMissingInputSecret           ErrorCode = "missing-input-secret"
	ErrInvalidInputSecret           ErrorCode = "invalid-input-secret"
	ErrMissingInputResponse         ErrorCode = "missing-input-response"
	ErrInvalidInputResponse         ErrorCode = "invalid-input-response"
	ErrBadRequest                   ErrorCode = "bad-request"
	ErrInvalidOrAlreadySeenResponse ErrorCode = "invalid-or-already-seen-response"
	ErrSitekeySecretMismatch        ErrorCode = "sitekey-secret-mismatch"
)

func (ErrorCode) Error

func (err ErrorCode) Error() string

Error fulfills the error interface

func (ErrorCode) String

func (err ErrorCode) String() string

String fulfills the Stringer interface

type PostOptions

type PostOptions struct {
	RemoteIP string
	Sitekey  string
}

PostOptions are optional post form values

type Response

type Response struct {
	Success     bool        `json:"success"`
	ChallengeTS string      `json:"challenge_ts"`
	Hostname    string      `json:"hostname"`
	Credit      bool        `json:"credit,omitempty"`
	ErrorCodes  []ErrorCode `json:"error-codes"`
}

Response is an hCaptcha response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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