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.

52 lines
960 B

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