Documentation
¶
Index ¶
- Variables
- func BoundString(content string, fontFace font.Face) (width, height int)
- func Check(id, code string) (bool, error)
- func CheckOk(id, code string) bool
- func Create() (id string, result string, img image.Image)
- func CreateB64() (id string, result string, data string, err error)
- func CreateBytes() (id string, result string, buf []byte, err error)
- func Debug()
- func RandomBytes(n int) []byte
- func RandomBytesHex(n int) string
- func RandomCode() string
- func RandomString(n int) string
- func SetCaptcha(m Captcha)
- type Captcha
- type CaptchaBase
- type CaptchaData
- type CaptchaEquation
- type CaptchaErr
- type Option
- func WithBackground(color color.Color) Option
- func WithExpire(t int64) Option
- func WithFont(fontFace font.Face, size float64) Option
- func WithFontByte(buf []byte, fontSize float64, dpi ...float64) Option
- func WithFontName(fontName string, fontSize float64, dpi ...float64) Option
- func WithFontSize(size float64) Option
- func WithFront(color color.Color) Option
- func WithLine(n int) Option
- func WithPoint(n int) Option
- func WithSize(width, hight int) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCodeExpired = CaptchaErr{ErrCode: 301001, /* contains filtered or unexported fields */} ErrCodeInvalid = CaptchaErr{ErrCode: 301002, /* contains filtered or unexported fields */} )
View Source
var Equation = DefaultCaptchaEquation()
Functions ¶
func BoundString ¶ added in v0.1.1
BoundString 根据内容、字体,返回图像大小
func CreateB64 ¶
CreateB64 创建验证码,返回图片base64
Example ¶
package main import ( "fmt" "github.com/virzz/captcha" ) func main() { id, result, data, err := captcha.CreateB64() if err != nil { fmt.Println(err) return } fmt.Println(id) fmt.Println(data) if captcha.CheckOk(id, "xxxx") { fmt.Println("test check") } else if captcha.CheckOk(id, result) { fmt.Println("ok") } else { fmt.Println("fail") } }
Output:
func CreateBytes ¶
CreateBytes 创建验证码,返回图片数据[]byte
func RandomBytes ¶ added in v0.1.1
func RandomBytesHex ¶ added in v0.1.1
func RandomCode ¶ added in v0.1.1
func RandomCode() string
func RandomString ¶ added in v0.1.1
func SetCaptcha ¶ added in v0.1.1
func SetCaptcha(m Captcha)
Types ¶
type Captcha ¶ added in v0.1.1
type Captcha interface {
Draw() (image.Image, *CaptchaData) // 验证码生成逻辑并绘制图片
}
func DefaultCaptchaEquation ¶ added in v0.1.1
func DefaultCaptchaEquation() Captcha
func NewCaptchaEquation ¶ added in v0.1.1
type CaptchaBase ¶ added in v0.1.1
type CaptchaBase struct {
// contains filtered or unexported fields
}
func New ¶ added in v0.1.1
func New(opts ...Option) *CaptchaBase
func (*CaptchaBase) Draw ¶ added in v0.1.1
func (c *CaptchaBase) Draw() (image.Image, *CaptchaData)
func (*CaptchaBase) Options ¶ added in v0.1.1
func (c *CaptchaBase) Options(opts ...Option) *CaptchaBase
type CaptchaData ¶ added in v0.1.1
type CaptchaEquation ¶ added in v0.1.1
type CaptchaEquation struct { *CaptchaBase // contains filtered or unexported fields }
func (*CaptchaEquation) Draw ¶ added in v0.1.1
func (c *CaptchaEquation) Draw() (image.Image, *CaptchaData)
type CaptchaErr ¶ added in v0.1.1
type CaptchaErr struct { ErrCode int // contains filtered or unexported fields }
func (CaptchaErr) Error ¶ added in v0.1.1
func (e CaptchaErr) Error() string
type Option ¶ added in v0.1.1
type Option func(cb *CaptchaBase)
func WithBackground ¶ added in v0.1.1
func WithExpire ¶ added in v0.1.1
func WithFontByte ¶ added in v0.1.1
func WithFontName ¶ added in v0.1.1
func WithFontSize ¶ added in v0.1.1
Click to show internal directories.
Click to hide internal directories.