misskey

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: GPL-3.0 Imports: 22 Imported by: 6

README

Go Report Card Coverage Status GoDoc Chat on Matrix

Misskey Go SDK

Misskey API Documentation: https://slippy.xyz/api-doc

Check the docs directory for more information.

For examples on given endpoints, please check the corresponding _test.go file, they have at least one ExampleService_XYZ function, examples:

Progress

Status Endpoint Group Implementation Issue Note
antennas #3
app #5
clips #8
drive #9
federation #4
following #10
groups #19
hashtags #12
meta
notes #6
notifications #15
reactions #14
admin #21 In Progress (84%)
account
auth
channels
charts #7
list #20
messaging #13
pages #16
users #17

How to use

For detailed examples, check the example directory.

package main

import (
  "log"

  "github.com/sirupsen/logrus"
  "github.com/yitsushi/go-misskey"
  "github.com/yitsushi/go-misskey/core"
  "github.com/yitsushi/go-misskey/services/meta"
)

func main() {
	client, err := misskey.NewClientWithOptions(
		misskey.WithAPIToken(os.Getenv("MISSKEY_TOKEN")),
		misskey.WithBaseURL("https", "slippy.xyz", ""),
		misskey.WithLogLevel(logrus.DebugLevel),
	)
	if err != nil {
		logrus.Error(err.Error())
	}

  stats, err := client.Meta().Stats()
  if err != nil {
    log.Printf("[Meta] Error happened: %s", err)
    return
  }

  log.Printf("[Stats] Instances:          %d", stats.Instances)
  log.Printf("[Stats] NotesCount:         %d", stats.NotesCount)
  log.Printf("[Stats] UsersCount:         %d", stats.UsersCount)
  log.Printf("[Stats] OriginalNotesCount: %d", stats.OriginalNotesCount)
  log.Printf("[Stats] OriginalUsersCount: %d", stats.OriginalUsersCount)
}

How can I get a Misskey Token?

Navigate to Settings > API and there you generate a new token.

How can I debug what's wrong?

There is a logging system, right now it's not very wide spread in the codebase, but if you turn it on, you will be able to see:

  • all request with method, endpoint and body
  • all responds with status code, from what endpoint told and the body

To enable debug mode, just change the LogLevel to DebugLevel:

client, _ := misskey.NewClientWithOptions(
  misskey.WithAPIToken(os.Getenv("MISSKEY_TOKEN")),
  misskey.WithBaseURL("https", "slippy.xyz", ""),
  misskey.WithLogLevel(logrus.DebugLevel),
)

The output should look like this:

DEBU[0000] POST https://slippy.xyz/api/antennas/show     _type=request
DEBU[0000] {"antennaId":"8dbpybhulw","i":"my misskey token"}  _type=request
DEBU[0000] {"id":"8dbpybhulw","createdAt":"2020-10-13T16:03:22.674Z","name":"Genshin Impact","keywords":[["genshin"]],"excludeKeywords":[[""]],"src":"all","userListId":null,"userGroupId":null,"users":[""],"caseSensitive":false,"notify":false,"withReplies":true,"withFile":false,"hasUnreadNote":false}  _type=response code=200 from="https://slippy.xyz/api/antennas/show"

Documentation

Index

Constants

View Source
const RequestTimout = 10

RequestTimout is the timeout of a request in seconds.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL    string
	Token      string
	HTTPClient core.HTTPClient
	// contains filtered or unexported fields
}

Client is the main Misskey client struct.

func NewClient deprecated

func NewClient(baseURL, token string) *Client

NewClient creates a new Misskey Client.

Deprecated: use NewClientWithOptions instead.

func NewClientWithOptions added in v1.1.0

func NewClientWithOptions(options ...ClientOption) (*Client, error)

NewClientWithOptions creates a new Misskey Client with defined options.

func (*Client) Admin added in v1.0.1

func (c *Client) Admin() *admin.Service

Admin contains all endpoints under /admin.

func (*Client) Antennas

func (c *Client) Antennas() *antennas.Service

Antennas contains all endpoints under /antennas.

func (*Client) App added in v1.1.1

func (c *Client) App() *app.Service

App contains all endpoints under /app.

func (*Client) Clips

func (c *Client) Clips() *clips.Service

Clips contains all endpoints under /clips.

func (*Client) Drive

func (c *Client) Drive() *drive.Service

Drive contains all endpoints under /drive.

func (*Client) Federation

func (c *Client) Federation() *federation.Service

Federation contains all endpoints under /federation.

func (*Client) Following added in v1.0.2

func (c *Client) Following() *following.Service

Following contains all endpoints under /following.

func (*Client) Hashtags

func (c *Client) Hashtags() *hashtags.Service

Hashtags contains all endpoints under /hashtags.

func (*Client) LogLevel

func (c *Client) LogLevel(level logrus.Level)

LogLevel sets logger level.

func (*Client) Meta

func (c *Client) Meta() *meta.Service

Meta is all the endpoints under Meta in the documentation. They don't have an API pth prefix.

func (*Client) Notes

func (c *Client) Notes() *notes.Service

Notes contains all endpoints under /notes.

func (*Client) Notifications

func (c *Client) Notifications() *notifications.Service

Notifications contains all endpoints under /notifications.

func (*Client) Promo

func (c *Client) Promo() *promo.Service

Promo contains all endpoints under /promo.

func (*Client) Users added in v1.0.4

func (c *Client) Users() *users.Service

Users contains all endpoints under /users.

type ClientOption added in v1.1.0

type ClientOption func(*Client) error

ClientOption is a function that can be used to configure a client.

func WithAPIToken added in v1.1.0

func WithAPIToken(token string) ClientOption

WithAPIToken configures the API token on the client.

func WithBaseURL added in v1.1.0

func WithBaseURL(protocol, domain, path string) ClientOption

WithBaseURL configures the base url of the Misskey instance.

  • Protocol: http, https
  • Domain: Well, that's the domain name
  • Path: Leave it empty, unless the target instance is not served from the root path. Important: Do not add a tailing slash.

func WithHTTPClient added in v1.1.0

func WithHTTPClient(httpClient core.HTTPClient) ClientOption

WithHTTPClient configures an HTTP Client instead of creating a new one.

func WithLogLevel added in v1.1.0

func WithLogLevel(level logrus.Level) ClientOption

WithLogLevel configures the logger to use the specified log level.

func WithSimpleConfig added in v1.1.0

func WithSimpleConfig(baseURL, token string) ClientOption

WithSimpleConfig configures the client with similar logic as NewClient().

The sole purpose of this to make it easier to migrate to the new function.

type ClientOptionError added in v1.1.0

type ClientOptionError struct {
	Message string
}

ClientOptionError occures when something goes wrong with any of the requested options.

func (ClientOptionError) Error added in v1.1.0

func (e ClientOptionError) Error() string

Jump to

Keyboard shortcuts

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