From 836d699400e767fd4a194cc2d6a32f6554dc9f52 Mon Sep 17 00:00:00 2001 From: Fabian Vowie Date: Tue, 4 Jan 2022 19:00:05 +0100 Subject: [PATCH] Use byte slice instead of string slice for DeserializePipelines --- pipeline.go | 24 +++++++++++++++++++++--- pipeline_test.go | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pipeline.go b/pipeline.go index 9a12672..dfa6681 100644 --- a/pipeline.go +++ b/pipeline.go @@ -1,6 +1,10 @@ package main -import "encoding/json" +import ( + "encoding/json" +) + +var Pipelines []Pipeline type PipelineType int type PipelineStepType int @@ -28,14 +32,28 @@ type Step struct { Type PipelineStepType } -func DeserializePipelines(pipelines []string) []Pipeline { +func DeserializePipelines(pipelines [][]byte) []Pipeline { values := make([]Pipeline, len(pipelines)) for index, pipeline := range pipelines { var deserializedObject Pipeline - json.Unmarshal([]byte(pipeline), &deserializedObject) + json.Unmarshal(pipeline, &deserializedObject) values[index] = deserializedObject } return values } + +// func LoadPipelines() { +// var files []string + +// err := filepath.Walk("./pipelines", func(path string, info fs.FileInfo, err error) error { +// data, err := os.ReadFile(path) + +// return nil +// }) + +// if err != nil { +// panic(err) +// } +// } diff --git a/pipeline_test.go b/pipeline_test.go index 9b7a135..59450d8 100644 --- a/pipeline_test.go +++ b/pipeline_test.go @@ -24,7 +24,7 @@ const ValidPayload string = `{ func TestPipelineDeserialization(t *testing.T) { t.Run("Pipelines deserialization is successful", func(t *testing.T) { - values := DeserializePipelines([]string{ValidPayload}) + values := DeserializePipelines([][]byte{[]byte(ValidPayload)}) assert.Equal(t, 1, len(values), "Output should contain one element") assert.Equal(t, "example pipeline", values[0].Name)