package pipelines import ( "encoding/json" "errors" ) type StepType int const ( TypeResizeImageStep StepType = iota TypeRotateImageStep TypeGrayscaleImageStep ) type Step struct { Name string `json:"name" faker:"name"` Type StepType `json:"type" faker:"-"` Options json.RawMessage `json:"options"` } func (s Step) GetExecutable() (IExecutableStep, error) { switch s.GetType() { case TypeResizeImageStep: step := ResizeImageStep{} if err := json.Unmarshal(s.Options, &step.Options); err != nil { return nil, err } return step, nil case TypeRotateImageStep: step := RotateImageStep{} if err := json.Unmarshal(s.Options, &step.Options); err != nil { return nil, err } return step, nil case TypeGrayscaleImageStep: return GrayscaleImageStep{}, nil } return nil, errors.New("invalid type") } func (s Step) GetType() StepType { return s.Type } func (s Step) GetName() string { return s.Name }