Browse Source
Load pipelines on program start
feature/add-pipeline-loading
Fabian Vowie
3 years ago
No known key found for this signature in database
GPG Key ID: C27317C33B27C410
3 changed files with
39 additions and
10 deletions
-
main.go
-
pipeline.go
-
pipelines/example.json
|
@ -21,6 +21,8 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
|
|
|
LoadPipelines() |
|
|
|
|
|
|
|
|
r := mux.NewRouter() |
|
|
r := mux.NewRouter() |
|
|
r.HandleFunc("/", IndexHandler) |
|
|
r.HandleFunc("/", IndexHandler) |
|
|
|
|
|
|
|
|
|
@ -2,6 +2,10 @@ package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
"fmt" |
|
|
|
|
|
"io/fs" |
|
|
|
|
|
"os" |
|
|
|
|
|
"path/filepath" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var Pipelines []Pipeline |
|
|
var Pipelines []Pipeline |
|
@ -44,16 +48,24 @@ func DeserializePipelines(pipelines [][]byte) []Pipeline { |
|
|
return values |
|
|
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) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
// panic(err)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Pipelines = DeserializePipelines(files) |
|
|
|
|
|
} |
|
@ -0,0 +1,15 @@ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "example pipeline", |
|
|
|
|
|
"type": 0, |
|
|
|
|
|
"removeMetadata": false, |
|
|
|
|
|
"steps": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "resize image", |
|
|
|
|
|
"type": 0 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "compress image", |
|
|
|
|
|
"type": 1 |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |