initcontainer

package module
v0.0.0-...-441eba0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2015 License: MIT Imports: 1 Imported by: 0

README

go-initcontainer

A simple Go library that allows for ordering of the initialization process, in terms of levels.

For cases when Go's built-in initialization functionality using the init() funcs are not sufficient.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-initcontainer

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container interface {
	// RegisterFunc registers an initialization func to be run at a specific level.
	// The lower the level, the earlier the initialization func is run.
	//
	// Here is an example:
	//
	//	const numLevels = 5
	//	initContainer := initcontainer.New(numLevels)
	//
	//	const level = 2
	//	initContainer.RegisterFunc(myInit, level)
	RegisterFunc(func(), uint) error

	// Register registers something that fits the Initializer interface (i.e., something
	// which provides the Init() method)  to be run at a specific level.
	// The lower the level, the earlier the initialization func is run.
	//
	// Here is an example:
	//
	//	const numLevels = 5
	//	initContainer := initcontainer.New(numLevels)
	//
	//	type MyInitializer struct {
	//		// Your stuff in here.
	//	}
	//
	//	func (thing *MyInitializer) Init() {
	//		// some initialization happens here.
	//	}
	//
	//	myInit := &MyInitializer{}
	//
	//	const level = 2
	//	initContainer.RegisterFunc(myInit, level)
	Register(Initializer, uint) error

	// Init causes all the initialization funcs (registered with the Register func)
	// to be run.
	//
	// Initialization starts with level 0, then does level 1, then does level 2, etc.
	Init() error
}

func New

func New(numLevels uint) Container

New returns a new initialization container.

Each initialization container has a concept of "levels".

Levels are "named" using non-negative integers. I.e., 0, 1, 2, ....

More specifically, the parameter to the New func 'numLevels' determines how many levels there are.

So if, for example, 'numLeves' is 5 then the levels are: 0, 1, 2, 3, 4. (Notice that 5 is NOT a level in this example, because we count the levels starting at 0 (zero).)

type Initializer

type Initializer interface {
	Init()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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