captcha4g

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: Apache-2.0 Imports: 22 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ErrCodeBadArgument  = "BadArgument"
	ErrCodeUnavailable  = "Unavailable"
	ErrCodeServerError  = "ServerError"
	ErrCodeNotFound     = "NotFound"
	ErrCodeAccessDenied = "AccessDenied"
	ErrCodeUnauthorized = "Unauthorized"
)

Variables

View Source
var (
	DefaultConfig = Options{
		ImageWidth:      160,
		ImageHeight:     80,
		ImageExpiration: 86400000,
		ImageColor:      []uint8{51, 102, 204},
		Symbols:         defSymbols,
		LengthMin:       4,
		LengthMax:       6,
		ServerPort:      9527,
		// contains filtered or unexported fields
	}

	DataConnector kvapi.Client
)

Functions

func Config

func Config(cfg Options) error

func WebServerModule

func WebServerModule() *httpsrv.Module

func WebServerStart

func WebServerStart()

Types

type Api

type Api struct {
	*httpsrv.Controller
}

func (Api) ImageAction

func (c Api) ImageAction()

func (Api) VerifyAction

func (c Api) VerifyAction()

type ErrorMeta added in v0.1.2

type ErrorMeta struct {
	// A machine-readable description of the type of the error. If this value is
	// empty there is no information available.
	Code string `json:"code,omitempty" toml:"code,omitempty"`

	// A human-readable description of the error message.
	Message string `json:"message,omitempty" toml:"message,omitempty"`
}

ErrorMeta provides more information about an api failure.

func ImageFetch

func ImageFetch(token string, reload bool) ([]byte, *ErrorMeta)

func NewErrorMeta added in v0.1.2

func NewErrorMeta(code, message string) *ErrorMeta

func Verify

func Verify(token, word string) *ErrorMeta

type FontEntry

type FontEntry struct {
	Symbol string
	Width  int
	Height int
	Image  *image.RGBA
}

type FontList

type FontList struct {
	MaxHeight int
	Length    int
	Items     []*FontEntry
}

type Options

type Options struct {
	//
	FontPath string `json:"font_path,omitempty" toml:"font_path,omitempty"`
	DataDir  string `json:"data_dir,omitempty" toml:"data_dir,omitempty"`

	// Standard width and height of a CAPTCHA image.
	ImageWidth  int `json:"image_width,omitempty" toml:"image_width,omitempty"`
	ImageHeight int `json:"image_height,omitempty" toml:"image_height,omitempty"`

	// RGB red, green, blue values for the color of a CAPTCHA image.
	ImageColor []uint8 `json:"image_color,omitempty" toml:"image_color,omitempty"`

	// Expiration time (in milliseconds) of CAPTCHAs used by store.
	ImageExpiration int64 `json:"image_expiration,omitempty" toml:"image_expiration,omitempty"`

	// Symbols used to draw CAPTCHA
	//
	// Example:
	//   symbols 0123456789
	// Example:
	//   symbols 34578acdekpsvxy
	//   (!) alphabet without similar symbols (0=o, 1=l, 2=z, 6=b, 9=g, ...)
	Symbols string `json:"symbols,omitempty" toml:"symbols,omitempty"`

	// Default number of symbols in CAPTCHA solution.
	LengthMin int `json:"length_min,omitempty" toml:"length_min,omitempty"`
	LengthMax int `json:"length_max,omitempty" toml:"length_max,omitempty"`

	//
	ServerPort uint16 `json:"server_port,omitempty" toml:"server_port,omitempty"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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