Skip to content

Commit

Permalink
feat: initial documentation and interface thoughts
Browse files Browse the repository at this point in the history
  • Loading branch information
krak3n committed May 1, 2020
1 parent cf28bc4 commit a08bacc
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ifndef GODOCPORT
godoc: GODOCPORT = 8080
endif
godoc:
godoc -http=:$(GODOCPORT)
34 changes: 34 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go.krak3n.codes/gofig

go 1.13
23 changes: 23 additions & 0 deletions gofig.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions parsers/json/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go.krak3n.codes/gofig/parsers/json

go 1.13
1 change: 1 addition & 0 deletions parsers/json/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package json
3 changes: 3 additions & 0 deletions parsers/toml/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go.krak3n.codes/gofig/parsers/toml

go 1.13
1 change: 1 addition & 0 deletions parsers/toml/toml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package toml
3 changes: 3 additions & 0 deletions parsers/yaml/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go.krak3n.codes/gofig/parsers/yaml

go 1.13
1 change: 1 addition & 0 deletions parsers/yaml/yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package yaml

0 comments on commit a08bacc

Please sign in to comment.