common

package module
v0.0.0-...-4289f7d Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultDBType = "postgres"

DefaultDBType is the default db type

Variables

This section is empty.

Functions

func Debug

func Debug(event, message string)

Debug writes a debug message to the underlying logger

func Error

func Error(event string, err error)

Error writes a error message to the underlying logger

func Exists

func Exists(key string) bool

Exists confirms if the the key exists

func GetBool

func GetBool(key string, defaultValue bool) bool

GetBool gets the boolean value or defaults as required

func GetDuration

func GetDuration(key string, defaultDuration time.Duration) time.Duration

GetDuration provides additional valiation on top of the standard library because Viper returned zero duraction which could cause significant performance issues

func GetInt

func GetInt(key string, defaultNumber int) int

GetInt gets the value from Viper

func GetString

func GetString(key, defaultValue string) string

GetString gets the value from Viper

func GetUint

func GetUint(key string, defaultNumber uint) uint

GetUint gets the value from Viper

func Healthz

func Healthz(request *Request, response *Response)

Healthz is the health check - the name is inspired by a forgotten source that this is the naming conventions at Google

func Info

func Info(event, message string)

Info writes a info message to the underlying logger

func Warn

func Warn(event, message string)

Warn writes a warn message to the underlying logger

Types

type Command

type Command func(request *Request, response *Response)

Command performs the required action for the service

type Configurator

type Configurator struct {
	Env      string
	Location string
}

Configurator sets up configuration in production

func NewConfigurator

func NewConfigurator(env, location string) *Configurator

NewConfigurator gets a new production configurator

func (*Configurator) Load

func (c *Configurator) Load()

Load loads without a callback

func (*Configurator) LoadWithCallback

func (c *Configurator) LoadWithCallback(reload func(in fsnotify.Event))

LoadWithCallback loads up the configuration from the sources

type DBInfo

type DBInfo struct {
	Type             string
	ConnectionString string
	Tries            int // Actual attempts
}

DBInfo represents the connection details

type IConfigurator

type IConfigurator interface {
	Load(func(in fsnotify.Event))
}

IConfigurator interface for injectiong configuration set up

type ILogger

type ILogger interface {
	Load()
}

ILogger interface the logger

type IRepository

type IRepository interface {
	Migrate() error
}

IRepository for all repositories

type Logger

type Logger struct {
	DefaultLevel zapcore.Level
	Level        zapcore.Level
	Config       string
}

Logger is the implementation of the logger

func NewLogger

func NewLogger(config string) *Logger

NewLogger creates an instance of the Logger

func (*Logger) Load

func (l *Logger) Load()

Load loads the logger based in the config

type Monitor

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

Monitor is the wrapper around the health checks

func NewMonitor

func NewMonitor() *Monitor

NewMonitor access the monitors

func (*Monitor) AddCheck

func (m *Monitor) AddCheck(name string, interval time.Duration, fatal bool, config h.Config)

AddCheck adds checkers that implement IChecker dynamically to list TODO: This is bleeding the underlying interface

func (*Monitor) AddHTTPCheck

func (m *Monitor) AddHTTPCheck(name string, interval time.Duration, fatal bool, rawurl string)

AddHTTPCheck adds a check to a specific HTTP end point

func (*Monitor) GetStatus

func (m *Monitor) GetStatus() MonitorStatus

GetStatus returns the status of the monitor

type MonitorStatus

type MonitorStatus struct {
	IsMonitoring bool
	Failed       bool
}

MonitorStatus represents the current status of the dependencies

type Repository

type Repository struct {
	Name           string
	Database       *gorm.DB
	Username       string
	Password       string
	DBName         string
	DBTypeKey      string
	AllowedDBTypes []string
	DefaultDBType  string
	Attempts       uint // Number of attempts
	Delay          time.Duration
	MaxIdle        int
	MaxOpen        int
	MaxLifetime    time.Duration
	SetDBFunc      func() (*gorm.DB, error)
	Info           DBInfo
}

Repository that reprents the access to the underlying database

func NewRepository

func NewRepository(name string) *Repository

NewRepository returns production database access

func (*Repository) Close

func (r *Repository) Close() error

Close the DB connection

func (*Repository) Create

func (r *Repository) Create(entity interface{}) error

Create the entity in the database

func (*Repository) Migrate

func (r *Repository) Migrate(entity interface{}) error

Migrate placeholder for service specific migration

func (*Repository) Open

func (r *Repository) Open() error

Open the database and sets the underlying configuration

func (*Repository) Ping

func (r *Repository) Ping() error

Ping pings the underlying database to ensure it's contactable

type Request

type Request struct {
	Body map[string]interface{}
}

Request generically represents inputs to the service

func (*Request) Map

func (r *Request) Map(entity interface{}) error

Map maps request body to the domain model

type Response

type Response struct {
	Code int         `json:"code"`
	Body interface{} `json:"body,omitempty"`
}

Response generically represents outputs from the service

type Route

type Route struct {
	Method  string
	Path    string
	Handler func(request *Request, response *Response)
}

Route for handling

Jump to

Keyboard shortcuts

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