core

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeExpired = fmt.Errorf("验证码已过期")
	ErrCodeInvalid = fmt.Errorf("验证码无效")
)

Functions

func BitNumInt63n

func BitNumInt63n(bit int) func() int64

func DefaultFontFace

func DefaultFontFace(size int) font.Face

func GetFontFace

func GetFontFace(buf []byte, fontSize int, dpi int) (font.Face, error)

func RandomBytes

func RandomBytes(n int) []byte

func RandomBytesHex

func RandomBytesHex(n int) string

func RandomCode

func RandomCode() string

func RandomSpecialBytes

func RandomSpecialBytes(n int, special string) []byte

func RandomString

func RandomString(n int) string

Types

type Captcha

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

func DefaultCaptcha

func DefaultCaptcha() *Captcha

func (*Captcha) Check

func (c *Captcha) Check(id, code string) (bool, error)

func (*Captcha) Create

func (c *Captcha) Create() (id, result string, img image.Image)

Create 创建验证码,返回图片对象image.Image

func (*Captcha) CreateB64

func (c *Captcha) CreateB64() (id, result, data string, err error)

CreateB64 创建验证码,返回图片base64

func (*Captcha) CreateBytes

func (c *Captcha) CreateBytes() (id, result string, buf []byte, err error)

CreateBytes 创建验证码,返回图片数据[]byte

func (*Captcha) Draw

func (c *Captcha) Draw() (string, *Data, image.Image)

func (*Captcha) Get

func (c *Captcha) Get(id string) (*Data, bool)

func (*Captcha) Init

func (c *Captcha) Init() *Captcha

Init 初始化验证码

func (*Captcha) Options

func (c *Captcha) Options(opts ...Option) *Captcha

func (*Captcha) Remove

func (c *Captcha) Remove(id string)

type Data

type Data struct {
	Content string
	Result  string
	Expire  int64
}

type Generator

type Generator func() (string, string)

type ICache

type ICache interface {
	Get(id string) (*Data, bool)
	Remove(id string)
	Check(id, code string) (bool, error)
}

type ICaptcha

type ICaptcha interface {
	// 验证码缓存
	Get(id string) (*Data, bool)
	Remove(id string)
	Check(id, code string) (bool, error)
	// Draw 绘制验证码
	Draw() (string, *Data, image.Image)
	// Create 创建验证码
	Create() (string, string, image.Image)
	CreateBytes() (string, string, []byte, error)
	CreateB64() (string, string, string, error)
}

type Option

type Option func(b *Captcha)

func WithBackground

func WithBackground(color color.Color) Option

func WithExpire

func WithExpire(t int64) Option

func WithFont

func WithFont(fontFace font.Face, size int) Option

func WithFontByte

func WithFontByte(buf []byte, fontSize int, dpi int) Option

func WithFontName

func WithFontName(fontName string, fontSize int, dpi int) Option

func WithFontSize

func WithFontSize(size int) Option

func WithFront

func WithFront(color color.Color) Option

func WithGenerator

func WithGenerator(generator Generator) Option

func WithLine

func WithLine(n int) Option

func WithPoint

func WithPoint(n int) Option

func WithSize

func WithSize(width, hight int) Option

Jump to

Keyboard shortcuts

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