nodeinfo

package module
Version: v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 4 Imported by: 1

README

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
}

Documentation

Index

Constants

View Source
const (
	// Protocols that can be supported by this node.
	ProtocolActivityPub NodeProtocol = "activitypub"
	ProtocolBuddyCloud               = "buddycloud"
	ProtocolDFRN                     = "dfrn"
	ProtocolDisaspora                = "diaspora"
	ProtocolLibertree                = "libertree"
	ProtocolOStatus                  = "ostatus"
	ProtocolPumpIO                   = "pumpio"
	ProtocolTent                     = "tent"
	ProtocolXMPP                     = "xmpp"
	ProtocolZot                      = "zot"

	// Services that can be supported (inbound or outbound) by this node's API.
	ServiceAtom      NodeService = "atom1.0"
	ServiceGNUSocial             = "gnusocial"
	ServiceIMAP                  = "imap"
	ServicePnut                  = "pnut"
	ServicePOP3                  = "pop3"
	ServicePumpIO                = "pumpio"
	ServiceRSS                   = "rss2.0"
	ServiceTwitter               = "twitter"
	ServiceTumblr                = "tumblr"
)
View Source
const NodeInfoPath = "/.well-known/nodeinfo"

NodeInfoPath defines the default path of the nodeinfo handler.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BaseURL   string
	InfoURL   string
	Metadata  Metadata
	Protocols []NodeProtocol
	Services  Services
	Software  SoftwareInfo
}

type Metadata

type Metadata struct {
	NodeName        string       `json:"nodeName,omitempty"`
	NodeDescription string       `json:"nodeDescription,omitempty"`
	Private         bool         `json:"private,omitempty"`
	Software        SoftwareMeta `json:"software,omitempty"`
}

Metadata for nodeinfo. Properties are based on what Pleroma uses.

From the spec: Free form key value pairs for software specific values. Clients should not rely on any specific key present.

type NodeInfo

type NodeInfo struct {
	Metadata          Metadata       `json:"metadata"`
	OpenRegistrations bool           `json:"openRegistrations"`
	Protocols         []NodeProtocol `json:"protocols"`
	Services          Services       `json:"services"`
	Software          SoftwareInfo   `json:"software"`
	Usage             Usage          `json:"usage"`
	Version           string         `json:"version"`
}

NodeInfo includes all required node info.

type NodeProtocol

type NodeProtocol string

type NodeService

type NodeService string

type Resolver

type Resolver interface {
	// IsOpenRegistration returns whether or not registration is open on this node.
	IsOpenRegistration() (bool, error)
	// Usage returns usage stats for this node.
	Usage() (Usage, error)
}

type Service

type Service struct {
	InfoURL string
	Info    NodeInfo
	// contains filtered or unexported fields
}

func NewService

func NewService(cfg Config, r Resolver) *Service

func (Service) BuildInfo

func (s Service) BuildInfo() NodeInfo

func (*Service) NodeInfo

func (s *Service) NodeInfo(w http.ResponseWriter, r *http.Request)

func (*Service) NodeInfoDiscover

func (s *Service) NodeInfoDiscover(w http.ResponseWriter, r *http.Request)

type Services

type Services struct {
	Inbound  []NodeService `json:"inbound"`
	Outbound []NodeService `json:"outbound"`
}

type SoftwareInfo

type SoftwareInfo struct {
	// Name (canonical) of this server software.
	Name string `json:"name"`
	// Version of this server software.
	Version string `json:"version"`
}

type SoftwareMeta

type SoftwareMeta struct {
	HomePage string `json:"homepage"`
	GitHub   string `json:"github"`
	Follow   string `json:"follow"`
}

type Usage

type Usage struct {
	Users         UsageUsers `json:"users"`
	LocalPosts    int        `json:"localPosts,omitempty"`
	LocalComments int        `json:"localComments,omitempty"`
}

Usage is usage statistics for this server.

type UsageUsers

type UsageUsers struct {
	Total          int `json:"total,omitempty"`
	ActiveHalfYear int `json:"activeHalfyear,omitempty"`
	ActiveMonth    int `json:"activeMonth,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL