Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

blbgo/runner

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

runner

A dependency management tool for go

GoDoc Go Report Card License

Overview

Run a system built from a list of functions that provide all the dependencies.

Install

go get github.com/blbgo/runner

Usage

Import the runner package

import "github.com/blbgo/runner"

Given the following interface, implementation, and producer function

type testInterface interface { Method() string }

type testStruct struct { field string }
func (r *testStruct) Method() string { return r.field }

func newTestInterface() testInterface { return &testStruct{ field: "testInterface" } }

And a runner.Main implementation that uses it

type mainImplementor struct{testInterface}
func (r *mainImplementor) Run() error { fmt.Println(r.Method()) }

func newMain(ti testInterface) runner.Main { return &mainImplementor{ testInterface: ti } }

This system can be run with

errs := runner.Run([]interface{}{newTestInterface, newMain})
for _, err := range errs {
    fmt.Println(err)
}

This causes each function passed to Run to be called once. If any functions return an error or any functions have dependencies that are not produced by other functions error(s) will be returned. If all functions are successfully called and a runner.Main interface was produced its Run method is called (if no runner.Main was produced an error is returned).

Finally (either because there was an error at any point or because the runner.Main Run method returned) any produced values that implement io.Closer or general.DelayCloser will have there Close method called.

The functions passed to main must only take parameters of interface type or slice of interfaces. They must return only interfaces and an optional error as the last return value.

Note that if the same interface is provided more than once then a slice of that interface is what must be depended on.

License

MIT

About

A dependency injection tool for go

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.