Documentation ¶
Index ¶
- Constants
- func DBWithLogger(env EnvMode, db *gorm.DB, logger *log.Logger) *gorm.DB
- type APIBase
- func (ab *APIBase) Cleanup()
- func (ab *APIBase) DB() *gorm.DB
- func (ab *APIBase) Data() *Data
- func (ab *APIBase) Database() Database
- func (ab *APIBase) Environment() EnvMode
- func (ab *APIBase) Logger(service string) *log.Logger
- func (ab *APIBase) ReloadData() error
- func (ab *APIBase) Service(name string) Service
- type APIConfig
- type BaseConfig
- type BaseService
- type Catalog
- type Category
- type Config
- type Data
- type Database
- type Default
- type EnvMode
- type JWTConfig
- type Scope
- type Service
Constants ¶
const DBDialect = "postgres"
DBDialect defines dialect for db connection
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIBase ¶
type APIBase struct {
// contains filtered or unexported fields
}
APIBase defines the base configuration every service requires
func APIBaseFromEnv ¶
APIBaseFromEnv initialises APIBase Object passing .env.dev file to APIBaseFromEnvFile which will have configuration for development mode. This will initialise db connection and logger only. This is called while running db migration.
func APIBaseFromEnvFile ¶
APIBaseFromEnvFile expects a filepath to env file which has configurations It loads .env file, skips it if not found, initialises a db connection & logger depending on the EnvMode and returns a APIBase Object.
func (*APIBase) Cleanup ¶
func (ab *APIBase) Cleanup()
Cleanup flushes any buffered log entries & closes the db connection
func (*APIBase) Environment ¶
Environment returns the EnvMode server would be running
func (*APIBase) ReloadData ¶
ReloadData reads config file and loads data in Data object
type APIConfig ¶
type APIConfig struct { *APIBase // contains filtered or unexported fields }
APIConfig defines struct on top of APIBase with GitHub Oauth, GHEConfig & JWT Configurations
func FromEnv ¶
FromEnv will initialise APIConfig Object. This is called while starting the api server. It passes .env.dev which contains configurations for development mode, if it doesn't find the file it skips it and will look for configration among env variable
func FromEnvFile ¶
FromEnvFile expects a file name containing configurations. This is called when for running test where test config file is passed to initialise a APIConfig Object.
type BaseConfig ¶
type BaseConfig interface { Environment() EnvMode Service(name string) Service Logger(service string) *log.Logger DB() *gorm.DB Data() *Data ReloadData() error Cleanup() }
BaseConfig defines methods on APIBase
type BaseService ¶
type BaseService struct {
// contains filtered or unexported fields
}
BaseService defines configuraition for creating logger and db object with http request id
func (*BaseService) DB ¶
func (s *BaseService) DB(ctx context.Context) *gorm.DB
DB gets logger initialized with http request id and creates a gorm db session replacing writer for gorm logger with log.Logger so that gorm log will have http request id.
func (*BaseService) Logger ¶
func (s *BaseService) Logger(ctx context.Context) *log.Logger
Logger looks for http request id in passed context and append it to logger. This would help in filtering logs with request id.
func (*BaseService) LoggerWith ¶
func (s *BaseService) LoggerWith(ctx context.Context, args ...interface{}) *log.Logger
LoggerWith gets logger created with http request id from context then appends args to it
type Config ¶
type Config interface { BaseConfig JWTConfig() *JWTConfig }
Config defines methods on APIConfig includes BaseConfig
type Database ¶
Database Object defines db configuration fields
func (Database) ConnectionString ¶
ConnectionString returns the db connection string
type EnvMode ¶
type EnvMode string
EnvMode defines the mode the server is running in
const ( Production EnvMode = "production" Development EnvMode = "development" Test EnvMode = "test" )
Types of EnvMode
func Environment ¶
func Environment() EnvMode
Environment return EnvMode the Api server would be running in. It looks for 'ENVIRONMENT' to be defined as environment variable and if does not found it then set it as development mode