https://github.com/joshbetz/config
  
  
    🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. 
    https://github.com/joshbetz/config
  
config configuration env environment-variables go golang json sighup
        Last synced: 6 months ago 
        JSON representation
    
🛠A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP.
- Host: GitHub
 - URL: https://github.com/joshbetz/config
 - Owner: joshbetz
 - License: mit
 - Created: 2017-04-02T18:37:05.000Z (over 8 years ago)
 - Default Branch: main
 - Last Pushed: 2021-11-12T16:58:10.000Z (almost 4 years ago)
 - Last Synced: 2025-05-08T23:43:38.876Z (6 months ago)
 - Topics: config, configuration, env, environment-variables, go, golang, json, sighup
 - Language: Go
 - Homepage: https://josh.blog/2017/04/go-configure
 - Size: 21.5 KB
 - Stars: 215
 - Watchers: 3
 - Forks: 14
 - Open Issues: 0
 - 
            Metadata Files:
            
- Readme: README.md
 - License: LICENSE
 
 
Awesome Lists containing this project
- awesome-go - joshbetz/config - Small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. (Configuration / Standard CLI)
 - fucking-awesome-go - joshbetz/config - Small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. (Configuration / Standard CLI)
 - awesome-go - joshbetz/config - Small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. (Configuration / Standard CLI)
 - awesome-go - joshbetz/config - Small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. (Configuration / Standard CLI)
 - awesome-go-extra - config - 04-02T18:37:05Z|2021-11-12T16:58:10Z| (Configuration / Advanced Console UIs)
 - awesome-go-with-stars - joshbetz/config - Small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. (Configuration / Standard CLI)
 - awesome-discoveries - config - a small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP _(`Go`)_ (Libraries)
 - awesome-go-plus - joshbetz/config - Small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP.  (Configuration / Standard CLI)
 - awesome-go-cn - joshbetz/config
 - awesome-go-plus - joshbetz/config - Small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP.   (Configuration / Standard CLI)
 - awesome-go - config - A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP - ★ 190 (Configuration)
 
README
          # config
[](https://travis-ci.org/joshbetz/config) [](https://goreportcard.com/report/github.com/joshbetz/config) [](http://godoc.org/github.com/joshbetz/config)
A small configuration library for Go that parses environment variables, JSON
files, and reloads automatically on `SIGHUP`.
## Example
```go
func main() {
	c := config.New("config.json")
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		var value string
		c.Get("value", &value)
		fmt.Fprintf(w, "Value: %s", value)
	})
	http.ListenAndServe(":3000", nil)
}
```

## API
```go
func New(file string) *Config
```
Constructor that initializes a Config object and sets up the SIGHUP watcher.
```go
func (config *Config) Get(key string, v interface{}) error
```
Takes the path to a JSON file, the name of the configuration option, and a
pointer to the variable where the config value will be stored. `v` can be a
pointer to a string, bool, or float64.
```go
func (config *Config) Reload()
```
Reloads the config. Happens automatically on `SIGHUP`.