about.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. /*
  11. Package api contains general REST API definitions.
  12. The REST API provides an interface to EliasDB. It allows querying and modifying
  13. of the datastore. The API responds to GET, POST, PUT and DELETE requests in JSON
  14. if the request was successful (Return code 200 OK) and plain text in all other cases.
  15. Common API definitions
  16. /about
  17. Endpoint which returns an object with version information.
  18. api_versions : List of available API versions e.g. [ "v1" ]
  19. product : Name of the API provider (EliasDB)
  20. version: : Version of the API provider
  21. revision: : Revision of the API provider
  22. /swagger.json
  23. Dynamically generated swagger definition file. See: http://swagger.io
  24. */
  25. package api
  26. import (
  27. "encoding/json"
  28. "net/http"
  29. "devt.de/krotik/eliasdb/config"
  30. )
  31. /*
  32. EndpointAbout is the about endpoint URL (rooted). Handles about/
  33. */
  34. const EndpointAbout = APIRoot + "/about/"
  35. /*
  36. AboutEndpointInst creates a new endpoint handler.
  37. */
  38. func AboutEndpointInst() RestEndpointHandler {
  39. return &aboutEndpoint{}
  40. }
  41. /*
  42. Handler object for about operations.
  43. */
  44. type aboutEndpoint struct {
  45. *DefaultEndpointHandler
  46. }
  47. /*
  48. HandleGET returns about data for the REST API.
  49. */
  50. func (a *aboutEndpoint) HandleGET(w http.ResponseWriter, r *http.Request, resources []string) {
  51. data := map[string]interface{}{
  52. "api_versions": []string{"v1"},
  53. "product": "EliasDB",
  54. "version": config.ProductVersion,
  55. }
  56. // Write data
  57. w.Header().Set("content-type", "application/json; charset=utf-8")
  58. ret := json.NewEncoder(w)
  59. ret.Encode(data)
  60. }