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.

49 lines
1.0 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. )
  15. // IsValid returns true if the underlying string is one of the correct values.
  16. func (e LogImporter) IsValid() bool {
  17. switch e {
  18. case LogImporterForumLog, LogImporterMircLike:
  19. return true
  20. }
  21. return false
  22. }
  23. func (e LogImporter) String() string {
  24. return string(e)
  25. }
  26. // UnmarshalGQL unmarshals the underlying graphql value.
  27. func (e *LogImporter) UnmarshalGQL(v interface{}) error {
  28. str, ok := v.(string)
  29. if !ok {
  30. return fmt.Errorf("enums must be strings")
  31. }
  32. *e = LogImporter(str)
  33. if !e.IsValid() {
  34. return fmt.Errorf("%s is not a valid LogImporter", str)
  35. }
  36. return nil
  37. }
  38. // MarshalGQL marshals the underlying graphql value.
  39. func (e LogImporter) MarshalGQL(w io.Writer) {
  40. fmt.Fprint(w, strconv.Quote(e.String()))
  41. }