From 7869d1e96fb72485b9a6988471ed08f864c5cd88 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Sat, 15 Jan 2022 13:58:04 +0100 Subject: [PATCH] Move pipeline files to subpackage --- main.go | 9 +++++---- main_test.go | 5 +++-- pipeline.go => pipelines/pipeline.go | 2 +- pipeline_test.go => pipelines/pipeline_test.go | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) rename pipeline.go => pipelines/pipeline.go (99%) rename pipeline_test.go => pipelines/pipeline_test.go (99%) diff --git a/main.go b/main.go index ce5f598..490b7ee 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "github.com/geplauder/lithium/pipelines" "net/http" "github.com/gorilla/mux" @@ -15,7 +16,7 @@ type Metadata struct { Version string } -func PipelineHandler(pipeline IPipeline, w http.ResponseWriter, r *http.Request) { +func PipelineHandler(pipeline pipelines.IPipeline, w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(pipeline) } @@ -25,7 +26,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(Metadata{Name, Version}) } -func RegisterPipelineRoutes(r *mux.Router, pipelines []IPipeline) { +func RegisterPipelineRoutes(r *mux.Router, pipelines []pipelines.IPipeline) { for _, pipeline := range pipelines { r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { PipelineHandler(pipeline, w, r) @@ -34,12 +35,12 @@ func RegisterPipelineRoutes(r *mux.Router, pipelines []IPipeline) { } func main() { - pipelines := LoadPipelines() + pipes := pipelines.LoadPipelines() r := mux.NewRouter() r.HandleFunc("/", IndexHandler) - RegisterPipelineRoutes(r, pipelines) + RegisterPipelineRoutes(r, pipes) http.ListenAndServe(":8000", r) } diff --git a/main_test.go b/main_test.go index f887bc5..e183155 100644 --- a/main_test.go +++ b/main_test.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "github.com/geplauder/lithium/pipelines" "net/http" "net/http/httptest" "testing" @@ -25,7 +26,7 @@ func TestIndexRoute(t *testing.T) { } func TestEndpointRoute(t *testing.T) { - data := Pipeline{} + data := pipelines.Pipeline{} err := faker.FakeData(&data) if err != nil { fmt.Println(err) @@ -33,7 +34,7 @@ func TestEndpointRoute(t *testing.T) { t.Run("Registered pipelines are valid routes", func(t *testing.T) { router := mux.NewRouter() - RegisterPipelineRoutes(router, []IPipeline{data}) + RegisterPipelineRoutes(router, []pipelines.IPipeline{data}) request, _ := http.NewRequest("GET", "/"+data.Slug, nil) responseRecorder := httptest.NewRecorder() diff --git a/pipeline.go b/pipelines/pipeline.go similarity index 99% rename from pipeline.go rename to pipelines/pipeline.go index 9ff9293..b67f22b 100644 --- a/pipeline.go +++ b/pipelines/pipeline.go @@ -1,4 +1,4 @@ -package main +package pipelines import ( "encoding/json" diff --git a/pipeline_test.go b/pipelines/pipeline_test.go similarity index 99% rename from pipeline_test.go rename to pipelines/pipeline_test.go index 0c91123..4acf90b 100644 --- a/pipeline_test.go +++ b/pipelines/pipeline_test.go @@ -1,4 +1,4 @@ -package main +package pipelines import ( "testing"