Documentation ¶
Index ¶
- Constants
- func RegisterImageFilter(id string, f func(FilterConfigGroup) ImageFilter) bool
- func RegisterStore(name string, f func(*StoreConfig) (StoreInterface, error)) bool
- type CImage
- type CStore
- func (store *CStore) Add(captcha *CaptchaInfo) string
- func (store *CStore) Del(key string)
- func (store *CStore) Destroy()
- func (store *CStore) Dump(file string) error
- func (store *CStore) Get(key string) *CaptchaInfo
- func (store *CStore) LoadDumped(file string) error
- func (store *CStore) OnConstruct()
- func (store *CStore) OnDestruct()
- func (store *CStore) Update(key string, captcha *CaptchaInfo) bool
- type Captcha
- type CaptchaConfig
- type CaptchaInfo
- type CaptchaRedisStore
- func (this *CaptchaRedisStore) Add(captcha *CaptchaInfo) string
- func (this *CaptchaRedisStore) Del(key string)
- func (this *CaptchaRedisStore) Destroy()
- func (this *CaptchaRedisStore) Get(key string) *CaptchaInfo
- func (this *CaptchaRedisStore) OnConstruct()
- func (this *CaptchaRedisStore) OnDestruct()
- func (this *CaptchaRedisStore) Update(key string, captcha *CaptchaInfo) bool
- type FilterConfig
- type FilterConfigGroup
- type FontManager
- type ImageConfig
- type ImageFilter
- type ImageFilterBase
- type ImageFilterManager
- type ImageFilterNoiseLine
- type ImageFilterNoisePoint
- type ImageFilterStrike
- type MCStore
- func (store *MCStore) Add(captcha *CaptchaInfo) string
- func (store *MCStore) Del(key string)
- func (store *MCStore) Destroy()
- func (store *MCStore) Get(key string) *CaptchaInfo
- func (store *MCStore) OnConstruct()
- func (store *MCStore) OnDestruct()
- func (store *MCStore) Update(key string, captcha *CaptchaInfo) bool
- type StoreConfig
- type StoreInterface
- type WordManager
Constants ¶
const ( DEFAULT_LIFE_TIME = time.Minute * 5 DEFAULT_FONT_SIZE = 26 DEFAULT_WIDTH = 120 DEFAULT_HEIGHT = 40 DEFAULT_GC_PROBABILITY = 1 DEFAULT_GC_DIVISOR = 100 )
const IMAGE_FILTER_NOISE_LINE = "ImageFilterNoiseLine"
ImageFilter is the interface of image filter
const IMAGE_FILTER_NOISE_POINT = "ImageFilterNoisePoint"
const IMAGE_FILTER_STRIKE = "ImageFilterStrike"
const (
MC_KEY_PREFIX = "gocaptcha-"
)
const STORE_ENGINE_BUILDIN = "buildin"
const STORE_ENGINE_MEMCACHE = "memcache"
Variables ¶
This section is empty.
Functions ¶
func RegisterImageFilter ¶
func RegisterImageFilter(id string, f func(FilterConfigGroup) ImageFilter) bool
func RegisterStore ¶
func RegisterStore(name string, f func(*StoreConfig) (StoreInterface, error)) bool
Types ¶
type CImage ¶
CImage is a image process tool
func CreateCImage ¶
func CreateCImage(config *ImageConfig) *CImage
CreateCImage will create a CImage struct with config
type CStore ¶
type CStore struct {
// contains filtered or unexported fields
}
CStore is the Captcha info store service
func CreateCStore ¶
CreateCStore will create a new CStore
func (*CStore) Add ¶
func (store *CStore) Add(captcha *CaptchaInfo) string
Add captcha info and get the auto generated key
func (*CStore) LoadDumped ¶
LoadDumped file to store
type Captcha ¶
type Captcha struct {
// contains filtered or unexported fields
}
Captcha is the core captcha struct
func CreateCaptcha ¶
func CreateCaptcha(wordManager *WordManager, captchaConfig *CaptchaConfig, imageConfig *ImageConfig, filterConfig *FilterConfig, storeConfig *StoreConfig) (*Captcha, error)
CreateCaptcha is a method to create new Captcha struct
func CreateCaptchaFromConfigFile ¶
CreateCaptchaFromConfigFile is a method to create new Captcha struct
func (*Captcha) CreateImage ¶
type CaptchaConfig ¶
CaptchaConfig ,the captcha config
type CaptchaInfo ¶
CaptchaInfo is the entity of a captcha text:the content text,for the image display and user to recognize createTime:the time when the captcha is created
type CaptchaRedisStore ¶
type CaptchaRedisStore struct {
// contains filtered or unexported fields
}
func (*CaptchaRedisStore) Add ¶
func (this *CaptchaRedisStore) Add(captcha *CaptchaInfo) string
func (*CaptchaRedisStore) Del ¶
func (this *CaptchaRedisStore) Del(key string)
func (*CaptchaRedisStore) Destroy ¶
func (this *CaptchaRedisStore) Destroy()
func (*CaptchaRedisStore) Get ¶
func (this *CaptchaRedisStore) Get(key string) *CaptchaInfo
func (*CaptchaRedisStore) OnConstruct ¶
func (this *CaptchaRedisStore) OnConstruct()
func (*CaptchaRedisStore) OnDestruct ¶
func (this *CaptchaRedisStore) OnDestruct()
func (*CaptchaRedisStore) Update ¶
func (this *CaptchaRedisStore) Update(key string, captcha *CaptchaInfo) bool
type FilterConfig ¶
type FilterConfig struct { Filters []string // contains filtered or unexported fields }
func (*FilterConfig) GetGroup ¶
func (this *FilterConfig) GetGroup(key string) (FilterConfigGroup, bool)
func (*FilterConfig) Init ¶
func (this *FilterConfig) Init()
func (*FilterConfig) SetGroup ¶
func (this *FilterConfig) SetGroup(key string, group *FilterConfigGroup)
type FilterConfigGroup ¶
type FilterConfigGroup struct {
// contains filtered or unexported fields
}
FilterConfigGroup
func (*FilterConfigGroup) GetItem ¶
func (this *FilterConfigGroup) GetItem(key string) (string, bool)
func (*FilterConfigGroup) Init ¶
func (this *FilterConfigGroup) Init()
func (*FilterConfigGroup) SetItem ¶
func (this *FilterConfigGroup) SetItem(key string, val string)
type FontManager ¶
type FontManager struct {
// contains filtered or unexported fields
}
FontManager is a Font Manager the manage font list
func CreateFontManager ¶
func CreateFontManager() *FontManager
CreateFontManager will create a new Font Manager
func (*FontManager) AddFont ¶
func (fm *FontManager) AddFont(pathToFontFile string) error
AddFont will add a new font file to the list
func (*FontManager) GetFont ¶
func (fm *FontManager) GetFont(pathToFontFile string) *truetype.Font
GetFont will return a Font struct by path
func (*FontManager) GetRandomFont ¶
func (fm *FontManager) GetRandomFont() *truetype.Font
GetRandomFont will return a random Font struct
type ImageConfig ¶
type ImageConfig struct { Width int Height int FontSize float64 FontFiles []string // contains filtered or unexported fields }
ImageConfig ,the image config
type ImageFilter ¶
type ImageFilter interface { Proc(cimage *CImage) GetId() string SetConfig(FilterConfigGroup) GetConfig() FilterConfigGroup }
ImageFilter is the interface of image filter
type ImageFilterBase ¶
type ImageFilterBase struct {
// contains filtered or unexported fields
}
ImageFilter is the base class of image filter
func (*ImageFilterBase) GetConfig ¶
func (filter *ImageFilterBase) GetConfig() FilterConfigGroup
func (*ImageFilterBase) GetId ¶
func (filter *ImageFilterBase) GetId() string
func (*ImageFilterBase) Proc ¶
func (filter *ImageFilterBase) Proc(cimage *CImage)
func (*ImageFilterBase) SetConfig ¶
func (filter *ImageFilterBase) SetConfig(config FilterConfigGroup)
type ImageFilterManager ¶
type ImageFilterManager struct {
// contains filtered or unexported fields
}
ImageFilterManager
func CreateImageFilterManager ¶
func CreateImageFilterManager() *ImageFilterManager
func CreateImageFilterManagerByConfig ¶
func CreateImageFilterManagerByConfig(config *FilterConfig) *ImageFilterManager
func (*ImageFilterManager) AddFilter ¶
func (manager *ImageFilterManager) AddFilter(filter ImageFilter)
func (*ImageFilterManager) GetFilters ¶
func (manager *ImageFilterManager) GetFilters() []ImageFilter
type ImageFilterNoiseLine ¶
type ImageFilterNoiseLine struct {
ImageFilterBase
}
func (*ImageFilterNoiseLine) GetId ¶
func (filter *ImageFilterNoiseLine) GetId() string
func (*ImageFilterNoiseLine) Proc ¶
func (filter *ImageFilterNoiseLine) Proc(cimage *CImage)
Proc the image
type ImageFilterNoisePoint ¶
type ImageFilterNoisePoint struct {
ImageFilterBase
}
ImageFilter is the interface of image filter
func (*ImageFilterNoisePoint) GetId ¶
func (filter *ImageFilterNoisePoint) GetId() string
func (*ImageFilterNoisePoint) Proc ¶
func (filter *ImageFilterNoisePoint) Proc(cimage *CImage)
Proc the image
type ImageFilterStrike ¶
type ImageFilterStrike struct {
ImageFilterBase
}
ImageFilter is the interface of image filter
func (*ImageFilterStrike) GetId ¶
func (filter *ImageFilterStrike) GetId() string
func (*ImageFilterStrike) Proc ¶
func (filter *ImageFilterStrike) Proc(cimage *CImage)
Proc the image
type MCStore ¶
type MCStore struct {
// contains filtered or unexported fields
}
MCStore is the Captcha info store service
func CreateMCStore ¶
CreateCStore will create a new CStore
func (*MCStore) Add ¶
func (store *MCStore) Add(captcha *CaptchaInfo) string
Add captcha info and get the auto generated key
type StoreConfig ¶
type StoreConfig struct { CaptchaConfig Engine string Servers []string GcProbability int GcDivisor int }
StoreConfig ,the store engine config
type StoreInterface ¶
type StoreInterface interface { Get(key string) *CaptchaInfo Add(captcha *CaptchaInfo) string Update(key string, captcha *CaptchaInfo) bool Del(key string) Destroy() OnConstruct() OnDestruct() }
StoreInterface is the interface of store
func CreateCaptchaRedisStore ¶
func CreateCaptchaRedisStore(config *StoreConfig) (StoreInterface, error)
type WordManager ¶
type WordManager struct {
// contains filtered or unexported fields
}
WordManager is a captcha word manage tool
func CreateWordManagerFromDataFile ¶
func CreateWordManagerFromDataFile(filename string) (*WordManager, error)
CreateWordManagerFromDataFile will create a entity from a dictionary file
func (*WordManager) Get ¶
func (mgr *WordManager) Get(length int) (string, error)
Get a specifical length word
func (*WordManager) SetWords ¶
func (mgr *WordManager) SetWords(words []string)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
samples
|
|
gocaptcha-server
CServer project main.go
|
CServer project main.go |