diff --git a/.gitignore b/.gitignore index 335ebcf..0bab6bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ *.so -/types -/controllers /test /aicra /.vscode \ No newline at end of file diff --git a/api/error.defaults.go b/api/error.defaults.go index 8c461fc..53bf58d 100644 --- a/api/error.defaults.go +++ b/api/error.defaults.go @@ -1,7 +1,7 @@ package api var ( - // ErrorSuccess represents a generic successful controller execution + // ErrorSuccess represents a generic successful service execution ErrorSuccess = func() Error { return Error{0, "all right", nil} } // ErrorFailure is the most generic error @@ -29,16 +29,16 @@ var ( ErrorDownload = func() Error { return Error{101, "download failed", nil} } // MissingDownloadHeaders has to be set when the implementation - // of a controller of type 'download' (which returns a file instead of + // of a service of type 'download' (which returns a file instead of // a set or output fields) is missing its HEADER field MissingDownloadHeaders = func() Error { return Error{102, "download headers are missing", nil} } // ErrorMissingDownloadBody has to be set when the implementation - // of a controller of type 'download' (which returns a file instead of + // of a service of type 'download' (which returns a file instead of // a set or output fields) is missing its BODY field ErrorMissingDownloadBody = func() Error { return Error{103, "download body is missing", nil} } - // ErrorUnknownService is set when there is no controller matching + // ErrorUnknownService is set when there is no service matching // the http request URI. ErrorUnknownService = func() Error { return Error{200, "unknown service", nil} } @@ -46,11 +46,11 @@ var ( // request's http method ErrorUnknownMethod = func() Error { return Error{201, "unknown method", nil} } - // ErrorUncallableService is set when there the requested controller's + // ErrorUncallableService is set when there the requested service's // implementation (plugin file) is not found/callable ErrorUncallableService = func() Error { return Error{202, "uncallable service", nil} } - // ErrorUncallableMethod is set when there the requested controller's + // ErrorUncallableMethod is set when there the requested service's // implementation does not features the requested method ErrorUncallableMethod = func() Error { return Error{203, "uncallable method", nil} } diff --git a/api/error.go b/api/error.go index 7112fbb..6bee525 100644 --- a/api/error.go +++ b/api/error.go @@ -5,7 +5,7 @@ import ( ) // Error represents an http response error following the api format. -// These are used by the controllers to set the *execution status* +// These are used by the services to set the *execution status* // directly into the response as JSON alongside response output fields. type Error struct { Code int `json:"code"` diff --git a/internal/config/service.go b/internal/config/service.go index 78ff407..34f5407 100644 --- a/internal/config/service.go +++ b/internal/config/service.go @@ -86,12 +86,12 @@ func (svc *Service) checkAndFormat(servicePath string) error { return nil } - // 2. for each controller */ + // 2. for each service */ for childService, ctl := range svc.Children { // 3. invalid name */ if strings.ContainsAny(childService, "/-") { - return fmt.Errorf("Controller '%s' must not contain any slash '/' nor '-' symbols", childService) + return fmt.Errorf("service '%s' must not contain any slash '/' nor '-' symbols", childService) } // 4. check recursively */ diff --git a/internal/reqdata/parameter.go b/internal/reqdata/parameter.go index 71092e7..79201b9 100644 --- a/internal/reqdata/parameter.go +++ b/internal/reqdata/parameter.go @@ -5,7 +5,7 @@ package reqdata type Parameter struct { // whether the value has been json-parsed // for optimisation purpose, parameters are only parsed - // if they are required by the current controller + // if they are required by the current service Parsed bool // whether the value is a file diff --git a/internal/reqdata/store.go b/internal/reqdata/store.go index de4d4e5..514d4d4 100644 --- a/internal/reqdata/store.go +++ b/internal/reqdata/store.go @@ -12,13 +12,13 @@ import ( ) // Store represents all data that can be caught: -// - URI (guessed from the URI by removing the controller path) +// - URI (guessed from the URI by removing the service path) // - GET (default url data) // - POST (from json, form-data, url-encoded) type Store struct { // ordered values from the URI - // catches all after the controller path + // catches all after the service path // // points to Store.Data URI []*Parameter @@ -58,7 +58,7 @@ func New(uriParams []string, req *http.Request) *Store { ds.setURIParams(uriParams) // 2. GET (query) data - ds.fetchGet(req) + ds.readQuery(req) // 3. We are done if GET method if req.Method == http.MethodGet { @@ -66,7 +66,7 @@ func New(uriParams []string, req *http.Request) *Store { } // 4. POST (body) data - ds.fetchForm(req) + ds.readForm(req) return ds } @@ -92,19 +92,19 @@ func (i *Store) setURIParams(orderedUParams []string) { } -// fetchGet stores data from the QUERY (in url parameters) -func (i *Store) fetchGet(req *http.Request) { +// readQuery stores data from the QUERY (in url parameters) +func (i *Store) readQuery(req *http.Request) { for name, value := range req.URL.Query() { // prevent invalid names - if !validName(name) { + if !isNameValid(name) { log.Printf("invalid variable name: '%s'\n", name) continue } // prevent injections - if nameInjection(name) { + if hasNameInjection(name) { log.Printf("get.injection: '%s'\n", name) continue } @@ -125,12 +125,12 @@ func (i *Store) fetchGet(req *http.Request) { } -// fetchForm stores FORM data +// readForm stores FORM data // // - parse 'form-data' if not supported (not POST requests) // - parse 'x-www-form-urlencoded' // - parse 'application/json' -func (i *Store) fetchForm(req *http.Request) { +func (i *Store) readForm(req *http.Request) { contentType := req.Header.Get("Content-Type") @@ -173,13 +173,13 @@ func (i *Store) parseJSON(req *http.Request) { for name, value := range parsed { // prevent invalid names - if !validName(name) { + if !isNameValid(name) { log.Printf("invalid variable name: '%s'\n", name) continue } // prevent injections - if nameInjection(name) { + if hasNameInjection(name) { log.Printf("post.injection: '%s'\n", name) continue } @@ -210,13 +210,13 @@ func (i *Store) parseUrlencoded(req *http.Request) { for name, value := range req.PostForm { // prevent invalid names - if !validName(name) { + if !isNameValid(name) { log.Printf("invalid variable name: '%s'\n", name) continue } // prevent injections - if nameInjection(name) { + if hasNameInjection(name) { log.Printf("post.injection: '%s'\n", name) continue } @@ -254,13 +254,13 @@ func (i *Store) parseMultipart(req *http.Request) { for name, data := range mpr.Data { // prevent invalid names - if !validName(name) { + if !isNameValid(name) { log.Printf("invalid variable name: '%s'\n", name) continue } // prevent injections - if nameInjection(name) { + if hasNameInjection(name) { log.Printf("post.injection: '%s'\n", name) continue } @@ -281,16 +281,16 @@ func (i *Store) parseMultipart(req *http.Request) { } -// nameInjection returns whether there is +// hasNameInjection returns whether there is // a parameter name injection: // - inferred GET parameters // - inferred URL parameters -func nameInjection(pName string) bool { +func hasNameInjection(pName string) bool { return strings.HasPrefix(pName, "GET@") || strings.HasPrefix(pName, "URL#") } -// validName returns whether a parameter name (without the GET@ or URL# prefix) is valid +// isNameValid returns whether a parameter name (without the GET@ or URL# prefix) is valid // if fails if the name begins/ends with underscores -func validName(pName string) bool { +func isNameValid(pName string) bool { return strings.Trim(pName, "_") == pName }