You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/geplauder/lithium/pipelines"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
const Name string = "Lithium"
|
|
const Version string = "0.1.0"
|
|
|
|
type Metadata struct {
|
|
Name string
|
|
Version string
|
|
}
|
|
|
|
func PipelineHandler(pipeline pipelines.IPipeline, w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
err := json.NewEncoder(w).Encode(pipeline)
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
}
|
|
}
|
|
|
|
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
err := json.NewEncoder(w).Encode(Metadata{Name, Version})
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
}
|
|
}
|
|
|
|
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)
|
|
})
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
pipes := pipelines.LoadPipelines()
|
|
|
|
r := mux.NewRouter()
|
|
r.HandleFunc("/", IndexHandler)
|
|
|
|
RegisterPipelineRoutes(r, pipes)
|
|
|
|
err := http.ListenAndServe(":8000", r)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|