Browse Source

Load pipelines on program start

feature/add-pipeline-loading
Fabian Vowie 2 years ago
parent
commit
7717df32e0
No known key found for this signature in database GPG Key ID: C27317C33B27C410
  1. 2
      main.go
  2. 32
      pipeline.go
  3. 15
      pipelines/example.json

2
main.go

@ -21,6 +21,8 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
}
func main() {
LoadPipelines()
r := mux.NewRouter()
r.HandleFunc("/", IndexHandler)

32
pipeline.go

@ -2,6 +2,10 @@ package main
import (
"encoding/json"
"fmt"
"io/fs"
"os"
"path/filepath"
)
var Pipelines []Pipeline
@ -44,16 +48,24 @@ func DeserializePipelines(pipelines [][]byte) []Pipeline {
return values
}
// func LoadPipelines() {
// var files []string
func LoadPipelines() {
var files [][]byte
// err := filepath.Walk("./pipelines", func(path string, info fs.FileInfo, err error) error {
// data, err := os.ReadFile(path)
path, _ := os.Getwd()
// return nil
// })
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)
}
// if err != nil {
// panic(err)
// }
// }
return nil
})
if err != nil {
panic(err)
}
Pipelines = DeserializePipelines(files)
}

15
pipelines/example.json

@ -0,0 +1,15 @@
{
"name": "example pipeline",
"type": 0,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0
},
{
"name": "compress image",
"type": 1
}
]
}
Loading…
Cancel
Save