1
0
의 미러 https://github.com/writeas/go-nodeinfo.git synced 2024-10-08 20:19:38 +00:00
NodeInfo server implemented in Go.
Go to file
2018-08-09 13:14:10 -04:00
example Add example implementation 2018-07-23 20:32:53 +02:00
.gitignore Add .gitignore 2018-07-23 20:10:59 +02:00
LICENSE Add MIT license 2018-07-23 20:27:59 +02:00
nodeinfo.go Add more NodeServices 2018-08-09 13:14:10 -04:00
README.md Fix typo in README 2018-07-23 20:30:51 +02:00
resolver.go Create nodeinfo library 2018-07-23 19:49:38 +02:00
routes.go Create nodeinfo library 2018-07-23 19:49:38 +02:00
service.go Include BaseURL in nodeinfo discover href 2018-07-23 20:10:38 +02:00

go-nodeinfo

GoDoc Discuss on our forum

go-nodeinfo is an implementation of NodeInfo, a standard metadata format for federated social networks, in Go (golang).

Usage

nodeinfo.Service integrates with your existing net/http server.

package main

import (
	"github.com/writeas/go-nodeinfo"
	"net/http"
)

func main() {
	cfg := nodeinfo.Config{
		BaseURL: "http://localhost:8080",
		InfoURL: "/api/nodeinfo",

		Metadata: nodeinfo.Metadata{
			NodeName:        "Agora",
			NodeDescription: "A federated something-something.",
			Private:         false,
		},
		Protocols: []nodeinfo.NodeProtocol{
			nodeinfo.ProtocolActivityPub,
		},
		Services: nodeinfo.Services{
			Inbound: []nodeinfo.NodeService{},
			Outbound: []nodeinfo.NodeService{
				nodeinfo.ServiceTwitter,
				nodeinfo.ServiceTumblr,
			},
		},
		Software: nodeinfo.SoftwareInfo{
			Name:    "Agora",
			Version: "1.0",
		},
	}
	ni := nodeinfo.NewService(cfg, nodeInfoResolver{})

	http.Handle(nodeinfo.NodeInfoPath, http.HandlerFunc(ni.NodeInfoDiscover))
	http.Handle(cfg.InfoURL, http.HandlerFunc(ni.NodeInfo))

	http.ListenAndServe(":8080", nil)
}

type nodeInfoResolver struct{}

func (r nodeInfoResolver) IsOpenRegistration() (bool, error) {
	return true, nil
}

func (r nodeInfoResolver) Usage() (nodeinfo.Usage, error) {
	u := nodeinfo.Usage{
		Users: nodeinfo.UsageUsers{
			Total: 1,
		},
		LocalPosts: 1,
	}
	return u, nil
}