captcha

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: MIT Imports: 2 Imported by: 1

README

Captcha - Powerful and easy to use

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/captcha

Getting Started

package main

import (
	"fmt"
	"net/http"

	"github.com/go-zoox/captcha"
)

func main() {
	http.HandleFunc("/", rootHandler)
	http.HandleFunc("/captcha", captchaHandler)

	fmt.Println("Server start at port 8080")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		panic(err)
	}
}

func rootHandler(w http.ResponseWriter, _ *http.Request) {
	w.Write([]byte("hello, world"))
}

func captchaHandler(w http.ResponseWriter, _ *http.Request) {
	cap := captcha.New()
	fmt.Println("text:", cap.Text())
	cap.Write(w)
}

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.0.3"

Version is the current version of the package.

Functions

This section is empty.

Types

type Captcha

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

Captcha is a captcha generator.

func New

func New(config ...*Config) *Captcha

New creates a new captcha.

func (*Captcha) Length added in v1.0.3

func (c *Captcha) Length() int

Length returns the captcha text length.

func (*Captcha) Text

func (c *Captcha) Text() string

Text returns the captcha text.

func (*Captcha) Write

func (c *Captcha) Write(w io.Writer) error

Write writes the captcha image to writer.

type Config

type Config struct {
	// Length is the length of captcha text.
	Length int

	// BaseChars is the base chars to use.
	// Default: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
	// You can custom number only: "0123456789"
	BaseChars string

	// Noise is the number of noise dots.
	// Default: 1.0
	Noise float64

	// Witdh is the width of captcha image.
	// Default: 150px
	Width int

	// Height is the height of captcha image.
	// Default: 50px
	Height int
}

Config is the configuration for captcha.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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