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

package pipelines
import (
"encoding/json"
"errors"
)
type StepType int
const (
TypeResizeImageStep StepType = iota
TypeCompressImageStep
)
type Step struct {
Name string `json:"name" faker:"name"`
Type StepType `json:"type" faker:"-"`
Options json.RawMessage `json:"options"`
}
func (s Step) Translate() (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 TypeCompressImageStep:
step := CompressImageStep{}
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
}