From a3cd605787791e79da2222eef5e8ac8aa06637c8 Mon Sep 17 00:00:00 2001 From: Dale Campbell Date: Thu, 23 Mar 2017 02:06:33 +0000 Subject: [PATCH] Adding `Value.IsValid()` check in `NickMode.String()`. Fixes #98 --- state/nick.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/state/nick.go b/state/nick.go index 7704b0b..c89a9ad 100644 --- a/state/nick.go +++ b/state/nick.go @@ -144,7 +144,9 @@ func (nk *Nick) Equals(other *Nick) bool { // Duplicates a NickMode struct. func (nm *NickMode) Copy() *NickMode { - if nm == nil { return nil } + if nm == nil { + return nil + } n := *nm return &n } @@ -183,18 +185,20 @@ func (nk *nick) String() string { func (nm *NickMode) String() string { str := "+" v := reflect.Indirect(reflect.ValueOf(nm)) - t := v.Type() - for i := 0; i < v.NumField(); i++ { - switch f := v.Field(i); f.Kind() { - // only bools here at the mo! - case reflect.Bool: - if f.Bool() { - str += NickModeToString[t.Field(i).Name] + if v.IsValid() { + t := v.Type() + for i := 0; i < v.NumField(); i++ { + switch f := v.Field(i); f.Kind() { + // only bools here at the mo! + case reflect.Bool: + if f.Bool() { + str += NickModeToString[t.Field(i).Name] + } } } - } - if str == "+" { - str = "No modes set" + if str == "+" { + str = "No modes set" + } } return str }