package channels import ( "errors" "strings" "git.aiterp.net/rpdata/api/models" ) // ErrInvalidName is an error for an invalid channel name. var ErrInvalidName = errors.New("Invalid channel name") // Add creates a new channel. func Add(name string, logged, hub bool, event, location string) (*models.Channel, error) { if len(name) < 3 && !strings.HasPrefix(name, "#") { return nil, ErrInvalidName } channel := models.Channel{ Name: name, Logged: logged, Hub: hub, EventName: event, LocationName: location, } err := collection.Insert(channel) if err != nil { return nil, err } return &channel, nil }