top

Package cephlapod is a Sepia plugin framework for Go.

All Sepia plugins are gRPC servers which respond to requests from Sepia itself, which acts as a client. This package wraps the complex and sometimes messy gRPC functionality, and allows plugins to be developed and tested in an abstract, test-driven way.

All Sepia plugins are independent, stand-alone applications that run as a discreet process at the operating system level. They must be independently executable (as in, their package must be named 'main' and contain a main() function) and are required to clear up after themselved when their process is killed by an interrupt signal. Aside from using some standard code to interact with Sepia, they are free to operate in any way they would like.

Cephlapod-driven plugins can provide deployment strategies, models, modules, themes, APIs (for both specific models and general purposes), MVC controllers, and URL handlers, including files from the disk or memory. A full description of how to design and integrate a plugin is contained in the Sepia documentation.

At the core of Cephlapod is the Server interface (see formal definition and examples below), which acts as the gateway to all the supported plugin functionality. Once you have created a valid server all the power of the plugin system becomes available. The Server instance should be stored as a persistent entity in the plugin application.

A cephlapod-powered plugin could be as simple as:

 package main

 import "bitbucket.org/homemade/cephlapod"

 func main() {

	 server, err := cephlapod.NewGrpcServer()

	 if err != nil {
		 // handle fatal error
	 }

	 server.Serve()
 }

Note that to actually be used in Sepia is will require a Pluginfile (see the 'Plugins' section in sep doc). Also that plugin won't actually do anything - it would just idle in the background.

A more realistic example of a very simple plugin is:

 package main

 import "bitbucket.org/homemade/cephlapod"

 func main() {

	 server, err := cephlapod.NewGrpcServer()

	 if err != nil {
		 // handle fatal error
	 }

	 server.HandleHook("hookname", myHookHandler, cephlapod.ScopePublic)

	 server.Serve()
 }

 func myHookHandler(ctx cephlapod.Context, logger cephlapod.Logger, req cephlapod.HookRequest, resp *cephlapod.HookResponse) {

	logger.Log("Received a hook request for '%s'", req.Function)

	resp.Model.Set("someField", "This was set by my hook!")
 }

That plugin (again, it requires a Pluginfile) could be attacked to a model hook field, and would set the value of `someField`, if it could. It would also log to Sepia's main log output.

The best way to get started with a plugin is to use one of the templates from the sep binary itself. For a hook template, run

sep new hook-plugin

in a directory under `plugins` in your sepia project. A fully-formed, documented and unit tested template will be generated with multuple hooks and complex configuration.

Imported by 1 package(s)

  1. bitbucket.org/homemade/cephlapod/cephtest

Imports 3 package(s)

  1. golang.org/x/net/context
  2. bitbucket.org/homemade/cephlapod/pb
  3. google.golang.org/grpc

Test imports 2 package(s)

  1. github.com/Pallinder/go-randomdata
  2. github.com/stretchr/testify/require