server

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Mode        Mode     // Server mode: static or proxy
	Directory   string   // Directory to serve (static mode)
	ProxyURL    string   // Backend URL to proxy (proxy mode)
	Port        int      // Server port (0 = auto-detect)
	Host        string   // Bind host ("localhost" or "0.0.0.0")
	WatchPaths  []string // Paths to watch for changes
	IgnorePaths []string // Glob patterns to ignore
	OnReload    func()   // Callback when files change (triggers reload)
	Debug       bool     // Enable debug logging
}

Config holds server configuration.

type FileEvent

type FileEvent struct {
	Path string
	Op   string
	Time time.Time
}

FileEvent represents a file system event.

type Mode

type Mode string

Mode represents the server mode (static or proxy).

const (
	ModeStatic Mode = "static"
	ModeProxy  Mode = "proxy"
)

type Server

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

Server is a development web server with hot reload capabilities.

func New

func New(cfg Config) (*Server, error)

New creates a new server with the given configuration.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the server's listening address.

func (*Server) IsRunning

func (s *Server) IsRunning() bool

IsRunning returns true if the server is running.

func (*Server) Port

func (s *Server) Port() int

Port returns the server's listening port.

func (*Server) Start

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

Start starts the server and file watcher.

func (*Server) Stop

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

Stop stops the server and file watcher.

func (*Server) URL

func (s *Server) URL() string

URL returns the server's full URL.

type Watcher

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

Watcher watches files for changes and triggers callbacks.

func NewWatcher

func NewWatcher(cfg WatcherConfig) (*Watcher, error)

NewWatcher creates a new file watcher.

func (*Watcher) Start

func (w *Watcher) Start() error

Start starts watching the configured paths.

func (*Watcher) Stop

func (w *Watcher) Stop() error

Stop stops the file watcher.

type WatcherConfig

type WatcherConfig struct {
	Paths   []string              // Paths to watch (files or directories)
	Ignore  []string              // Glob patterns to ignore
	OnEvent func(event FileEvent) // Callback for file events
	Debug   bool                  // Enable debug logging
}

WatcherConfig holds file watcher configuration.

Jump to

Keyboard shortcuts

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