Adding `Value.IsValid()` check in `NickMode.String()`. Fixes #98

This commit is contained in:
Dale Campbell 2017-03-23 02:06:33 +00:00
parent 64ad58533d
commit a3cd605787
1 changed files with 15 additions and 11 deletions

View File

@ -144,7 +144,9 @@ func (nk *Nick) Equals(other *Nick) bool {
// Duplicates a NickMode struct. // Duplicates a NickMode struct.
func (nm *NickMode) Copy() *NickMode { func (nm *NickMode) Copy() *NickMode {
if nm == nil { return nil } if nm == nil {
return nil
}
n := *nm n := *nm
return &n return &n
} }
@ -183,18 +185,20 @@ func (nk *nick) String() string {
func (nm *NickMode) String() string { func (nm *NickMode) String() string {
str := "+" str := "+"
v := reflect.Indirect(reflect.ValueOf(nm)) v := reflect.Indirect(reflect.ValueOf(nm))
t := v.Type() if v.IsValid() {
for i := 0; i < v.NumField(); i++ { t := v.Type()
switch f := v.Field(i); f.Kind() { for i := 0; i < v.NumField(); i++ {
// only bools here at the mo! switch f := v.Field(i); f.Kind() {
case reflect.Bool: // only bools here at the mo!
if f.Bool() { case reflect.Bool:
str += NickModeToString[t.Field(i).Name] if f.Bool() {
str += NickModeToString[t.Field(i).Name]
}
} }
} }
} if str == "+" {
if str == "+" { str = "No modes set"
str = "No modes set" }
} }
return str return str
} }