|
@ -2,6 +2,7 @@ package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
"github.com/geplauder/lithium/pipelines" |
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
|
|
|
"github.com/gorilla/mux" |
|
|
"github.com/gorilla/mux" |
|
@ -15,7 +16,7 @@ type Metadata struct { |
|
|
Version string |
|
|
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") |
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
json.NewEncoder(w).Encode(pipeline) |
|
|
json.NewEncoder(w).Encode(pipeline) |
|
|
} |
|
|
} |
|
@ -25,7 +26,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { |
|
|
json.NewEncoder(w).Encode(Metadata{Name, Version}) |
|
|
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 { |
|
|
for _, pipeline := range pipelines { |
|
|
r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { |
|
|
r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { |
|
|
PipelineHandler(pipeline, w, r) |
|
|
PipelineHandler(pipeline, w, r) |
|
@ -34,12 +35,12 @@ func RegisterPipelineRoutes(r *mux.Router, pipelines []IPipeline) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
pipelines := LoadPipelines() |
|
|
|
|
|
|
|
|
pipes := pipelines.LoadPipelines() |
|
|
|
|
|
|
|
|
r := mux.NewRouter() |
|
|
r := mux.NewRouter() |
|
|
r.HandleFunc("/", IndexHandler) |
|
|
r.HandleFunc("/", IndexHandler) |
|
|
|
|
|
|
|
|
RegisterPipelineRoutes(r, pipelines) |
|
|
|
|
|
|
|
|
RegisterPipelineRoutes(r, pipes) |
|
|
|
|
|
|
|
|
http.ListenAndServe(":8000", r) |
|
|
http.ListenAndServe(":8000", r) |
|
|
} |
|
|
} |