rc

package
v1.48.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package rc implements a remote control server and registry for rclone

To register your internal calls, call rc.Add(path, function). Your function should take ane return a Param. It can also return an error. Use rc.NewError to wrap an existing error along with an http response type if another response other than 500 internal error is required on error.

Index

Constants

This section is empty.

Variables

View Source
var Calls = NewRegistry()

Calls is the global registry of Call objects

View Source
var DefaultOpt = Options{
	HTTPOptions: httplib.DefaultOpt,
	Enabled:     false,
}

DefaultOpt is the default values used for Options

Functions

func Add

func Add(call Call)

Add a function to the global registry

func AddOption added in v1.46.0

func AddOption(name string, option interface{})

AddOption adds an option set

func AddOptionReload added in v1.47.0

func AddOptionReload(name string, option interface{}, reload func() error)

AddOptionReload adds an option set with a reload function to be called when options are changed

func GetFs added in v1.46.0

func GetFs(in Params) (f fs.Fs, err error)

GetFs gets a fs.Fs named "fs" either from the cache or creates it afresh

func GetFsAndRemote added in v1.46.0

func GetFsAndRemote(in Params) (f fs.Fs, remote string, err error)

GetFsAndRemote gets the `fs` parameter from in, makes a remote or fetches it from the cache then gets the `remote` parameter from in too.

func GetFsAndRemoteNamed added in v1.46.0

func GetFsAndRemoteNamed(in Params, fsName, remoteName string) (f fs.Fs, remote string, err error)

GetFsAndRemoteNamed gets the fsName parameter from in, makes a remote or fetches it from the cache then gets the remoteName parameter from in too.

func GetFsNamed added in v1.46.0

func GetFsNamed(in Params, fsName string) (f fs.Fs, err error)

GetFsNamed gets a fs.Fs named fsName either from the cache or creates it afresh

func IsErrParamInvalid added in v1.46.0

func IsErrParamInvalid(err error) bool

IsErrParamInvalid returns whether err is ErrParamInvalid

func IsErrParamNotFound added in v1.46.0

func IsErrParamNotFound(err error) bool

IsErrParamNotFound returns whether err is ErrParamNotFound

func NotErrParamNotFound added in v1.46.0

func NotErrParamNotFound(err error) bool

NotErrParamNotFound returns true if err != nil and !IsErrParamNotFound(err)

This is for checking error returns of the Get* functions to ignore error not found returns and take the default value.

func Reshape added in v1.46.0

func Reshape(out interface{}, in interface{}) error

Reshape reshapes one blob of data into another via json serialization

out should be a pointer type

This isn't a very efficient way of dealing with this!

func WriteJSON

func WriteJSON(w io.Writer, out Params) error

WriteJSON writes JSON in out to w

Types

type Call

type Call struct {
	Path         string // path to activate this RC
	Fn           Func   `json:"-"` // function to call
	Title        string // help for the function
	AuthRequired bool   // if set then this call requires authorisation to be set
	Help         string // multi-line markdown formatted help
}

Call defines info about a remote control function and is used in the Add function to create new entry points.

type ErrParamInvalid added in v1.46.0

type ErrParamInvalid struct {
	// contains filtered or unexported fields
}

ErrParamInvalid - this is returned from the Get* functions if the parameter is invalid.

Returning an error of this type from an rc.Func will cause the http method to return http.StatusBadRequest

type ErrParamNotFound added in v1.46.0

type ErrParamNotFound string

ErrParamNotFound - this is returned from the Get* functions if the parameter isn't found along with a zero value of the requested item.

Returning an error of this type from an rc.Func will cause the http method to return http.StatusBadRequest

func (ErrParamNotFound) Error added in v1.46.0

func (e ErrParamNotFound) Error() string

Error turns this error into a string

type Func

type Func func(in Params) (out Params, err error)

Func defines a type for a remote control function

type Job added in v1.46.0

type Job struct {
	ID        int64     `json:"id"`
	StartTime time.Time `json:"startTime"`
	EndTime   time.Time `json:"endTime"`
	Error     string    `json:"error"`
	Finished  bool      `json:"finished"`
	Success   bool      `json:"success"`
	Duration  float64   `json:"duration"`
	Output    Params    `json:"output"`
	// contains filtered or unexported fields
}

Job describes a asynchronous task started via the rc package

type Jobs added in v1.46.0

type Jobs struct {
	// contains filtered or unexported fields
}

Jobs describes a collection of running tasks

func (*Jobs) Expire added in v1.46.0

func (jobs *Jobs) Expire()

Expire expires any jobs that haven't been collected

func (*Jobs) Get added in v1.46.0

func (jobs *Jobs) Get(ID int64) *Job

Get a job with a given ID or nil if it doesn't exist

func (*Jobs) IDs added in v1.46.0

func (jobs *Jobs) IDs() (IDs []int64)

IDs returns the IDs of the running jobs

func (*Jobs) NewJob added in v1.46.0

func (jobs *Jobs) NewJob(fn Func, in Params) *Job

NewJob start a new Job off

type Options

type Options struct {
	HTTPOptions httplib.Options
	Enabled     bool   // set to enable the server
	Serve       bool   // set to serve files from remotes
	Files       string // set to enable serving files locally
	NoAuth      bool   // set to disable auth checks on AuthRequired methods
}

Options contains options for the remote control server

type Params

type Params map[string]interface{}

Params is the input and output type for the Func

func StartJob added in v1.46.0

func StartJob(fn Func, in Params) (Params, error)

StartJob starts a new job and returns a Param suitable for output

func (Params) Get added in v1.46.0

func (p Params) Get(key string) (interface{}, error)

Get gets a parameter from the input

If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be nil.

func (Params) GetBool added in v1.46.0

func (p Params) GetBool(key string) (bool, error)

GetBool gets a boolean parameter from the input

If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be false.

func (Params) GetFloat64 added in v1.46.0

func (p Params) GetFloat64(key string) (float64, error)

GetFloat64 gets a float64 parameter from the input

If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be 0.

func (Params) GetInt64 added in v1.46.0

func (p Params) GetInt64(key string) (int64, error)

GetInt64 gets a int64 parameter from the input

If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be 0.

func (Params) GetString added in v1.46.0

func (p Params) GetString(key string) (string, error)

GetString gets a string parameter from the input

If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be "".

func (Params) GetStruct added in v1.46.0

func (p Params) GetStruct(key string, out interface{}) error

GetStruct gets a struct from key from the input into the struct pointed to by out. out must be a pointer type.

If the parameter isn't found then error will be of type ErrParamNotFound and out will be unchanged.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds the list of all the registered remote control functions

func NewRegistry

func NewRegistry() *Registry

NewRegistry makes a new registry for remote control functions

func (*Registry) Add added in v1.46.0

func (r *Registry) Add(call Call)

Add a call to the registry

func (*Registry) Get added in v1.46.0

func (r *Registry) Get(path string) *Call

Get a Call from a path or nil

func (*Registry) List added in v1.46.0

func (r *Registry) List() (out []*Call)

List of all calls in alphabetical order

Directories

Path Synopsis
Package rcflags implements command line flags to set up the remote control
Package rcflags implements command line flags to set up the remote control
Package rcserver implements the HTTP endpoint to serve the remote control
Package rcserver implements the HTTP endpoint to serve the remote control

Jump to

Keyboard shortcuts

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