github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/fs/rc/rc.go (about) 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. 8 package rc 9 10 import ( 11 "encoding/json" 12 "io" 13 _ "net/http/pprof" // install the pprof http handlers 14 15 "github.com/ncw/rclone/cmd/serve/httplib" 16 ) 17 18 // Options contains options for the remote control server 19 type Options struct { 20 HTTPOptions httplib.Options 21 Enabled bool // set to enable the server 22 Serve bool // set to serve files from remotes 23 Files string // set to enable serving files locally 24 NoAuth bool // set to disable auth checks on AuthRequired methods 25 } 26 27 // DefaultOpt is the default values used for Options 28 var DefaultOpt = Options{ 29 HTTPOptions: httplib.DefaultOpt, 30 Enabled: false, 31 } 32 33 func init() { 34 DefaultOpt.HTTPOptions.ListenAddr = "localhost:5572" 35 } 36 37 // WriteJSON writes JSON in out to w 38 func WriteJSON(w io.Writer, out Params) error { 39 enc := json.NewEncoder(w) 40 enc.SetIndent("", "\t") 41 return enc.Encode(out) 42 }