Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
ad958fa4
Commit
ad958fa4
authored
4 years ago
by
Patrick
Browse files
Options
Downloads
Patches
Plain Diff
modify some comments and modify some logger's message
parent
dcc2d263
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
protocol/rest/server/rest_server.go
+10
-7
10 additions, 7 deletions
protocol/rest/server/rest_server.go
protocol/rest/server/server_impl/go_restful_server.go
+2
-2
2 additions, 2 deletions
protocol/rest/server/server_impl/go_restful_server.go
with
12 additions
and
9 deletions
protocol/rest/server/rest_server.go
+
10
−
7
View file @
ad958fa4
...
...
@@ -95,6 +95,9 @@ func GetRouteFunc(invoker protocol.Invoker, methodConfig *rest_config.RestMethod
method
:=
svc
.
Method
()[
methodConfig
.
MethodName
]
argsTypes
:=
method
.
ArgsType
()
replyType
:=
method
.
ReplyType
()
// two ways to prepare arguments
// if method like this 'func1(req []interface{}, rsp *User) error'
// we don't have arguments type
if
(
len
(
argsTypes
)
==
1
||
len
(
argsTypes
)
==
2
&&
replyType
==
nil
)
&&
argsTypes
[
0
]
.
String
()
==
"[]interface {}"
{
args
,
err
=
getArgsInterfaceFromRequest
(
req
,
methodConfig
)
...
...
@@ -102,7 +105,7 @@ func GetRouteFunc(invoker protocol.Invoker, methodConfig *rest_config.RestMethod
args
,
err
=
getArgsFromRequest
(
req
,
argsTypes
,
methodConfig
)
}
if
err
!=
nil
{
logger
.
Errorf
(
"[Go Restful] parsing parameters error:%v"
,
err
)
logger
.
Errorf
(
"[Go Restful] parsing
http
parameters error:%v"
,
err
)
err
=
resp
.
WriteError
(
http
.
StatusInternalServerError
,
errors
.
New
(
parseParameterErrorStr
))
if
err
!=
nil
{
logger
.
Errorf
(
"[Go Restful] WriteErrorString error:%v"
,
err
)
...
...
@@ -199,7 +202,7 @@ func assembleArgsFromHeaders(methodConfig *rest_config.RestMethodConfig, req Res
for
k
,
v
:=
range
methodConfig
.
HeadersMap
{
param
:=
req
.
HeaderParameter
(
v
)
if
k
<
0
||
k
>=
argsLength
{
return
perrors
.
Errorf
(
"[Go restful] Header param parse error, the
args:%v doesn't exist"
,
k
)
return
perrors
.
Errorf
(
"[Go restful] Header param parse error, the
index %v args of method:%v doesn't exist"
,
k
,
methodConfig
.
MethodName
)
}
t
:=
argsTypes
[
k
]
if
t
.
Kind
()
==
reflect
.
Ptr
{
...
...
@@ -208,7 +211,7 @@ func assembleArgsFromHeaders(methodConfig *rest_config.RestMethodConfig, req Res
if
t
.
Kind
()
==
reflect
.
String
{
args
[
k
]
=
param
}
else
{
return
perrors
.
Errorf
(
"[Go restful] Header param parse error, the
args:%v of
type isn't string"
,
k
)
return
perrors
.
Errorf
(
"[Go restful] Header param parse error, the
index %v args's
type isn't string"
,
k
)
}
}
return
nil
...
...
@@ -251,7 +254,7 @@ func assembleArgsFromQueryParams(methodConfig *rest_config.RestMethodConfig, arg
)
for
k
,
v
:=
range
methodConfig
.
QueryParamsMap
{
if
k
<
0
||
k
>=
argsLength
{
return
perrors
.
Errorf
(
"[Go restful] Query param parse error, the
args:%v doesn't exist"
,
k
)
return
perrors
.
Errorf
(
"[Go restful] Query param parse error, the
index %v args of method:%v doesn't exist"
,
k
,
methodConfig
.
MethodName
)
}
t
:=
argsTypes
[
k
]
kind
:=
t
.
Kind
()
...
...
@@ -272,7 +275,7 @@ func assembleArgsFromQueryParams(methodConfig *rest_config.RestMethodConfig, arg
}
else
if
kind
==
reflect
.
Int64
{
param
,
err
=
strconv
.
ParseInt
(
req
.
QueryParameter
(
v
),
10
,
64
)
}
else
{
return
perrors
.
Errorf
(
"[Go restful] Query param parse error, the
args:%v of
type isn't int or string or slice"
,
k
)
return
perrors
.
Errorf
(
"[Go restful] Query param parse error, the
index %v args's
type isn't int or string or slice"
,
k
)
}
if
err
!=
nil
{
return
perrors
.
Errorf
(
"[Go restful] Query param parse error, error:%v"
,
perrors
.
WithStack
(
err
))
...
...
@@ -291,7 +294,7 @@ func assembleArgsFromPathParams(methodConfig *rest_config.RestMethodConfig, args
)
for
k
,
v
:=
range
methodConfig
.
PathParamsMap
{
if
k
<
0
||
k
>=
argsLength
{
return
perrors
.
Errorf
(
"[Go restful] Path param parse error, the
args:%v doesn't exist"
,
k
)
return
perrors
.
Errorf
(
"[Go restful] Path param parse error, the
index %v args of method:%v doesn't exist"
,
k
,
methodConfig
.
MethodName
)
}
t
:=
argsTypes
[
k
]
kind
:=
t
.
Kind
()
...
...
@@ -310,7 +313,7 @@ func assembleArgsFromPathParams(methodConfig *rest_config.RestMethodConfig, args
}
else
if
kind
==
reflect
.
String
{
param
=
req
.
PathParameter
(
v
)
}
else
{
return
perrors
.
Errorf
(
"[Go restful] Path param parse error, the
args:%v of
type isn't int or string"
,
k
)
return
perrors
.
Errorf
(
"[Go restful] Path param parse error, the
index %v args's
type isn't int or string"
,
k
)
}
if
err
!=
nil
{
return
perrors
.
Errorf
(
"[Go restful] Path param parse error, error is %v"
,
perrors
.
WithStack
(
err
))
...
...
This diff is collapsed.
Click to expand it.
protocol/rest/server/server_impl/go_restful_server.go
+
2
−
2
View file @
ad958fa4
...
...
@@ -46,13 +46,13 @@ func init() {
var
filterSlice
[]
restful
.
FilterFunction
//
A
rest server implement by go-restful
//
GoRestfulServer a
rest server implement by go-restful
type
GoRestfulServer
struct
{
srv
*
http
.
Server
container
*
restful
.
Container
}
//
A
constructor of GoRestfulServer
//
NewGoRestfulServer a
constructor of GoRestfulServer
func
NewGoRestfulServer
()
server
.
RestServer
{
return
&
GoRestfulServer
{}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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