config

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config will have necessary configuration for the application

Index

Constants

View Source
const (
	//DbHost is the environment variable storing the database access url
	DbHost = "DB_HOST"
	//DbPort is the environment variable storing the database access port
	DbPort = "DB_PORT"
	//DbDatabaseName is the environment variable storing the database name
	DbDatabaseName = "DB_DATABASE_NAME"
	//DbUsername is the environment variable storing the database username
	DbUsername = "DB_USERNAME"
	//DbPassword is the environment variable storing the database password
	DbPassword = "DB_PASSWORD"
	//EnabledDB is the environment variable stating whether the db is enabled or not
	EnabledDB = "ENABLE_DB"
)

Variables

View Source
var (
	//Port in which the application is being served
	Port = "8080"
	//ResponseTimeout of the api to respond in milliseconds
	ResponseTimeout = time.Duration(100 * time.Millisecond)
	//RequestRTimeout of the api request body read timeout in milliseconds
	RequestRTimeout = time.Duration(20 * time.Millisecond)
	//ResponseWTimeout of the api response write timeout in milliseconds
	ResponseWTimeout = time.Duration(20 * time.Millisecond)
	//MaxRequests is the maximum no. of requests catered at a given point of time
	MaxRequests = 2
	//RequestCleanUpCheck is the time after which request cleanup check has to happen
	RequestCleanUpCheck = time.Duration(2 * time.Minute)
)
View Source
var IsTest bool

IsTest indicates that the current runtime is for test

View Source
var (
	//PRODUCTION is the switch to turn on and off the Production environment.
	//1: On, 0: Off
	PRODUCTION = 0
)
View Source
var SkipVault bool

SkipVault will skip the vault initialization if set true

Functions

This section is empty.

Types

type AppContext added in v1.2.1

type AppContext struct {
	//Db is the database connection
	Db *gorm.DB
	//Log for logging purposes
	Log Logger
}

AppContext contains the

func NewAppContext added in v1.2.1

func NewAppContext(l Logger) *AppContext

NewAppContext returns an initlized app context

func (*AppContext) ConnectToDB added in v1.2.1

func (a *AppContext) ConnectToDB() error

ConnectToDB connects the database and updates the Db property of the context as new connection If any error happens in between , it will be returned and connection won't be set in the context

type DbConfig added in v1.2.1

type DbConfig struct {
	//Host to be used to connect to the database
	Host string
	//Port with which the database can be accessed
	Port string
	//Database to connect
	Database string
	//Username to access the connection
	Username string
	//Password to access the connection
	Password string
}

DbConfig is the database configuration to connect to it

func NewDbConfig added in v1.2.1

func NewDbConfig() *DbConfig

NewDbConfig will read the db config from the os environment variables and set it in the config

func (DbConfig) Connect added in v1.2.1

func (d DbConfig) Connect() (*gorm.DB, error)

Connect will connect the database. Will return an error if anything comes up else nil

type Logger added in v1.2.1

type Logger interface {
	//Info logs the informative logs
	Info(l ...interface{})
	//Debug logs for the debugging logs
	Debug(l ...interface{})
	//Warn logs the warning logs
	Warn(l ...interface{})
	//Error logs the error
	Error(l ...interface{})
	//Fatal logs the fatal issues
	Fatal(l ...interface{})
	//GetID returns the ID of the logger
	GetID() int
}

Logger must be implemented by the logger utilities to be an app logger

Jump to

Keyboard shortcuts

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