forked from libopenstorage/openstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code refactoring and simplification. Signed-off-by: Saurabh Deoras <[email protected]>
- Loading branch information
Showing
18 changed files
with
361 additions
and
1,160 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# osdconfig | ||
osdconfig is a library to work with distributed configuration parameters. It defines an interface and provides an | ||
implementation against KVDB backend. | ||
|
||
General purpose of this package is as follows: | ||
* Allow users to register their callback functions on updates to backend | ||
* Allow users to set/get config parameters | ||
|
||
# installation | ||
osdconfig is written in go (golang). It can be installed using go get | ||
```bash | ||
$ go get github.com/libopenstorage/openstorage/osdconfig/... | ||
``` | ||
|
||
# example | ||
Create an instance of kvdb | ||
```go | ||
kv, err := kvdb.New(mem.Name, "", []string{}, nil, nil) | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
``` | ||
|
||
Create an instance of osdconfig manager | ||
```go | ||
manager, err := osdconfig.NewManager(kv) | ||
if err != nil { | ||
// do something | ||
} | ||
defer manager.Close() | ||
``` | ||
|
||
Define a function literal that can be registered to watch for changes | ||
```go | ||
f := func(config *osdconfig.Config) error { | ||
// do something with config (say print) | ||
fmt.Println(config) | ||
return nil | ||
} | ||
``` | ||
|
||
Register this function literal to watch on kvdb changes | ||
```go | ||
if err := manager.WatchCluster("watcher", f); err != nil { | ||
// do something | ||
} | ||
``` | ||
|
||
Update cluster config on kvdb | ||
```go | ||
conf := new(osdconfig.ClusterConfig) | ||
conf.ClusterID = "myID" | ||
if err := manager.SetClusterConf(conf); err != nil { | ||
// do something | ||
return | ||
} | ||
``` | ||
|
||
once updates are pushed to backend (kvdb in this implementation), callback function is called |
Oops, something went wrong.