= config
Matt Nicholls <[email protected]>
:keywords: golang,config,configuration
:experimental: true
:icons: font
:iconfont-cdn: //cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/fontawesome.min.css
:imagesdir: docs/image
:sectanchors: true
:source-highlighter: prettify
:toc: left
:toclevels: 3
:toc-title: Contents
ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]
== Overview
Compact, no frills, configuration library for Go.
== Installation
.Prerequisites
* The link:https://golang.org/dl/[Golang Runtime], version 1.24.x or later
[source%nowrap,bash]
----
❯ go get -u github.com/transientvariable/config-go
----
== Usage
Configuration property values are specified using a configuration file (e.g. YAML) whose default values can be overridden using environment variables.
Using an environment variable override:
.Example application.yaml
[source,yaml]
----
config:
api:
url: ${APP_API_URL | https://example.com}
----
=== Property Value Syntax
Property values that use the placeholder syntax `${ ... }` are resolved via environment variables. For example, on a POSIX system, the following variable could be defined in `.bashrc`, `.profile`, `.bash_profile`, or via the command-line:
export FOO="bar"
which could then be referenced by value:
someApplicationProperty: ${FOO}
At runtime, the value for `someApplicationProperty` would be `bar`.
The pipe `|` symbol can be used within a placeholder to specify a default value if an environment variable cannot be resolved. For example:
requiredApplicationProperty: ${DOES_NOT_EXIST | baz}
At runtime, the value for `requiredApplicationProperty` would be `baz` if the environment variable `DOES_NOT_EXIST` was not set.
== License
This project is licensed under the link:LICENSE[MIT License].