server

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MPL-2.0 Imports: 13 Imported by: 0

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