nodeinfo

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 7 Imported by: 1

README

nodeinfo-go

golang lib to query federation node information.

Based on Well-known URI for nodeinfo and matrix discovery it obtains node information(s) about it's service and user stats.

This repo also contains a small CLI tool to use this lib.

Lib

go get "codeberg.org/thefederationinfo/nodeinfo-go"
import "codeberg.org/thefederationinfo/nodeinfo-go"

func main() {
  // ...
  testNodeInfos, err := nodeinfo.QueryNode("example.org")
  // ...
}

CLI Tool

how to build:

  1. have go compiler installed
  2. clone this repo
  3. cd into cli folder
  4. go build .

exec: ./nodeinfo <node domain>

Documentation

Index

Constants

View Source
const (
	ProtocolMatrix = "matrix"
)

Variables

This section is empty.

Functions

func Extend added in v0.3.0

func Extend(client *http.Client, domain string, node *Node) error

func RegisterExtension added in v0.3.0

func RegisterExtension(e Extension)

func RegisterGenericExtension added in v0.3.0

func RegisterGenericExtension(e Extension)

Types

type Extension added in v0.3.0

type Extension interface {
	Name() string
	Extend(client *http.Client, domain string, node *Node) error
}

type Fetcher added in v0.2.1

type Fetcher interface {
	QueryNode(domain string) ([]*Node, error)
}

func NewFetcher added in v0.2.1

func NewFetcher(opts ...QueryNodeOption) (Fetcher, error)

type Node

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

Node metadata about a server running in the federation

func QueryNode

func QueryNode(domain string, opts ...QueryNodeOption) ([]*Node, error)

QueryNode fetch node info based on domain, can return more than one node if e.g. matrix and mastodon share the same domain name

type QueryNodeOption

type QueryNodeOption func(f *fetcher) error

QueryNodeOption are functions to be used as options for QueryNode

func QueryOptionClient

func QueryOptionClient(c *http.Client) QueryNodeOption

QueryOptionClient return an option for QueryNode that can set an specific http client

func QueryOptionNoMatrix added in v0.1.0

func QueryOptionNoMatrix() QueryNodeOption

QueryOptionNoMatrix do not discovery based on the matrix specification

func QueryOptionNoNodeinfo added in v0.1.0

func QueryOptionNoNodeinfo() QueryNodeOption

QueryOptionNoNodeinfo do not discovery based on the nodeinfo2 specification

type Services

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

Services tell about third party sites the node can connect to or interact with

type Software

type Software struct {
	Name       string `json:"name"`
	Version    string `json:"version"`
	Repository string `json:"repository"`
	Homepage   string `json:"homepage"`
}

Software is about node software

type Usage

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

Usage are usage statistics for the node

type UsersUsage

type UsersUsage struct {
	Total          int64 `json:"total,omitempty"`
	ActiveHalfyear int64 `json:"activeHalfyear,omitempty"`
	ActiveMonth    int64 `json:"activeMonth,omitempty"`
}

UsersUsage are statistics about the users of the node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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