GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
657 B

6 years ago
6 years ago
6 years ago
6 years ago
  1. package channels
  2. import (
  3. "errors"
  4. "strings"
  5. "git.aiterp.net/rpdata/api/models"
  6. )
  7. // ErrInvalidName is an error for an invalid channel name.
  8. var ErrInvalidName = errors.New("Invalid channel name")
  9. // Add creates a new channel.
  10. func Add(name string, logged, hub bool, event, location string) (*models.Channel, error) {
  11. if len(name) < 3 && !strings.HasPrefix(name, "#") {
  12. return nil, ErrInvalidName
  13. }
  14. channel := models.Channel{
  15. Name: name,
  16. Logged: logged,
  17. Hub: hub,
  18. EventName: event,
  19. LocationName: location,
  20. }
  21. err := collection.Insert(channel)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return &channel, nil
  26. }