Make LoadFromString not panic but return an error instead.

Change-Id: I9f52fe807c8e9771a530f90ede8bd46fcdb467ae
This commit is contained in:
Bjoern Rabenstein 2014-11-27 19:29:17 +01:00
parent 87a585def8
commit bfd70e3280
1 changed files with 10 additions and 2 deletions

View File

@ -40,12 +40,20 @@ func (f Fingerprint) Equal(o Fingerprint) bool {
} }
// LoadFromString transforms a string representation into a Fingerprint. // LoadFromString transforms a string representation into a Fingerprint.
func (f *Fingerprint) LoadFromString(s string) { func (f *Fingerprint) LoadFromString(s string) error {
num, err := strconv.ParseUint(s, 16, 64) num, err := strconv.ParseUint(s, 16, 64)
if err != nil { if err != nil {
panic(err) return err
} }
*f = Fingerprint(num) *f = Fingerprint(num)
return nil
}
// MustLoadFromString works like LoadFromString but panics in case of an error.
func (f *Fingerprint) MustLoadFromString(s string) {
if err := f.LoadFromString(s); err != nil {
panic(err)
}
} }
// LoadFromMetric decomposes a Metric into this Fingerprint // LoadFromMetric decomposes a Metric into this Fingerprint