1// Package rc implements a remote control server and registry for rclone 2// 3// To register your internal calls, call rc.Add(path, function). Your 4// function should take ane return a Param. It can also return an 5// error. Use rc.NewError to wrap an existing error along with an 6// http response type if another response other than 500 internal 7// error is required on error. 8package rc 9 10import ( 11 "encoding/json" 12 "io" 13 _ "net/http/pprof" // install the pprof http handlers 14 "time" 15 16 "github.com/rclone/rclone/cmd/serve/httplib" 17) 18 19// Options contains options for the remote control server 20type Options struct { 21 HTTPOptions httplib.Options 22 Enabled bool // set to enable the server 23 Serve bool // set to serve files from remotes 24 Files string // set to enable serving files locally 25 NoAuth bool // set to disable auth checks on AuthRequired methods 26 WebUI bool // set to launch the web ui 27 WebGUIUpdate bool // set to check new update 28 WebGUIForceUpdate bool // set to force download new update 29 WebGUINoOpenBrowser bool // set to disable auto opening browser 30 WebGUIFetchURL string // set the default url for fetching webgui 31 AccessControlAllowOrigin string // set the access control for CORS configuration 32 EnableMetrics bool // set to disable prometheus metrics on /metrics 33 JobExpireDuration time.Duration 34 JobExpireInterval time.Duration 35} 36 37// DefaultOpt is the default values used for Options 38var DefaultOpt = Options{ 39 HTTPOptions: httplib.DefaultOpt, 40 Enabled: false, 41 JobExpireDuration: 60 * time.Second, 42 JobExpireInterval: 10 * time.Second, 43} 44 45func init() { 46 DefaultOpt.HTTPOptions.ListenAddr = "localhost:5572" 47} 48 49// WriteJSON writes JSON in out to w 50func WriteJSON(w io.Writer, out Params) error { 51 enc := json.NewEncoder(w) 52 enc.SetIndent("", "\t") 53 return enc.Encode(out) 54} 55