configdir

package module
v0.0.0-...-6eba0cd Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2016 License: BSD-2-Clause Imports: 8 Imported by: 0

README

go-configdir: channel upates for config directories

GODOC

receive channel-based updates as when directory contents are modified.

a go-routine reads all files into a single bytes slice and compares against previous reads to only notify on unique changes.

this package should be limited to config file updates or other directory contents that fit reasonably in memory.



	chBytes, err := DirectoryUpdates("/etc/server.d", "toml", logger)
	if err != nil {
		panic(err)
	}
	var buf []byte
	// uniquified byte buffers arrive from channel
	// directory files are concatenated and md5 sum checked
	buf = <-chBytes

	// dummy config parser func
	makeToml(string(buf))

Documentation

Overview

Package configdir monitors a config directory for a supplied file suffix. Channel updates return bytes.Buffer containing all matching files concatenated together.

Updates return only if the update contains a unique byte array from previous runs by calculating md5 checksums.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirectoryUpdates

func DirectoryUpdates(dir, suffix string, p Printer) (chan []byte, error)

DirectoryUpdates starts a goroutine and returns bytes.Buffer receive channel

Example
logger = log.New(os.Stderr, "[dircfg]",
	log.Ldate|log.Ltime|log.Lshortfile,
)

chBytes, err := DirectoryUpdates("/etc/server.d", "toml", logger)
if err != nil {
	panic(err)
}
var b []byte
b = <-chBytes

// dummy config parser func
makeToml(string(b))
Output:

func DirectoryUpdatesF

func DirectoryUpdatesF(dir, suffix string, userCb func([]byte, []byte, error)) error

DirectoryUpdatesF similar to DirectoryUpdates but instead feeds daata to caller's closure on updates

closure is called with directory bytes, checksum bytes, and any error

Types

type Printer

type Printer interface {
	Print(...interface{})
	Printf(string, ...interface{})
	Println(...interface{})
}

Printer interface just to make a passable Logger

Jump to

Keyboard shortcuts

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