From e5f7cf1147b617ca98bf4fb465e7c8d6d3babde8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 8 Jul 2018 11:30:53 +0200 Subject: [PATCH] controller name cannot contain '-', plugin packages are in 'controller/plugin-path-dash-separated/main.go' + root is '/controller/ROOT/main.go' --- config/controller.go | 4 ++-- request/request.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config/controller.go b/config/controller.go index 56cfc16..fd1df86 100644 --- a/config/controller.go +++ b/config/controller.go @@ -210,8 +210,8 @@ func (c *Controller) format(controllerName string) error { for ctlName, ctl := range c.Children { /* (3) Invalid name */ - if strings.Contains(ctlName, "/") { - return fmt.Errorf("Controller '%s' must not contain any slash '/'", ctlName) + if strings.ContainsAny(ctlName, "/-") { + return fmt.Errorf("Controller '%s' must not contain any slash '/' nor '-' symbols", ctlName) } /* (4) Check recursively */ diff --git a/request/request.go b/request/request.go index 1ffef65..26e8eb4 100644 --- a/request/request.go +++ b/request/request.go @@ -96,7 +96,12 @@ func FetchFormData(req *http.Request) map[string]interface{} { func (i *Request) LoadController(method string) (func(implement.Arguments, *implement.Response) implement.Response, error) { /* (1) Build controller path */ - path := fmt.Sprintf(".build/controller/%s/i.so", strings.Join(i.Path, "/")) + path := strings.Join(i.Path, "-") + if len(path) == 0 { + path = fmt.Sprintf(".build/controller/ROOT/main.so") + } else { + path = fmt.Sprintf(".build/controller/%s/main.so", path) + } /* (2) Format url */ tmp := []byte(strings.ToLower(method))