Documentation ¶
Overview ¶
Package server implements an ATproto labeler, using SQLite 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 ¶
- type Entry
- type Server
- func (s *Server) AddLabel(ctx context.Context, label comatproto.LabelDefs_Label) (bool, error)
- func (s *Server) ImportEntries(entries map[int64]comatproto.LabelDefs_Label) error
- func (s *Server) IsEmpty() (bool, error)
- func (s *Server) LabelEntries(ctx context.Context, labelName string) ([]comatproto.LabelDefs_Label, error)
- func (s *Server) Query() http.Handler
- func (s *Server) SetAllowedLabels(labels []string)
- func (s *Server) Subscribe() http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct { Seq int64 `gorm:"type:INTEGER PRIMARY KEY;primaryKey"` Cts string `gorm:"not null"` Uri string `gorm:"not null;index:idx_lookups,priority:1"` Val string `gorm:"not null;index:idx_lookups,priority:2"` Src string `gorm:"not null;index:idx_lookups,priority:3"` Cid string `gorm:"index:idx_lookups,priority:4"` Exp string Neg bool `gorm:"default:false"` }
func (*Entry) FromLabel ¶ added in v0.3.0
func (e *Entry) FromLabel(seq int64, other comatproto.LabelDefs_Label) *Entry
func (*Entry) ToLabel ¶ added in v0.3.0
func (e *Entry) ToLabel() comatproto.LabelDefs_Label
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewWithConfig ¶ added in v0.3.0
NewWithConfig creates a new server instance using parameters provided in the config.
func (*Server) AddLabel ¶
func (s *Server) AddLabel(ctx context.Context, 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) 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.
func (*Server) IsEmpty ¶ added in v0.2.0
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 ¶
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 ¶
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.