rcd: refactor rclone rc server to use lib/http

This commit is contained in:
Nick Craig-Wood
2022-12-11 14:47:47 +00:00
parent a9ce86f9a3
commit 08a1ca434b
6 changed files with 173 additions and 83 deletions

View File

@@ -13,12 +13,14 @@ import (
_ "net/http/pprof" // install the pprof http handlers
"time"
"github.com/rclone/rclone/cmd/serve/httplib"
libhttp "github.com/rclone/rclone/lib/http"
)
// Options contains options for the remote control server
type Options struct {
HTTPOptions httplib.Options
HTTP libhttp.Config
Auth libhttp.AuthConfig
Template libhttp.TemplateConfig
Enabled bool // set to enable the server
Serve bool // set to serve files from remotes
Files string // set to enable serving files locally
@@ -36,14 +38,16 @@ type Options struct {
// DefaultOpt is the default values used for Options
var DefaultOpt = Options{
HTTPOptions: httplib.DefaultOpt,
HTTP: libhttp.DefaultCfg(),
Auth: libhttp.DefaultAuthCfg(),
Template: libhttp.DefaultTemplateCfg(),
Enabled: false,
JobExpireDuration: 60 * time.Second,
JobExpireInterval: 10 * time.Second,
}
func init() {
DefaultOpt.HTTPOptions.ListenAddr = "localhost:5572"
DefaultOpt.HTTP.ListenAddr = []string{"localhost:5572"}
}
// WriteJSON writes JSON in out to w