Extend MustRegister function to accept variadic args

This commit is contained in:
Andrew Stuart 2016-07-08 14:05:10 -07:00
parent 9f1ed1ed4a
commit e63e6e3db7
No known key found for this signature in database
GPG Key ID: D409317C5B5ACD4D
1 changed files with 7 additions and 5 deletions

View File

@ -115,11 +115,13 @@ func Register(m Collector) error {
}
// MustRegister works like Register but panics where Register would have
// returned an error.
func MustRegister(m Collector) {
err := Register(m)
if err != nil {
panic(err)
// returned an error. MustRegister is also Variadic, where Register only
// accepts a single Collector to register.
func MustRegister(m ...Collector) {
for i := range m {
if err := Register(m[i]); err != nil {
panic(err)
}
}
}