i

package module
v0.0.0-...-b9fa5c3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2015 License: Apache-2.0 Imports: 2 Imported by: 0

README

#I Need

easily give your structs and constructors what they need

wercker status Coverage Status

Written because:

  • all i need is a clean way to invert control
  • i want to keep as close to idiomatic go struct initialization as possible
  • i dont want struct element tags (thats way too much like annotations for me)
  • I dont want a over the top DI framework
  • I dont want be required to have a 100 argument 'New' constructor functions in my packages
  • I want to just be able to pass in fakes or real objects to initialize my structs with

Examples:


package main

import (
	"fmt"

	i "github.com/xchapter7x/ineed"
)

func NewFromType(deps i.Need) *Something {
	s := new(Something)
	deps.CastInto(s)
	return s
}

func NewWithUnexported(deps i.Need) *Something {
	s := &Something{
		randomPriv: deps.Get("randomPriv").(string),
	}
	deps.MapInto(s)
	return s
}

func New(deps i.Need) *Something {
	s := new(Something)
	deps.MapInto(s)
	return s
}

type Something struct {
	randomPriv string
	RandomPub  string
	Cool       CoolObject
}

type CoolObject struct {
	AField       string
	AnotherField string
}

func (s Something) PrintAll() {
	fmt.Println(s.randomPriv)
	fmt.Println(s.RandomPub)
	fmt.Println(s.Cool)
}

func main() {
	deps := i.Want().
		ToMap("RandomPub", "i am public").
		ToMap("randomPriv", "i am private")

	coolDep := CoolObject{
		AField:       "inject me",
		AnotherField: "Don't forget me too",
	}
	blindDeps := i.Want().
		ToUse(coolDep)

	something := New(deps)
	something.PrintAll()

	somethingPrivate := NewWithUnexported(deps)
	somethingPrivate.PrintAll()

	somethingWithRandomNamedFields := NewFromType(blindDeps)
	somethingWithRandomNamedFields.PrintAll()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Want

func Want() want

Types

type Need

type Need interface {
	MapInto(interface{})
	Get(string) interface{}
	CastInto(interface{})
}

Directories

Path Synopsis
Godeps
_workspace/src/github.com/oleiade/reflections
Package reflections provides high level abstractions above the reflect library.
Package reflections provides high level abstractions above the reflect library.
_workspace/src/github.com/onsi/ginkgo
Ginkgo is a BDD-style testing framework for Golang The godoc documentation describes Ginkgo's API.
Ginkgo is a BDD-style testing framework for Golang The godoc documentation describes Ginkgo's API.
_workspace/src/github.com/onsi/ginkgo/config
Ginkgo accepts a number of configuration options.
Ginkgo accepts a number of configuration options.
_workspace/src/github.com/onsi/ginkgo/ginkgo
The Ginkgo CLI The Ginkgo CLI is fully documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli) You can also learn more by running: ginkgo help Here are some of the more commonly used commands: To install: go install github.com/onsi/ginkgo/ginkgo To run tests: ginkgo To run tests in all subdirectories: ginkgo -r To run tests in particular packages: ginkgo <flags> /path/to/package /path/to/another/package To pass arguments/flags to your tests: ginkgo <flags> <packages> -- <pass-throughs> To run tests in parallel ginkgo -p this will automatically detect the optimal number of nodes to use.
The Ginkgo CLI The Ginkgo CLI is fully documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli) You can also learn more by running: ginkgo help Here are some of the more commonly used commands: To install: go install github.com/onsi/ginkgo/ginkgo To run tests: ginkgo To run tests in all subdirectories: ginkgo -r To run tests in particular packages: ginkgo <flags> /path/to/package /path/to/another/package To pass arguments/flags to your tests: ginkgo <flags> <packages> -- <pass-throughs> To run tests in parallel ginkgo -p this will automatically detect the optimal number of nodes to use.
_workspace/src/github.com/onsi/ginkgo/internal/remote
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
_workspace/src/github.com/onsi/ginkgo/reporters
Ginkgo's Default Reporter A number of command line flags are available to tweak Ginkgo's default output.
Ginkgo's Default Reporter A number of command line flags are available to tweak Ginkgo's default output.
_workspace/src/github.com/onsi/gomega
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
_workspace/src/github.com/onsi/gomega/format
Gomega's format package pretty-prints objects.
Gomega's format package pretty-prints objects.
_workspace/src/github.com/onsi/gomega/gbytes
Package gbytes provides a buffer that supports incrementally detecting input.
Package gbytes provides a buffer that supports incrementally detecting input.
_workspace/src/github.com/onsi/gomega/gexec
Package gexec provides support for testing external processes.
Package gexec provides support for testing external processes.
_workspace/src/github.com/onsi/gomega/ghttp
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
_workspace/src/github.com/onsi/gomega/ghttp/protobuf
Package protobuf is a generated protocol buffer package.
Package protobuf is a generated protocol buffer package.
_workspace/src/github.com/onsi/gomega/matchers
Gomega matchers This package implements the Gomega matchers and does not typically need to be imported.
Gomega matchers This package implements the Gomega matchers and does not typically need to be imported.
_workspace/src/github.com/pborman/uuid
The uuid package generates and inspects UUIDs.
The uuid package generates and inspects UUIDs.

Jump to

Keyboard shortcuts

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