A REST API for the DN42 registry, written in Go, to provide a bridge between interactive applications and the registry. https://explorer.burble.com
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.

56 lines
1.4KB

  1. //////////////////////////////////////////////////////////////////////////
  2. // DN42 Registry API Server
  3. //////////////////////////////////////////////////////////////////////////
  4. package main
  5. //////////////////////////////////////////////////////////////////////////
  6. import (
  7. "github.com/gorilla/mux"
  8. log "github.com/sirupsen/logrus"
  9. "net/http"
  10. "os"
  11. )
  12. //////////////////////////////////////////////////////////////////////////
  13. // called from main to initialise the API routing
  14. func InstallStaticRoutes(router *mux.Router, staticPath string) {
  15. // an empty path disables static route serving
  16. if staticPath == "" {
  17. log.Info("Disabling static route serving")
  18. return
  19. }
  20. // validate that the staticPath exists
  21. stat, err := os.Stat(staticPath)
  22. if err != nil {
  23. log.WithFields(log.Fields{
  24. "error": err,
  25. "path": staticPath,
  26. }).Fatal("Unable to find static page directory")
  27. }
  28. // and it is a directory
  29. if !stat.IsDir() {
  30. log.WithFields(log.Fields{
  31. "error": err,
  32. "path": staticPath,
  33. }).Fatal("Static path is not a directory")
  34. }
  35. // install a file server for the static route
  36. router.PathPrefix("/").Handler(http.StripPrefix("/",
  37. http.FileServer(http.Dir(staticPath)))).Methods("GET")
  38. log.WithFields(log.Fields{
  39. "path": staticPath,
  40. }).Info("Static route installed")
  41. }
  42. //////////////////////////////////////////////////////////////////////////
  43. // end of code