package main import ( "encoding/json" "net/http" "github.com/gorilla/mux" ) const Name string = "Lithium" const Version string = "0.1.0" type Metadata struct { Name string Version string } func PipelineHandle(pipeline IPipeline, w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(true) } func IndexHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(Metadata{Name, Version}) } func RegisterPipelineRoutes(r *mux.Router, pipelines []IPipeline) { for _, pipeline := range pipelines { r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { PipelineHandle(pipeline, w, r) }) } } func main() { pipelines := LoadPipelines() r := mux.NewRouter() r.HandleFunc("/", IndexHandler) RegisterPipelineRoutes(r, pipelines) http.ListenAndServe(":8000", r) }