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