Categorygithub.com/nhatthm/plugin-registry
repositorypackage
0.3.0
Repository: https://github.com/nhatthm/plugin-registry.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Plugin Registry for Golang

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

Install and manage plugins for Golang application.

Prerequisites

  • Go >= 1.15

Install

go get github.com/nhatthm/plugin-registry

Usage

plugin-registry helps to install plugins to a container at your choice. There are 4 tasks to manage them:

  • Install
  • Uninstall
  • Enable
  • Disable

plugin-registry is backed by spf13/afero so feel free to use it with your favorite backend file system by using WithFs(fs afero.Fs) option. For example

package mypackage

import (
	registry "github.com/nhatthm/plugin-registry"
	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
	"github.com/spf13/afero"
)

func createRegistry() (registry.Registry, error) {
	return registry.NewRegistry("~/plugins", registry.WithFs(afero.NewMemMapFs()))
}

By default, plugin-registry will record the installed plugin in config.yaml file in the given container, you can change it to a new place of your choice by using WithConfigFile(path string) option, for example:

package mypackage

import (
	registry "github.com/nhatthm/plugin-registry"
	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
)

func createRegistry() (registry.Registry, error) {
	return registry.NewRegistry("/usr/local/bin/plugins", registry.WithConfigFile("~/plugins/config.yaml"))
}

If you want to manage the plugins differently, you can write your own Configurator and use WithConfigurator() option to set it, for example:

package mypackage

import (
	registry "github.com/nhatthm/plugin-registry"
	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
	"github.com/nhatthm/plugin-registry/config"
)

var _ config.Configurator = (*MyConfigurator)(nil)

type MyConfigurator struct{}

func createConfigurator() *MyConfigurator {
	var c MyConfigurator

	// init c.

	return &c
}

func createRegistry() (registry.Registry, error) {
	return registry.NewRegistry("/usr/local/bin/plugins", registry.WithConfigurator(createConfigurator()))
}

Installer

There is no installer provided by this library, you need to install and import it in your project.

Known 3rd party installers:

Examples

package mypackage

import (
	"context"

	registry "github.com/nhatthm/plugin-registry"
	_ "github.com/nhatthm/plugin-registry-github" // Add github installer.
)

var defaultRegistry = mustCreateRegistry()

func mustCreateRegistry() registry.Registry {
	r, err := createRegistry()
	if err != nil {
		panic(err)
	}

	return r
}

func createRegistry() (registry.Registry, error) {
	return registry.NewRegistry("~/plugins")
}

func installPlugin(source string) error {
	return defaultRegistry.Install(context.Background(), source)
}

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this