Documentation ¶
Index ¶
- Constants
- Variables
- func NewDriverMath(height int, width int, noiseCount int, showLineOptions int, ...) (*driverMath, error)
- func NewDriverString(height int, width int, noiseCount int, showLineOptions int, length int, ...) (*driverString, error)
- func RandColor() color.RGBA
- func RandDeepColor() color.RGBA
- func RandLightColor() color.RGBA
- func RandText(size int, sourceChars string) string
- func RandomId() string
- type Driver
- type EmbeddedFontsStorage
- type FontsStorage
- type Item
- type ItemChar
- type Store
- type StoreSyncMap
Constants ¶
const ( //TxtNumbers chacters for numbers. TxtNumbers = "012346789" //TxtAlphabet characters for alphabet. TxtAlphabet = "ABCDEFGHJKMNOQRSTUVXYZabcdefghjkmnoqrstuvxyz" //TxtSimpleCharaters simple numbers and alphabet TxtSimpleCharaters = "13467ertyiadfhjkxcvbnERTYADFGHJKXCVBN" //TxtChineseCharaters makes characters in chinese TxtChineseCharaters = "的一是在不了有和人这中大为上个国我以要他" + "时来用们生到作地于出就分对成会可主发年动" + "同工也能下过子说产种面而方后多定行学法所" + "民得经十三之进着等部度家电力里如水化高自" + "二理起小物现实加量都两体制机当使点从业本" + "去把性好应开它合还因由其些然前外天政四日" + "那社义事平形相全表间样与关各重新线内数正" + "心反你明看原又么利比或但质气第向道命此变" + "条只没结解问意建月公无系军很情者最立代想" + "已通并提直题党程展五果料象员革位入常文总" + "次品式活设及管特件长求老头基资边流路级少" + "图山统接知较将组见计别她手角期根论运农指" + "几九区强放决西被干做必战先回则任取据处队" + "南给色光门即保治北造百规热领七海口东导器" + "压志世金增争济阶油思术极交受联什认六共权" + "收证改清己美再采转更单风切打白教速花带安" + "场身车例真务具万每目至达走积示议声报斗完" + "类八离华名确才科张信马节话米整空元况今集" + "温传土许步群广石记需段研界拉林律叫且究观" + "越织装影算低持音众书布复容儿须际商非验连" + "断深难近矿千周委素技备半办青省列习响约支" + "般史感劳便团往酸历市克何除消构府称太准精" + "值号率族维划选标写存候毛亲快效斯院查江型" + "眼王按格养易置派层片始却专状育厂京识适属" + "圆包火住调满县局照参红细引听该铁价严龙飞" //MimeTypeAudio output base64 mine-type. MimeTypeAudio = "audio/wav" //MimeTypeImage output base64 mine-type. MimeTypeImage = "image/png" //Emoji is a source string for randTxt Emoji = "" /* 268-byte string literal not displayed */ )
const ( //OptionShowHollowLine shows hollow line OptionShowHollowLine = 2 //OptionShowSlimeLine shows slime line OptionShowSlimeLine = 4 //OptionShowSineLine shows sine line OptionShowSineLine = 8 )
Variables ¶
var ( // GCLimitNumber The number of captchas created that triggers garbage collection used by default store. GCLimitNumber = 10240 // Expiration time of captchas used by default store. Expiration = 10 * time.Minute // DefaultMemStore is a shared storage for captchas, generated by New function. DefaultMemStore = NewMemoryStore(GCLimitNumber, Expiration) )
Functions ¶
func NewDriverMath ¶
func NewDriverMath(height int, width int, noiseCount int, showLineOptions int, bgColor *color.RGBA, fontsStorage FontsStorage, fonts []string) (*driverMath, error)
NewDriverMath creates a driver of math
func NewDriverString ¶
func NewDriverString(height int, width int, noiseCount int, showLineOptions int, length int, source string, bgColor *color.RGBA, fontsStorage FontsStorage, fonts []string) (*driverString, error)
NewDriverString creates driver
func RandLightColor ¶
RandLightColor get random ligth color. 随机生成浅色.
Types ¶
type Driver ¶
type Driver interface { //DrawCaptcha draws binary item DrawCaptcha(content string) (item Item, err error) //GenerateIdQuestionAnswer creates rand id, content and answer GenerateIdQuestionAnswer() (id, q, a string) }
Driver captcha interface for captcha engine to to write staff
type EmbeddedFontsStorage ¶
type EmbeddedFontsStorage struct {
// contains filtered or unexported fields
}
func NewEmbeddedFontsStorage ¶
func NewEmbeddedFontsStorage(fs embed.FS) *EmbeddedFontsStorage
func (*EmbeddedFontsStorage) LoadFontByName ¶
func (s *EmbeddedFontsStorage) LoadFontByName(name string) *truetype.Font
func (*EmbeddedFontsStorage) LoadFontsByNames ¶
func (s *EmbeddedFontsStorage) LoadFontsByNames(assetFontNames []string) []*truetype.Font
LoadFontsByNames import fonts from dir. make the simple-font(RitaSmith.ttf) the first font of trueTypeFonts.
type FontsStorage ¶
type FontsStorage interface { // LoadFontByName returns the font from the storage LoadFontByName(name string) *truetype.Font // LoadFontsByNames returns multiple fonts from storage LoadFontsByNames(assetFontNames []string) []*truetype.Font }
FontsStorage interface for working with fonts
type Item ¶
type Item interface { // WriteTo writes to a writer WriteTo(w io.Writer) (n int64, err error) // EncodeBinary encodes as raw byte slice EncodeBinary() []byte }
Item is captcha item interface
type ItemChar ¶
type ItemChar struct {
// contains filtered or unexported fields
}
ItemChar captcha item of unicode characters
func NewItemChar ¶
NewItemChar creates a captcha item of characters
func (*ItemChar) EncodeBinary ¶
BinaryEncoding encodes an image to PNG and returns a byte slice.
type Store ¶
type Store interface { // Set sets the digits for the captcha id. Set(id string, value string) error // Get returns stored digits for the captcha id. Clear indicates // whether the captcha must be deleted from the store. Get(id string, clear bool) string //Verify captcha's answer directly Verify(id, answer string, clear bool) bool }
Store An object implementing Store interface can be registered with SetCustomStore function to handle storage and retrieval of captcha ids and solutions for them, replacing the default memory store.
It is the responsibility of an object to delete expired and used captchas when necessary (for example, the default memory store collects them in Set method after the certain amount of captchas has been stored.)
func NewMemoryStore ¶
NewMemoryStore returns a new standard memory store for captchas with the given collection threshold and expiration time (duration). The returned store must be registered with SetCustomStore to replace the default one.
type StoreSyncMap ¶
type StoreSyncMap struct {
// contains filtered or unexported fields
}
StoreSyncMap use sync.Map as store
func NewStoreSyncMap ¶
func NewStoreSyncMap(liveTime time.Duration) *StoreSyncMap
NewStoreSyncMap new a instance