2018-03-05 11:44:16 +00:00
|
|
|
// 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.
|
|
|
|
package rc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2018-04-06 19:33:51 +00:00
|
|
|
"io"
|
2018-05-11 10:12:58 +00:00
|
|
|
_ "net/http/pprof" // install the pprof http handlers
|
2018-03-05 11:44:16 +00:00
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd/serve/httplib"
|
2018-03-05 11:44:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Options contains options for the remote control server
|
|
|
|
type Options struct {
|
2019-08-04 11:32:37 +00:00
|
|
|
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 download new update
|
|
|
|
WebGUIFetchURL string // set the default url for fetching webgui
|
|
|
|
|
2018-03-05 11:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultOpt is the default values used for Options
|
|
|
|
var DefaultOpt = Options{
|
|
|
|
HTTPOptions: httplib.DefaultOpt,
|
|
|
|
Enabled: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
DefaultOpt.HTTPOptions.ListenAddr = "localhost:5572"
|
|
|
|
}
|
|
|
|
|
2018-04-06 19:33:51 +00:00
|
|
|
// WriteJSON writes JSON in out to w
|
|
|
|
func WriteJSON(w io.Writer, out Params) error {
|
|
|
|
enc := json.NewEncoder(w)
|
|
|
|
enc.SetIndent("", "\t")
|
|
|
|
return enc.Encode(out)
|
|
|
|
}
|