Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
7b9d39d2
Commit
7b9d39d2
authored
3 years ago
by
Francé Wilke
Browse files
Options
Downloads
Patches
Plain Diff
Remove "legacy" handler checks
parent
10715b81
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
handler_utils/api.go
+5
-17
5 additions, 17 deletions
handler_utils/api.go
handler_utils/sqs.go
+6
-15
6 additions, 15 deletions
handler_utils/sqs.go
struct_utils/map_params.go
+5
-7
5 additions, 7 deletions
struct_utils/map_params.go
with
16 additions
and
39 deletions
handler_utils/api.go
+
5
−
17
View file @
7b9d39d2
...
@@ -3,7 +3,6 @@ package handler_utils
...
@@ -3,7 +3,6 @@ package handler_utils
import
(
import
(
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/events"
"gitlab.com/uafrica/go-utils/errors"
"gitlab.com/uafrica/go-utils/errors"
"gitlab.com/uafrica/go-utils/logs"
"reflect"
"reflect"
"strconv"
"strconv"
"strings"
"strings"
...
@@ -12,8 +11,6 @@ import (
...
@@ -12,8 +11,6 @@ import (
// ValidateAPIEndpoints checks that all API endpoints are correctly defined using one of the supported handler types
// ValidateAPIEndpoints checks that all API endpoints are correctly defined using one of the supported handler types
// return updated endpoints with additional information
// return updated endpoints with additional information
func
ValidateAPIEndpoints
(
endpoints
map
[
string
]
map
[
string
]
interface
{})
(
map
[
string
]
map
[
string
]
interface
{},
error
)
{
func
ValidateAPIEndpoints
(
endpoints
map
[
string
]
map
[
string
]
interface
{})
(
map
[
string
]
map
[
string
]
interface
{},
error
)
{
countLegacy
:=
0
countHandler
:=
0
for
resource
,
methodHandlers
:=
range
endpoints
{
for
resource
,
methodHandlers
:=
range
endpoints
{
if
resource
==
""
{
if
resource
==
""
{
return
nil
,
errors
.
Errorf
(
"blank resource"
)
return
nil
,
errors
.
Errorf
(
"blank resource"
)
...
@@ -35,21 +32,14 @@ func ValidateAPIEndpoints(endpoints map[string]map[string]interface{}) (map[stri
...
@@ -35,21 +32,14 @@ func ValidateAPIEndpoints(endpoints map[string]map[string]interface{}) (map[stri
return
nil
,
errors
.
Errorf
(
"nil handler on %s %s"
,
method
,
resource
)
return
nil
,
errors
.
Errorf
(
"nil handler on %s %s"
,
method
,
resource
)
}
}
if
_
,
ok
:=
handlerFunc
.
(
func
(
req
events
.
APIGatewayProxyRequest
)
(
response
events
.
APIGatewayProxyResponse
,
err
error
));
ok
{
//ok - leave as is - we support this legacyHandler
countLegacy
++
}
else
{
handler
,
err
:=
NewHandler
(
handlerFunc
)
handler
,
err
:=
NewHandler
(
handlerFunc
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"%s %s has invalid handler %T"
,
method
,
resource
,
handlerFunc
)
return
nil
,
errors
.
Wrapf
(
err
,
"%s %s has invalid handler %T"
,
method
,
resource
,
handlerFunc
)
}
}
//replace the endpoint value so that we can quickly call this handler
//replace the endpoint value so that we can quickly call this handler
endpoints
[
resource
][
method
]
=
handler
endpoints
[
resource
][
method
]
=
handler
countHandler
++
}
}
}
}
}
logs
.
Info
(
"Checked %d legacy and %d new handlers
\n
"
,
countLegacy
,
countHandler
)
return
endpoints
,
nil
return
endpoints
,
nil
}
}
...
@@ -106,8 +96,6 @@ func ValidateRequestParams(request *events.APIGatewayProxyRequest, paramsStructT
...
@@ -106,8 +96,6 @@ func ValidateRequestParams(request *events.APIGatewayProxyRequest, paramsStructT
return
paramsStructValuePtr
,
nil
return
paramsStructValuePtr
,
nil
}
}
func
setParamFromStr
(
fieldValue
reflect
.
Value
,
paramStrValue
string
)
error
{
func
setParamFromStr
(
fieldValue
reflect
.
Value
,
paramStrValue
string
)
error
{
switch
fieldValue
.
Type
()
.
Kind
()
{
switch
fieldValue
.
Type
()
.
Kind
()
{
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
...
...
This diff is collapsed.
Click to expand it.
handler_utils/sqs.go
+
6
−
15
View file @
7b9d39d2
...
@@ -11,8 +11,6 @@ import (
...
@@ -11,8 +11,6 @@ import (
// ValidateSQSEndpoints checks that all SQS endpoints are correctly defined using one of the supported handler types
// ValidateSQSEndpoints checks that all SQS endpoints are correctly defined using one of the supported handler types
// return updated endpoints with additional information
// return updated endpoints with additional information
func
ValidateSQSEndpoints
(
endpoints
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
func
ValidateSQSEndpoints
(
endpoints
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
countLegacy
:=
0
countHandler
:=
0
for
messageType
,
handlerFunc
:=
range
endpoints
{
for
messageType
,
handlerFunc
:=
range
endpoints
{
if
messageType
==
""
{
if
messageType
==
""
{
return
nil
,
errors
.
Errorf
(
"blank messageType"
)
return
nil
,
errors
.
Errorf
(
"blank messageType"
)
...
@@ -21,10 +19,6 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac
...
@@ -21,10 +19,6 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac
return
nil
,
errors
.
Errorf
(
"nil handler on %s"
,
messageType
)
return
nil
,
errors
.
Errorf
(
"nil handler on %s"
,
messageType
)
}
}
if
_
,
ok
:=
handlerFunc
.
(
func
(
req
events
.
SQSEvent
)
(
err
error
));
ok
{
// ok - leave as is - we support this legacyHandler
countLegacy
++
}
else
{
handler
,
err
:=
NewSQSHandler
(
handlerFunc
)
handler
,
err
:=
NewSQSHandler
(
handlerFunc
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"%v has invalid handler %T"
,
messageType
,
handlerFunc
)
return
nil
,
errors
.
Wrapf
(
err
,
"%v has invalid handler %T"
,
messageType
,
handlerFunc
)
...
@@ -32,10 +26,7 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac
...
@@ -32,10 +26,7 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac
// replace the endpoint value so we can quickly call this handler
// replace the endpoint value so we can quickly call this handler
endpoints
[
messageType
]
=
handler
endpoints
[
messageType
]
=
handler
logs
.
Info
(
"%s: OK (request: %v)
\n
"
,
messageType
,
handler
.
RecordType
)
logs
.
Info
(
"%s: OK (request: %v)
\n
"
,
messageType
,
handler
.
RecordType
)
countHandler
++
}
}
}
logs
.
Info
(
"Checked %d legacy and %d new handlers
\n
"
,
countLegacy
,
countHandler
)
return
endpoints
,
nil
return
endpoints
,
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
struct_utils/map_params.go
+
5
−
7
View file @
7b9d39d2
...
@@ -7,9 +7,8 @@ import (
...
@@ -7,9 +7,8 @@ import (
"strings"
"strings"
)
)
//convert fields in a struct to a map of parameters, as if defined in a URL
// MapParams convert fields in a struct to a map of parameters, as if defined in a URL
//we use this mainly for legacy functions that expect params to be defined in a map[string]string
// to convert the new params struct into a map[string]string
//to convert the new params struct into such a map
func
MapParams
(
data
interface
{})
map
[
string
]
string
{
func
MapParams
(
data
interface
{})
map
[
string
]
string
{
params
:=
map
[
string
]
string
{}
params
:=
map
[
string
]
string
{}
addStructParams
(
params
,
reflect
.
ValueOf
(
data
))
addStructParams
(
params
,
reflect
.
ValueOf
(
data
))
...
@@ -42,7 +41,6 @@ func addStructParams(params map[string]string, structValue reflect.Value) {
...
@@ -42,7 +41,6 @@ func addStructParams(params map[string]string, structValue reflect.Value) {
}
}
if
!
skip
{
if
!
skip
{
// lists must be written as JSON lists so they can be unmarshalled
// lists must be written as JSON lists so they can be unmarshalled
//jsut because that is how the legacy code did it
if
t
.
Field
(
i
)
.
Type
.
Kind
()
==
reflect
.
Slice
{
if
t
.
Field
(
i
)
.
Type
.
Kind
()
==
reflect
.
Slice
{
jsonValue
,
_
:=
json
.
Marshal
(
structValue
.
Field
(
i
)
.
Interface
())
jsonValue
,
_
:=
json
.
Marshal
(
structValue
.
Field
(
i
)
.
Interface
())
params
[
jsonTags
[
0
]]
=
string
(
jsonValue
)
params
[
jsonTags
[
0
]]
=
string
(
jsonValue
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment