gapp

package module
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 5 Imported by: 12

README

GApp

This library intent to provide a flexible and opinionated structure to build applications in a way that removes the problems of coding the same functionalities over and over regarding system components as configuration or logging.

Is the opinion of the library that the application scaffolding should revolve around the idea of a service container, seen in other types of frameworks. This container is responsible for storing factories of the application services that should be called for service instantiation, per need. This facilitates not only the composition of the application, but also directs the application architecture for a more dependency injection way of structuring services. By following this decoupled way of writing the application. will enable for more scalable and maintainable testing and production code.

Documentation

Index

Constants

View Source
const (
	// ContainerID defines the gapp package container entry id base string.
	ContainerID = "gapp"

	// ContainerMiddlewareID defines the default id used to register
	// the application middleware related services.
	ContainerMiddlewareID = ContainerID + ".middleware"
)
View Source
const (
	// Env defines the gapp package environment entry id base string.
	Env = "GAPP"

	// EnvMiddleware defines the gapp package middleware environment entry id
	// base string.
	EnvMiddleware = Env + "_MIDDLEWARE"
)

Variables

This section is empty.

Functions

func EnvBool added in v1.8.0

func EnvBool(env string, def bool) bool

EnvBool will try to retrieve a boolean value from the environment variables.

func EnvInt added in v1.11.0

func EnvInt(env string, def int) int

EnvInt will try to retrieve an integer value from the environment variables.

func EnvString added in v1.8.0

func EnvString(env string, def string) string

EnvString will try to retrieve a string value from the environment variables.

Types

type Application

type Application interface {
	Container() Container
	Add(provider Provider) error
	Boot() error
}

Application interface used to define the methods of a gapp application.

func NewApplication

func NewApplication(container Container) Application

NewApplication used to instantiate a new application.

type Container

type Container interface {
	io.Closer
	Has(id string) bool
	Remove(id string) error
	Service(id string, factory ContainerFactory, tags ...string) error
	Factory(id string, factory ContainerFactory, tags ...string) error
	Tagged(tag string) ([]interface{}, error)
	Get(id string) (interface{}, error)
}

Container is an interface for an object used to lazy load and store instances of registered objects. This is achieved by the registration of factory functions that will instantiate the instances as needed.

func NewContainer

func NewContainer() Container

NewContainer instantiates a new container object.

type ContainerFactory

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

ContainerFactory is a callback function used to instantiate an object used by the application container when a not yet instantiated object is requested.

type Provider

type Provider interface {
	Register(Container) error
	Boot(Container) error
}

Provider is an interface used to define the methods of an object that can be registered into a gapp application and register elements in the application container and do some necessary boot actions on initialization.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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