m

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ImageFileExt            = "png"
	FileExtFullPng          = "." + ImageFileExt
	ImageFormat             = "PNG"
	ImageMimeType           = "image/png"
	QueryKeyId              = "id"
	RUIDPrefix              = "RCS-"
	CaptchaImageMinWidth    = 128
	CaptchaImageMinHeight   = 128
	RingMinCount            = 3
	RingMaxCount            = 6
	RingMinRadius           = 24
	BrushOuterRadiusMin     = 2
	BrushOuterRadiusMax     = 32
	ColourComponentMaxValue = 65535
	KR                      = 0.5
	KDMin                   = 1.0
	KDMax                   = 1.5

	// C1 is a maximum colour channel value of a pixel in an 'image.RGBA' of
	// the built-in library.
	C1 = float64(65_535)
)
View Source
const (
	Err_Anomaly                       = "anomaly"
	Err_BrushRadiusRatio              = "brush radius ratio error"
	Err_CacheSettingsError            = "error in cache settings"
	Err_CanvasIsTooSmall              = "canvas is too small"
	Err_DensityCoefficient            = "density coefficient error"
	Err_Dimensions                    = "dimensions error"
	ErrF_FileExtensionMismatch        = "file extension mismatch: png vs %s"
	Err_FileStorageIsDisabled         = "file storage is disabled"
	Err_IdIsDuplicate                 = "duplicate ID"
	Err_IdIsNotFound                  = "ID is not found"
	Err_IdIsNotSet                    = "ID is not set"
	Err_ImageFormatIsInvalid          = "image format is invalid"
	Err_ImagesFolderIsNotSet          = "images folder is not set"
	Err_ImagesHaveDifferentDimensions = "images have different dimensions"
	Err_ImageHeightIsNotSet           = "image height is not set"
	Err_ImageWidthIsNotSet            = "image width is not set"
	Err_RequestIsAbsent               = "request is absent"
)
View Source
const (
	Msg_CaptchaManagerStart    = "Captcha manager has started"
	Msg_CaptchaManagerStop     = "Captcha manager has been stopped"
	Msg_CleaningImagesFolder   = "Cleaning the images folder ... "
	Msg_Done                   = "Done"
	Msg_Failure                = "Failure"
	Msg_ImageCleanerHasStarted = "image cleaner has started"
	Msg_ImageCleanerHasStopped = "image cleaner has stopped"
	MsgF_CleaningImages        = "cleaning %v images ... "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Captcha

type Captcha struct {
	Id          string
	Image       *image.NRGBA
	ImageData   []byte
	ImageFormat string
	RingCount   uint
}

func NewCaptchaWithId

func NewCaptchaWithId(id string) (captcha *Captcha)

func NewCaptchaWithIdAndAnswer

func NewCaptchaWithIdAndAnswer(id string, answer uint) (captcha *Captcha)

type CaptchaServerSettings

type CaptchaServerSettings struct {
	// Main settings.
	IsImageStorageUsed        bool
	IsImageServerEnabled      bool
	IsImageCleanupAtStartUsed bool
	IsStorageCleaningEnabled  bool

	// Image settings.
	ImagesFolder      string
	ImageWidth        uint
	ImageHeight       uint
	FilesCountToClean int

	// HTTP server settings.
	HttpHost       string
	HttpPort       uint16
	HttpErrorsChan *chan error
	HttpServerName string

	// File cache settings.
	FileCacheSizeLimit   int
	FileCacheVolumeLimit int
	FileCacheItemTtl     uint

	// Record cache settings.
	RecordCacheSizeLimit int
	RecordCacheItemTtl   uint
}

func (*CaptchaServerSettings) Check

func (s *CaptchaServerSettings) Check() (err error)

type CheckCaptchaRequest

type CheckCaptchaRequest struct {
	TaskId string
	Value  uint
}

func (*CheckCaptchaRequest) Check

func (req *CheckCaptchaRequest) Check() (err error)

type CheckCaptchaResponse

type CheckCaptchaResponse struct {
	TaskId    string
	IsSuccess bool
}

type CreateCaptchaRequest

type CreateCaptchaRequest struct{}

type CreateCaptchaResponse

type CreateCaptchaResponse struct {
	TaskId      string
	ImageFormat string

	// When storage is used, images are not returned in response objects;
	// instead, they are manually requested by clients from storage. Opposite
	// is also true: when storage is not used, server returns images in
	// response objects.
	IsImageDataReturned bool
	ImageData           []byte
}

type ErrorWithHttpStatusCode

type ErrorWithHttpStatusCode struct {
	// contains filtered or unexported fields
}

func NewErrorWithHttpStatusCode

func NewErrorWithHttpStatusCode(msg string, httpStatusCode int) *ErrorWithHttpStatusCode

func NewErrorWithHttpStatusCodeFromError

func NewErrorWithHttpStatusCodeFromError(e error) *ErrorWithHttpStatusCode

func (*ErrorWithHttpStatusCode) Error

func (e *ErrorWithHttpStatusCode) Error() string

func (*ErrorWithHttpStatusCode) GetHttpStatusCode

func (e *ErrorWithHttpStatusCode) GetHttpStatusCode() int

type GetCaptchaImageRequest

type GetCaptchaImageRequest struct {
	TaskId string
}

func NewGetImageRequestFromHttpRequest

func NewGetImageRequestFromHttpRequest(httpReq *http.Request) (req *GetCaptchaImageRequest, err error)

func (*GetCaptchaImageRequest) Check

func (req *GetCaptchaImageRequest) Check() (err error)

type GetCaptchaImageResponse

type GetCaptchaImageResponse struct {
	TaskId    string
	ImageData []byte
}

type HasCaptchaRequest

type HasCaptchaRequest struct {
	TaskId string
}

func (*HasCaptchaRequest) Check

func (req *HasCaptchaRequest) Check() (err error)

type HasCaptchaResponse

type HasCaptchaResponse struct {
	TaskId  string
	IsFound bool
}

type ICaptchaServer

type ICaptchaServer interface {
	Start() (err error)
	Stop() (err error)
	GetListenDsn() (dsn string)

	CreateCaptcha() (resp *CreateCaptchaResponse, err error)
	CheckCaptcha(req *CheckCaptchaRequest) (resp *CheckCaptchaResponse, err error)
	HasCaptcha(req *HasCaptchaRequest) (resp *HasCaptchaResponse, err error)
	GetCaptchaImage(req *GetCaptchaImageRequest) (resp *GetCaptchaImageResponse, err error)
}

type IEasyServer

type IEasyServer interface {
	Start()
	Stop()
	GetListenDsn() (dsn string)

	CreateCaptcha() (captcha *Captcha)
	CheckCaptcha(captcha *Captcha) (ok bool)
	HasCaptcha(captcha *Captcha) (ok bool)
	GetCaptchaImage(captcha *Captcha) (data []byte)
}

type IRegistry

type IRegistry interface {
	Start()
	Stop()

	CreateCaptcha(captcha *Captcha) (err error)
	CheckCaptcha(captcha *Captcha) (ok bool, isFound bool, err error)
	HasCaptcha(captcha *Captcha) (exists bool, err error)
	GetCaptchaImage(captcha *Captcha) (data []byte, err error)
}

type RegistrySettings

type RegistrySettings struct {
	// Main settings.
	IsImageStorageUsed       bool
	IsStorageCleaningEnabled bool

	// Image settings.
	ImagesFolder      string
	FilesCountToClean int

	// File cache settings.
	FileCacheSizeLimit   int
	FileCacheVolumeLimit int
	FileCacheItemTtl     uint

	// Record cache settings.
	RecordCacheSizeLimit int
	RecordCacheItemTtl   uint
}

Jump to

Keyboard shortcuts

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