rpc

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParseError            = -32700
	ParseErrorMessage     = "Parse error"
	InvalidRequest        = -32600
	InvalidRequestMessage = "Invalid request"
	MethodNotFound        = -32601
	MethodNotFoundMessage = "Method not found"
	InvalidParams         = -32602
	InvalidParamsMessage  = "Invalid params"
	InternalError         = -32603
	InternalErrorMessage  = "Internal error"
	// Implementation-defined errors
	CallerError        = -32000
	ServerErrorMessage = "Server error"
)
View Source
const ScopeName = "github.com/kofuk/premises/runner/internal/rpc"

Variables

View Source
var (
	ToExteriord      = NewClient(env.DataPath("rpc@exteriord"))
	ToSnapshotHelper = NewClient(env.DataPath("rpc@snapshot-helper"))
	ToLauncher       = NewClient(env.DataPath("rpc@launcher"))
	ToConnector      = NewClient(env.DataPath("rpc@connector"))
)

Functions

func InitializeDefaultServer

func InitializeDefaultServer(path string)

Types

type AbstractRequest

type AbstractRequest Request[json.RawMessage]

func (*AbstractRequest) Bind

func (req *AbstractRequest) Bind(v any) error

type Client

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

func NewClient

func NewClient(path string) *Client

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params, result any) error

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, method string, params any) error

type HandlerFunc

type HandlerFunc func(ctx context.Context, req *AbstractRequest) (any, error)

type NotifyHandlerFunc

type NotifyHandlerFunc func(ctx context.Context, req *AbstractRequest) error

type Packet added in v0.3.0

type Packet struct {
	ContentLength int
	Traceparent   string
	Body          json.RawMessage
}

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    string `json:"data,omitempty"`
}

func (*RPCError) Error

func (e *RPCError) Error() string

type Request

type Request[T any] struct {
	Version     string `json:"jsonrpc"`
	ID          *int   `json:"id,omitempty"`
	Method      string `json:"method"`
	Params      T      `json:"params"`
	Traceparent string `json:"-"`
}

type Response

type Response[T any] struct {
	Version     string    `json:"jsonrpc"`
	ID          int       `json:"id"`
	Result      T         `json:"result,omitempty"`
	Error       *RPCError `json:"error,omitempty"`
	Traceparent string    `json:"-"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}
var DefaultServer *Server

func NewServer

func NewServer(path string) *Server

func (*Server) RegisterMethod

func (s *Server) RegisterMethod(name string, fn HandlerFunc)

func (*Server) RegisterNotifyMethod

func (s *Server) RegisterNotifyMethod(name string, fn NotifyHandlerFunc)

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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