CrowdStrike/fortio

Name: fortio

Owner: Crowdstrike

Description: null

Created: 2017-07-13 20:09:56.0

Updated: 2018-05-08 21:51:47.0

Pushed: 2018-05-08 21:51:46.0

Homepage: null

Size: 25

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Fortio

What is Fortio?

Fortio is a config auto wiring module at CrowdStrike. Fortio means cargo in Greek, configs are our cargo that needs to be loaded and carried along in our services. Fortio is used to auto wire configurations from multiple sources like environment variables, config files, HTTP endpoints etc and follows the precedence order as viper into predefined defined config structs at startup. Fortio makes use of cobra and viper to achieve some of these features and not reinvent the wheel, but Fortio is also designed in such a way that replacing cobra or viper to a different solution should be easier and seamless.

Using Fortio

Get Fortio

et github.com/CrowdStrike/fortio

Define your config that must be auto wired

rt (
"encoding/json"
"github.com/CrowdStrike/fortio"
"gopkg.in/yaml.v2"


 ExampleConfig struct {
Timeout fortio.Duration  `config:"env=TIMEOUT,default=100ms;usage=Timeout for service" json:"timeout"`
Name    string           `config:"default=;usage=Name of service" json:"name"`


alidates assigned config values
 (ec *ExampleConfig) Validate() error {
if ec.Timeout.Duration > time.Duration(100) * time.Millisecond {
    return errors.New("Timeout can't be greater than 100ms")
}
if ec.Name == "" {
    return errors.New("Name can't be empty")
}
return nil


umpJSON will return JSON marshalled string of config
 (ec *ExampleConfig) DumpJSON() (string, error) {
v, err := json.Marshal(ec)
return string(v), err


umpYAML will return YAML marshalled string of config
 (ec *ExampleConfig) DumpYAML() (string, error) {
v, err := yaml.Marshal(ec)
return string(v), err

In your main file

rt "github.com/CrowdStrike/fortio"

 main() {
// Initialize empty config as pointer
config := &ExampleConfig{}
// Initialize config manager
cm := fortio.NewConfigManager("fortio-test", "My Fortio example")
// Pass config pointer to be loaded from env variables
err := cm.Load(config)
if err != nil {
    // handle error
}

// validate configs loaded
err = config.Validate()
if err != nil {
    // handle error
}

Checkout above example from example.go

Contributors

Praveen Bathala

Wes Widner

Contribute

We will be happy to accept contributions, please open a issue first on what you are trying to fix or solve and once you get feedback on it from other team members, go ahead and submit a pull request and we will be happy to take a look at merge it.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.