plugin

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 3 Imported by: 0

README

Plugin

PkgGoDev Go

The goal of this lib is to provide a set of API to load plugins from different locations (remote, local, etc.)

Example

Let's suppose one plugin is stored locally:

package main

import (
        "fmt"

        "github.com/tormath1/plugin"
        "github.com/tormath1/plugin/factory"
)

func main() {
        loader, _ := factory.Get(plugin.Local)
        p, _ := loader.Open("/tmp/plugin.so")
        fmt.Printf("%T\n", p)
}

Then:

$ go run main.go
*plugin.Plugin

Supported plugin types

  • local: basically, the default behavior of plugins
  • remote: fetch a plugin from a remote location and download it in the $XDG_CACHE directory
  • embedded: extract a plugin packaged with pkger from a Go binary

Contributing

Just create a new dir in the plugin/ directory:

mkdir my-new-plugin-type

Then, you just need to define a structure implementing the plugin.Plugin interface:

package local

import "plugin"

// Local is the implementation of Plugin in order
// to lookup for local plugin
type Local struct{}

// Open will try to find the plugin locally, it's the default
// behavior
func (l Local) Open(path string) (*plugin.Plugin, error) {
        return plugin.Open(path)
}

Finally, it's required to add the my-new-plugin-type to the list of constants in plugin.Type, generate the new content: make and finally add the mapping in the plugin/factory.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TypeStrings

func TypeStrings() []string

TypeStrings returns a slice of all String values of the enum

Types

type Plugin

type Plugin interface {
	Open(string) (*plugin.Plugin, error)
}

Plugin is the interface to implement for each new types

type Type

type Type int

Type defines the type of the plugin

const (
	Local Type = iota
	Remote
	Embedded
)

func TypeString

func TypeString(s string) (Type, error)

TypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TypeValues

func TypeValues() []Type

TypeValues returns all values of the enum

func (Type) IsAType

func (i Type) IsAType() bool

IsAType returns "true" if the value is listed in the enum definition. "false" otherwise

func (Type) String

func (i Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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