rpc

package module
v0.0.0-...-790c65b Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

README

go-rpc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRequest = errors.New("invalid request payload")
	ErrNoResponse     = errors.New("no response")
)

Functions

func Call

func Call[Req any, Res any](
	client *ServiceClient,
	req *Request[Req, Res],
) (*Res, error)

func DecodeJSON

func DecodeJSON[T any](r io.Reader) (T, error)

func DecodeReq

func DecodeReq[T any](r *http.Request) (T, error)

func EncodeJSON

func EncodeJSON[T any](w http.ResponseWriter, payload *T) error

func JsonError

func JsonError(w http.ResponseWriter, statusCode int, err error)

func Register

func Register[Req any, Res any](
	service *Service,
	name string,
	handler ServiceHandler[Req, Res],
)

Types

type Request

type Request[Req any, Res any] struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest[Req any, Res any](
	ctx context.Context,
	name string,
	payload *Req,
) *Request[Req, Res]

type Service

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

func NewService

func NewService(name string, addr string, service ServiceImpl) *Service

func (*Service) Name

func (s *Service) Name() string

func (*Service) Run

func (s *Service) Run()

func (*Service) Stop

func (s *Service) Stop()

type ServiceClient

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

func NewServiceClient

func NewServiceClient(name, addr string) (*ServiceClient, error)

func (*ServiceClient) Call

func (c *ServiceClient) Call(
	ctx context.Context,
	name string,
	payload io.Reader,
) (*http.Response, error)

type ServiceHandler

type ServiceHandler[Req any, Res any] func(
	ctx context.Context,
	req *Req,
) (*Res, error)

type ServiceImpl

type ServiceImpl interface {
	Init(service *Service)
}

Directories

Path Synopsis
examples
api

Jump to

Keyboard shortcuts

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