core

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 15 Imported by: 1

README

Azugo Core

Azugo framework core.

Features

  • Structured logger go.uber.org/zap
  • Extendable configuration viper and command line cobra support
  • Caching using memory or Redis
  • Logger based on zap with output compatible with ECS

Special Environment variables used by the Azugo framework

Core
  • ENVIRONMENT - An App environment setting (allowed values are Development, Staging and Production).
  • LOG_LEVEL - Minimal log level (defaults to info, allowed values are debug, info, warn, error, fatal, panic).
Cache
  • CACHE_TYPE - Cache type to use in service (defaults to memory, allowed values are memory, redis, redis-cluster).
  • CACHE_TTL - Duration on how long to keep items in cache. Defaults to 0 meaning to never expire.
  • CACHE_KEY_PREFIX - Prefix all cache keys with specified value.
  • CACHE_CONNECTION - If other than memory cache is used specifies connection string on how to connect to cache storage.
  • CACHE_PASSWORD - Password to use in connection string.
  • CACHE_PASSWORD_FILE - File to read value for CACHE_PASSWORD from.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {

	// App settings
	AppVer       string
	AppBuiltWith string
	AppName      string
	// contains filtered or unexported fields
}

func New

func New() *App

func (*App) AddTask added in v0.6.0

func (a *App) AddTask(task Tasker) error

AddTask adds task to the app.

If app is already started, task is started immediately.

func (*App) BackgroundContext

func (a *App) BackgroundContext() context.Context

BackgroundContext returns global background context

func (*App) Cache

func (a *App) Cache() *cache.Cache

func (*App) Config

func (a *App) Config() *config.Configuration

Config returns application configuration.

Panics if configuration is not loaded.

func (*App) Env

func (a *App) Env() Environment

Env returns the current application environment

func (*App) Instrumentation added in v0.7.0

func (a *App) Instrumentation(instr instrumenter.Instrumenter)

Instrumentation defines callback to be used as instrumenter.

func (*App) Instrumenter added in v0.7.0

func (a *App) Instrumenter() instrumenter.Instrumenter

Instrumenter returns application instrumentation callback.

func (*App) Log

func (a *App) Log() *zap.Logger

Log returns application logger.

func (*App) ReplaceLogger added in v0.3.0

func (a *App) ReplaceLogger(logger *zap.Logger) error

ReplaceLogger replaces current application logger with custom.

Default fields are automatically added to the logger.

func (*App) SetConfig

func (a *App) SetConfig(cmd *cobra.Command, conf *config.Configuration)

SetConfig binds application configuration to the application

func (*App) SetVersion

func (a *App) SetVersion(version, builtWith string)

SetVersion sets application version and built with tags

func (*App) Start

func (a *App) Start() error

Start web application.

func (*App) Stop

func (a *App) Stop()

Stop application and its services

func (*App) String

func (a *App) String() string

func (*App) Validate

func (a *App) Validate() *validation.Validate

Validate returns validation service instance.

type Environment

type Environment string

Environment type.

const (
	EnvironmentDevelopment Environment = "Development"
	EnvironmentStaging     Environment = "Staging"
	EnvironmentProduction  Environment = "Production"
)

func NewEnvironment

func NewEnvironment(defaultMode Environment) Environment

NewEnvironment creates new Environment instance.

func (Environment) IsDevelopment

func (e Environment) IsDevelopment() bool

IsDevelopment checks if current environment is development.

func (Environment) IsProduction

func (e Environment) IsProduction() bool

IsProduction checks if current environment is production.

func (Environment) IsStaging

func (e Environment) IsStaging() bool

IsStaging checks if current environment is staging.

type Tasker added in v0.6.0

type Tasker interface {
	// Start task
	//
	// This method is called when task is started and MUST not block.
	Start(ctx context.Context) error
	// Stop task
	Stop()
	// Name returns task name
	Name() string
}

Tasker interface for staring task

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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