rest

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPFilterMiddleware added in v1.1.0

func IPFilterMiddleware(filter IPFilter, trustProxy bool) func(http.Handler) http.Handler

IPFilterMiddleware wraps an http.Handler with IP-based access control. If the filter is nil, the middleware passes all requests through unchanged. When a filter is provided, each request is validated using filter.IsAllowed. Denied requests receive a 403 Forbidden response with a JSON error message. The middleware logs warnings for denied requests including the remote address and path.

func Logger

func Logger(next http.Handler, trustProxy bool) http.Handler

Logger wraps an http.Handler with request/response logging

func NewTelegramHandler

func NewTelegramHandler(
	mux *http.ServeMux,
	c cache.Cache, s Scraper, g Generator,
)

NewTelegramHandler registers all Telegram-related handlers

Types

type Firewall added in v1.1.0

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

Firewall implements IP-based access control for HTTP requests. It maintains a list of allowed IP addresses and CIDR ranges, and can optionally trust reverse proxy headers (X-Real-IP, X-Forwarded-For) to determine the client's real IP address.

func NewFirewall added in v1.1.0

func NewFirewall(allowedIPsStr string, trustProxy bool) (*Firewall, error)

NewFirewall creates a new Firewall instance with the specified configuration. The allowedIPsStr parameter accepts a comma-separated list of IP addresses and/or CIDR ranges (e.g., "10.0.0.0/24,192.168.1.1,2001:db8::/32"). If allowedIPsStr is empty, all IP addresses are allowed by default. Returns an error if any IP address or CIDR notation is invalid.

func (*Firewall) IsAllowed added in v1.1.0

func (f *Firewall) IsAllowed(r *http.Request) bool

IsAllowed checks if the request originates from an allowed IP address. If no IP restrictions are configured (empty allowlist), all requests are allowed. Returns false if the IP cannot be extracted or is not in the allowlist.

type Generator

type Generator interface {
	Generate(channel *entity.Channel, params *entity.FeedParams) ([]byte, error)
}

Generator defines the interface for generating RSS/Atom feeds from channel data.

type IPFilter added in v1.1.0

type IPFilter interface {
	IsAllowed(r *http.Request) bool
}

IPFilter defines the interface for IP-based access control.

type Scraper

type Scraper interface {
	Scrape(ctx context.Context, username string) (*entity.Channel, error)
}

Scraper defines the interface for scraping Telegram channel data.

type Server

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

Server represents the REST API server

func NewServer

func NewServer(c cache.Cache, s Scraper, g Generator, ipFilter IPFilter, port string, trustProxy bool) *Server

NewServer creates a new REST API server with the specified dependencies. The ipFilter parameter controls IP-based access restrictions; pass nil to disable filtering. The port parameter specifies the TCP port to listen on (e.g., "8080"). The server is pre-configured with secure timeout values to mitigate common attacks.

func (*Server) Run

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

Run starts the server and blocks until the context is canceled

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server

Jump to

Keyboard shortcuts

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