routerplugin

package module
v0.0.0-...-81f247c Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 1

README

Cosmo Router Plugin

This package provides a simple framework for building gRPC-based plugins for the Cosmo router.

Overview

The Router Plugin system allows you to extend the Cosmo router with custom gRPC services. This README focuses on how to build a server-side plugin.

Getting Started

Read the official documentation for the Cosmo router to understand how to set up your environment and build a plugin.

API Reference

The router plugin package provides a simple API:

  • NewRouterPlugin(registrationFunc func(*grpc.Server)) (*RouterPlugin, error): Creates a new router plugin with a function to register services
  • (*RouterPlugin) Serve(): Starts serving the plugin

Requirements

  • Go 1.16 or later
  • Protocol Buffer compiler (protoc)
  • Go plugins for Protocol Buffers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PluginMapName = "grpc_datasource"

PluginMapName is the name of the plugin in the plugin map.

View Source
var RouterPluginHandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "GRPC_DATASOURCE_PLUGIN",
	MagicCookieValue: "GRPC_DATASOURCE_PLUGIN",
}

HandshakeConfig is the handshake config for the plugin.

Functions

This section is empty.

Types

type PluginOption

type PluginOption func(*RouterPlugin)

func WithCustomLogger

func WithCustomLogger(logger hclog.Logger) PluginOption

WithCustomLogger sets the logger to the provided logger. This is useful for when you want to use a custom logger. For example, when you want to use a custom logger for the plugin.

func WithLogger

func WithLogger(level hclog.Level) PluginOption

WithLogger configures a plugin logger at the provided level. The `level` parameter is the level of the logger.

func WithServiceName

func WithServiceName(serviceName string) PluginOption

WithServiceName sets the service name for the plugin.

func WithServiceVersion

func WithServiceVersion(serviceVersion string) PluginOption

WithServiceVersion sets the service version for the plugin.

func WithTestConfig

func WithTestConfig(testConfig *plugin.ServeTestConfig) PluginOption

func WithTracing

func WithTracing() PluginOption

WithTracing enables tracing for the plugin. This includes creating a tracing interceptor

func WithTracingErrorHandler

func WithTracingErrorHandler(errHandler func(err error)) PluginOption

WithTracingErrorHandler sets the tracing error handler for the plugin.

type RouterPlugin

type RouterPlugin struct {
	plugin.Plugin
	// contains filtered or unexported fields
}

func NewRouterPlugin

func NewRouterPlugin(registrationfunc func(*grpc.Server), opts ...PluginOption) (*RouterPlugin, error)

func (*RouterPlugin) GRPCClient

func (p *RouterPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, cc *grpc.ClientConn) (interface{}, error)

GRPCClient is the interface that is implemented to serve/connect to a plugin over gRPC.

func (*RouterPlugin) GRPCServer

func (p *RouterPlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error

GRPCPlugin is the interface that is implemented to serve/connect to a plugin over gRPC.

func (*RouterPlugin) Serve

func (r *RouterPlugin) Serve()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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