lokerpc

package
v0.0.0-...-2222f40 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentType defines the content type to be served.
	ContentType = "application/json; charset=utf-8"
)

Variables

This section is empty.

Functions

func DecodeRequest

func DecodeRequest[Req any](_ context.Context, msg json.RawMessage) (any, error)

func FieldNames

func FieldNames(i interface{}) []string

func MountHandlers

func MountHandlers(logger log.Logger, mux Mux, services ...*Service)

MountHandlers mounts all the service endpoints onto the mux Endpoints are mounted at

POST /rpc/<service>/<method>

Meta data is serviced from

GET /rpc
GET /rpc/<service>

func NewServer deprecated

func NewServer(serviceName string, ecm EndpointCodecMap, logger log.Logger) http.Handler

NewServer constructs a new server, which implements http.Handler.

Deprecated: Use the MountHandlers with Services instead

func TypeSchema

func TypeSchema(t reflect.Type, defs map[string]jtd.Schema) *jtd.Schema

Types

type DecodeRequestFunc

type DecodeRequestFunc func(context.Context, json.RawMessage) (request interface{}, err error)

type EncodeResponseFunc

type EncodeResponseFunc func(context.Context, interface{}) (response json.RawMessage, err error)

type Endpoint

type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error)

Endpoint is an abstract rpc endpoint

func MakeStandardEndpoint

func MakeStandardEndpoint[Req any, Res any](method StandardMethod[Req, Res]) Endpoint

type EndpointCodec

type EndpointCodec struct {
	Endpoint   Endpoint
	Decode     DecodeRequestFunc
	Help       string
	ParamNames []string
	// contains filtered or unexported fields
}

EndpointCodec defines a server Endpoint and its associated codecs

func MakeStandardEndpointCodec

func MakeStandardEndpointCodec[Req any, Res any](method StandardMethod[Req, Res], help string, opts ...EndpointCodecOption) EndpointCodec

MakeStandardEndpointCodec

type EndpointCodecMap

type EndpointCodecMap map[string]EndpointCodec

EndpointCodecMap maps the Request.Method to the proper EndpointCodec

type EndpointCodecOption

type EndpointCodecOption func(*EndpointCodec)

func NoNilResponse

func NoNilResponse() EndpointCodecOption

type EndpointMeta

type EndpointMeta struct {
	MethodName      string      `json:"methodName"`
	ParamNames      []string    `json:"paramNames"`
	MethodTimeout   int         `json:"methodTimeout"`
	Help            string      `json:"help"`
	RequestTypeDef  *jtd.Schema `json:"requestTypeDef,omitempty"`
	ResponseTypeDef *jtd.Schema `json:"responseTypeDef,omitempty"`
}

type Failer

type Failer interface {
	Failed() error
}

type Meta

type Meta struct {
	ServiceName string                `json:"serviceName"`
	MultiArg    bool                  `json:"multiArg"`
	Help        string                `json:"help"`
	Interfaces  []EndpointMeta        `json:"interfaces"`
	Definitions map[string]jtd.Schema `json:"definitions,omitempty"`
}

type Mux

type Mux interface {
	Handle(pattern string, handler http.Handler)
}

type Resulter

type Resulter interface {
	Result() interface{}
}

type RootMeta

type RootMeta struct {
	Services []*Meta `json:"services"`
}

type Service

type Service struct {
	Name string
	Help string
	// contains filtered or unexported fields
}

Service

func NewService

func NewService(name, help string, ecm EndpointCodecMap) *Service

NewService creates a new Service

type StandardMethod

type StandardMethod[Req any, Res any] func(context.Context, Req) (Res, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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