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
fa27aa23
Commit
fa27aa23
authored
5 years ago
by
Patrick
Browse files
Options
Downloads
Patches
Plain Diff
modify rest protocol
parent
3a46e046
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
protocol/rest/rest_protocol.go
+19
-10
19 additions, 10 deletions
protocol/rest/rest_protocol.go
with
19 additions
and
10 deletions
protocol/rest/rest_protocol.go
+
19
−
10
View file @
fa27aa23
...
...
@@ -27,6 +27,7 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/config"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/rest/rest_interface"
...
...
@@ -63,10 +64,14 @@ func (rp *RestProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
url
:=
invoker
.
GetUrl
()
serviceKey
:=
url
.
ServiceKey
()
exporter
:=
NewRestExporter
(
serviceKey
,
invoker
,
rp
.
ExporterMap
())
restConfig
:=
GetRestProviderServiceConfig
(
strings
.
TrimPrefix
(
url
.
Path
,
"/"
))
restServiceConfig
:=
GetRestProviderServiceConfig
(
strings
.
TrimPrefix
(
url
.
Path
,
"/"
))
if
restServiceConfig
==
nil
{
logger
.
Errorf
(
"%s service doesn't has provider config"
,
url
.
Path
)
return
nil
}
rp
.
SetExporterMap
(
serviceKey
,
exporter
)
restServer
:=
rp
.
getServer
(
url
,
rest
Config
)
restServer
.
Deploy
(
invoker
,
restConfig
.
RestMethodConfigsMap
)
restServer
:=
rp
.
getServer
(
url
,
rest
ServiceConfig
.
Server
)
restServer
.
Deploy
(
invoker
,
rest
Service
Config
.
RestMethodConfigsMap
)
return
exporter
}
...
...
@@ -78,15 +83,19 @@ func (rp *RestProtocol) Refer(url common.URL) protocol.Invoker {
if
t
,
err
:=
time
.
ParseDuration
(
requestTimeoutStr
);
err
==
nil
{
requestTimeout
=
t
}
restConfig
:=
GetRestConsumerServiceConfig
(
strings
.
TrimPrefix
(
url
.
Path
,
"/"
))
restServiceConfig
:=
GetRestConsumerServiceConfig
(
strings
.
TrimPrefix
(
url
.
Path
,
"/"
))
if
restServiceConfig
==
nil
{
logger
.
Errorf
(
"%s service doesn't has consumer config"
,
url
.
Path
)
return
nil
}
restOptions
:=
rest_interface
.
RestOptions
{
RequestTimeout
:
requestTimeout
,
ConnectTimeout
:
connectTimeout
}
restClient
:=
rp
.
getClient
(
restOptions
,
rest
Config
)
invoker
:=
NewRestInvoker
(
url
,
&
restClient
,
restConfig
.
RestMethodConfigsMap
)
restClient
:=
rp
.
getClient
(
restOptions
,
rest
ServiceConfig
.
Client
)
invoker
:=
NewRestInvoker
(
url
,
&
restClient
,
rest
Service
Config
.
RestMethodConfigsMap
)
rp
.
SetInvokers
(
invoker
)
return
invoker
}
func
(
rp
*
RestProtocol
)
getServer
(
url
common
.
URL
,
restConfig
*
rest_interface
.
RestServiceConfi
g
)
rest_interface
.
RestServer
{
func
(
rp
*
RestProtocol
)
getServer
(
url
common
.
URL
,
serverType
strin
g
)
rest_interface
.
RestServer
{
restServer
,
ok
:=
rp
.
serverMap
[
url
.
Location
]
if
!
ok
{
_
,
ok
:=
rp
.
ExporterMap
()
.
Load
(
url
.
ServiceKey
())
...
...
@@ -96,7 +105,7 @@ func (rp *RestProtocol) getServer(url common.URL, restConfig *rest_interface.Res
rp
.
serverLock
.
Lock
()
restServer
,
ok
=
rp
.
serverMap
[
url
.
Location
]
if
!
ok
{
restServer
=
extension
.
GetNewRestServer
(
restConfig
.
S
erver
)
restServer
=
extension
.
GetNewRestServer
(
s
erver
Type
)
restServer
.
Start
(
url
)
rp
.
serverMap
[
url
.
Location
]
=
restServer
}
...
...
@@ -106,13 +115,13 @@ func (rp *RestProtocol) getServer(url common.URL, restConfig *rest_interface.Res
return
restServer
}
func
(
rp
*
RestProtocol
)
getClient
(
restOptions
rest_interface
.
RestOptions
,
restConfig
*
rest_interface
.
RestServiceConfi
g
)
rest_interface
.
RestClient
{
func
(
rp
*
RestProtocol
)
getClient
(
restOptions
rest_interface
.
RestOptions
,
clientType
strin
g
)
rest_interface
.
RestClient
{
restClient
,
ok
:=
rp
.
clientMap
[
restOptions
]
rp
.
clientLock
.
Lock
()
if
!
ok
{
restClient
,
ok
=
rp
.
clientMap
[
restOptions
]
if
!
ok
{
restClient
=
extension
.
GetNewRestClient
(
restConfig
.
C
lient
,
&
restOptions
)
restClient
=
extension
.
GetNewRestClient
(
c
lient
Type
,
&
restOptions
)
rp
.
clientMap
[
restOptions
]
=
restClient
}
}
...
...
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