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 ¶
- Variables
- func Add(call Call)
- func AddOption(name string, option interface{})
- func AddOptionReload(name string, option interface{}, reload func() error)
- func GetFs(in Params) (f fs.Fs, err error)
- func GetFsAndRemote(in Params) (f fs.Fs, remote string, err error)
- func GetFsAndRemoteNamed(in Params, fsName, remoteName string) (f fs.Fs, remote string, err error)
- func GetFsNamed(in Params, fsName string) (f fs.Fs, err error)
- func IsErrParamInvalid(err error) bool
- func IsErrParamNotFound(err error) bool
- func NotErrParamNotFound(err error) bool
- func Reshape(out interface{}, in interface{}) error
- func WriteJSON(w io.Writer, out Params) error
- type Call
- type ErrParamInvalid
- type ErrParamNotFound
- type Func
- type Options
- type Params
- func (p Params) Get(key string) (interface{}, error)
- func (p Params) GetBool(key string) (bool, error)
- func (p Params) GetDuration(key string) (time.Duration, error)
- func (p Params) GetFloat64(key string) (float64, error)
- func (p Params) GetHTTPRequest() (*http.Request, error)
- func (p Params) GetHTTPResponseWriter() (*http.ResponseWriter, error)
- func (p Params) GetInt64(key string) (int64, error)
- func (p Params) GetString(key string) (string, error)
- func (p Params) GetStruct(key string, out interface{}) error
- func (p Params) GetStructMissingOK(key string, out interface{}) error
- type Registry
Constants ¶
This section is empty.
Variables ¶
var Calls = NewRegistry()
Calls is the global registry of Call objects
var DefaultOpt = Options{ HTTPOptions: httplib.DefaultOpt, Enabled: false, JobExpireDuration: 60 * time.Second, JobExpireInterval: 10 * time.Second, }
DefaultOpt is the default values used for Options
Functions ¶
func AddOptionReload ¶
AddOptionReload adds an option set with a reload function to be called when options are changed
func GetFsAndRemote ¶
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 ¶
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 ¶
GetFsNamed gets an fs.Fs named fsName either from the cache or creates it afresh
func IsErrParamInvalid ¶
IsErrParamInvalid returns whether err is ErrParamInvalid
func IsErrParamNotFound ¶
IsErrParamNotFound returns whether err is ErrParamNotFound
func NotErrParamNotFound ¶
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.
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 NeedsRequest bool // if set then this call will be passed the original request object as _request NeedsResponse bool // if set then this call will be passed the original response object as _response }
Call defines info about a remote control function and is used in the Add function to create new entry points.
type ErrParamInvalid ¶
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 ¶
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 ¶
func (e ErrParamNotFound) Error() string
Error turns this error into a string
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 WebUI bool // set to launch the web ui WebGUIUpdate bool // set to check new update WebGUIForceUpdate bool // set to force download new update WebGUINoOpenBrowser bool // set to disable auto opening browser WebGUIFetchURL string // set the default url for fetching webgui AccessControlAllowOrigin string // set the access control for CORS configuration EnableMetrics bool // set to disable prometheus metrics on /metrics JobExpireDuration time.Duration JobExpireInterval time.Duration }
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 (Params) Get ¶
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 ¶
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) GetDuration ¶ added in v1.53.0
GetDuration get the duration parameters from in
func (Params) GetFloat64 ¶
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) GetHTTPRequest ¶ added in v1.53.0
GetHTTPRequest gets a http.Request parameter associated with the request with the key "_request"
If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be nil.
func (Params) GetHTTPResponseWriter ¶ added in v1.53.0
func (p Params) GetHTTPResponseWriter() (*http.ResponseWriter, error)
GetHTTPResponseWriter gets a http.ResponseWriter parameter associated with the request with the key "_response"
If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be nil.
func (Params) GetInt64 ¶
GetInt64 gets an 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 ¶
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 ¶
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.
func (Params) GetStructMissingOK ¶ added in v1.52.0
GetStructMissingOK works like GetStruct but doesn't return an error if the key is missing
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
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 |