config

package
v0.0.0-...-6321d4b Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

The scope of this file is: - Define the configuration struct. - Set default configuration values. - Map the data so viper can load the configuration there. See: https://articles.wesionary.team/environment-variable-configuration-in-your-golang-project-using-viper-4e8289ef664d See: https://consoledot.pages.redhat.com/docs/dev/getting-started/migration/config.html

Index

Constants

View Source
const (
	// DefaultAppName is used to compose the route paths
	DefaultAppName = "todo"
	// API URL path prefix
	DefaultPathPrefix = "/api/" + DefaultAppName + "/v1"
	// DefaultExpirationTime is used for the default token expiration period
	// expressed in seconds. The default value is set to 7200 (2 hours)
	DefaultTokenExpirationTimeSeconds = 7200
	// DefaultWebPort is the default port where the public API is listening
	DefaultWebPort = 8000

	// PaginationDefaultLimit is the default limit for the pagination
	PaginationDefaultLimit = 10
	// PaginationMaxLimit is the default max limit for the pagination
	PaginationMaxLimit = 1000

	// DefaultValidateAPI is true
	DefaultValidateAPI = true
)

Variables

This section is empty.

Functions

func Load

func Load(cfg *Config) *viper.Viper

func Validate

func Validate(cfg *Config) (err error)

Types

type Application

type Application struct {
	// PathPrefix is the API URL's path prefix, e.g. /api/todo
	PathPrefix string `mapstructure:"url_path_prefix" validate:"required"`
	// Indicate the default pagination limit when it is 0 or not filled
	PaginationDefaultLimit int `mapstructure:"pagination_default_limit"`
	// Indicate the max pagination limit when it is grather
	PaginationMaxLimit int `mapstructure:"pagination_max_limit"`
	// ValidateAPI enable the API validation for every request
	ValidateAPI bool `mapstructure:"validate_api"`
}

Application hold specific application settings

type Clients

type Clients struct {
	Inventory InventoryClient
}

Clients gather all the client settings for the

type Cloudwatch

type Cloudwatch struct {
	Region  string
	Key     string `json:"-"`
	Secret  string `json:"-"`
	Session string
	Group   string
	Stream  string
}

type Config

type Config struct {
	Loaded      bool
	Web         Web
	Database    Database
	Logging     Logging
	Cloudwatch  Cloudwatch
	Metrics     Metrics
	Clients     Clients
	Application Application `mapstructure:"app"`
}

func Get

func Get() *Config

Get is a singleton to get the global loaded configuration.

type Database

type Database struct {
	Host     string
	Port     int
	User     string `json:"-"`
	Password string `json:"-"`
	Name     string
	// https://stackoverflow.com/questions/54844546/how-to-unmarshal-golang-viper-snake-case-values
	CACertPath string `mapstructure:"ca_cert_path"`
}

type InventoryClient

type InventoryClient struct {
	// Define the base url for the host inventory service
	BaseUrl string `mapstructure:"base_url"`
}

type Logging

type Logging struct {
	Level    string
	Console  bool
	Location bool
}

type Metrics

type Metrics struct {
	// Defines the path to the metrics server that the app should be configured to
	// listen on for metric traffic.
	Path string `mapstructure:"path"`

	// Defines the metrics port that the app should be configured to listen on for
	// metric traffic.
	Port int `mapstructure:"port"`
}

type Web

type Web struct {
	Port int16
}

Jump to

Keyboard shortcuts

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