Permalink
Browse files

metrics: add Must methods

  • Loading branch information...
1 parent 004329b commit ffa5a52419e06e3665483bb0a978248f695980e5 @suyash suyash committed Jul 15, 2016
Showing with 21 additions and 1 deletion.
  1. +21 −1 metrics.go
View
@@ -256,8 +256,11 @@ type SingletonMetric interface {
// gets the value of the metric
Val() interface{}
- // Sets the value of the metric to a value, optionally returns an error on failure
+ // sets the value of the metric to a value, optionally returns an error on failure
Set(interface{}) error
+
+ // tries to set and panics on error
+ MustSet(interface{})
}
///////////////////////////////////////////////////////////////////////////////
@@ -272,6 +275,9 @@ type InstanceMetric interface {
// sets the value of a particular instance
SetInstance(string, interface{}) error
+
+ // tries to set the value of a particular instance and panics on error
+ MustSetInstance(string, interface{})
}
///////////////////////////////////////////////////////////////////////////////
@@ -424,6 +430,13 @@ func (m *PCPSingletonMetric) Set(val interface{}) error {
return nil
}
+// MustSet is a Set that panics
+func (m *PCPSingletonMetric) MustSet(val interface{}) {
+ if err := m.Set(val); err != nil {
+ panic(err)
+ }
+}
+
// Indom returns the instance domain for a PCPSingletonMetric
func (m *PCPSingletonMetric) Indom() *PCPInstanceDomain { return nil }
@@ -523,3 +536,10 @@ func (m *PCPInstanceMetric) SetInstance(instance string, val interface{}) error
m.vals[instance].val = val
return nil
}
+
+// MustSetInstance is a SetInstance that panics
+func (m *PCPInstanceMetric) MustSetInstance(instance string, val interface{}) {
+ if err := m.SetInstance(instance, val); err != nil {
+ panic(err)
+ }
+}

0 comments on commit ffa5a52

Please sign in to comment.