Micro-service for file storage and processing written in Go
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.

46 lines
1021 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package main
  2. import (
  3. "encoding/json"
  4. "github.com/geplauder/lithium/pipelines"
  5. "net/http"
  6. "github.com/gorilla/mux"
  7. )
  8. const Name string = "Lithium"
  9. const Version string = "0.1.0"
  10. type Metadata struct {
  11. Name string
  12. Version string
  13. }
  14. func PipelineHandler(pipeline pipelines.IPipeline, w http.ResponseWriter, r *http.Request) {
  15. w.Header().Set("Content-Type", "application/json")
  16. json.NewEncoder(w).Encode(pipeline)
  17. }
  18. func IndexHandler(w http.ResponseWriter, r *http.Request) {
  19. w.Header().Set("Content-Type", "application/json")
  20. json.NewEncoder(w).Encode(Metadata{Name, Version})
  21. }
  22. func RegisterPipelineRoutes(r *mux.Router, pipelines []pipelines.IPipeline) {
  23. for _, pipeline := range pipelines {
  24. r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) {
  25. PipelineHandler(pipeline, w, r)
  26. })
  27. }
  28. }
  29. func main() {
  30. pipes := pipelines.LoadPipelines()
  31. r := mux.NewRouter()
  32. r.HandleFunc("/", IndexHandler)
  33. RegisterPipelineRoutes(r, pipes)
  34. http.ListenAndServe(":8000", r)
  35. }