app

package
v0.0.0-...-520f1c6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DBDialect = "postgres"

DBDialect defines dialect for db connection

Variables

This section is empty.

Functions

func DBWithLogger

func DBWithLogger(env EnvMode, db *gorm.DB, logger *log.Logger) *gorm.DB

DBWithLogger returns gorm db object initialised with logger

Types

type APIBase

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

APIBase defines the base configuration every service requires

func APIBaseFromEnv

func APIBaseFromEnv() (*APIBase, error)

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

func APIBaseFromEnvFile(file string) (*APIBase, error)

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) DB

func (ab *APIBase) DB() *gorm.DB

DB returns gorm db object

func (*APIBase) Data

func (ab *APIBase) Data() *Data

Data returns Data object which consist app data from config file

func (*APIBase) Database

func (ab *APIBase) Database() Database

Database returns the database object used for initializing db connection

func (*APIBase) Environment

func (ab *APIBase) Environment() EnvMode

Environment returns the EnvMode server would be running

func (*APIBase) Logger

func (ab *APIBase) Logger(service string) *log.Logger

Logger returns log.Logger appended with service name

func (*APIBase) ReloadData

func (ab *APIBase) ReloadData() error

ReloadData reads config file and loads data in Data object

func (*APIBase) Service

func (ab *APIBase) Service(name string) Service

Service creates a base service 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

func FromEnv() (*APIConfig, error)

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

func FromEnvFile(file string) (*APIConfig, error)

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.

func (*APIConfig) JWTConfig

func (ac *APIConfig) JWTConfig() *JWTConfig

JWTConfig returns JWTConfig 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 Catalog

type Catalog struct {
	Name       string
	Org        string
	Type       string
	URL        string
	ContextDir string
	Revision   string
	Provider   string
}

type Category

type Category struct {
	Name string
}

type Config

type Config interface {
	BaseConfig
	JWTConfig() *JWTConfig
}

Config defines methods on APIConfig includes BaseConfig

type Data

type Data struct {
	Checksum   string
	Catalogs   []Catalog
	Categories []Category
	Scopes     []Scope
	Default    Default
}

type Database

type Database struct {
	Host     string
	Port     string
	Name     string
	User     string
	Password string
}

Database Object defines db configuration fields

func (Database) ConnectionString

func (db Database) ConnectionString() string

ConnectionString returns the db connection string

func (*Database) String

func (db *Database) String() string

type Default

type Default struct {
	Scopes []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

type JWTConfig

type JWTConfig struct {
	SigningKey       string
	AccessExpiresIn  time.Duration
	RefreshExpiresIn time.Duration
}

JWTConfig defines configuration requires to create token

type Scope

type Scope struct {
	Name  string
	Users []string
}

type Service

type Service interface {
	Logger(ctx context.Context) *log.Logger
	LoggerWith(ctx context.Context, args ...interface{}) *log.Logger
	DB(ctx context.Context) *gorm.DB
}

Service defines methods on BaseService

Jump to

Keyboard shortcuts

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