|
|
@ -2,9 +2,10 @@ package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"github.com/geplauder/lithium/pipelines" |
|
|
|
"net/http" |
|
|
|
|
|
|
|
"github.com/geplauder/lithium/pipelines" |
|
|
|
"github.com/geplauder/lithium/storage" |
|
|
|
"github.com/gorilla/mux" |
|
|
|
) |
|
|
|
|
|
|
@ -16,7 +17,7 @@ type Metadata struct { |
|
|
|
Version string |
|
|
|
} |
|
|
|
|
|
|
|
func PipelineHandler(pipeline pipelines.IPipeline, w http.ResponseWriter, r *http.Request) { |
|
|
|
func PipelineHandler(pipeline pipelines.IPipeline, storageProvider storage.IStorageProvider, w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
|
err := json.NewEncoder(w).Encode(pipeline) |
|
|
|
if err != nil { |
|
|
@ -32,21 +33,25 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func RegisterPipelineRoutes(r *mux.Router, pipelines []pipelines.IPipeline) { |
|
|
|
func RegisterPipelineRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { |
|
|
|
for _, pipeline := range pipelines { |
|
|
|
r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { |
|
|
|
PipelineHandler(pipeline, w, r) |
|
|
|
PipelineHandler(pipeline, storageProvider, w, r) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
|
storageProvider := storage.GetFileSystemStorageProvider("test") |
|
|
|
|
|
|
|
storageProvider.StoreRaw("abc", "def.test", []byte{0x12, 0x10}) |
|
|
|
|
|
|
|
pipes := pipelines.LoadPipelines() |
|
|
|
|
|
|
|
r := mux.NewRouter() |
|
|
|
r.HandleFunc("/", IndexHandler) |
|
|
|
|
|
|
|
RegisterPipelineRoutes(r, pipes) |
|
|
|
RegisterPipelineRoutes(r, pipes, storageProvider) |
|
|
|
|
|
|
|
err := http.ListenAndServe(":8000", r) |
|
|
|
if err != nil { |
|
|
|