From a08bacccacc73151627ce2bd71879cb7f4c256ff Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Fri, 1 May 2020 16:23:52 +0100 Subject: [PATCH] feat: initial documentation and interface thoughts --- Makefile | 5 +++++ doc.go | 34 ++++++++++++++++++++++++++++++++++ go.mod | 3 +++ gofig.go | 23 +++++++++++++++++++++++ parsers/json/go.mod | 3 +++ parsers/json/json.go | 1 + parsers/toml/go.mod | 3 +++ parsers/toml/toml.go | 1 + parsers/yaml/go.mod | 3 +++ parsers/yaml/yaml.go | 1 + 10 files changed, 77 insertions(+) create mode 100644 Makefile create mode 100644 doc.go create mode 100644 go.mod create mode 100644 gofig.go create mode 100644 parsers/json/go.mod create mode 100644 parsers/json/json.go create mode 100644 parsers/toml/go.mod create mode 100644 parsers/toml/toml.go create mode 100644 parsers/yaml/go.mod create mode 100644 parsers/yaml/yaml.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b7a0da5 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +ifndef GODOCPORT +godoc: GODOCPORT = 8080 +endif +godoc: + godoc -http=:$(GODOCPORT) diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..43b23c0 --- /dev/null +++ b/doc.go @@ -0,0 +1,34 @@ +// Package gofig provides a library for loading configuration into a struct type. It also provides +// notification functionality (for parsers supporting it) for when configuration changes whilst the +// application is running, allowing you to hot reload your application when configuration changes. +// +// At it's core Gofig takes no 3rd party dependencies, parsers are implemented as their own sub +// modules, which may take 3rd party dependencies so you only get what you decide to use. +// +// Gofig It aims to provide a simple set of interfaces and API's to make it easy for users to implement +// their own parsers beyond those bundled within the parsers package. +// +// Example. +// +// package main +// +// import ( +// "go.krak3n.codes/gofig" +// "go.krak3n.codes/gofig/parsers/toml" // because why aren't you using TOML? +// ) +// +// type MyConfig struct { +// Foo string `gofig:"foo"` +// Bar string `gofig:"bar"` +// } +// +// func main() { +// var cfg MyConfig +// +// // gofig.Must will panic on error +// fig := gofig.Must(gofig.New(&cfg)) +// gofig.Must(fig.Parse(toml.File("/path/to/my/config.toml"))) +// +// // Use your config +// } +package gofig diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ab39fa8 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go.krak3n.codes/gofig + +go 1.13 diff --git a/gofig.go b/gofig.go new file mode 100644 index 0000000..73f3b9e --- /dev/null +++ b/gofig.go @@ -0,0 +1,23 @@ +package gofig + +// Gofig default configuration. +const ( + DefaultStructTag = "gofig" +) + +// A Parser parses configuration. +type Parser interface { + Parse() error +} + +// A Notifier notifies via a channel if changes to configuration have occurred. +// Remember to check the error on the channel. +type Notifier interface { + Notify() <-chan error +} + +// A ParseNotifier can parse config and notify on changes to configuration. +type ParseNotifier interface { + Parser + Notifier +} diff --git a/parsers/json/go.mod b/parsers/json/go.mod new file mode 100644 index 0000000..06d4616 --- /dev/null +++ b/parsers/json/go.mod @@ -0,0 +1,3 @@ +module go.krak3n.codes/gofig/parsers/json + +go 1.13 diff --git a/parsers/json/json.go b/parsers/json/json.go new file mode 100644 index 0000000..a5b981c --- /dev/null +++ b/parsers/json/json.go @@ -0,0 +1 @@ +package json diff --git a/parsers/toml/go.mod b/parsers/toml/go.mod new file mode 100644 index 0000000..d80a0e6 --- /dev/null +++ b/parsers/toml/go.mod @@ -0,0 +1,3 @@ +module go.krak3n.codes/gofig/parsers/toml + +go 1.13 diff --git a/parsers/toml/toml.go b/parsers/toml/toml.go new file mode 100644 index 0000000..f9fa173 --- /dev/null +++ b/parsers/toml/toml.go @@ -0,0 +1 @@ +package toml diff --git a/parsers/yaml/go.mod b/parsers/yaml/go.mod new file mode 100644 index 0000000..64f0ad8 --- /dev/null +++ b/parsers/yaml/go.mod @@ -0,0 +1,3 @@ +module go.krak3n.codes/gofig/parsers/yaml + +go 1.13 diff --git a/parsers/yaml/yaml.go b/parsers/yaml/yaml.go new file mode 100644 index 0000000..72f5087 --- /dev/null +++ b/parsers/yaml/yaml.go @@ -0,0 +1 @@ +package yaml