Coder Social home page Coder Social logo

dodeca's Introduction

Dodeca

Go utilities for developers of 12-Factor applications.

Documentation Latest Version Build Status Code Coverage

This project is deprecated.

  • All Dogmatiq projects that use the Dodeca logging package are transitioning to use slog instead, in anticipation of its inclusion in Go's standard library.

  • The Dodeca config package has been superceded by dogmatiq/ferrite. Please see the migration guide for more information.

This repository will be archived once it is no longer used by other Dogmatiq projects.

Logging

The logging package provides a very simple logging interface.

The 12 Factor methodology states that all application logs should be written to STDOUT, and as such this is the default behavior of the logging package.

Additionally, the logger discriminates between application messages and debug messages, as per Dave Cheney's post about logging.

Configuration

The config package provides features to abstract the specification of a configuration value, from the consumption of a configuration value, using environment variables.

The 12 Factor methodology states that all application configuration should be read from environment variables. However, it is not uncommon to have configuration requirements with complexity that exceeds the capability of simple key/value pairs. In such situations, the obvious solution is to use a configuration file.

The approach we've taken is to allow configuration to be specified as a regular environment variable, or as an environment variable that describes the path to a configuration file.

The developer can then chose to consume this configuration as a string, []byte, io.ReadCloser, or as a path to a real file on disk, regardless of how the configuration as specified.

Usage

Specifying configuration

For any given environment variable K, the environment variable K__DATASOURCE indicates how the content of K should be interpreted.

If K__DATASOURCE is:

  • empty, undefined or the value string:plain, then K is a regular variable
  • the value string:hex, then K contains a binary value with hexadecimal encoding
  • the value string:base64, then K contains a binary value with base-64 encoding
  • the value file, then K contains a path to a file containing the value

Consuming configuration

There are three primary approaches to consuming configuration. The preferred way is to use once of the "typed" functions, such as AsBool(), AsInt(), etc.

These accept a config.Bucket type. The second approach is to use the bucket directly, which gives access to config.Value which in turn has methods for representing that value as a string, []byte, io.ReadCloser, or as a path to a real file on disk.

Finally, the config.GetEnv() function can be used as a drop-in replacement for os.Getenv(). However, it should be noted that when there is a problem loading a configuration value, such as when a non-existent file is specified this function simply returns an empty string.

dodeca's People

Contributors

danilvpetrov avatar dependabot-preview[bot] avatar dependabot[bot] avatar dogmatiq-automation[bot] avatar github-actions[bot] avatar jmalloc avatar koden-km avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dodeca's Issues

Standardise the test suite.

Just some simple things to bring inline with current practices:

  • Use When() instead of Context("when ...")
  • Use Describe("func Foo()") for functions / methods, including closing parens

Add functions for reading environment variables with strict typing.

For example, it would be great to be able to read integers, floats, bools, durations, etc from a bucket and have the values parsed and validated.

  • bool
  • int
  • int8
  • int16
  • int32
  • int64
  • uint
  • uint8
  • uint16
  • uint32
  • uint64
  • float32
  • float64
  • time.Duration
  • complex64 - I'm not going add functions for complex types unless someone comes up with a use case
  • complex128

Add adaptors for "promoting" and "demoting" message levels.

For example, promote would convert debug messages into regular log messages:

func Promote(l Logger) Logger { ... }

promoted := logging.Promote(logger)
promoted.Debug("foo") // equivalent to logger.Log("foo")
promoted.Log("foo")   // also equivalent to logger.Log("foo")

And demote, the opposite:

// capture would be similar to the CaptureDebug flag on StandardLogger
func Demote(l Logger, capture bool) Logger { ... }

demoted := logging.Demote(logger, true)
demoted.Debug("foo") // equivalent to logger.Debug("foo") if capture is true, or blackholed if false
demoted.Log("foo")   // also equivalent to logger.Debug("foo")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.