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.

43 lines
768 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{s}
  26. }
  27. return nil, errors.New("invalid type")
  28. }
  29. func (s Step) GetType() StepType {
  30. return s.Type
  31. }
  32. func (s Step) GetName() string {
  33. return s.Name
  34. }