Skip to content

Commit

Permalink
Housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jan 16, 2024
1 parent 9498085 commit ec23c82
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 30 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI
on: [push, pull_request]
jobs:
test:
name: Test
runs-on: ubuntu-latest

strategy:
matrix:
go-version: [1.19.x, 1.20.x, 1.21.x]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Run tests
run: go test -p=1 -coverprofile=coverage.text -covermode=atomic ./...

- name: Upload coverage
if: success()
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# EZConf
# EZConf [![Build Status](https://github.com/nyaruka/ezconf/workflows/CI/badge.svg)](https://github.com/nyaruka/ezconf/actions?query=workflow%3ACI) [![codecov](https://codecov.io/gh/nyaruka/ezconf/branch/main/graph/badge.svg)](https://codecov.io/gh/nyaruka/ezconf) [![Go Report Card](https://goreportcard.com/badge/github.com/nyaruka/ezconf)](https://goreportcard.com/report/github.com/nyaruka/ezconf)

[![Build Status](https://travis-ci.org/nyaruka/ezconf.svg?branch=main)](https://travis-ci.org/nyaruka/ezconf)
[![codecov](https://codecov.io/gh/nyaruka/ezconf/branch/main/graph/badge.svg)](https://codecov.io/gh/nyaruka/ezconf)
[![Go Report Card](https://goreportcard.com/badge/github.com/nyaruka/ezconf)](https://goreportcard.com/report/github.com/nyaruka/ezconf)

EZConf provides a simple way of reading configuration settings from four sources, in order of priority (each level is higher priority than the previous ones):
Go library to provide simple way of reading configuration settings from four sources, in order of priority
(each level is higher priority than the previous ones):

1. The default settings for your app
2. A TOML file with settings
3. Environment variables mapping to your top level settings
4. Command line parameters mapping to your top level settings

To use it, you only need to create a struct representing the desired configuration and create an instance
with the defaults for your app. You can then pass that struct to EZConf and read the settings from all
with the defaults for your app. You can then pass that struct to the library and read the settings from all
the sources above.

EZConf will automatically parse command line parameters and environment variables for all top level fields
The library will automatically parse command line parameters and environment variables for all top level fields
in your struct of the following types:

* int, int8, int16, int32, int64
Expand Down Expand Up @@ -67,8 +64,6 @@ Environment variables:

## Example



```golang
package main

Expand Down
10 changes: 5 additions & 5 deletions ezconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestSetValue(t *testing.T) {

func TestEndToEnd(t *testing.T) {
at := &allTypes{}
conf := NewLoader(at, "foo", "description", []string{"missing.toml", "fields.toml", "simple.toml"})
conf := NewLoader(at, "foo", "description", []string{"testdata/missing.toml", "testdata/fields.toml", "testdata/simple.toml"})
conf.args = []string{"-my-int=48", "-debug-conf"}
err := conf.Load()
if err != nil {
Expand All @@ -151,7 +151,7 @@ func TestEndToEnd(t *testing.T) {

func TestPriority(t *testing.T) {
at := &allTypes{MyInt: 16}
conf := NewLoader(at, "foo", "description", []string{"missing.toml", "fields.toml", "simple.toml"})
conf := NewLoader(at, "foo", "description", []string{"testdata/missing.toml", "testdata/fields.toml", "testdata/simple.toml"})
conf.args = []string{}
conf.Load()

Expand All @@ -160,7 +160,7 @@ func TestPriority(t *testing.T) {
}

// override with environment variable
conf = NewLoader(at, "foo", "description", []string{"missing.toml", "fields.toml", "simple.toml"})
conf = NewLoader(at, "foo", "description", []string{"testdata/missing.toml", "testdata/fields.toml", "testdata/simple.toml"})
conf.args = []string{}
os.Setenv("FOO_MY_INT", "48")
conf.Load()
Expand All @@ -170,7 +170,7 @@ func TestPriority(t *testing.T) {
}

// override with args
conf = NewLoader(at, "foo", "description", []string{"missing.toml", "fields.toml", "simple.toml"})
conf = NewLoader(at, "foo", "description", []string{"testdata/missing.toml", "testdata/fields.toml", "testdata/simple.toml"})
conf.args = []string{"-my-int=56"}
os.Setenv("FOO_MY_INT", "48")
conf.Load()
Expand All @@ -181,7 +181,7 @@ func TestPriority(t *testing.T) {

// clear our env, args should take precedence now even though we are setting to the same as our new default
os.Setenv("FOO_MY_INT", "")
conf = NewLoader(at, "foo", "description", []string{"missing.toml", "fields.toml", "simple.toml"})
conf = NewLoader(at, "foo", "description", []string{"testdata/missing.toml", "testdata/fields.toml", "testdata/simple.toml"})
conf.args = []string{"-my-int=56"}
conf.Load()

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module github.com/nyaruka/ezconf

go 1.19

require (
github.com/fatih/structs v1.0.0
github.com/fatih/structs v1.1.0
github.com/naoina/go-stringutil v0.1.0
github.com/naoina/toml v0.1.1
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/fatih/structs v1.0.0 h1:BrX964Rv5uQ3wwS+KRUAJCBBw5PQmgJfJ6v4yly5QwU=
github.com/fatih/structs v1.0.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type simpleStruct struct {

func TestParsing(t *testing.T) {
s := &simpleStruct{}
err := parseTOMLFiles(s, []string{"notthere.toml", "simple.toml", "skipped.toml"}, true)
err := parseTOMLFiles(s, []string{"testdata/notthere.toml", "testdata/simple.toml", "testdata/skipped.toml"}, true)
if err != nil {
t.Errorf("error encountered parsing: %s", err)
return
Expand Down

0 comments on commit ec23c82

Please sign in to comment.