Skip to content

grsmv/go-plugin-example

Repository files navigation

Chain of responsibility based on Go plugins

This repository and particularly this document describes Chain of responsibility pattern implementation, based on Go 1.8+ Plugin capabilities.

Restrictions

At this point Go 1.8+ plugins working only in Linux environment.

High level overview

Current implementation includes Pipeline Manager (main.go), Plugin update service (plugins.go) and Plugin Repository (plugins.go). Plugin updating service look up for changes in PluginsFolder and launches plugin updating process (re-reading list of plugins) when changes available. All long-term operations with Plugin repository are wrapped with mutexes.

Pipeline

Pipeline is building dynamically, basing on available plugins. Order of execution is based on plugin meta-information.

Plugin

Each plugin has meta-information and handler. Here's basic example of plugin:

package main

import (
	"context"
	"go-plugin-example/models"
	"time"
)

func Weight() int {
	return 20
}

func Handler(ctx context.Context, data models.Data) (models.Data, error) {
	time.Sleep(20 * time.Second)
	return models.Data{A: data.A + 10}, nil
}

Type signatures for Weight and Handler functions should be constant across all plugins. Notice the Weight function - this is meta-information, which shows place of plugin execution in Pipeline query.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published