plugin

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Handshake = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "EASYREST_PLUGIN",
	MagicCookieValue: "easyrest",
}

Handshake configuration for plugin security.

View Source
var Version = "v0.4.3"

Version is the plugin version.

Functions

func BuildWhereClause

func BuildWhereClause(where map[string]any) (string, []any, error)

BuildWhereClause constructs a SQL WHERE clause from a given where map. The where map is expected to be in the form:

{ "field": {"=": value}, ... }

It returns the SQL string (starting with " WHERE ") and the list of arguments. This is the original logic.

func FormatToContext

func FormatToContext(input map[string]any) (map[string]string, error)

FormatToContext flattens an arbitrarily nested map into a flat map with keys joined by underscores. It replaces dots and dashes with underscores and converts keys to lowercase. For arrays, it uses the index as part of the key. It also validates that the final values do not contain dangerous characters.

Types

type CallFunctionRequest

type CallFunctionRequest struct {
	UserID   string
	FuncName string
	Data     map[string]any
	Ctx      map[string]any
}

type CallFunctionResponse

type CallFunctionResponse struct {
	Result any
	Error  string
}

type DBPlugin

type DBPlugin interface {
	InitConnection(uri string) error
	TableGet(userID string, table string, selectFields []string, where map[string]any,
		ordering []string, groupBy []string, limit, offset int, ctx map[string]any) ([]map[string]any, error)
	TableCreate(userID string, table string, data []map[string]any, ctx map[string]any) ([]map[string]any, error)
	TableUpdate(userID string, table string, data map[string]any, where map[string]any, ctx map[string]any) (int, error)
	TableDelete(userID string, table string, where map[string]any, ctx map[string]any) (int, error)
	CallFunction(userID string, funcName string, data map[string]any, ctx map[string]any) (any, error)
	GetSchema(ctx map[string]any) (any, error)
}

DBPlugin – interface for DB access plugins.

type DBPluginPlugin

type DBPluginPlugin struct {
	Impl DBPlugin
}

DBPluginPlugin wraps the DBPlugin implementation for go-plugin.

func (*DBPluginPlugin) Client

func (p *DBPluginPlugin) Client(broker *plugin.MuxBroker, c *rpc.Client) (any, error)

func (*DBPluginPlugin) Server

func (p *DBPluginPlugin) Server(broker *plugin.MuxBroker) (any, error)

type DBPluginRPC

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

DBPluginRPC is the client wrapper.

func (*DBPluginRPC) CallFunction

func (g *DBPluginRPC) CallFunction(userID, funcName string, data map[string]any, ctx map[string]any) (any, error)

func (*DBPluginRPC) GetSchema added in v0.2.0

func (g *DBPluginRPC) GetSchema(ctx map[string]any) (any, error)

New GetSchema method.

func (*DBPluginRPC) InitConnection

func (g *DBPluginRPC) InitConnection(uri string) error

func (*DBPluginRPC) TableCreate

func (g *DBPluginRPC) TableCreate(userID, table string, data []map[string]any, ctx map[string]any) ([]map[string]any, error)

func (*DBPluginRPC) TableDelete

func (g *DBPluginRPC) TableDelete(userID, table string, where map[string]any, ctx map[string]any) (int, error)

func (*DBPluginRPC) TableGet

func (g *DBPluginRPC) TableGet(userID, table string, selectFields []string, where map[string]any,
	ordering []string, groupBy []string, limit, offset int, ctx map[string]any) ([]map[string]any, error)

func (*DBPluginRPC) TableUpdate

func (g *DBPluginRPC) TableUpdate(userID, table string, data map[string]any, where map[string]any, ctx map[string]any) (int, error)

type DBPluginRPCServer

type DBPluginRPCServer struct {
	Impl DBPlugin
}

DBPluginRPCServer is the server-side RPC implementation.

func (*DBPluginRPCServer) CallFunction

func (*DBPluginRPCServer) GetSchema added in v0.2.0

func (s *DBPluginRPCServer) GetSchema(req GetSchemaRequest, resp *GetSchemaResponse) error

New GetSchema server method.

func (*DBPluginRPCServer) InitConnection

func (*DBPluginRPCServer) TableCreate

func (*DBPluginRPCServer) TableDelete

func (*DBPluginRPCServer) TableGet

func (s *DBPluginRPCServer) TableGet(req TableGetRequest, resp *TableGetResponse) error

func (*DBPluginRPCServer) TableUpdate

type GetSchemaRequest added in v0.2.0

type GetSchemaRequest struct {
	Ctx map[string]any
}

New structures for GetSchema.

type GetSchemaResponse added in v0.2.0

type GetSchemaResponse struct {
	Schema any
	Error  string
}

type InitConnectionRequest

type InitConnectionRequest struct {
	URI string
}

RPC request/response structures.

type InitConnectionResponse

type InitConnectionResponse struct {
	Error string
}

type TableCreateRequest

type TableCreateRequest struct {
	UserID string
	Table  string
	Data   []map[string]any
	Ctx    map[string]any
}

type TableCreateResponse

type TableCreateResponse struct {
	Rows  []map[string]any
	Error string
}

type TableDeleteRequest

type TableDeleteRequest struct {
	UserID string
	Table  string
	Where  map[string]any
	Ctx    map[string]any
}

type TableDeleteResponse

type TableDeleteResponse struct {
	Deleted int
	Error   string
}

type TableGetRequest

type TableGetRequest struct {
	UserID       string
	Table        string
	SelectFields []string
	Where        map[string]any
	Ordering     []string
	GroupBy      []string
	Limit        int
	Offset       int
	Ctx          map[string]any
}

type TableGetResponse

type TableGetResponse struct {
	Rows  []map[string]any
	Error string
}

type TableUpdateRequest

type TableUpdateRequest struct {
	UserID string
	Table  string
	Data   map[string]any
	Where  map[string]any
	Ctx    map[string]any
}

type TableUpdateResponse

type TableUpdateResponse struct {
	Updated int
	Error   string
}

Jump to

Keyboard shortcuts

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