webapi

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 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 ApprovedUsersStore added in v1.5.1

type ApprovedUsersStore interface {
	Store(ids []string) error
	Timestamp(id string) (time.Time, error)
	Delete(id string) error
}

ApprovedUsersStore is a storage interface for approved users.

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
	ApprovedUsersStore ApprovedUsersStore // storage for approved users
	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(msg string, userID string) (spam bool, cr []lib.CheckResult)
	AddApprovedUsers(ids ...string)
	RemoveApprovedUsers(ids ...string)
	ApprovedUsers() (res []string)
}

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