web

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MockRSSFFSResponses = map[string]MockRSSFFSResponse{
	"https://example.com": {
		Success:   true,
		FeedCount: 1,
	},
	"https://multi-feed.example.com": {
		Success:   true,
		FeedCount: 3,
	},
	"https://no-feeds.example.com": {
		Success:   true,
		FeedCount: 0,
	},
	"https://error.example.com": {
		Success: false,
		Error:   "Connection timeout",
	},
}

MockRSSFFSResponses maps URLs to mock responses for testing

Functions

func AssertResponseContains

func AssertResponseContains(t interface{}, response *httptest.ResponseRecorder, expected string)

AssertResponseContains checks if response body contains expected content

func AssetExists

func AssetExists(assetPath string) bool

AssetExists checks if an asset exists in the embedded filesystem

func CreateTestRequest

func CreateTestRequest(method, path, body string) *httptest.ResponseRecorder

CreateTestRequest creates a test HTTP request with proper headers

func ExtractCSRFTokenFromHTML

func ExtractCSRFTokenFromHTML(html string) string

ExtractCSRFTokenFromHTML extracts CSRF token from HTML response (simplified)

func GenerateCSRFToken

func GenerateCSRFToken() (string, error)

GenerateCSRFToken generates a new, random CSRF token.

func GetAsset

func GetAsset(assetPath string) ([]byte, error)

GetAsset retrieves an embedded asset by path

func GetAssetMimeType

func GetAssetMimeType(assetPath string) string

GetAssetMimeType determines the MIME type for an asset based on file extension

func ListAssets

func ListAssets() ([]string, error)

ListAssets returns a list of all embedded assets (useful for debugging)

func LoadTemplates

func LoadTemplates() (*template.Template, error)

LoadTemplates loads and parses embedded HTML templates

func ReloadTemplates

func ReloadTemplates() error

ReloadTemplates forces a reload of templates (useful for development)

func RenderTemplate

func RenderTemplate(w http.ResponseWriter, name string, data TemplateData) error

RenderTemplate renders the specified template with the provided data

func ServeAsset

func ServeAsset(w http.ResponseWriter, r *http.Request, assetPath string)

ServeAsset serves an embedded asset with proper headers and caching

func ServeAssetWithFallback

func ServeAssetWithFallback(w http.ResponseWriter, r *http.Request, assetPath, fallbackPath string)

ServeAssetWithFallback serves an asset or falls back to a default asset

Types

type CategoryResponse

type CategoryResponse struct {
	Success    bool                   `json:"success"`
	Categories []CategoryResponseItem `json:"categories,omitempty"`
	Error      string                 `json:"error,omitempty"`
}

CategoryResponse represents the JSON response for category list

type CategoryResponseItem

type CategoryResponseItem struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
}

CategoryResponseItem represents a single category in the response

type LogBuffer added in v1.3.0

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

LogBuffer manages a circular buffer of log entries for the web UI

func NewLogBuffer added in v1.3.0

func NewLogBuffer(size int) *LogBuffer

NewLogBuffer creates a new log buffer with the specified size

func (*LogBuffer) Add added in v1.3.0

func (lb *LogBuffer) Add(entry LogEntry)

Add adds a new log entry to the buffer

func (*LogBuffer) GetRecent added in v1.3.0

func (lb *LogBuffer) GetRecent(limit int) []LogEntry

GetRecent returns the most recent log entries (up to limit)

type LogEntry added in v1.3.0

type LogEntry struct {
	Timestamp time.Time              `json:"timestamp"`
	Level     string                 `json:"level"`
	Message   string                 `json:"message"`
	Fields    map[string]interface{} `json:"fields,omitempty"`
}

LogEntry represents a single log entry for the web UI

type LogsResponse added in v1.3.0

type LogsResponse struct {
	Success bool       `json:"success"`
	Logs    []LogEntry `json:"logs,omitempty"`
	Error   string     `json:"error,omitempty"`
}

LogsResponse represents the JSON response for log entries

type MockRSSFFSResponse

type MockRSSFFSResponse struct {
	Success   bool
	FeedCount int
	Error     string
}

MockRSSFFSResponse represents a mock response from RSSFFS processing

type RateLimiter

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

RateLimiter implements basic rate limiting

func NewRateLimiter

func NewRateLimiter(limit int, window time.Duration) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) IsAllowed

func (rl *RateLimiter) IsAllowed(ip string) bool

IsAllowed checks if a request from the given IP is allowed

type Server

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

Server represents the HTTP server with configuration and debug settings

func NewServer

func NewServer(conf config.Config, debug bool) *Server

NewServer creates a new Server instance with the provided configuration

func (*Server) SetupRoutes

func (s *Server) SetupRoutes() *http.ServeMux

SetupRoutes configures HTTP routes and middleware

func (*Server) Start

func (s *Server) Start(host string, port int) error

Start starts the HTTP server on the specified host and port

type SubmitRequest

type SubmitRequest struct {
	URL           string `json:"url"`
	Category      string `json:"category"`
	SingleURLMode bool   `json:"single_url_mode"`
}

SubmitRequest represents the form submission data

type SubmitResponse

type SubmitResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Count   int    `json:"count,omitempty"`
	Error   string `json:"error,omitempty"`
}

SubmitResponse represents the JSON response sent back to the client

type TemplateData

type TemplateData struct {
	Title   string // Page title
	Debug   bool   // Debug mode flag
	Version string // Application version
}

TemplateData represents the data structure passed to HTML templates

type TestServer

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

TestServer wraps the web server for testing purposes

func NewTestServer

func NewTestServer(conf config.Config, debug bool) *TestServer

NewTestServer creates a server instance configured for testing

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError represents a validation error with field-specific details

type ValidationErrors

type ValidationErrors struct {
	Errors []ValidationError `json:"errors"`
}

ValidationErrors represents multiple validation errors

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

type WebUIHook added in v1.3.0

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

WebUIHook is a logrus hook that captures logs for the web UI

func NewWebUIHook added in v1.3.0

func NewWebUIHook(bufferSize int) *WebUIHook

NewWebUIHook creates a new web UI log hook

func (*WebUIHook) Fire added in v1.3.0

func (hook *WebUIHook) Fire(entry *log.Entry) error

Fire is called when a log entry is made

func (*WebUIHook) GetBuffer added in v1.3.0

func (hook *WebUIHook) GetBuffer() *LogBuffer

GetBuffer returns the log buffer for external access

func (*WebUIHook) Levels added in v1.3.0

func (hook *WebUIHook) Levels() []log.Level

Levels returns the log levels this hook should fire for

Jump to

Keyboard shortcuts

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