server

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The default port of the server
	DefaultPort uint = 8080
	// The default route from where the js script that handles page reloads will be served from
	DefaultClientScriptRoute = "/hot-reload.js"
	// The default route from where the websocket that sends reload signals to the client will be listening from
	DefaultWebsocketRoute = "/hot-reload-websocket"
	// The default interval between ping messages sent by the server to the client
	DefaultPingIntervalMs = 10_000
)

Variables

This section is empty.

Functions

func DefaultDirectory

func DefaultDirectory() (string, error)

Returns the default directory that contains the files that will be watched for changes and served by the server

Types

type Config

type Config struct {
	// The default port of the server
	Port uint `json:"port"`
	// The directory that contains the files that will be watched for changes and served by the server
	Directory string `json:"directory"`
	// The route from where the js script that handles page reloads will be served from
	ClientScriptRoute string `json:"clientScriptRoute"`
	// The route from where the websocket that sends reload signals to the client will be listening from
	WebSocketRoute string `json:"websocketRoute"`
	// The interval between ping messages sent by the server to the client
	PingIntervalMs uint `json:"pingIntervalMs"`
}

Configuration for the server

func (*Config) FillInDefaults

func (self *Config) FillInDefaults()

Sets the uninitialized fields of this config to their default values

func (Config) GenerateClientScript

func (self Config) GenerateClientScript() ([]byte, error)

Generate a js script that will connect to the server launched with this config

func (Config) Validate

func (self Config) Validate() error

Validate this config

type Server

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

A server is responsible for watching and serving the files inside a directry and notifying the client for changes to such files

func NewServer

func NewServer(config Config, logHttp bool) (self *Server, err error)

Create a new server

func (*Server) Start

func (self *Server) Start()

Start the server

func (*Server) Stop

func (self *Server) Stop()

type WebsocketServer

type WebsocketServer struct {
	http.Handler
	// contains filtered or unexported fields
}

func NewWebsocketServer

func NewWebsocketServer(
	fileEvent <-chan watcher.Event,
	shutdown <-chan bool,
	pingIntervalMs uint,
) (self *WebsocketServer, err error)

func (*WebsocketServer) ServeHTTP

func (self *WebsocketServer) ServeHTTP(response http.ResponseWriter, request *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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