Documentation
¶
Index ¶
- Constants
- Variables
- func RandomBytes(length int) (b []byte)
- func RandomColor() color.RGBA
- func RandomDigits(length int) []byte
- func RandomInt(n int) int
- func RandomRange[T int | float64](from, to T) T
- func RandomString() string
- func RandomText(size int, sourceChars string) string
- type Driver
- type DriverAudio
- type DriverChinese
- type DriverDigit
- type DriverLetter
- type DriverMath
- type DriverString
- type Fonts
- type Item
- type ItemAudio
- type ItemChar
Constants ¶
const ( // MimeTypeImage output base64 mine-type. MimeTypeImage = "image/png" // MimeTypeAudio output base64 mine-type. MimeTypeAudio = "audio/wav" // OptionShowHollowLine shows hollow line OptionShowHollowLine = 2 // OptionShowSlimeLine shows slime line OptionShowSlimeLine = 4 // OptionShowSineLine shows sine line OptionShowSineLine = 8 )
const ( StringLength = 20 TxtNumbers = "012346789" TxtAlphabet = "ABCDEFGHJKMNOQRSTUVXYZabcdefghjkmnoqrstuvxyz" )
Variables ¶
var DefaultDriverAudio = &DriverAudio{
Length: 6,
Language: "en",
}
DefaultDriverAudio is a default audio driver
var DefaultDriverChinese = &DriverChinese{ Width: 100, Height: 32, Length: 6, ShowLineOptions: 0, NoiseCount: 0, Source: "县果栋容他锹射纳堤洲冶架缓飞善挑捏绒既寨剧缝辆语愉谱鸟详坛饶碰扛笔试晶巴呀塘有谣辜确丝活将宪染淋范殖", Fonts: []string{"wqy-microhei.ttc"}, }
DefaultDriverChinese is a default chinese driver
var DefaultDriverDigit = &DriverDigit{
Width: 100,
Height: 32,
Length: 6,
ShowLineOptions: 0,
NoiseCount: 0,
}
DefaultDriverDigit is a default digit driver
var DefaultDriverLetter = &DriverLetter{ Width: 100, Height: 32, Length: 6, ShowLineOptions: 1, NoiseCount: 0, Source: TxtAlphabet, }
DefaultDriverLetter is a default letter driver
var DefaultDriverMath = &DriverMath{
Width: 100,
Height: 32,
ShowLineOptions: 0,
NoiseCount: 0,
}
DefaultDriverMath is a default math driver
var DefaultDriverString = &DriverString{ Width: 100, Height: 32, Length: 6, ShowLineOptions: 0, NoiseCount: 0, Source: TxtNumbers + TxtAlphabet, }
DefaultDriverString is a default string driver
Functions ¶
func RandomBytes ¶
RandomBytes returns a byte slice of the given length read from CSPRNG.
func RandomDigits ¶
RandomDigits returns a byte slice of the given length, where each byte is a
func RandomRange ¶
RandomRange returns a random number in range [from, to).]
func RandomText ¶
RandomText returns a random string of given size.
Types ¶
type Driver ¶
type Driver interface { // DrawCaptcha draws binary item DrawCaptcha(content string) (item Item, err error) // GenerateCaptcha creates rand id, content and answer GenerateCaptcha() (id, q, a string) }
Driver captcha interface for captcha engine to write staff
type DriverAudio ¶
type DriverAudio struct { // Length Default number of digits in captcha solution. Length int // Language possible values for lang are "en", "ja", "ru", "zh". Language string }
DriverAudio captcha config for captcha-engine-audio.
func NewDriverAudio ¶
func NewDriverAudio(d DriverAudio) *DriverAudio
NewDriverAudio creates a driver of audio
func (*DriverAudio) DrawCaptcha ¶
func (d *DriverAudio) DrawCaptcha(content string) (item Item, err error)
DrawCaptcha creates audio captcha item
func (*DriverAudio) GenerateCaptcha ¶
func (d *DriverAudio) GenerateCaptcha() (id, q, a string)
GenerateCaptcha creates id,captcha content and answer
type DriverChinese ¶
type DriverChinese struct { // Width Captcha png width in pixel. Width int // Height png height in pixel. Height int // Length random string length. Length int // NoiseCount text noise count. NoiseCount int // ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine . ShowLineOptions int // Source is a Unicode which is the rand string from. Source string // BgColor captcha image background color (optional) BgColor *color.RGBA // Fonts loads by name see fonts.go's comment Fonts []string // contains filtered or unexported fields }
DriverChinese config for chinese driver.
func NewDriverChinese ¶
func NewDriverChinese(d DriverChinese) *DriverChinese
NewDriverChinese creates a driver of Chinese characters
func (*DriverChinese) DrawCaptcha ¶
func (d *DriverChinese) DrawCaptcha(content string) (item Item, err error)
DrawCaptcha draws captcha item for chinese driver.
func (*DriverChinese) GenerateCaptcha ¶
func (d *DriverChinese) GenerateCaptcha() (id, content, answer string)
GenerateCaptcha generates captcha id, content and answer for chinese driver.
type DriverDigit ¶
type DriverDigit struct { // Width Captcha png width in pixel. Width int // Height png height in pixel. Height int // Length random string length. Length int // NoiseCount text noise count. NoiseCount int // ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine . ShowLineOptions int // Source is a Unicode which is the rand string from. Source string // BgColor captcha image background color (optional) BgColor *color.RGBA }
DriverDigit config for digit driver.
func NewDriverDigit ¶
func NewDriverDigit(d DriverDigit) *DriverDigit
NewDriverDigit creates a digit driver.
func (*DriverDigit) DrawCaptcha ¶
func (d *DriverDigit) DrawCaptcha(content string) (item Item, err error)
DrawCaptcha draws captcha item for digit driver.
func (*DriverDigit) GenerateCaptcha ¶
func (d *DriverDigit) GenerateCaptcha() (id, content, answer string)
GenerateCaptcha generates id, content and answer for digit driver.
type DriverLetter ¶ added in v1.3.9
type DriverLetter struct { // Width Captcha png width in pixel. Width int // Height png height in pixel. Height int // Length random string length. Length int // NoiseCount text noise count. NoiseCount int // ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine . ShowLineOptions int // Source is a Unicode which is the rand string from. Source string // BgColor captcha image background color (optional) BgColor *color.RGBA }
DriverLetter config for letter driver.
func NewDriverLetter ¶ added in v1.3.9
func NewDriverLetter(d DriverLetter) *DriverLetter
NewDriverLetter creates a letter driver.
func (*DriverLetter) DrawCaptcha ¶ added in v1.3.9
func (d *DriverLetter) DrawCaptcha(content string) (item Item, err error)
DrawCaptcha draws captcha item for letter driver
func (*DriverLetter) GenerateCaptcha ¶ added in v1.3.9
func (d *DriverLetter) GenerateCaptcha() (id, content, answer string)
GenerateCaptcha generates id, content and answer for letter driver.
type DriverMath ¶
type DriverMath struct { // Width Captcha png width in pixel. Width int // Height png height in pixel. Height int // NoiseCount text noise count. NoiseCount int // ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine . ShowLineOptions int // BgColor captcha image background color (optional) BgColor *color.RGBA // Fonts loads by name see fonts.go's comment Fonts []string // contains filtered or unexported fields }
DriverMath config for math driver.
func NewDriverMath ¶
func NewDriverMath(d DriverMath) *DriverMath
NewDriverMath creates a math driver.
func (*DriverMath) DrawCaptcha ¶
func (d *DriverMath) DrawCaptcha(question string) (item Item, err error)
DrawCaptcha draws captcha item for math driver.
func (*DriverMath) GenerateCaptcha ¶
func (d *DriverMath) GenerateCaptcha() (id, question, answer string)
GenerateCaptcha generates id, content and answer for math captcha.
type DriverString ¶
type DriverString struct { // Width Captcha png width in pixel. Width int // Height png height in pixel. Height int // Length random string length. Length int // NoiseCount text noise count. NoiseCount int // ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine . ShowLineOptions int // Source is a Unicode which is the rand string from. Source string // BgColor captcha image background color (optional) BgColor *color.RGBA // Fonts loads by name see fonts.go's comment Fonts []string // contains filtered or unexported fields }
DriverString config for string driver.
func NewDriverString ¶
func NewDriverString(d DriverString) *DriverString
NewDriverString creates a string driver.
func (*DriverString) DrawCaptcha ¶
func (d *DriverString) DrawCaptcha(content string) (item Item, err error)
DrawCaptcha draws captcha item for string driver.
func (*DriverString) GenerateCaptcha ¶
func (d *DriverString) GenerateCaptcha() (id, content, answer string)
GenerateCaptcha generates id,content and answer for string driver.
type Item ¶
type Item interface { // Writer writes to a writer Writer(w io.Writer) (n int64, err error) // Encoder encodes as base64 string Encoder() string }
Item is captcha item interface
type ItemAudio ¶
type ItemAudio struct {
// contains filtered or unexported fields
}
ItemAudio captcha-audio-engine return type.