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.
97 lines
1.6 KiB
97 lines
1.6 KiB
package pipelines
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/fs"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// Pipelines
|
|
|
|
const (
|
|
Image PipelineType = iota
|
|
Video
|
|
)
|
|
|
|
type PipelineType int
|
|
|
|
type IPipeline interface {
|
|
GetName() string
|
|
GetSlug() string
|
|
GetType() PipelineType
|
|
GetSteps() []Step
|
|
}
|
|
|
|
type Pipeline struct {
|
|
Name string `json:"name" faker:"name"`
|
|
Slug string `json:"slug" faker:"word"`
|
|
Type PipelineType `json:"type" faker:"-"`
|
|
RemoveMetadata bool `json:"remove_metadata" faker:"-"`
|
|
Steps []Step `json:"steps"`
|
|
}
|
|
|
|
func (p Pipeline) GetName() string {
|
|
return p.Name
|
|
}
|
|
|
|
func (p Pipeline) GetSlug() string {
|
|
return p.Slug
|
|
}
|
|
|
|
func (p Pipeline) GetType() PipelineType {
|
|
return p.Type
|
|
}
|
|
|
|
func (p Pipeline) GetSteps() []Step {
|
|
return p.Steps
|
|
}
|
|
|
|
type ImagePipeline struct {
|
|
Pipeline
|
|
}
|
|
|
|
type VideoPipeline struct {
|
|
Pipeline
|
|
}
|
|
|
|
// Deserialization
|
|
|
|
func DeserializePipelines(pipelines [][]byte) []IPipeline {
|
|
var values []IPipeline
|
|
|
|
for _, pipeline := range pipelines {
|
|
var deserializedObject Pipeline
|
|
err := json.Unmarshal(pipeline, &deserializedObject)
|
|
if err != nil {
|
|
log.Fatalf("Could not deserialize pipelines config: %s", err)
|
|
}
|
|
values = append(values, deserializedObject)
|
|
}
|
|
|
|
return values
|
|
}
|
|
|
|
func LoadPipelines() []IPipeline {
|
|
var files [][]byte
|
|
|
|
path, _ := os.Getwd()
|
|
|
|
err := filepath.Walk(path+"/config", func(path string, info fs.FileInfo, err error) error {
|
|
if err == nil && info.IsDir() == false {
|
|
fmt.Println(path)
|
|
data, _ := os.ReadFile(path)
|
|
files = append(files, data)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return DeserializePipelines(files)
|
|
}
|