Documentation ¶
Overview ¶
Package fig implements the Golang client for fig
The typical use of fig to fetch configuration is something like this;
import "github.com/rameshvk/fig/pkg/fig" ... var cfg := fig.Config(url, key, secret, time.Second) ... val, err := cfg.Get("my.entry", map[string]string{"user": 42})
The arg provided to Get is typically a map or a struct whose fields can be accessed by the setting definition to provide the specific cofiguration value. The setting is a simple expression which is evaluated for the matching arguments.
Package fig implements the Golang client for fig
Example ¶
package main import ( "net/http" "net/http/httptest" "time" "github.com/alicebob/miniredis" "github.com/rameshvk/fig/pkg/fig" "github.com/rameshvk/fig/pkg/server" ) func main() { store, url, key, secret, cleanup := getStoreAndInfo() defer cleanup() cfg := fig.Config(url, key, secret, time.Second) store.Set("my.setting", `if(it.user == "boo", "hoo", "woo")`) // now get the setting and provide user = boo as arg v, err := cfg.Get("my.setting", map[interface{}]interface{}{"user": "boo"}) if v != "hoo" || err != nil { panic("unexpected result") } } func getStoreAndInfo() (server.Store, string, string, string, func()) { s, err := miniredis.Run() if err != nil { panic(err) } store := server.NewRedisStore(s.Addr(), "test-cfg") authStore := server.NewRedisStore(s.Addr(), "auth-store") unauthorized := func(r *http.Request) server.Store { return nil } authorized := func(r *http.Request) server.Store { return store } ts := httptest.NewServer(server.Handler(server.BasicAuth(authStore, authorized, unauthorized))) server.SetBasicAuthInfo(authStore, "mykey", "mysecret") cleanup := func() { ts.Close() s.Close() } return store, ts.URL, "mykey", "mysecret", cleanup }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrConfigNotFound = errors.New("config not found")
ErrConfigNotFound is returned by GetConfig if config is not found
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client implements the raw fig client API.
This is typically not used by services. For fetching configuration, the Config() function is a lot simpler.
Click to show internal directories.
Click to hide internal directories.