run

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Builtin = make(builtinRunnerMap)

Functions

func GetEndpoint

func GetEndpoint(datadir string, uri string) (method string, host string, err error)

GetEndpoint parses the given URI and returns an endpoint

func GetPlugin

func GetPlugin(plugin, uri string) (string, string, string)

func NewReverseProxy

func NewReverseProxy(datadir, uri string) (http.Handler, error)

NewReverseProxy generates a reverse proxy from a given uri, automatically handling unix sockets, and builtin handlers

func ParseUnixSock

func ParseUnixSock(datadir string, uri string) (sockfile string, requestPath string, err error)

Extracts the unix socket file and request path

func Request

func Request(h http.Handler, method, path string, body interface{}, headers map[string]string) (*bytes.Buffer, error)

Request runs the given http handler, and optionally unmarshals the result

func RequestWithContext

func RequestWithContext(adb *database.AdminDB, h http.Handler, method, path string, body interface{}, headers map[string]string) (*bytes.Buffer, error)

RequestWithContext is just like request, but it also creates a heedy request context, so that it can request things from builtin plugins

func Route

func Route(m *chi.Mux, route string, h http.Handler) error

func WaitForAPI

func WaitForAPI(method string, host string, timeout time.Duration) error

WaitForAPI is like WaitForEndpoint, but it doesn't have a cmd.

func WaitForEndpoint

func WaitForEndpoint(method string, host string, e *Cmd) error

WaitForEndpoint waits for the given endpoint

func WithNilInfo

func WithNilInfo(bis BuiltinStartFunc) func(*database.AdminDB) error

WithNilInfo can be used to convert a plugin start func that doesn't require an Info struct into a function compatible with database.AddCreateHook.

Types

type APIHandler

type APIHandler struct {
	Log *logrus.Entry
	M   *Manager
	H   http.Handler
	V   assets.RunType
}

func NewAPIHandler

func NewAPIHandler(M *Manager, runtype string, rtv assets.RunType) *APIHandler

func (*APIHandler) Kill

func (ah *APIHandler) Kill(apikey string) error

func (*APIHandler) Run

func (ah *APIHandler) Run(i *Info) error

func (*APIHandler) Start

func (ah *APIHandler) Start(i *Info) (http.Handler, error)

func (*APIHandler) Stop

func (ah *APIHandler) Stop(apikey string) error

type BuiltinHandler

type BuiltinHandler struct {
	DB      *database.AdminDB
	Running map[string]string
	// contains filtered or unexported fields
}

func NewBuiltinHandler

func NewBuiltinHandler(db *database.AdminDB, m *Manager) *BuiltinHandler

func (*BuiltinHandler) Kill

func (bg *BuiltinHandler) Kill(apikey string) error

func (*BuiltinHandler) Run

func (bh *BuiltinHandler) Run(i *Info) (err error)

func (*BuiltinHandler) Start

func (bh *BuiltinHandler) Start(i *Info) (h http.Handler, err error)

func (*BuiltinHandler) Stop

func (bh *BuiltinHandler) Stop(apikey string) error

type BuiltinHelper

type BuiltinHelper interface {
	GetHandler(uri string) (http.Handler, error)
}

type BuiltinRunner

type BuiltinRunner struct {
	Key     string
	Start   BuiltinStartFunc
	Stop    func(db *database.AdminDB, apikey string) error
	Handler http.Handler
}

Builtin is passed in to the BuiltinHandler with

type BuiltinStartFunc

type BuiltinStartFunc func(db *database.AdminDB, i *Info, h BuiltinHelper) error

func WithVersion

func WithVersion(pluginName string, dbversion int, pstart func(*database.AdminDB, *Info, BuiltinHelper, int) error) BuiltinStartFunc

type ChiClearer

type ChiClearer struct {
	Handler http.Handler
}

func (ChiClearer) ServeHTTP

func (cc ChiClearer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Cmd

type Cmd struct {
	Cmd *exec.Cmd

	sync.Mutex
	// contains filtered or unexported fields
}

func NewCmd

func NewCmd(c *exec.Cmd) *Cmd

func (*Cmd) Done

func (c *Cmd) Done() bool

func (*Cmd) Wait

func (c *Cmd) Wait() error

type ExecHandler

type ExecHandler struct {
	sync.Mutex
	DB  *database.AdminDB
	Cmd map[string]*Cmd
}

func NewExecHandler

func NewExecHandler(db *database.AdminDB) *ExecHandler

func (*ExecHandler) Kill

func (e *ExecHandler) Kill(apikey string) error

func (*ExecHandler) Run

func (e *ExecHandler) Run(i *Info) error

func (*ExecHandler) Start

func (e *ExecHandler) Start(i *Info) (http.Handler, error)

func (*ExecHandler) Stop

func (e *ExecHandler) Stop(apikey string) error

type Info

type Info struct {
	Plugin    string                `json:"plugin"`
	Name      string                `json:"name"`
	APIKey    string                `json:"apikey"`
	Run       *assets.Run           `json:"run"`
	HeedyDir  string                `json:"heedy_dir"`
	DataDir   string                `json:"data_dir"`
	PluginDir string                `json:"plugin_dir"`
	Config    *assets.Configuration `json:"config"`
}

type Manager

type Manager struct {
	sync.RWMutex

	DB       *database.AdminDB
	RunTypes map[string]TypeHandler

	Runners map[string]*Runner

	// The APIKey that represents the "core" heedy server
	CoreKey string
	// contains filtered or unexported fields
}

func NewManager

func NewManager(db *database.AdminDB) *Manager

func (*Manager) Find

func (m *Manager) Find(plugin, name string) (*Runner, error)

func (*Manager) GetHandler

func (m *Manager) GetHandler(plugin, uri string) (http.Handler, error)

func (*Manager) Kill

func (m *Manager) Kill() error

func (*Manager) Start

func (m *Manager) Start(plugin, name string, run *assets.Run) error

func (*Manager) Stop

func (m *Manager) Stop(plugin, name string) error

func (*Manager) StopPlugin

func (m *Manager) StopPlugin(plugin string) error

type Runner

type Runner struct {
	I       *Info
	Handler http.Handler
	// contains filtered or unexported fields
}

func (*Runner) Run

func (r *Runner) Run()

type StartMessage

type StartMessage struct {
	API string `json:"api"`
}

type TypeHandler

type TypeHandler interface {
	// Start performs initialization of the runner
	Start(*Info) (http.Handler, error)
	Run(*Info) error
	Stop(apikey string) error
	Kill(apikey string) error
}

Jump to

Keyboard shortcuts

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