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.

47 lines
871 B

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