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