|
|
@ -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) |
|
|
|
} |