SDK Reference
The GatewayD plugin SDK provides a number of interfaces, structs and methods to help you build your plugin. This section provides a reference to all of them. The SDK is built for Go, but the protocol buffers definitions can be used to build plugins in other languages.
This documentation is not complete. Please refer to the SDK source code for more information. Also, it might be removed in the future in favor of GoDoc.
The SDK is still in development and subject to change.
Packages
The root of the SDK is the github.com/gatewayd-io/gatewayd-plugin-sdk. It contains the following sub-packages:
config
-
GetEnvreturns the value of an environment variable. If the environment variable is not set, it returns the default value as fallback.func GetEnv(key, fallback string) string
databases/postgres
-
IsPostgresStartupMessagechecks if a message is a Postgres startup message. It returnstrueif the message is a startup message,falseotherwise.func IsPostgresStartupMessage(message []byte) bool -
DecodeBytesdecodes a base64 encoded string to bytes. It uses thebase64.StdEncodingdecoder. It returns the decoded bytes and an empty byte array if there is an error.func DecodeBytes(encoded string) ([]byte, error) -
HandleClientMessagehandles a client message. This function should be called fromonTrafficFromClienthook. It returns av1.Structwith extra fields that are decoded from the message. It logs the error and returnsnilif there is an error.func HandleClientMessage(req *v1.Struct, logger hclog.Logger) (*v1.Struct, error) -
HandleServerMessagehandles a server message. This function should be called fromonTrafficFromServerhook. It returns av1.Structwith extra fields that are decoded from the message. It logs the error and returnsnilif there is an error.func HandleServerMessage(resp *v1.Struct, logger hclog.Logger) (*v1.Struct, error) -
GetQueryFromRequestdecodes the request and returns the query. It returns an error if the request cannot be decoded. It returns an empty string if the query is not found.func GetQueryFromRequest(req *v1.Struct) (string, error) -
GetTablesFromQueryreturns the tables used in a query. It returns an error if the query cannot be parsed.func GetTablesFromQuery(query string) ([]string, error)
logging
-
GetLogLevelreturns thehcloglevel based on the (log level) string passed in.func GetLogLevel(level string) hclog.Level
metrics
-
NewMetricsConfigreturns a newMetricsConfigstruct. It returns an error if the environment variables are not set. It returnsnilif the metrics are disabled.func NewMetricsConfig(config map[string]interface{}) *MetricsConfig -
ExposeMetricsexposes the Prometheus metrics via HTTP over Unix domain socket. It logs an error if the metrics cannot be exposed.func ExposeMetrics(config *MetricsConfig, logger hclog.Logger) error
plugin
-
DefaultGRPCServerreturns a gRPC server with a 2GB max message size.func DefaultGRPCServer(opts []grpc.ServerOption) *grpc.Server -
GetAttrreturns the value of an attribute from thev1.Struct. It returns the default value if the attribute is not found.func GetAttr(req *v1.Struct, key string, defaultValue interface{}) interface{}
plugin/v1
-
GetPluginMapreturns the plugin map for the plugin.func GetPluginMap(pluginName string) map[string]goplugin.Plugin -
GetPluginSetMapreturns the plugin set map for the plugin.func GetPluginSetMap(plugins map[string]goplugin.Plugin) goplugin.PluginSet plugin.protois the protocol buffers definition for the plugin and its generated Go code stubs are inplugin.pb.goandplugin_grpc.pb.go.struct.protois the protocol buffers definition for thev1.Structand its generated Go code stubs are instruct.pb.goandstructpb.go. This is a modified version of theStructfrom the Google Protobuf library with an additionalbytesfield.