This repository has been archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vscode | ||
debug.test | ||
coverage.out | ||
coverage.out | ||
example* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Containous SAS, Emile Vauge, emile@vauge.com | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,116 @@ | ||
# staert | ||
# Stært | ||
[![Travis branch](https://img.shields.io/travis/containous/staert/master.svg)](https://travis-ci.org/containous/staert) | ||
[![Coverage Status](https://coveralls.io/repos/github/containous/staert/badge.svg?branch=master)](https://coveralls.io/github/containous/staert?branch=master) | ||
[![license](https://img.shields.io/github/license/containous/staert.svg)](https://github.com/containous/staert/blob/master/LICENSE.md) | ||
|
||
Stært is a Go library for loading and merging a program configuration structure from many sources. | ||
|
||
## Overview | ||
Stært born in order to merge two sources of Configuration ([Flæg](https://github.com/containous/flaeg), [Toml](http://github.com/BurntSushi/toml)) | ||
|
||
## Features | ||
- Load your Configuration structure from many sources | ||
- Keep your Configuration structure values unchanged if no overwriting (support defaults values) | ||
- Two native sources : | ||
- [Flæg](https://github.com/containous/flaeg) | ||
- [Toml](http://github.com/BurntSushi/toml) | ||
- An Interface to add your own sources | ||
- Handle pointers field : | ||
- You can give a structure of default values for pointers | ||
- Same comportment as [Flæg](https://github.com/containous/flaeg) | ||
- Stært is Command oriented | ||
- It use `flaeg.Command` | ||
- Same comportment as [Flæg](https://github.com/containous/flaeg) commands | ||
|
||
## Getting Started | ||
### The configuration | ||
It works on your own Configuration structure, like this one : | ||
```go | ||
import ( | ||
"github.com/containous/flaeg" | ||
"github.com/containous/staert" | ||
) | ||
|
||
//Configuration is a struct which contains all differents type to field | ||
type Configuration struct { | ||
IntField int `description:"An integer field"` | ||
StringField string `description:"A string field"` | ||
PointerField *PointerSubConfiguration `description:"A pointer field"` | ||
} | ||
|
||
//PointerSubConfiguration is a SubStructure Configuration | ||
type PointerSubConfiguration struct { | ||
BoolField `description:"A boolean field"` | ||
FloatField `description:"A float field"` | ||
} | ||
``` | ||
|
||
Let's initialize it: | ||
```go | ||
//Init with default value | ||
config := &Configuration{ | ||
IntField: 1, | ||
StringField: "init", | ||
PointerField: &PointerSubConfiguration{ | ||
FloatField: 1.1, | ||
}, | ||
} | ||
//Set default pointers value | ||
defaultPointersConfig := &Configuration{ | ||
PointerField: &PointerSubConfiguration{ | ||
BoolField: true, | ||
FloatField: 99.99, | ||
}, | ||
} | ||
``` | ||
|
||
### The command | ||
Stært uses `flaeg.Command` Structure, like this : | ||
```go | ||
//Creat Command | ||
command:=&flaeg.Command{ | ||
Name:"example", | ||
Description:"This is an example of description", | ||
Config:config, | ||
DefaultPointersConfig:defaultPointersConfig, | ||
Run: func() error { | ||
fmt.Printf("Run example with the config :\n%+v\n",config) | ||
return nil | ||
} | ||
} | ||
``` | ||
|
||
### Use stært with sources | ||
Init Stært | ||
```go | ||
s:=staert.NewStaert(command) | ||
``` | ||
Init TOML source | ||
```go | ||
toml:=staert.NewTomlSource("example", []string{"./toml/", "/any/other/path"}) | ||
``` | ||
Init Flæg source | ||
```go | ||
f:=flaeg.New(command, os.Args[1]) | ||
``` | ||
### Add sources | ||
Add TOML and flæg sources | ||
```go | ||
s.AddSource(toml) | ||
s.AddSource(f) | ||
``` | ||
|
||
### Now run | ||
JUST RUN | ||
```go | ||
if err := s.Run(); err != nil { | ||
//OUPS | ||
} | ||
``` | ||
|
||
## Contributing | ||
1. Fork it! | ||
2. Create your feature branch: `git checkout -b my-new-feature` | ||
3. Commit your changes: `git commit -am 'Add some feature'` | ||
4. Push to the branch: `git push origin my-new-feature` | ||
5. Submit a pull request :D |