diff options
-rw-r--r-- | cmd/rr/main.go | 6 | ||||
-rw-r--r-- | http/config.go (renamed from service/http/config.go) | 0 | ||||
-rw-r--r-- | http/parse.go (renamed from service/http/parse.go) | 7 | ||||
-rw-r--r-- | http/request.go (renamed from service/http/request.go) | 0 | ||||
-rw-r--r-- | http/response.go (renamed from service/http/response.go) | 0 | ||||
-rw-r--r-- | http/rpc.go | 73 | ||||
-rw-r--r-- | http/server.go (renamed from service/http/server.go) | 0 | ||||
-rw-r--r-- | http/service.go (renamed from service/http/service.go) | 0 | ||||
-rw-r--r-- | http/static.go | 57 | ||||
-rw-r--r-- | http/uploads.go (renamed from service/http/uploads.go) | 0 | ||||
-rw-r--r-- | http/uploads_config.go (renamed from service/http/uploads_config.go) | 0 | ||||
-rw-r--r-- | http/uploads_config_test.go (renamed from service/http/uploads_config_test.go) | 0 | ||||
-rw-r--r-- | rpc/config.go (renamed from service/rpc/config.go) | 0 | ||||
-rw-r--r-- | rpc/config_test.go (renamed from service/rpc/config_test.go) | 0 | ||||
-rw-r--r-- | rpc/service.go (renamed from service/rpc/service.go) | 0 | ||||
-rw-r--r-- | rpc/service_test.go (renamed from service/rpc/service_test.go) | 0 | ||||
-rw-r--r-- | service/http/rpc.go | 78 | ||||
-rw-r--r-- | static/config.go (renamed from service/static/config.go) | 0 | ||||
-rw-r--r-- | static/config_test.go (renamed from service/static/config_test.go) | 0 | ||||
-rw-r--r-- | static/service.go (renamed from service/static/service.go) | 2 |
20 files changed, 81 insertions, 142 deletions
diff --git a/cmd/rr/main.go b/cmd/rr/main.go index ea16a99a..3d15924b 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -26,9 +26,9 @@ import ( rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) - "github.com/spiral/roadrunner/service/http" - "github.com/spiral/roadrunner/service/rpc" - "github.com/spiral/roadrunner/service/static" + "github.com/spiral/roadrunner/http" + "github.com/spiral/roadrunner/rpc" + "github.com/spiral/roadrunner/static" // cli plugins _ "github.com/spiral/roadrunner/cmd/rr/http" diff --git a/service/http/config.go b/http/config.go index efcaae30..efcaae30 100644 --- a/service/http/config.go +++ b/http/config.go diff --git a/service/http/parse.go b/http/parse.go index fe8361d6..01030831 100644 --- a/service/http/parse.go +++ b/http/parse.go @@ -6,7 +6,8 @@ import ( "os" ) -const maxLevel = 127 +// MaxLevel defines maximum tree depth for incoming request data and files. +const MaxLevel = 127 type dataTree map[string]interface{} type fileTree map[string]interface{} @@ -37,7 +38,7 @@ func (d dataTree) push(k string, v []string) { indexes = append(indexes, strings.Trim(index, "]")) } - if len(indexes) <= maxLevel { + if len(indexes) <= MaxLevel { d.mount(indexes, v) } } @@ -115,7 +116,7 @@ func (d fileTree) push(k string, v []*FileUpload) { indexes = append(indexes, strings.Trim(index, "]")) } - if len(indexes) <= maxLevel { + if len(indexes) <= MaxLevel { d.mount(indexes, v) } } diff --git a/service/http/request.go b/http/request.go index c7304c8d..c7304c8d 100644 --- a/service/http/request.go +++ b/http/request.go diff --git a/service/http/response.go b/http/response.go index dd092353..dd092353 100644 --- a/service/http/response.go +++ b/http/response.go diff --git a/http/rpc.go b/http/rpc.go new file mode 100644 index 00000000..d9f911f4 --- /dev/null +++ b/http/rpc.go @@ -0,0 +1,73 @@ +package http + +// +//type rpcServer struct { +// service *Service +//} +// +//// WorkerList contains list of workers. +//type WorkerList struct { +// // Workers is list of workers. +// Workers []utils.Worker `json:"workers"` +//} +// +//// Reset resets underlying RR worker pool and restarts all of it's workers. +//func (rpc *rpcServer) Reset(reset bool, r *string) error { +// if rpc.service.srv == nil { +// return errors.New("no http server") +// } +// +// logrus.Info("http: restarting worker pool") +// *r = "OK" +// +// err := rpc.service.srv.rr.Reset() +// if err != nil { +// logrus.Errorf("http: %s", err) +// } +// +// return err +//} +// +//// Workers returns list of active workers and their stats. +//func (rpc *rpcServer) Workers(list bool, r *WorkerList) error { +// if rpc.service.srv == nil { +// return errors.New("no http server") +// } +// +// r.Workers = utils.FetchWorkers(rpc.service.srv.rr) +// return nil +//} +// +//// Worker provides information about specific worker. +//type Worker struct { +// // Pid contains process id. +// Pid int `json:"pid"` +// +// // Status of the worker. +// Status string `json:"status"` +// +// // Number of worker executions. +// NumExecs uint64 `json:"numExecs"` +// +// // Created is unix nano timestamp of worker creation time. +// Created int64 `json:"created"` +// +// // Updated is unix nano timestamp of last worker execution. +// Updated int64 `json:"updated"` +//} +// +//// FetchWorkers fetches list of workers from RR Server. +//func FetchWorkers(srv *roadrunner.Server) (result []Worker) { +// for _, w := range srv.Workers() { +// state := w.State() +// result = append(result, Worker{ +// Pid: *w.Pid, +// Status: state.String(), +// NumExecs: state.NumExecs(), +// Created: w.Created.UnixNano(), +// Updated: state.Updated().UnixNano(), +// }) +// } +// +// return +//} diff --git a/service/http/server.go b/http/server.go index 178980a7..178980a7 100644 --- a/service/http/server.go +++ b/http/server.go diff --git a/service/http/service.go b/http/service.go index c31c4a47..c31c4a47 100644 --- a/service/http/service.go +++ b/http/service.go diff --git a/http/static.go b/http/static.go deleted file mode 100644 index 3bd69160..00000000 --- a/http/static.go +++ /dev/null @@ -1,57 +0,0 @@ -package http - -import ( - "github.com/sirupsen/logrus" - "net/http" - "os" - "path" - "strings" -) - -// staticServer serves static files -type staticServer struct { - cfg *FsConfig - root http.Dir -} - -// serve attempts to serve static file and returns true in case of success, will return false in case if file not -// found, not allowed or on read error. -func (svr *staticServer) serve(w http.ResponseWriter, r *http.Request) bool { - fPath := r.URL.Path - if !strings.HasPrefix(fPath, "/") { - fPath = "/" + fPath - } - fPath = path.Clean(fPath) - - if svr.cfg.Forbids(fPath) { - logrus.Warningf("attempt to access forbidden file %s", fPath) // todo: better logs - return false - } - - f, err := svr.root.Open(fPath) - if err != nil { - if !os.IsNotExist(err) { - logrus.Error(err) //todo: rr or access error - } - - return false - } - defer f.Close() - - d, err := f.Stat() - if err != nil { - logrus.Error(err) //todo: rr or access error - - // todo: do i need it, bypass log? - - return false - } - - if d.IsDir() { - // do not serve directories - return false - } - - http.ServeContent(w, r, d.Name(), d.ModTime(), f) - return true -} diff --git a/service/http/uploads.go b/http/uploads.go index 62167a6c..62167a6c 100644 --- a/service/http/uploads.go +++ b/http/uploads.go diff --git a/service/http/uploads_config.go b/http/uploads_config.go index ac80723f..ac80723f 100644 --- a/service/http/uploads_config.go +++ b/http/uploads_config.go diff --git a/service/http/uploads_config_test.go b/http/uploads_config_test.go index e2de97f2..e2de97f2 100644 --- a/service/http/uploads_config_test.go +++ b/http/uploads_config_test.go diff --git a/service/rpc/config.go b/rpc/config.go index 8a34752a..8a34752a 100644 --- a/service/rpc/config.go +++ b/rpc/config.go diff --git a/service/rpc/config_test.go b/rpc/config_test.go index a953e30e..a953e30e 100644 --- a/service/rpc/config_test.go +++ b/rpc/config_test.go diff --git a/service/rpc/service.go b/rpc/service.go index ce1e3351..ce1e3351 100644 --- a/service/rpc/service.go +++ b/rpc/service.go diff --git a/service/rpc/service_test.go b/rpc/service_test.go index a57ce1bd..a57ce1bd 100644 --- a/service/rpc/service_test.go +++ b/rpc/service_test.go diff --git a/service/http/rpc.go b/service/http/rpc.go deleted file mode 100644 index 673ff2bb..00000000 --- a/service/http/rpc.go +++ /dev/null @@ -1,78 +0,0 @@ -package http - -import ( - "github.com/sirupsen/logrus" - "github.com/spiral/roadrunner/_____/utils" - "github.com/pkg/errors" -) - -type rpcServer struct { - service *Service -} - -// WorkerList contains list of workers. -type WorkerList struct { - // Workers is list of workers. - Workers []utils.Worker `json:"workers"` -} - -// Reset resets underlying RR worker pool and restarts all of it's workers. -func (rpc *rpcServer) Reset(reset bool, r *string) error { - if rpc.service.srv == nil { - return errors.New("no http server") - } - - logrus.Info("http: restarting worker pool") - *r = "OK" - - err := rpc.service.srv.rr.Reset() - if err != nil { - logrus.Errorf("http: %s", err) - } - - return err -} - -// Workers returns list of active workers and their stats. -func (rpc *rpcServer) Workers(list bool, r *WorkerList) error { - if rpc.service.srv == nil { - return errors.New("no http server") - } - - r.Workers = utils.FetchWorkers(rpc.service.srv.rr) - return nil -} - -// Worker provides information about specific worker. -type Worker struct { - // Pid contains process id. - Pid int `json:"pid"` - - // Status of the worker. - Status string `json:"status"` - - // Number of worker executions. - NumExecs uint64 `json:"numExecs"` - - // Created is unix nano timestamp of worker creation time. - Created int64 `json:"created"` - - // Updated is unix nano timestamp of last worker execution. - Updated int64 `json:"updated"` -} - -// FetchWorkers fetches list of workers from RR Server. -func FetchWorkers(srv *roadrunner.Server) (result []Worker) { - for _, w := range srv.Workers() { - state := w.State() - result = append(result, Worker{ - Pid: *w.Pid, - Status: state.String(), - NumExecs: state.NumExecs(), - Created: w.Created.UnixNano(), - Updated: state.Updated().UnixNano(), - }) - } - - return -}
\ No newline at end of file diff --git a/service/static/config.go b/static/config.go index 2a1f6c13..2a1f6c13 100644 --- a/service/static/config.go +++ b/static/config.go diff --git a/service/static/config_test.go b/static/config_test.go index ce31348a..ce31348a 100644 --- a/service/static/config_test.go +++ b/static/config_test.go diff --git a/service/static/service.go b/static/service.go index 916c18a2..eab9fe49 100644 --- a/service/static/service.go +++ b/static/service.go @@ -6,7 +6,7 @@ import ( "os" "path" "strings" - rrttp "github.com/spiral/roadrunner/service/http" + rrttp "github.com/spiral/roadrunner/http" "github.com/spiral/roadrunner/service" ) |