webapi

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package webapi provides a web API spam detection service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomPassword

func GenerateRandomPassword(length int) (string, error)

GenerateRandomPassword generates a random password of a given length

Types

type Config

type Config struct {
	Version    string     // version to show in /ping
	ListenAddr string     // listen address
	Detector   Detector   // spam detector
	SpamFilter SpamFilter // spam filter (bot)
	Locator    Locator    // locator for user info
	AuthPasswd string     // basic auth password for user "tg-spam"
	Dbg        bool       // debug mode
}

Config defines server parameters

type Detector added in v1.5.0

type Detector interface {
	Check(req spamcheck.Request) (spam bool, cr []spamcheck.Response)
	ApprovedUsers() []approved.UserInfo
	AddApprovedUser(user approved.UserInfo) error
	RemoveApprovedUser(id string) error
}

Detector is a spam detector interface.

type Locator added in v1.5.0

type Locator interface {
	UserIDByName(userName string) int64
	UserNameByID(userID int64) string
}

Locator is a storage interface used to get user id by name and vice versa.

type Server

type Server struct {
	Config
}

Server is a web API server.

func NewServer

func NewServer(config Config) *Server

NewServer creates a new web API server.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts server and accepts requests checking for spam messages.

type SpamFilter

type SpamFilter interface {
	UpdateSpam(msg string) error
	UpdateHam(msg string) error
	ReloadSamples() (err error)
	DynamicSamples() (spam, ham []string, err error)
	RemoveDynamicSpamSample(sample string) (int, error)
	RemoveDynamicHamSample(sample string) (int, error)
}

SpamFilter is a spam filter, bot interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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