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.
 
 

117 lines
1.7 KiB

package main
import (
"encoding/json"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
)
// Pipelines
const (
Image PipelineType = iota
Video
)
type PipelineType int
type IPipeline interface {
GetName() string
GetType() PipelineType
GetSteps() []Step
}
type Pipeline struct {
Name string `json:"name"`
Type PipelineType `json:"type"`
RemoveMetadata bool `json:"remove_metadata"`
Steps []Step `json:"steps"`
}
func (p Pipeline) GetName() string {
return p.Name
}
func (p Pipeline) GetType() PipelineType {
return p.Type
}
func (p Pipeline) GetSteps() []Step {
return p.Steps
}
type ImagePipeline struct {
Pipeline
}
type VideoPipeline struct {
Pipeline
}
// Steps
type IStep interface {
Run()
GetName() string
}
type Step struct {
Name string
Type int
}
func (s Step) Run() {}
func (s Step) GetName() string {
return s.Name
}
type ResizeImageStep struct {
Step
}
type CompressImageStep struct {
Step
}
// 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+"/pipelines", 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)
}