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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
4c5df47f
Commit
4c5df47f
authored
3 years ago
by
Jan Semmelink
Browse files
Options
Downloads
Patches
Plain Diff
Remove restrictions on handler response type - any type that can marshal to JSON is ok.
parent
745750a4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/context.go
+5
-1
5 additions, 1 deletion
api/context.go
api/handler.go
+0
-14
0 additions, 14 deletions
api/handler.go
with
5 additions
and
15 deletions
api/context.go
+
5
−
1
View file @
4c5df47f
...
...
@@ -150,7 +150,6 @@ func (ctx apiContext) GetRequestBody(requestStructType reflect.Type) (interface{
return
nil
,
errors
.
Wrapf
(
err
,
"invalid request body"
)
}
}
return
requestStructValuePtr
.
Elem
()
.
Interface
(),
nil
}
...
...
@@ -175,6 +174,11 @@ func (ctx *apiContext) applyClaim(name string, valuePtr interface{}) error {
}
func
(
ctx
*
apiContext
)
setClaim
(
name
string
,
structType
reflect
.
Type
,
structValue
reflect
.
Value
)
error
{
if
len
(
ctx
.
Claim
())
==
0
{
ctx
.
Debugf
(
"NO CLAIM to apply to %s of type (%s)"
,
name
,
structType
.
Name
())
return
nil
}
for
fieldName
,
claimValue
:=
range
ctx
.
Claim
()
{
if
field
:=
structValue
.
FieldByName
(
fieldName
);
field
.
IsValid
()
{
if
err
:=
reflection
.
SetValue
(
field
,
claimValue
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
api/handler.go
+
0
−
14
View file @
4c5df47f
...
...
@@ -60,20 +60,6 @@ func NewHandler(fnc interface{}) (handler, error) {
h
.
RequestBodyType
=
fncType
.
In
(
2
)
}
//if 2 results, first must be response struct or array of response structs that will be marshalled to JSON
if
fncType
.
NumOut
()
>
1
{
if
fncType
.
Out
(
0
)
.
Kind
()
==
reflect
.
Slice
{
if
err
:=
validateStructType
(
fncType
.
Out
(
0
)
.
Elem
());
err
!=
nil
{
return
h
,
errors
.
Errorf
(
"first result %v is not valid response []struct type"
,
fncType
.
Out
(
0
))
}
}
else
{
if
err
:=
validateStructType
(
fncType
.
Out
(
0
));
err
!=
nil
{
return
h
,
errors
.
Errorf
(
"first result %v is not valid response struct type"
,
fncType
.
Out
(
0
))
}
}
h
.
ResponseType
=
fncType
.
Out
(
0
)
}
//last result must be error
if
_
,
ok
:=
reflect
.
New
(
fncType
.
Out
(
fncType
.
NumOut
()
-
1
))
.
Interface
()
.
(
*
error
);
!
ok
{
return
h
,
errors
.
Errorf
(
"last result %v is not error type"
,
fncType
.
Out
(
fncType
.
NumOut
()
-
1
))
...
...
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