core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchFiles

func MatchFiles(globs []string) []fs.FileInfo

MatchFiles is a function that takes a list of globs and returns array of FileInfo

ex: files := MatchFiles([]string{"test/*.go", "test/wwwroot/*"})

Types

type Build

type Build struct {
	Name        string        `json:"name,omitzero"`
	Description string        `json:"description,omitzero"`
	Match       []string      `json:"match,omitzero"`
	HeartBeat   time.Duration `json:"heartBeat,omitzero"`
	BuildCmd    string        `json:"buildCmd,omitzero"`
	BuildArgs   []string      `json:"buildArgs,omitzero"`
	BuildEnv    []string      `json:"buildEnv,omitzero"`
	BuildDir    string        `json:"buildDir,omitzero"`
	RunCmd      string        `json:"runCmd,omitzero"`
	RunArgs     []string      `json:"runArgs,omitzero"`
	RunEnv      []string      `json:"runEnv,omitzero"`
	RunDir      string        `json:"runDir,omitzero"`
}

Build is a struct that represents a build and run process

func (*Build) Build

func (b *Build) Build() error

Build executes the configured buildCmd with buildArgs and buildEnv variables.

ex: err := b.Build()

func (*Build) Run

func (b *Build) Run(ctx context.Context)

Run executes the configured runCmd with runArgs and runEnv variables.

ex: b.Run(ctx)

func (*Build) Start

func (b *Build) Start(parentContext context.Context, restart chan struct{})

Start manages the build and run processes

Calling cancel on the parent context will stop the build and run processes; otherwise the restart channel will trigger a rebuild and rerun. If a build fails, the routine halts until it receives a signal from the restart channel.

ex: b.Start(parentContext)

func (*Build) Watch

func (b *Build) Watch(parentContext context.Context, restart chan struct{})

Watch starts a ticker and compares scans for changes in the files.

Calling cancel on the parent context will stop the watch process otherwise it ticks ever duration to check for changes. If a change is detected it signals the restart channel.

ex: b.Watch(ctx)

type Config

type Config struct {
	// Name and Description are used internally
	Name        string `json:"name"`
	Description string `json:"description"`

	// Builds is a list of Build structs
	Builds []Build `json:"builds"`

	// ReverseProxy is a map of paths to HttpTarget
	//	ex: "/api" -> HttpTarget{Host: "http://localhost:8080"}
	ReverseProxy map[string]HttpTarget `json:"reverseProxy"`

	// Address is the IP and port to bind the server to
	Bind string `json:"bind,omitzero"`

	// TLSCertFile is the relative path to the TLS certificate file for the server
	TLSCertFile string `json:"tlsCertFile,omitzero"`
	// TLSKeyFile is the relative path to the TLS key file for the server
	TLSKeyFile string `json:"tlsKeyFile,omitzero"`
}

func NewConfig

func NewConfig() *Config

NewConfig returns a new Config with reasonable defaults

func (*Config) Load

func (c *Config) Load(filename string) error

Load reads filename into a Config struct

ex: myConfig.Load("go-live-reload.json")

func (*Config) RunProxy

func (c *Config) RunProxy()

RunProxy starts a reverse proxy server

func (*Config) Save

func (c *Config) Save(filename string) error

Save saves a json representation of Config to filename

ex: myConfig.Save("go-live-reload.json")

type HttpTarget

type HttpTarget struct {

	// Host is the URL of the target
	// ex: "http://localhost:8080"
	Host string `json:"host"`

	// CustomHeaders is a map of headers to add to the request
	// ex: {"Speak-Friend": "mellon"}
	CustomHeaders map[string]string `json:"customHeaders,omitzero"`

	// InsecureSkipVerify is a flag to enable or disable TLS verification downstream
	InsecureSkipVerify bool `json:"insecureSkipVerify,omitzero"`
}

HttpTarget is a reverse proxy target

Jump to

Keyboard shortcuts

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