lokerpc

package
v0.0.0-...-6215b59 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package lokerpc implements LOKE's HTTP RPC server and client, including request schemas, Prometheus request metrics, and code generation for typed clients.

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 TypeDefs

func TypeDefs(tdefs map[reflect.Type]*NamedSchema) map[string]jtd.Schema

func TypeSchema

func TypeSchema(t reflect.Type, tdefs map[reflect.Type]*NamedSchema) *jtd.Schema

Types

type Client

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

func NewClient

func NewClient(baseURL string) Client

func (Client) DoRequest

func (c Client) DoRequest(ctx context.Context, method string, args, result any) (finalErr error)

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

func MakeVoidEndpoint

func MakeVoidEndpoint[Req any](method VoidMethod[Req]) 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

func MakeVoidEndpointCodec

func MakeVoidEndpointCodec[Req any](method VoidMethod[Req], help string, opts ...EndpointCodecOption) EndpointCodec

MakeVoidEndpointCodec creates an EndpointCodec for methods that return no value. The generated metadata will include "void": true on the response type.

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 NamedSchema

type NamedSchema struct {
	Name    string
	SortKey string
	Schema  jtd.Schema
}

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)

type VoidMethod

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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