package characters import ( "errors" "strings" "git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo/bson" ) // RemoveNick removes a nick to a characters func RemoveNick(character models.Character, nick string) (models.Character, error) { index := -1 for i := range character.Nicks { if strings.EqualFold(character.Nicks[i], nick) { index = i break } } if index == -1 { return models.Character{}, errors.New("Nick does not exist") } err := collection.UpdateId(character.ID, bson.M{"$pull": bson.M{"nicks": nick}}) if err != nil { return models.Character{}, err } character.Nicks = append(character.Nicks[:index], character.Nicks[index+1:]...) return character, nil }