plugin

package module
v0.0.0-...-058e59a Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 3 Imported by: 0

README

RoadRunner Plugin Template

Total alerts All releases

This repo can be used to scaffold a RoadRunner Plugin. Follow these steps to get started:
  1. Update the module name in go.mod

    module github.com/2ik/rr-plugin
    
  2. Ideally you should rename the package in all the .go files from plugin to something else.

    package plugin
    
  3. Rename the plugin to whatever is appropriate, this should be kept to snake case:

    const PluginName = "plugin"
    
  4. Update the LICENSE.md file

  5. If your plugin is not going to be public on GitHub then you should remove .github/workflows/codeql-analysis.yml. You may also need to enable code scanning for the repository

  6. Update the contributors in the README.md.

  7. Update the README.md references to the plugin, installation and usage.

  8. Update the badges at the top of README.md to point to your own repository.

  9. Update the .github/FUNDING.yml file.

  10. Remove the todo section from your README.md

Installation

To use this plugin with RoadRunner you will need to fork or clone your own copy of the RoadRunner binary.

You can import the plugin via go modules:

go get github.com/2ik/rr-plugin

From there you can edit the plugins.go file to import the plugin.

package container

import (
    // ...
    demoPlugin "github.com/2ik/rr-plugin"
    // ...
)

// Plugins returns active plugins for the endure container. Feel free to add or remove any plugins.
func Plugins() []interface{} {
	return []interface{}{
        // ...
        &demoPlugin.Plugin{},
        // ...
    }
}

By importing this plugin and registering it the plugin will be compiled into the final binary.

The plugin will require that the .rr.yaml config has the key plugin for the plugin won't initialise with roadrunner.

plugin:
  value: foobar

Usage

To make use of this plugin via PHP you must install the Spiral Goridge library.

You can use the following code as an example in php:

<?php

use Spiral\Goridge\RPC\RPC;
use Spiral\RoadRunner\Environment;

$rpc = RPC::create(Environment::fromGlobals()->getRPCAddress());

// returns ['message' => 'test']
$output = $rpc->call('plugin.Message', ['message' => 'test']);

Testing

You may download the project and test the plugin using the following command.

go test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

View Source
const PluginName = "plugin"

PluginName is the name for the plugin as found inside the container

Variables

This section is empty.

Functions

This section is empty.

Types

type Actionable

type Actionable interface {
	// Action is purely an example of an interface available to Endure
	Action() error
}

Actionable is an interface that can be used in additional plugins via endure container

type Config

type Config struct {
	Value string `mapstructure:"value"`
}

Config configures the plugin service.

func (*Config) InitDefaults

func (cfg *Config) InitDefaults()

InitDefaults for the plugin config

type Plugin

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

Plugin is the structure that will be initiated as per endure.Container interface

func (*Plugin) Action

func (p *Plugin) Action() error

Action is purely an example for the interface

func (*Plugin) Init

func (p *Plugin) Init(cfg config.Configurer, logger logger.Logger) error

Init initiates the plugin with any injected services implementing endure.Container, returning an error if the plugin fails to start, if the error is of type errors.Disabled then the plugin will not be active

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns endure.Named interface implementation

func (*Plugin) RPC

func (p *Plugin) RPC() interface{}

RPC provides a struct instance that allows for methods to be called via the RPC server in roadrunner

Jump to

Keyboard shortcuts

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