loader

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: JSON Imports: 9 Imported by: 6

Documentation

Overview

Package loader It has the responsibility to find the *CloudEnv* where your program run, store *Connector*s and retrieve services from *CloudEnv* which corresponds to one or many *Connector* and finally it will pass to *Connector* the service and store the result from connector.

Index

Constants

View Source
const (
	LOG_MESSAGE_PREFIX = "gautocloud"
	DEBUG_MODE_ENV_VAR = "GAUTOCLOUD_DEBUG"
)

Variables

This section is empty.

Functions

func NewErrGiveService

func NewErrGiveService(content string) error

func NewErrNoConnectorFound

func NewErrNoConnectorFound(id string) error

func NewErrNotInCloud

func NewErrNotInCloud(cloudEnvs []string) error

func NewErrPtrNotGiven

func NewErrPtrNotGiven() error

Types

type ErrGiveService

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

func (ErrGiveService) Error

func (e ErrGiveService) Error() string

type ErrNoConnectorFound

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

func (ErrNoConnectorFound) Error

func (e ErrNoConnectorFound) Error() string

type ErrNotInCloud

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

func (ErrNotInCloud) Error

func (e ErrNotInCloud) Error() string

type ErrPtrNotGiven

type ErrPtrNotGiven struct {
}

func (ErrPtrNotGiven) Error

func (e ErrPtrNotGiven) Error() string

type GautocloudLoader

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

func (*GautocloudLoader) CleanConnectors

func (l *GautocloudLoader) CleanConnectors()

CleanConnectors Remove all registered connectors

func (GautocloudLoader) CloudEnvs

func (l GautocloudLoader) CloudEnvs() []cloudenv.CloudEnv

CloudEnvs Return all cloud environments loaded

func (GautocloudLoader) Connectors

func (l GautocloudLoader) Connectors() map[string]connectors.Connector

Connectors Return all registered connectors

func (GautocloudLoader) CurrentCloudEnv

func (l GautocloudLoader) CurrentCloudEnv() cloudenv.CloudEnv

CurrentCloudEnv Return the current cloud env detected

func (GautocloudLoader) GetAll

func (l GautocloudLoader) GetAll(id string) ([]interface{}, error)

GetAll Return all services found by a connector id is the id of a connector Example:

var svc []interface{}
data, err = gautocloud.GetAll("mysql")
svc = data[0].(*dbtype.MysqlDB)

warning: a connector may give you different types that's why GetAll return a slice of interface{} It returns the first service found or an error if no service can be found or if the connector doesn't exist

func (GautocloudLoader) GetAppInfo

func (l GautocloudLoader) GetAppInfo() cloudenv.AppInfo

GetAppInfo Return information about instance of the running application

func (GautocloudLoader) GetFirst

func (l GautocloudLoader) GetFirst(id string) (interface{}, error)

GetFirst Return the first service found by a connector id is the id of a connector Example:

var svc *dbtype.MysqlDB
data, err = gautocloud.GetFirst("mysql")
svc = data.(*dbtype.MysqlDB)

It returns the first service found or an error if no service can be found or if the connector doesn't exist

func (GautocloudLoader) Inject

func (l GautocloudLoader) Inject(service interface{}) error

Inject service(s) found by connectors with given type Example:

var svc *dbtype.MysqlDB
err = loader.Inject(&svc)
// svc will have the value of the first service found with type *dbtype.MysqlDB

If service parameter is not a slice it will give the first service found If you pass a slice of a type in service parameter, it will inject in the slice all services found with this type It returns an error if parameter is not a pointer or if no service(s) can be found

func (GautocloudLoader) InjectFromId

func (l GautocloudLoader) InjectFromId(id string, service interface{}) error

InjectFromId Inject service(s) found by a connector with given type id is the id of a connector Example:

var svc *dbtype.MysqlDB
err = gautocloud.InjectFromId("mysql", &svc)
// svc will have the value of the first service found with type *dbtype.MysqlDB in this case

If service parameter is not a slice it will give the first service found If you pass a slice of a type in service parameter, it will inject in the slice all services found with this type It returns an error if service parameter is not a pointer, if no service(s) can be found and if connector with given id doesn't exist

func (GautocloudLoader) IsInACloudEnv

func (l GautocloudLoader) IsInACloudEnv() bool

IsInACloudEnv Return true if you are in a cloud environment

func (GautocloudLoader) LoadCloudEnvs

func (l GautocloudLoader) LoadCloudEnvs()

func (*GautocloudLoader) RegisterConnector

func (l *GautocloudLoader) RegisterConnector(connector connectors.Connector)

RegisterConnector Register a connector in the loader This is mainly use for connectors creators

func (GautocloudLoader) Reload

func (l GautocloudLoader) Reload()

Reload environment and connectors

func (*GautocloudLoader) ReloadConnectors

func (l *GautocloudLoader) ReloadConnectors()

ReloadConnectors Reload connectors to find services

func (*GautocloudLoader) Store

func (l *GautocloudLoader) Store() map[string][]StoredService

Store Return all services loaded

type Loader

type Loader interface {
	Reload()
	ReloadConnectors()
	RegisterConnector(connector connectors.Connector)
	Inject(service interface{}) error
	InjectFromId(id string, service interface{}) error
	GetFirst(id string) (interface{}, error)
	GetAll(id string) ([]interface{}, error)
	CloudEnvs() []cloudenv.CloudEnv
	Connectors() map[string]connectors.Connector
	Store() map[string][]StoredService
	CleanConnectors()
	CurrentCloudEnv() cloudenv.CloudEnv
	GetAppInfo() cloudenv.AppInfo
	IsInACloudEnv() bool
}

func NewLoader

func NewLoader(cloudEnvs []cloudenv.CloudEnv) Loader

NewLoader Create a new loader with cloud environment given

type StoredService

type StoredService struct {
	Data        interface{}
	ConnectorId string
	ReflectType reflect.Type
	Interceptor interceptor.Intercepter
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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