Help us shape the future of Go! Take the 2026 Go Developer Survey

gomif

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2017 License: MIT Imports: 8 Imported by: 0

README

gomif

GoDoc wercker status

GO Mastodon Instance status Fetcher

Examples

Use as CLI
$ go get -u github.com/m0t0k1ch1/gomif/cmd/gomif
$ gomif -i mastodon.m0t0k1ch1.com | jq .
{
  "date": 1492689362,
  "up": true,
  "users": 1,
  "statuses": 15,
  "connections": 17,
  "openRegistrations": false,
  "uptime": 0.9946714031971581,
  "https_rank": "A+",
  "https_score": 100,
  "ipv6": true
}
Use in code
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	"github.com/m0t0k1ch1/gomif"
)

func main() {
	client := gomif.NewClient()

	status, err := client.FetchLastInstanceStatus(
		context.Background(),
		"mastodon.m0t0k1ch1.com",
		3600, // span (sec)
	)
	if err != nil {
		log.Fatal(err)
	}

	b, err := json.Marshal(status)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(b))
}
{
  "date": 1492689362,
  "up": true,
  "users": 1,
  "statuses": 15,
  "connections": 17,
  "openRegistrations": false,
  "uptime": 0.9946714031971581,
  "https_rank": "A+",
  "https_score": 100,
  "ipv6": true
}

Documentation

Index

Constants

View Source
const (
	DefaultUri = "https://instances.mastodon.xyz/api/instances/history.json"
)

Variables

View Source
var (
	ErrInstanceNotFound            = errors.New("instance not found")
	ErrFailedToFetchInstanceStatus = errors.New("failed to fetch instanceStatus")
	ErrNoInstanceStatus            = errors.New("no instance status")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) FetchInstanceStatuses

func (client *Client) FetchInstanceStatuses(ctx context.Context, name string, start, end int64) ([]*InstanceStatus, error)

func (*Client) FetchLastInstanceStatus

func (client *Client) FetchLastInstanceStatus(ctx context.Context, name string, span int64) (*InstanceStatus, error)

func (*Client) SetUri

func (client *Client) SetUri(uri string)

type Config

type Config struct {
	Uri string
}

type InstanceStatus

type InstanceStatus struct {
	Date              int64   `json:"date"`
	Up                bool    `json:"up"`
	Users             int     `json:"users"`
	Statuses          int     `json:"statuses"`
	Connections       int     `json:"connections"`
	OpenRegistrations bool    `json:"openRegistrations"`
	Uptime            float64 `json:"uptime"`
	HttpsRank         string  `json:"https_rank"`
	HttpsScore        float64 `json:"https_score"`
	IPv6              bool    `json:"ipv6"`
}

Directories

Path Synopsis
cmd
gomif command

Jump to

Keyboard shortcuts

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