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.

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