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.
48 lines
870 B
48 lines
870 B
package pipelines
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
)
|
|
|
|
type StepType int
|
|
|
|
const (
|
|
TypeResizeImageStep StepType = iota
|
|
TypeRotateImageStep
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
return nil, errors.New("invalid type")
|
|
}
|
|
|
|
func (s Step) GetType() StepType {
|
|
return s.Type
|
|
}
|
|
|
|
func (s Step) GetName() string {
|
|
return s.Name
|
|
}
|