httpwatch

package module
v0.0.0-...-66a0833 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 15 Imported by: 2 modules, 1 package

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.

README

Overview

Simple tool to serve files from a given directory.

Supports watching for files changes and emitting an event over a websocket.

Example

# Serve the current directory at / and watch for html, js, or css file changes.
http-watch -dir=. -pattern=".*(.html|.js|.css)"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HeaderMiddleware

func HeaderMiddleware(headers http.Header) func(http.Handler) http.Handler

HeaderMiddleware returns a middleware that sets one or more values per header key

func NewFileServer

func NewFileServer(dir string, useGzip bool) http.Handler

func NewWatcherFn

func NewWatcherFn(ctx context.Context, cfg WatcherConfig, b *Broadcaster) (func(), error)

func NewWebsocketHandler

func NewWebsocketHandler(b *Broadcaster) http.HandlerFunc

Types

type Broadcaster

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

Broadcaster struct manages subscribers and broadcasting events to them.

func NewBroadcaster

func NewBroadcaster() *Broadcaster

func (*Broadcaster) AddSubscriber

func (b *Broadcaster) AddSubscriber() Subscriber

AddSubscriber adds a new subscriber channel to the broadcaster.

func (*Broadcaster) Broadcast

func (b *Broadcaster) Broadcast(message string)

Broadcast sends the message to all active subscribers.

func (*Broadcaster) Remove

func (b *Broadcaster) Remove(ch Subscriber)

Remove removes a subscriber channel from the broadcaster.

type Subscriber

type Subscriber chan string

type WatcherConfig

type WatcherConfig struct {
	Recursive   bool
	Dir         string
	FilePattern string
}

Directories

Path Synopsis
cmd
http-watch command
MIT License
MIT License

Jump to

Keyboard shortcuts

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