Documentation
¶
Index ¶
- func IPFilterMiddleware(filter IPFilter, trustProxy bool) func(http.Handler) http.Handler
- func Logger(next http.Handler, trustProxy bool) http.Handler
- func NewTelegramHandler(mux *http.ServeMux, c cache.Cache, s Scraper, g Generator)
- type Firewall
- type Generator
- type IPFilter
- type Scraper
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IPFilterMiddleware ¶ added in v1.1.0
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.
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
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.
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 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.