about.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Rufs - Remote Union File System
  3. *
  4. * Copyright 2017 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. /*
  11. Package api contains the REST API for RUFS.
  12. /about
  13. Endpoint which returns an object with version information.
  14. {
  15. api_versions : List of available API versions e.g. [ "v1" ]
  16. product : Name of the API provider (RUFS)
  17. version: : Version of the API provider
  18. }
  19. */
  20. package api
  21. import (
  22. "encoding/json"
  23. "net/http"
  24. "devt.de/krotik/rufs/config"
  25. )
  26. /*
  27. EndpointAbout is the about endpoint definition (rooted). Handles about/
  28. */
  29. const EndpointAbout = APIRoot + "/about/"
  30. /*
  31. AboutEndpointInst creates a new endpoint handler.
  32. */
  33. func AboutEndpointInst() RestEndpointHandler {
  34. return &aboutEndpoint{}
  35. }
  36. /*
  37. aboutEndpoint is the handler object for about operations.
  38. */
  39. type aboutEndpoint struct {
  40. *DefaultEndpointHandler
  41. }
  42. /*
  43. HandleGET returns about data for the REST API.
  44. */
  45. func (a *aboutEndpoint) HandleGET(w http.ResponseWriter, r *http.Request, resources []string) {
  46. data := map[string]interface{}{
  47. "product": "RUFS",
  48. "version": config.ProductVersion,
  49. }
  50. // Write data
  51. w.Header().Set("content-type", "application/json; charset=utf-8")
  52. ret := json.NewEncoder(w)
  53. ret.Encode(data)
  54. }