plugins

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: MIT Imports: 24 Imported by: 0

README

Sample plugin

package plugins

import (
	"context"
	"github.com/reddec/monexec/pool"
)


type MyPlugin struct {}

func (p *MyPlugin) Prepare(ctx context.Context, pl *pool.Pool) error { return nil }

func (p *MyPlugin) OnSpawned(ctx context.Context, sv pool.Instance) {}

func (p *MyPlugin) OnStarted(ctx context.Context, sv pool.Instance) {}

func (p *MyPlugin) OnStopped(ctx context.Context, sv pool.Instance, err error) {}

func (p *MyPlugin) OnFinished(ctx context.Context, sv pool.Instance) {}

func (p *MyPlugin) MergeFrom(other interface{}) error { return nil}

func (a *MyPlugin) Close() error { return nil }

func init() {
    registerPlugin("myPlugin", func(file string) PluginConfigNG {
        return &MyPlugin{}
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset added in v0.1.7

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir added in v0.1.7

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo added in v0.1.7

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames added in v0.1.7

func AssetNames() []string

AssetNames returns the names of the assets.

func CORSMiddleware added in v0.1.9

func CORSMiddleware() gin.HandlerFunc

func MustAsset added in v0.1.7

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset added in v0.1.7

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets added in v0.1.7

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type ConsulPlugin added in v0.1.6

type ConsulPlugin struct {
	URL                       string        `yaml:"url"`
	TTL                       time.Duration `yaml:"ttl"`
	AutoDeregistrationTimeout time.Duration `yaml:"timeout"`
	Dynamic                   []string      `yaml:"register,omitempty"`
	Permanent                 []string      `yaml:"permanent,omitempty"`

	Log    *log.Logger `yaml:"-"`
	Client *api.Client `yaml:"-"`
	// contains filtered or unexported fields
}

func DefaultConsul added in v0.1.6

func DefaultConsul() ConsulPlugin

func (*ConsulPlugin) Close added in v0.1.6

func (c *ConsulPlugin) Close() error

func (*ConsulPlugin) MergeFrom added in v0.1.6

func (p *ConsulPlugin) MergeFrom(a interface{}) error

func (*ConsulPlugin) OnFinished added in v0.1.6

func (p *ConsulPlugin) OnFinished(ctx context.Context, sv pool.Instance)

func (*ConsulPlugin) OnSpawned added in v0.1.6

func (p *ConsulPlugin) OnSpawned(ctx context.Context, sv pool.Instance)

func (*ConsulPlugin) OnStarted added in v0.1.6

func (c *ConsulPlugin) OnStarted(ctx context.Context, sv pool.Instance)

func (*ConsulPlugin) OnStopped added in v0.1.6

func (c *ConsulPlugin) OnStopped(ctx context.Context, sv pool.Instance, err error)

func (*ConsulPlugin) Prepare added in v0.1.6

func (p *ConsulPlugin) Prepare(ctx context.Context, pl *pool.Pool) error

type Critical added in v0.1.6

type Critical struct {
	Labels []string `mapstructure:"<ITEMS>"`
}

func (*Critical) Close added in v0.1.6

func (a *Critical) Close() error

func (*Critical) MergeFrom added in v0.1.6

func (a *Critical) MergeFrom(other interface{}) error

func (*Critical) OnFinished added in v0.1.6

func (p *Critical) OnFinished(ctx context.Context, sv pool.Instance)

func (*Critical) OnSpawned added in v0.1.6

func (p *Critical) OnSpawned(ctx context.Context, sv pool.Instance)

func (*Critical) OnStarted added in v0.1.6

func (p *Critical) OnStarted(ctx context.Context, sv pool.Instance)

func (*Critical) OnStopped added in v0.1.6

func (p *Critical) OnStopped(ctx context.Context, sv pool.Instance, err error)

func (*Critical) Prepare added in v0.1.6

func (a *Critical) Prepare(ctx context.Context, pl *pool.Pool) error

type Email

type Email struct {
	Smtp     string   `yaml:"smtp"`
	From     string   `yaml:"from"`
	Password string   `yaml:"password"`
	To       []string `yaml:"to"`
	Services []string `yaml:"services"`
	// contains filtered or unexported fields
}

func (*Email) Close added in v0.1.6

func (a *Email) Close() error

func (*Email) MergeFrom

func (a *Email) MergeFrom(other interface{}) error

func (*Email) OnFinished added in v0.1.6

func (p *Email) OnFinished(ctx context.Context, sv pool.Instance)

func (*Email) OnSpawned added in v0.1.6

func (c *Email) OnSpawned(ctx context.Context, sv pool.Instance)

func (*Email) OnStarted added in v0.1.6

func (c *Email) OnStarted(ctx context.Context, sv pool.Instance)

func (*Email) OnStopped added in v0.1.6

func (c *Email) OnStopped(ctx context.Context, sv pool.Instance, err error)

func (*Email) Prepare

func (c *Email) Prepare(ctx context.Context, pl *pool.Pool) error

type Http added in v0.1.4

type Http struct {
	URL      string            `yaml:"url" mapstructure:"url"`         // template URL string
	Method   string            `yaml:"method"`                         // default POST
	Headers  map[string]string `yaml:"headers" mapstructure:"headers"` // additional header (non-template)
	Services []string          `yaml:"services"`
	Timeout  time.Duration     `yaml:"timeout"`
	// contains filtered or unexported fields
}

func (*Http) Close added in v0.1.6

func (a *Http) Close() error

func (*Http) MergeFrom added in v0.1.4

func (a *Http) MergeFrom(other interface{}) error

func (*Http) OnFinished added in v0.1.6

func (p *Http) OnFinished(ctx context.Context, sv pool.Instance)

func (*Http) OnSpawned added in v0.1.6

func (p *Http) OnSpawned(ctx context.Context, sv pool.Instance)

func (*Http) OnStarted added in v0.1.6

func (c *Http) OnStarted(ctx context.Context, sv pool.Instance)

func (*Http) OnStopped added in v0.1.6

func (c *Http) OnStopped(ctx context.Context, sv pool.Instance, err error)

func (*Http) Prepare added in v0.1.4

func (c *Http) Prepare(ctx context.Context, pl *pool.Pool) error

type PluginConfigNG added in v0.1.6

type PluginConfigNG interface {
	// Must handle events
	pool.EventHandler
	// Closable
	io.Closer
	// Merge change from other instance. Other is always has same type as original
	MergeFrom(other interface{}) error
	// Prepare internal state
	Prepare(ctx context.Context, pl *pool.Pool) error
}

Base interface for any future plugins

func BuildPlugin

func BuildPlugin(name string, file string) (PluginConfigNG, bool)

Build but not fill one config

type RestPlugin added in v0.1.6

type RestPlugin struct {
	Listen string `yaml:"listen"`
	CORS   bool   `yaml:"cors"`
	// contains filtered or unexported fields
}

func (*RestPlugin) Close added in v0.1.6

func (a *RestPlugin) Close() error

func (*RestPlugin) MergeFrom added in v0.1.6

func (p *RestPlugin) MergeFrom(o interface{}) error

func (*RestPlugin) OnFinished added in v0.1.6

func (p *RestPlugin) OnFinished(ctx context.Context, sv pool.Instance)

func (*RestPlugin) OnSpawned added in v0.1.6

func (p *RestPlugin) OnSpawned(ctx context.Context, sv pool.Instance)

func (*RestPlugin) OnStarted added in v0.1.6

func (p *RestPlugin) OnStarted(ctx context.Context, sv pool.Instance)

func (*RestPlugin) OnStopped added in v0.1.6

func (p *RestPlugin) OnStopped(ctx context.Context, sv pool.Instance, err error)

func (*RestPlugin) Prepare added in v0.1.6

func (p *RestPlugin) Prepare(ctx context.Context, pl *pool.Pool) error

type Telegram

type Telegram struct {
	Token      string   `yaml:"token"`
	Recipients []int64  `yaml:"recipients"`
	Services   []string `yaml:"services"`
	// contains filtered or unexported fields
}

func (*Telegram) Close added in v0.1.6

func (a *Telegram) Close() error

func (*Telegram) MergeFrom

func (a *Telegram) MergeFrom(other interface{}) error

func (*Telegram) OnFinished added in v0.1.6

func (p *Telegram) OnFinished(ctx context.Context, sv pool.Instance)

func (*Telegram) OnSpawned added in v0.1.6

func (p *Telegram) OnSpawned(ctx context.Context, sv pool.Instance)

func (*Telegram) OnStarted added in v0.1.6

func (c *Telegram) OnStarted(ctx context.Context, sv pool.Instance)

func (*Telegram) OnStopped added in v0.1.6

func (c *Telegram) OnStopped(ctx context.Context, sv pool.Instance, err error)

func (*Telegram) Prepare

func (c *Telegram) Prepare(ctx context.Context, pl *pool.Pool) error

Jump to

Keyboard shortcuts

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