server

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: GPL-3.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrImagesFolderIsNotSet = "images folder is not set"
	ErrImageWidthIsNotSet   = "image width is not set"
	ErrImageHeightIsNotSet  = "image height is not set"
	ErrImageTtlIsNotSet     = "image TTL is not set"
	ErrCacheSettingsError   = "error in cache settings"
)
View Source
const (
	ImageFileExt  = "png"
	ImageFormat   = "PNG"
	ImageMimeType = "image/png"
	QueryKeyId    = "id"
	RUIDPrefix    = "RCS-"
)
View Source
const (
	MsgCleaningImagesFolder = "Cleaning the images folder ... "
	MsgDone                 = "Done"
	MsgCaptchaManagerStart  = "Captcha manager has started"
	MsgCaptchaManagerStop   = "Captcha manager has been stopped"
)
View Source
const (
	ErrFDuplicateId   = "duplicate id: %v"
	ErrFAbsentId      = "absent id: %v"
	ErrFileIsNotFound = "file is not found"
)

Variables

This section is empty.

Functions

func MakeFileName

func MakeFileName(id string) (fileName string)

func MakeRecordFilePath

func MakeRecordFilePath(imagesFolder string, id string) (path string)

Types

type CaptchaManager

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

CaptchaManager is a captcha manager.

func NewCaptchaManager

func NewCaptchaManager(
	storeImages bool,
	imagesFolder string,
	imageWidth uint,
	imageHeight uint,
	imageTtlSec uint,
	clearImagesFolderAtStart bool,
	useHttpServerForImages bool,
	httpHost string,
	httpPort uint16,
	httpErrorsChan *chan error,
	httpServerName string,
	isCachingEnabled bool,
	cacheSizeLimit int,
	cacheVolumeLimit int,
	cacheRecordTtl uint,
) (cm *CaptchaManager, err error)

func (*CaptchaManager) CheckCaptcha

func (cm *CaptchaManager) CheckCaptcha(req *CheckCaptchaRequest) (resp *CheckCaptchaResponse, err error)

func (*CaptchaManager) ClearJunk

func (cm *CaptchaManager) ClearJunk() (err error)

func (*CaptchaManager) CreateCaptcha

func (cm *CaptchaManager) CreateCaptcha() (resp *CreateCaptchaResponse, err error)

func (*CaptchaManager) GetListenDsn

func (cm *CaptchaManager) GetListenDsn() (dsn string)

func (*CaptchaManager) Stop

func (cm *CaptchaManager) Stop() (err error)

type CheckCaptchaRequest

type CheckCaptchaRequest struct {
	TaskId string
	Value  uint
}

type CheckCaptchaResponse

type CheckCaptchaResponse struct {
	TaskId    string
	IsSuccess bool
}

type CreateCaptchaResponse

type CreateCaptchaResponse struct {
	TaskId              string
	ImageFormat         string
	IsImageDataReturned bool
	ImageData           []byte
}

type Registry

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

func NewRegistry

func NewRegistry(
	storeImages bool,
	imagesFolder string,
	recordTtlSec uint,
	isCachingEnabled bool,
	cacheSizeLimit int,
	cacheVolumeLimit int,
	cacheRecordTtl uint,
) (r *Registry, err error)

func (*Registry) AddRecord

func (r *Registry) AddRecord(id string, answer uint) (err error)

func (*Registry) CheckCaptcha

func (r *Registry) CheckCaptcha(id string, value uint) (ok bool, err error)

func (*Registry) ClearJunk

func (r *Registry) ClearJunk() (err error)

func (*Registry) GetImageFile

func (r *Registry) GetImageFile(id string) (data []byte, err error)

func (*Registry) GetSize

func (r *Registry) GetSize() (size int)

func (*Registry) IsIdRegistered

func (r *Registry) IsIdRegistered(id string) (isRegistered bool)

type RegistryRecord

type RegistryRecord struct {
	Id     string
	Answer uint
	TTL    float64   // TTL is set in seconds.
	ToC    time.Time // Time of creation.
}

RegistryRecord stores an answer and timing information.

func NewRegistryRecord

func NewRegistryRecord(id string, answer uint, ttl float64) *RegistryRecord

func (*RegistryRecord) IsExpired

func (rr *RegistryRecord) IsExpired() bool

Jump to

Keyboard shortcuts

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