Micro-service for file storage and processing written in Go
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.

60 lines
1.1 KiB

  1. package pipelines
  2. import (
  3. "encoding/json"
  4. "errors"
  5. )
  6. type StepType int
  7. const (
  8. TypeResizeImageStep StepType = iota
  9. TypeRotateImageStep
  10. TypeFlipImageStep
  11. TypeGrayscaleImageStep
  12. )
  13. type Step struct {
  14. Name string `json:"name" faker:"name"`
  15. Type StepType `json:"type" faker:"-"`
  16. Options json.RawMessage `json:"options"`
  17. }
  18. func (s Step) GetExecutable() (IExecutableStep, error) {
  19. switch s.GetType() {
  20. case TypeResizeImageStep:
  21. step := ResizeImageStep{}
  22. if err := json.Unmarshal(s.Options, &step.Options); err != nil {
  23. return nil, err
  24. }
  25. return step, nil
  26. case TypeRotateImageStep:
  27. step := RotateImageStep{}
  28. if err := json.Unmarshal(s.Options, &step.Options); err != nil {
  29. return nil, err
  30. }
  31. return step, nil
  32. case TypeFlipImageStep:
  33. step := FlipImageStep{}
  34. if err := json.Unmarshal(s.Options, &step.Options); err != nil {
  35. return nil, err
  36. }
  37. return step, nil
  38. case TypeGrayscaleImageStep:
  39. return GrayscaleImageStep{}, nil
  40. }
  41. return nil, errors.New("invalid type")
  42. }
  43. func (s Step) GetType() StepType {
  44. return s.Type
  45. }
  46. func (s Step) GetName() string {
  47. return s.Name
  48. }