From ec23c8244bbf70f626600a60b3f65a65aa996213 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Tue, 16 Jan 2024 09:25:16 -0500 Subject: [PATCH] Housekeeping --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ .travis.yml | 13 ------------- README.md | 15 +++++---------- ezconf_test.go | 10 +++++----- go.mod | 4 +++- go.sum | 2 ++ fields.toml => testdata/fields.toml | 0 simple.toml => testdata/simple.toml | 0 toml_test.go | 2 +- 9 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml rename fields.toml => testdata/fields.toml (100%) rename simple.toml => testdata/simple.toml (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5efdb41 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0dc1b6b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go - -go: -- "1.10" - -script: -- go test -coverprofile=coverage.text -covermode=atomic github.com/nyaruka/ezconf/... - -after_success: -- bash <(curl -s https://codecov.io/bash) -- rm coverage.text - - diff --git a/README.md b/README.md index f7b63c0..51f1350 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@ -# 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 @@ -12,10 +9,10 @@ EZConf provides a simple way of reading configuration settings from four sources 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 @@ -67,8 +64,6 @@ Environment variables: ## Example - - ```golang package main diff --git a/ezconf_test.go b/ezconf_test.go index 1576fb0..1de049b 100644 --- a/ezconf_test.go +++ b/ezconf_test.go @@ -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 { @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/go.mod b/go.mod index 70cb2ef..05041f4 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 4c453ef..1af4ff4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/fields.toml b/testdata/fields.toml similarity index 100% rename from fields.toml rename to testdata/fields.toml diff --git a/simple.toml b/testdata/simple.toml similarity index 100% rename from simple.toml rename to testdata/simple.toml diff --git a/toml_test.go b/toml_test.go index 9a4a87f..a78bdc0 100644 --- a/toml_test.go +++ b/toml_test.go @@ -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