compression.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // this file was auto-generated by internal/cmd/gentypes/main.go: DO NOT EDIT
  2. package jwa
  3. import (
  4. "github.com/pkg/errors"
  5. )
  6. // CompressionAlgorithm represents the compression algorithms as described in https://tools.ietf.org/html/rfc7518#section-7.3
  7. type CompressionAlgorithm string
  8. // Supported values for CompressionAlgorithm
  9. const (
  10. Deflate CompressionAlgorithm = "DEF" // DEFLATE (RFC 1951)
  11. NoCompress CompressionAlgorithm = "" // No compression
  12. )
  13. // Accept is used when conversion from values given by
  14. // outside sources (such as JSON payloads) is required
  15. func (v *CompressionAlgorithm) Accept(value interface{}) error {
  16. var tmp CompressionAlgorithm
  17. switch x := value.(type) {
  18. case string:
  19. tmp = CompressionAlgorithm(x)
  20. case CompressionAlgorithm:
  21. tmp = x
  22. default:
  23. return errors.Errorf(`invalid type for jwa.CompressionAlgorithm: %T`, value)
  24. }
  25. switch tmp {
  26. case Deflate, NoCompress:
  27. default:
  28. return errors.Errorf(`invalid jwa.CompressionAlgorithm value`)
  29. }
  30. *v = tmp
  31. return nil
  32. }
  33. // String returns the string representation of a CompressionAlgorithm
  34. func (v CompressionAlgorithm) String() string {
  35. return string(v)
  36. }