reload

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 10 Imported by: 0

README ¶

logo

Reload 🔄

Reload automates hot-reloading of configuration files.
It allows to monitor multiple configuration files (currently supporting JSON) and automatically reload them whenever changes are made, without the need to restart your application.
Reload offers error handling and auto-rollback functionality to ensure that your application doesn't crash if there's an error in your configuration file. Reload is actively being developed and maintained.

Features 💻

  • Configuration hot-reloading
  • Multiple config file monitoring
  • Configuration validation

Introduction ℹ

Usage/Examples

For a fully working example check here

package main

import (
	"context"

	reload "github.com/ancalabrese/Reload"
)

type Config struct {
	Port     string `json:"port"`
	Address  string `json:"address"`
	Timeout  int    `json:"opTimeout"`
}

func main() {

	ctx := context.Background()
	config := &Config{}

  rc, _ := reload.New(ctx)
	rc.AddConfiguration("example/config.json", config)

  	for {
		select {
		case err := <-rc.GetErrChannel():
			// Handle errors
		case conf := <-rc.GetRoloadChan():
			// Reinitialize applicaiton
		}
	}
}

Authors

Appendix 🚀

Reload is still in active development and currently in beta. We’re working on adding even more features and functionality to make managing configuration even easier. Any feedback and contributions are welcome!

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type ConfigurationFile ¶

type ConfigurationFile struct {
	FilePath string
	Config   any
	// contains filtered or unexported fields
}

type Option ¶

type Option func(*ReloadConfig)

func WithFileRollback ¶

func WithFileRollback(enabled bool) Option

WithFileRollback enables file override. In case of any config error the configuration file will be reverted back to the previous working version. Default is disabled.

type ReloadConfig ¶

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

ReloadConfig is the main object to initialize the reload library.

func New ¶

func New(ctx context.Context, options ...Option) (*ReloadConfig, error)

New creates a new reload config starts obsevering for config changes. ctx is the scope used for Reload. When ctx is cancelled Reload will stop monitoring and reloading configurations

func (*ReloadConfig) AddConfiguration ¶

func (rc *ReloadConfig) AddConfiguration(path string, config any) error

AddConfiguration adds a new config file to the monitor. path is the file path config is a json tagged struct where the config file will be marshalled into

func (*ReloadConfig) GetErrChannel ¶

func (rc *ReloadConfig) GetErrChannel() <-chan (error)

func (*ReloadConfig) GetReloadChan ¶

func (rc *ReloadConfig) GetReloadChan() <-chan (*ConfigurationFile)

func (*ReloadConfig) Stop ¶

func (rc *ReloadConfig) Stop()

Stop will stop the monitor and clean up resources

Directories ¶

Path Synopsis
internal

Jump to

Keyboard shortcuts

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