hotreload

package
v1.8.0 Latest Latest
Warning

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

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

Documentation

Overview

Package hotreload implements helpers around code hot reloading.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfigInvalid reports that the configuration is invalid.
	ErrConfigInvalid = errors.New("configuration is invalid")
	// ErrChannelClosed reports that a channel has been closed.
	ErrChannelClosed = errors.New("channel closed")
	// ErrBuildPathDoesNotExist reports that the build path does not exist.
	ErrBuildPathDoesNotExist = errors.New("build path does not exist")
)

Functions

func Start

func Start(opts ...Option) error

Start hot-reloads the code, logging using slog.

Example
package main

import (
	"log/slog"

	"codeberg.org/kema/kmicro/pkg/hotreload"
)

func main() {
	err := hotreload.Start(
		hotreload.WithBuildPath("./cmd/hello"),
	)
	if err != nil {
		slog.Error("hot reloading", slog.String("error.message", err.Error()))

		return
	}
}

Types

type Option

type Option func(*config)

Option configures hot reloading.

func WithBuildPath

func WithBuildPath(path string) Option

WithBuildPath sets the executable path passed to `go build`.

func WithDebounce

func WithDebounce(d time.Duration) Option

WithDebounce sets the event coalescing delay before triggering a rebuild.

func WithExtensions

func WithExtensions(exts ...string) Option

WithExtensions sets the file extensions that trigger rebuilds.

func WithIgnoreDirs

func WithIgnoreDirs(dirs ...string) Option

WithIgnoreDirs sets directory names that are skipped while watching.

func WithKillGracePeriod

func WithKillGracePeriod(d