config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package config is an adapter which allows users to write a yaml configuration file and allow the caweb to instantiate different components, from the adapter or use cases layers, using those configuration settings. These settings may be versioned and maintained by migrations later. However, the parsed and validated configurations should be passed to their ultimate components as a series of individual params (for the mandatory items) and a series of functional options (for the optional items), so they may be accumulated and validated in another (possibly non-exorted) config struct (or directly in the relevant end-component such as a UseCase instance). This design decision causes a bit of redundancy in favor of a defensive solution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cars

type Cars struct {
	// OldParkingDelay indicates the amount of delay that an old
	// parking method should incur.
	OldParkingDelay *time.Duration `yaml:"old-parking-method-delay"`
}

Cars contains the configuration settings for the cars use cases.

func (Cars) NewUseCase

func (c Cars) NewUseCase(
	p repo.Pool, r repo.Cars,
) (*carsuc.UseCase, error)

NewUseCase instantiates a new cars use case based on the settings in the c struct.

type Config

type Config struct {
	Database Database
	Gin      Gin
	Usecases Usecases
}

Config contains all settings which are required by different parts of the project such as adapters or use cases. It is preferred to implement Config with primitive fields or other structs which are defined in this package, not models or structs which are defined in other layers, so the configuration can be versioned and kept intact while other layers can change freely. If two versions of the Config struct were implemented, the newer version may embed/depend on the older version (which is freezed).

func Load

func Load(path string) (*Config, error)

Load function loads, validates, and normalizes the configuration file and returns its settings as an instance of the Config struct.

func (*Config) ValidateAndNormalize

func (c *Config) ValidateAndNormalize() error

ValidateAndNormalize validates the configuration settings and returns an error if they were not acceptable. It can also modify settings in order to normalize them or replace some zero values with their expected default values (if any).

type Database

type Database struct {
	Host     string // domain name or IP address of the DBMS server
	Port     int    // port number of the DBMS server
	Name     string // database name, like caweb1_0_0
	Role     string // role/username for connecting to the database
	PassFile string `yaml:"pass-file"` // path of the password file
}

Database contains the database related configuration settings.

func (Database) NewPool

func (d Database) NewPool(ctx context.Context) (*postgres.Pool, error)

NewPool instantiates a new database connection pool based on the connection information which are stored in d instance.

type Gin

type Gin struct {
	Logger   bool // Whether to register the gin.Logger() middleware
	Recovery bool // Whether to register the gin.Recovery() middleware
}

Gin contains the gin-gonic related configuration settings.

func (Gin) NewEngine

func (g Gin) NewEngine() *gin.Engine

NewEngine instantiates a new gin-gonic engine instance based on the g settings.

type Usecases

type Usecases struct {
	Cars Cars // cars use cases related settings
}

Usecases contains the configuration settings for all use cases.

Jump to

Keyboard shortcuts

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