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.

47 lines
1.1 KiB

  1. package models
  2. import (
  3. "fmt"
  4. "io"
  5. )
  6. // TagKind represents the kind of tags.
  7. type TagKind string
  8. const (
  9. // TagKindOrganization is a tag kind, see GraphQL documentation.
  10. TagKindOrganization TagKind = "Organization"
  11. // TagKindCharacter is a tag kind, see GraphQL documentation.
  12. TagKindCharacter TagKind = "Character"
  13. // TagKindLocation is a tag kind, see GraphQL documentation.
  14. TagKindLocation TagKind = "Location"
  15. // TagKindEvent is a tag kind, see GraphQL documentation.
  16. TagKindEvent TagKind = "Event"
  17. // TagKindSeries is a tag kind, see GraphQL documentation.
  18. TagKindSeries TagKind = "Series"
  19. )
  20. // UnmarshalGQL unmarshals
  21. func (e *TagKind) UnmarshalGQL(v interface{}) error {
  22. str, ok := v.(string)
  23. if !ok {
  24. return fmt.Errorf("enums must be strings")
  25. }
  26. *e = TagKind(str)
  27. switch *e {
  28. case TagKindOrganization, TagKindCharacter, TagKindLocation, TagKindEvent, TagKindSeries:
  29. return nil
  30. default:
  31. return fmt.Errorf("%s is not a valid TagKind", str)
  32. }
  33. }
  34. // MarshalGQL turns it into a JSON string
  35. func (e TagKind) MarshalGQL(w io.Writer) {
  36. fmt.Fprint(w, "\""+string(e), "\"")
  37. }