From d590d3132792c32c9b8798fd7446e9583fb55db0 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 7 Oct 2018 11:14:04 +0200 Subject: [PATCH] add exported fields' comments --- internal/api/method.go | 6 +++--- internal/api/types.go | 5 ++++- internal/checker/public.go | 3 +++ response/arguments.go | 4 ++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/api/method.go b/internal/api/method.go index 5821209..e4c6099 100644 --- a/internal/api/method.go +++ b/internal/api/method.go @@ -18,7 +18,7 @@ func (m *Method) CheckScope(scope middleware.Scope) bool { for _, AND := range OR { - if !isPermInScope(AND, scope) { + if !scopeHasPermission(AND, scope) { granted = false break } @@ -35,8 +35,8 @@ func (m *Method) CheckScope(scope middleware.Scope) bool { return false } -// Returns whether @perm is present in @scope -func isPermInScope(perm string, scope []string) bool { +// scopeHasPermission returns whether @perm is present in a given @scope +func scopeHasPermission(perm string, scope []string) bool { for _, s := range scope { if perm == s { return true diff --git a/internal/api/types.go b/internal/api/types.go index d92b64d..876ed45 100644 --- a/internal/api/types.go +++ b/internal/api/types.go @@ -2,7 +2,7 @@ package api /* (1) Configuration ---------------------------------------------------------*/ - +// Parameter represents a parameter definition (from api.json) type Parameter struct { Description string `json:"info"` Type string `json:"type"` @@ -10,6 +10,8 @@ type Parameter struct { Optional bool Default *interface{} `json:"default"` } + +// Method represents a method definition (from api.json) type Method struct { Description string `json:"info"` Permission [][]string `json:"scope"` @@ -17,6 +19,7 @@ type Method struct { Download *bool `json:"download"` } +// Controller represents a controller definition (from api.json) type Controller struct { GET *Method `json:"GET"` POST *Method `json:"POST"` diff --git a/internal/checker/public.go b/internal/checker/public.go index 02e2fe8..d10960a 100644 --- a/internal/checker/public.go +++ b/internal/checker/public.go @@ -5,7 +5,10 @@ import ( "git.xdrm.io/go/aicra/driver" ) +// ErrNoMatchingType is returned when the Match() method does not find any type checker var ErrNoMatchingType = errors.New("no matching type") + +// ErrDoesNotMatch is returned when the Check() method fails (invalid type value) var ErrDoesNotMatch = errors.New("does not match") // CreateRegistry creates an empty type registry diff --git a/response/arguments.go b/response/arguments.go index 7a640fe..58963db 100644 --- a/response/arguments.go +++ b/response/arguments.go @@ -4,7 +4,11 @@ import ( "errors" ) +// ErrUnknownKey is returned when a key does not exist using a getter var ErrUnknownKey = errors.New("key does not exist") + +// ErrInvalidType is returned when a typed getter tries to get a value that cannot be +// translated into the requested type var ErrInvalidType = errors.New("invalid type") // Has checks whether a key exists in the arguments