xrpc

package
v0.0.0-...-e6a591c Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = &ErrorResponse{
	Code:    MethodNotImplemented,
	Message: "Not Implemented",
	Status:  http.StatusNotImplemented,
}

Functions

func NewMethod

func NewMethod(nsid syntax.NSID, typ RequestType) *rpcMethod

func NewReqBuilder

func NewReqBuilder() *requestBuilder

func Stream

func Stream[T any](ctx context.Context, c *websocket.Conn, seq iter.Seq[T]) (err error)

func WriteError

func WriteError(l *slog.Logger, w http.ResponseWriter, err error, defaultStatus Code)

func WriteInvalidRequest

func WriteInvalidRequest(l *slog.Logger, w http.ResponseWriter, err error, msg string, args ...any)

Types

type Auth

type Auth struct {
	AccessJwt  string `json:"accessJwt"`
	RefreshJwt string `json:"refreshJwt"`
	Handle     string `json:"handle"`
	DID        string `json:"did"`
}

type Client

type Client struct {
	Client     *http.Client
	Insecure   bool
	Host       string
	AdminToken *string
	Auth       *Auth
}

func NewClient

func NewClient(opts ...ClientOption) *Client

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

func (*Client) Procedure

func (c *Client) Procedure(ctx context.Context, req *Request) (io.ReadCloser, error)

func (*Client) Query

func (c *Client) Query(ctx context.Context, req *Request) (io.ReadCloser, error)

func (*Client) Subscription

func (c *Client) Subscription(ctx context.Context)

type ClientOption

type ClientOption func(*Client)

func WithAdminPassword

func WithAdminPassword(pw string) ClientOption

func WithClient

func WithClient(client *http.Client) ClientOption

func WithEnv

func WithEnv() ClientOption

func WithHost

func WithHost(host string) ClientOption

func WithInsecure

func WithInsecure() ClientOption

func WithJwt

func WithJwt(token string) ClientOption

func WithURL

func WithURL(uri string) ClientOption

type Code

type Code string
const (
	Unknown              Code = "Unknown"
	InvalidResponse      Code = "InvalidResponse"
	Success              Code = "Success"
	InvalidRequest       Code = "InvalidRequest"
	AuthRequired         Code = "AuthRequired"
	Forbidden            Code = "Forbidden"
	XRPCNotSupported     Code = "XRPCNotSupported"
	NotAcceptable        Code = "NotAcceptable"
	PayloadTooLarge      Code = "PayloadTooLarge"
	UnsupportedMediaType Code = "UnsupportedMediaType"
	RateLimitExceeded    Code = "RateLimitExceeded"
	InternalServerError  Code = "InternalServerError"
	MethodNotImplemented Code = "MethodNotImplemented"
	UpstreamFailure      Code = "UpstreamFailure"
	NotEnoughResources   Code = "NotEnoughResources"
	UpstreamTimeout      Code = "UpstreamTimeout"
)
const (
	RecordNotFound Code = "RecordNotFound"
	RepoNotFound   Code = "RepoNotFound"
)

Other Codes

func CodeFromStatus

func CodeFromStatus(status int) Code

func (Code) MarshalText

func (c Code) MarshalText() ([]byte, error)

func (Code) Message

func (c Code) Message() string

func (Code) Status

func (c Code) Status() int

func (Code) String

func (c Code) String() string

type ErrorResponse

type ErrorResponse struct {
	Code    Code   `json:"error"`
	Message string `json:"message"`

	// Status is for RPC handlers. Should not be send back to clients.
	Status int `json:"-"`
	// Inner is a private internal error associated with the response.
	Inner error `json:"-"`
}

func NewAuthRequired

func NewAuthRequired(msg string, args ...any) *ErrorResponse

func NewInternalError

func NewInternalError(msg string, args ...any) *ErrorResponse

func NewInvalidRequest

func NewInvalidRequest(msg string, args ...any) *ErrorResponse

func Status

func Status(status int, msg string) *ErrorResponse

func Wrap

func Wrap(err error, code Code, msg string) *ErrorResponse

func Wrapf

func Wrapf(err error, code Code, format string, args ...any) *ErrorResponse

func (*ErrorResponse) Cause

func (er *ErrorResponse) Cause() error

Cause is for errors.Cause.

func (*ErrorResponse) Error

func (er *ErrorResponse) Error() string

func (*ErrorResponse) Unwrap

func (er *ErrorResponse) Unwrap() error

func (*ErrorResponse) WithMsg

func (er *ErrorResponse) WithMsg(message string) *ErrorResponse

WithMsg sets the Message field.

func (*ErrorResponse) WithMsgf

func (er *ErrorResponse) WithMsgf(format string, args ...any) *ErrorResponse

WithMsgf sets the Message field with an fmt.Sprintf format string.

func (*ErrorResponse) WithStatus

func (er *ErrorResponse) WithStatus(status int) *ErrorResponse

WithStatus sets the Status field.

func (*ErrorResponse) Wrap

func (er *ErrorResponse) Wrap(err error) *ErrorResponse

Wrap sets the Inner error field.

type FromQuery

type FromQuery interface {
	FromQuery(url.Values) error
}

type MetaContextKey

type MetaContextKey string

type Method

type Method interface {
	NSID() syntax.NSID
	Type() RequestType
}

type Pipethrough

type Pipethrough struct {
	Host   string
	Client *http.Client
	Logger *slog.Logger
}

func NewPipethrough

func NewPipethrough(host string) *Pipethrough

func (*Pipethrough) ServeHTTP

func (p *Pipethrough) ServeHTTP(w http.ResponseWriter, req *http.Request)

type RPC

type RPC interface {
	Method() Method
	http.Handler
}

type Request

type Request struct {
	Type        RequestType
	ContentType string
	NSID        string
	Params      url.Values
	Body        io.Reader
}

func RequestFromHttp

func RequestFromHttp(r *http.Request) *Request

type RequestBuilder

type RequestBuilder interface {
	Build() (*http.Request, error)
	Err() error
	Type(RequestType) RequestBuilder
	Insecure() RequestBuilder
	Host(string) RequestBuilder
	NSID(syntax.NSID) RequestBuilder
	Query(url.Values) RequestBuilder
	Body(io.Reader) RequestBuilder
}

type RequestType

type RequestType int
const (
	Query RequestType = iota + 1
	Procedure
	Subscription
)

func ComAtprotoRequestType

func ComAtprotoRequestType(nsid string) RequestType

type Server

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

func NewServer

func NewServer() *Server

func (*Server) AddHandler

func (s *Server) AddHandler(method Method, handler http.Handler, middleware ...func(http.Handler) http.Handler)

func (*Server) AddHandlers

func (s *Server) AddHandlers(appliers ...interface {
	Apply(*Server, ...func(http.Handler) http.Handler)
})

func (*Server) AddRPCs

func (s *Server) AddRPCs(rpcs ...RPC)

func (*Server) Router

func (s *Server) Router() chi.Router

Router returns the internal router.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) With

func (s *Server) With(middleware ...func(http.Handler) http.Handler) *Server

Directories

Path Synopsis
cmd
server command

Jump to

Keyboard shortcuts

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