From d0c43348349e71d657b3c8d86bda4d7fe3f1471e Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Thu, 7 May 2015 12:52:39 -0700 Subject: [PATCH] Adding feature flags --- pkg/featureflags/featureflag.go | 30 ++++++++++++++++++++++++++++ pkg/featureflags/featureflag_test.go | 22 ++++++++++++++++++++ pkg/featureflags/features.go | 6 ++++++ 3 files changed, 58 insertions(+) create mode 100644 pkg/featureflags/featureflag.go create mode 100644 pkg/featureflags/featureflag_test.go create mode 100644 pkg/featureflags/features.go diff --git a/pkg/featureflags/featureflag.go b/pkg/featureflags/featureflag.go new file mode 100644 index 000000000..9a7bd3904 --- /dev/null +++ b/pkg/featureflags/featureflag.go @@ -0,0 +1,30 @@ +package featureflags + +import ( + "sync" +) + +var features = make(map[string]bool) +var lock = &sync.RWMutex{} + +// Get feature will return true if the feature is enabled, otherwise false +func Get(feature string) bool { + lock.RLock() + defer lock.RUnlock() + res := features[feature] + return res +} + +// Enable a feature +func Enable(feature string) { + lock.Lock() + defer lock.Unlock() + features[feature] = true +} + +// Disable a feature +func Disable(feature string) { + lock.Lock() + defer lock.Unlock() + features[feature] = false +} diff --git a/pkg/featureflags/featureflag_test.go b/pkg/featureflags/featureflag_test.go new file mode 100644 index 000000000..ff5de5d3a --- /dev/null +++ b/pkg/featureflags/featureflag_test.go @@ -0,0 +1,22 @@ +package featureflags + +import ( + "testing" +) + +func TestFeatureFlag(t *testing.T) { + foo := Get("foo") + if foo { + t.Fail() + } + Enable("foo") + foo = Get("foo") + if !foo { + t.Fail() + } + Disable("foo") + foo = Get("foo") + if foo { + t.Fail() + } +} diff --git a/pkg/featureflags/features.go b/pkg/featureflags/features.go new file mode 100644 index 000000000..da85bc1e1 --- /dev/null +++ b/pkg/featureflags/features.go @@ -0,0 +1,6 @@ +package featureflags + +const ( + // MultipartPutObject ... + MultipartPutObject = "minio.multipart_put_object" +)