config

package module
v0.0.0-...-5b212b9 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

config

A library for reading and parsing yaml config .

This library is integrated with noxdew/log and noxdew/metrics and parses their configs by default.

The library reads config from <dir>/<env>.yml or <dir>/<env>.json where dir is $CONFIG_DIR and env is $ENV. This way you can have separate config files in the repository for development, testing, production and any other environments in your pipeline.

Note: It uses zap for logging. Since it parses the config for the logger it panics on all errors and uses the global logger.

Installation

go get bitbucket.org/noxdew/config

Usage

import "bitbucket.org/noxdew/config"

func main() {
    // Any object defining your custom schema, it will be populated from the data in the "custom" top level property
    customConfig := CustomConfig{}
    conf := config.Load(customConfig)

    // Then you can call the initialisation code for noxdew/log and noxdew/metrics
    logger := conf.Logging.Create()
    conf.Metrics.Configure(logger)
}

Contributing

Feel free to create issues or contribute code. We are reviewing them regularly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ServiceName string                 `yaml:"serviceName" json:"serviceName"`
	Env         string                 `yaml:"env" json:"env"`
	Port        int                    `yaml:"port" json:"port"`
	Logging     log.Config             `yaml:"logging" json:"logging"`
	Metrics     metrics.Config         `yaml:"metrics" json:"metrics"`
	TLS         tlsConfig              `yaml:"tls" json:"tls"`
	Custom      map[string]interface{} `yaml:"custom" json:"custom"`
}

Config struct containing the structure of the config file

func Load

func Load(customConfig interface{}) Config

Load reads the appropriate config file and creates the config object

Jump to

Keyboard shortcuts

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