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.

51 lines
1.2 KiB

  1. package models
  2. import (
  3. "fmt"
  4. "io"
  5. "strconv"
  6. )
  7. // LogImporter describes a model related log importing.
  8. type LogImporter string
  9. const (
  10. // LogImporterMircLike is a value of LogImporter
  11. LogImporterMircLike LogImporter = "MircLike"
  12. // LogImporterForumLog is a value of LogImporter
  13. LogImporterForumLog LogImporter = "ForumLog"
  14. // LogImporterForumLog is a value of LogImporter
  15. LogImporterIrcCloud LogImporter = "IrcCloud"
  16. )
  17. // IsValid returns true if the underlying string is one of the correct values.
  18. func (e LogImporter) IsValid() bool {
  19. switch e {
  20. case LogImporterForumLog, LogImporterMircLike, LogImporterIrcCloud:
  21. return true
  22. }
  23. return false
  24. }
  25. func (e LogImporter) String() string {
  26. return string(e)
  27. }
  28. // UnmarshalGQL unmarshals the underlying graphql value.
  29. func (e *LogImporter) UnmarshalGQL(v interface{}) error {
  30. str, ok := v.(string)
  31. if !ok {
  32. return fmt.Errorf("enums must be strings")
  33. }
  34. *e = LogImporter(str)
  35. if !e.IsValid() {
  36. return fmt.Errorf("%s is not a valid LogImporter", str)
  37. }
  38. return nil
  39. }
  40. // MarshalGQL marshals the underlying graphql value.
  41. func (e LogImporter) MarshalGQL(w io.Writer) {
  42. fmt.Fprint(w, strconv.Quote(e.String()))
  43. }