server

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package server implements an ATproto labeler, using [bbolt](https://github.com/etcd-io/bbolt) as storage.

Example usage:

    server, err := server.New(ctx, config.DBFile, config.DID, key)
    if err != nil {
	       return fmt.Errorf("instantiating a server: %w", err)
    }
    http.Handle("/xrpc/com.atproto.label.subscribeLabels", server.Subscribe())
    http.Handle("/xrpc/com.atproto.label.queryLabels", server.Query())
    http.ListenAndServe(":8080", nil)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, path string, did string, key *secec.PrivateKey) (*Server, error)

New creates and returns a new server instance.

func (*Server) AddLabel

func (s *Server) AddLabel(label comatproto.LabelDefs_Label) (bool, error)

AddLabel updates the internal state and writes the label to the database.

Note that it will ignore values that have no effect (e.g., if the label already exists, or trying to negate a label that doesn't exist). Return value indicates if there was a change or not.

func (*Server) DoNotUseUnlessYouKnowWhatYoureDoing_BumpLastKeyTo

func (s *Server) DoNotUseUnlessYouKnowWhatYoureDoing_BumpLastKeyTo(n int64) error

func (*Server) ImportEntries added in v0.2.0

func (s *Server) ImportEntries(entries map[int64]comatproto.LabelDefs_Label) error

ImportEntries populates an empty server with the given entries. Each entry is written at a sequence number equal to the map key.

Note that this method does not update the in-memory state of the server, so it must be restarted before serving any requests.

func (*Server) IsEmpty added in v0.2.0

func (s *Server) IsEmpty() (bool, error)

IsEmpty returns true if there are no labels in the database.

func (*Server) LabelEntries

func (s *Server) LabelEntries(ctx context.Context, labelName string) ([]comatproto.LabelDefs_Label, error)

LabelEntries returns all non-negated label entries for the provided label name. Does not filter out expired entries.

func (*Server) Query

func (s *Server) Query() http.Handler

Query returns HTTP handler that implements [com.atproto.label.queryLabels](https://docs.bsky.app/docs/api/com-atproto-label-query-labels) XRPC method.

func (*Server) SetAllowedLabels

func (s *Server) SetAllowedLabels(labels []string)

SetAllowedLabels limits what label values can be used for new labels. Old existing labels are not affected, and label negations are also always allowed. By default all labels are allowed.

func (*Server) Subscribe

func (s *Server) Subscribe() http.Handler

Subscribe returns HTTP handler that implements [com.atproto.label.subscribeLabels](https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/label/subscribeLabels.json) XRPC method.

Jump to

Keyboard shortcuts

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