container

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 10 Imported by: 0

README

This is more or less a service locator / DI system.

I'm not sure if this is the way forward when it comes to idiomatic golang. I haven't seen this is larger projects so maybe the need for this is not there.

Documentation

Index

Constants

View Source
const (
	// APIKey key
	APIKey = "api-key"

	// AuthKey key
	AuthKey = "auth-key"

	// Resolver key
	Resolver = "resolver"

	// Subscription key
	Subscription = "subscription"

	// Ticket key
	Ticket = "ticket"

	// Webhook key
	Webhook = "webhook"
)

Variables

View Source
var Instance = Type{
	// contains filtered or unexported fields
}

Instance is the main bitmaelum service container

Functions

This section is empty.

Types

type Container

type Container interface {
	SetShared(key string, f ServiceFunc)
	SetNonShared(key string, f ServiceFunc)
	Get(key string) interface{}
	Has(key string) bool
}

Container is the interface each container needs to implement

func NewContainer

func NewContainer() Container

NewContainer will create a new container

type ServiceDefinition

type ServiceDefinition struct {
	Func ServiceFunc
	Type ServiceType
}

ServiceDefinition is a single service definition

type ServiceFunc

type ServiceFunc func() (interface{}, error)

ServiceFunc is the function that needs to be resolved in the definition

type ServiceType

type ServiceType int

ServiceType defines what kind of service it is (singleton, or new instance on each call)

const (
	ServiceTypeShared    ServiceType = iota // Service is shared. Each call returns the same instance
	ServiceTypeNonShared                    // Service is not shared. Each call returns a new instance
)

Service types

type Type

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

Type is the main container structure holding all service

func (*Type) Get

func (c *Type) Get(key string) interface{}

Get will retrieve the function for the given service, or nil when not found

func (*Type) GetAPIKeyRepo

func (c *Type) GetAPIKeyRepo() key.APIKeyRepo

GetAPIKeyRepo will return the current api key repository

func (*Type) GetAuthKeyRepo

func (c *Type) GetAuthKeyRepo() key.AuthKeyRepo

GetAuthKeyRepo will return the current auth key repository

func (*Type) GetResolveService

func (c *Type) GetResolveService() *resolver.Service

GetResolveService will return the current resolver service

func (*Type) GetStoreRepo

func (c *Type) GetStoreRepo() store.Repository

GetStoreRepo will return the current store repository

func (*Type) GetSubscriptionRepo

func (c *Type) GetSubscriptionRepo() subscription.Repository

GetSubscriptionRepo will return the current subscription repository

func (*Type) GetTicketRepo

func (c *Type) GetTicketRepo() ticket.Repository

GetTicketRepo will return the current ticket repository

func (*Type) GetWebhookRepo

func (c *Type) GetWebhookRepo() webhook.Repository

GetWebhookRepo will return the current webhook repository

func (*Type) Has

func (c *Type) Has(key string) bool

Has will return true when the definition exists

func (*Type) SetNonShared

func (c *Type) SetNonShared(key string, f ServiceFunc)

SetNonShared will set the function for the given service. It is not shared, meaning you will get a new instance on each call to get

func (*Type) SetShared

func (c *Type) SetShared(key string, f ServiceFunc)

SetShared will set the function for the given service. It will return a shared instance on each call to get

Jump to

Keyboard shortcuts

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