NodeInfo server implemented in Go.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

65 lignes
1.3 KiB

  1. package nodeinfo
  2. import (
  3. "encoding/json"
  4. "github.com/writeas/go-webfinger"
  5. "log"
  6. "net/http"
  7. )
  8. // NodeInfoPath defines the default path of the nodeinfo handler.
  9. const NodeInfoPath = "/.well-known/nodeinfo"
  10. type discoverInfo struct {
  11. Links []webfinger.Link `json:"links"`
  12. }
  13. func (s *Service) NodeInfoDiscover(w http.ResponseWriter, r *http.Request) {
  14. w.Header().Set("Content-Type", "application/json; charset=UTF-8")
  15. i := discoverInfo{
  16. Links: []webfinger.Link{
  17. {
  18. Rel: profile,
  19. HRef: s.InfoURL,
  20. },
  21. },
  22. }
  23. body, err := json.Marshal(i)
  24. if err != nil {
  25. log.Printf("Unable to marshal nodeinfo discovery: %v", err)
  26. w.WriteHeader(http.StatusInternalServerError)
  27. return
  28. }
  29. w.WriteHeader(http.StatusOK)
  30. _, err = w.Write(body)
  31. if err != nil {
  32. log.Printf("Unable to write body: %v", err)
  33. return
  34. }
  35. }
  36. func (s *Service) NodeInfo(w http.ResponseWriter, r *http.Request) {
  37. w.Header().Set("Content-Type", "application/json; profile="+profile+"#")
  38. i := s.BuildInfo()
  39. body, err := json.Marshal(i)
  40. if err != nil {
  41. log.Printf("Unable to marshal nodeinfo: %v", err)
  42. w.WriteHeader(http.StatusInternalServerError)
  43. return
  44. }
  45. w.WriteHeader(http.StatusOK)
  46. _, err = w.Write(body)
  47. if err != nil {
  48. log.Printf("Unable to write body: %v", err)
  49. return
  50. }
  51. }