orc

package module
v0.0.0-...-91a5d31 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: MIT Imports: 6 Imported by: 28

README

Orc

Orc (short for "orchestrator" or something along those lines) is a Golang library to manage initialization.

Specifically, it is designed to manage "singleton" libraries that add functionality to a command-line or server binary after being initialized.

These libraries can manage their own flags (using the Cobra library) and may have dependencies in between themselves and require a certain initialization order. The orc library is the glue code that calls them at startup to allow them to set up their flags, and figures out the initialization order.

Goal

The goal of Orc is to make it possible to write very short Go binaries -- especially server binaries -- that come with an ever-expanding set of batteries included, making them pleasant to debug and work with.

The Orc libraries handle all the boilerplate and essentially initialize themselves, letting the application code focus on the actual application logic.

Don't use this in its current state

Orc is a highly opinionated framework, and one that is still taking form and in pretty sketchy shape at the moment.

I'm releasing it to be able to use it as glue code for other hobby projects. I'm working out the kinks required for those projects as I go, but I don't recommend anyone else use it at the moment. Expect usability quirks, bugs, and API instability. At this point, even the expectations for code using Orc may change.

Using this library in your own code is strongly recommended against at the moment.

Dealing with Orc code

See STANDARDS.md for the peculiarities of Orc code. Don't use Orc without reading that document. (In fact, at the moment, don't use Orc at all. See above.)

Authorship

Orc was written by me, Steinar V. Kaldager.

This is a hobby project written primarily for my own usage. Don't expect support for it. It was developed in my spare time and is not affiliated with any employer of mine.

It is released as open source under the MIT license. Feel free to make use of it however you wish under the terms of that license.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(parent *cobra.Command, prereq Module, skeleton cobra.Command, body interface{}, options ...Option) *cobra.Command

func Describe

func Describe(m Module) string

func Fail

func Fail(err error)

func ReuseCommand

func ReuseCommand(parent *cobra.Command, existing *cobra.Command) *cobra.Command

Types

type Edge

type Edge struct {
	Dependent  Module
	Dependency Module
}

type Graph

type Graph struct {
	Edges []Edge
}

type Module

type Module interface {
	OnRegister(ModuleHooks)
}

func FlagsModule

func FlagsModule(setFlags func(*pflag.FlagSet)) Module

type ModuleBundle

type ModuleBundle struct {
	Modules []Module
}

func Modules

func Modules(ms ...Module) *ModuleBundle

func (*ModuleBundle) ModuleName

func (m *ModuleBundle) ModuleName() string

func (*ModuleBundle) OnRegister

func (m *ModuleBundle) OnRegister(h ModuleHooks)

type ModuleHooks

type ModuleHooks interface {
	OnUse(func(UseContext))

	OnValidate(func() error)

	OnSetup(func() error)
	OnTeardown(func() error)

	OnStart(func() error)
	OnStop(func() error)
}

type NamedModule

type NamedModule interface {
	ModuleName() string
}

type Option

type Option func(*orcOptions) error

func WithFlags

func WithFlags(flagset *pflag.FlagSet) Option

type Registry

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

type RunContext

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

func Use

func Use(module Module, options ...Option) *RunContext

func (*RunContext) Run

func (r *RunContext) Run(body func() error)

type Runnable

type Runnable interface {
	Run(func() error)
}

type UseContext

type UseContext struct {
	Flags *pflag.FlagSet
	// contains filtered or unexported fields
}

func (UseContext) Use

func (u UseContext) Use(mod Module, newOptions ...Option)

Jump to

Keyboard shortcuts

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