service.nodeinfo.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
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

type NodeInfo struct {
	Links []map[string]string `json:"links"`
}

type NodeInfo2 struct {
	Version   string       `json:"verson"`
	Software  NodeSoftware `json:"software"`
	Protocols []string     `json:"protocols"`
	Metadata  NodeMetadata `json:"metadata"`
}

type NodeSoftware struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type NodeMetadata struct {
	Name        string `json:"nodeName"`
	Description string `json:"nodeDescription"`
}

type NodeInfoServer struct {
	Host string
}

func (wb *NodeInfoServer) HandleWellKnown(w http.ResponseWriter, r *http.Request) {
	w.Header().Add("Content-Type", "application/json")
	data, _ := json.Marshal(NodeInfo{Links: []map[string]string{
		{"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
			"href": fmt.Sprintf("https:///%s/nodeinfo/2.0", wb.Host)},
	}})
	w.Write(data)
}

func (wb *NodeInfoServer) Handle2(w http.ResponseWriter, r *http.Request) {
	w.Header().Add("Content-Type", "application/json")
	data, _ := json.Marshal(NodeInfo2{
		Version:   "2.0",
		Protocols: []string{"activitypub"},
		Software:  NodeSoftware{Name: "tap", Version: Version},
		Metadata:  NodeMetadata{Name: wb.Host, Description: ""},
	})
	w.Write(data)
}