package characters import ( "errors" "strings" "git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo/bson" ) // AddNick adds a nick to a characters func AddNick(character models.Character, nick string) (models.Character, error) { for i := range character.Nicks { if strings.EqualFold(character.Nicks[i], nick) { return models.Character{}, errors.New("Nick already exists") } } err := collection.UpdateId(character.ID, bson.M{"$push": bson.M{"nicks": nick}}) if err != nil { return models.Character{}, err } character.Nicks = append(character.Nicks, nick) return character, nil }