Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #3

Merged
merged 319 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
319 commits
Select commit Hold shift + click to select a range
08c3674
add comment for public method
cityiron Jul 29, 2020
4ef21cb
Add: add ip address match function
watermelo Jul 29, 2020
891ec6c
Add: add listener for tag router
watermelo Jul 29, 2020
0d56ab0
Merge branch 'develop' into featrue/tagRouter
watermelo Jul 29, 2020
8580ad0
Mod: update tag router unit test
watermelo Jul 30, 2020
0686ca9
Merge pull request #670 from zouyx/hotfix/fix1.4
AlexStocks Jul 30, 2020
f2261ce
format code
Patrick0308 Jul 30, 2020
6f77a0c
add code format and comment
cityiron Jul 30, 2020
ddf63de
ugly code to elegant
cityiron Jul 31, 2020
9b73313
Modify README_CN
Jul 31, 2020
55c84cd
Modify README_CN.md
Jul 31, 2020
db1e5da
Merge pull request #676 from Patrick0308/rest_methodtype
AlexStocks Aug 1, 2020
abcc4df
Merge pull request #683 from QMHTMY/master
AlexStocks Aug 1, 2020
2e96585
refactor config center
zouyx Aug 2, 2020
bc46c9a
Modify README_CN
Jul 31, 2020
12680fd
Modify README_CN.md
Jul 31, 2020
70c01a5
Add: add unit test for dynamic tag
watermelo Aug 2, 2020
a31a4e2
Add: add zk jar for tag test
watermelo Aug 3, 2020
65b215a
Merge pull request #18 from apache/develop
lzp0412 Aug 3, 2020
73e7bdd
refactor config center
zouyx Aug 3, 2020
d5a491e
add case for this feature
zouyx Aug 3, 2020
3e9f57a
refactor config center
zouyx Aug 3, 2020
0ef7765
unregister instance when registry destroy
lzp0412 Aug 4, 2020
d32cbdb
fix review comment
zouyx Aug 4, 2020
e0dd74e
fix review comment
zouyx Aug 4, 2020
8e6d2ac
fix review comment
zouyx Aug 4, 2020
7ad26fd
try to fix zk problem
wenxuwan Aug 4, 2020
53587ec
try to fix ut failed
wenxuwan Aug 5, 2020
7a88bab
change the default value to 15m
wenxuwan Aug 5, 2020
c33f4ea
change the default value to 15min
wenxuwan Aug 5, 2020
2d8224e
fix review comment
lzp0412 Aug 5, 2020
da4225e
Fix kubernetes ut
Aug 5, 2020
79ade24
FMT k8s pkg
Aug 5, 2020
3bc2938
fix review comment
zouyx Aug 5, 2020
e654674
register service instance after provider config load
Patrick0308 Aug 5, 2020
dc075da
modify name
Patrick0308 Aug 5, 2020
eb919e1
fix review comment
zouyx Aug 5, 2020
9b4745f
fix comments
wenxuwan Aug 6, 2020
269714a
Merge pull request #693 from sxllwx/fix_k8s_ut
AlexStocks Aug 6, 2020
c4fbd60
Merge pull request #692 from wenxuwan/master
AlexStocks Aug 6, 2020
0b5e2f4
Merge pull request #689 from lzp0412/develop
AlexStocks Aug 6, 2020
bcffde9
fix travis
zouyx Aug 6, 2020
5e377f4
Merge pull request #665 from watermelo/featrue/tagRouter
AlexStocks Aug 6, 2020
603ffc1
Revert "Ftr: dynamic tag router"
AlexStocks Aug 6, 2020
6300a24
fix travis
zouyx Aug 6, 2020
debd07c
Merge pull request #3 from apache/develop
cityiron Aug 7, 2020
b8ec301
Merge branch 'develop' into zoneware
cityiron Aug 7, 2020
bd7c5ca
stack level
Aug 7, 2020
0a98a20
Merge pull request #687 from zouyx/feature/optimizeRemotesConfiguration
zouyx Aug 7, 2020
613cc6e
Merge pull request #696 from apache/revert-665-featrue/tagRouter
zouyx Aug 7, 2020
95e863e
add default priority 0 for condition url which neither application no…
Aug 7, 2020
01910a0
reduce cognitive in base_directory.go
Aug 7, 2020
4c250c2
add cluster interceptor
cityiron Aug 7, 2020
2b19ca5
a quick prototype for bitmap router chain
beiwei30 Aug 7, 2020
03bde75
import split
cityiron Aug 7, 2020
ddb2504
Add: add setInvoker function for router chain
watermelo Aug 7, 2020
f4481b0
Mod: merge branch to resolve conflict
watermelo Aug 7, 2020
cf75539
replace bzr to git
Aug 8, 2020
96a3688
fix empty application configure always return true in base_directory …
Aug 8, 2020
5f02d53
added comment to file.go
Aug 8, 2020
87a52c3
make condition router no-poolable and introduce consumer url in Regis…
beiwei30 Aug 8, 2020
2aafdeb
Merge pull request #662 from williamfeng323/feature/application-level…
pantianying Aug 9, 2020
04e0b4e
Correct words and Format codes
Howie59 Aug 9, 2020
c56ceb0
Format codes
Howie59 Aug 9, 2020
4dfc8aa
change format
cityiron Aug 9, 2020
f0017a8
Merge pull request #659 from DogBaoBao/zoneware
zouyx Aug 9, 2020
49ebaba
add tls support
Aug 2, 2020
ecdf8cc
add nolint
Howie59 Aug 9, 2020
443c1b8
change module version
Aug 9, 2020
bef03b4
upgrade getty version
Aug 9, 2020
c62ec2e
fix getty const
Aug 9, 2020
b75fcea
fix getty const
Aug 9, 2020
8e85afd
optimized code
Patrick0308 Mar 31, 2020
13369bf
use adapter model to modify restServer
Patrick0308 Mar 31, 2020
9a9b3a7
remove adapter
Patrick0308 Mar 31, 2020
bcb0100
optimize header transmit in RestClient and RestServer
Patrick0308 Apr 1, 2020
f2949db
add some comments
Patrick0308 Apr 1, 2020
79bd56c
modify some comments and when parsing parameters occurred error, retu…
Patrick0308 Apr 1, 2020
6540c89
modify comments
Patrick0308 Apr 1, 2020
4736cdc
remove new function
Patrick0308 Apr 1, 2020
f580ed0
modify some comments
Patrick0308 Apr 1, 2020
d469144
modify some comments and modify some logger's message
Patrick0308 Apr 1, 2020
ca2538a
optimized code
Patrick0308 Apr 4, 2020
a7174c3
let go_restful_server support same url and different methodType
Patrick0308 Jul 28, 2020
ea86567
format code
Patrick0308 Jul 30, 2020
af3176f
fix nacos unit test failed
lzp0412 Aug 9, 2020
4ef45c6
Merge remote-tracking branch 'remotes/dubbogo/develop' into develop
lzp0412 Aug 9, 2020
9652ae6
update getty pkg
zouyx Aug 9, 2020
6dc42eb
Merge pull request #705 from lzp0412/develop
AlexStocks Aug 9, 2020
457dc0c
add tls support
Aug 2, 2020
01c14c3
change module version
Aug 9, 2020
3b2dc85
upgrade getty version
Aug 9, 2020
c7cb13b
fix getty const
Aug 9, 2020
addc4b4
fix getty const
Aug 9, 2020
49d1c94
rm go version
Aug 9, 2020
9603daa
fix
Aug 9, 2020
5a51b7f
Merge remote-tracking branch 'origin/AddTslSupport' into AddTslSupport
Aug 9, 2020
967faf8
Merge pull request #702 from dubbo-x/fix
AlexStocks Aug 9, 2020
cb30a98
rm go version
Aug 9, 2020
aaa8be3
Merge pull request #704 from Howie66/master
fangyincheng Aug 9, 2020
58dc145
Correct words and Format codes
Howie59 Aug 9, 2020
2791895
Format codes
Howie59 Aug 9, 2020
25281bf
add nolint
Howie59 Aug 9, 2020
ef95dd9
refactor the code style
beiwei30 Aug 10, 2020
83ff9e7
honor HealthCheckRouter's enabled flag
beiwei30 Aug 10, 2020
30c587e
get application from both dir.url and dir.url.suburl
Aug 10, 2020
367c42b
use mutex to copy invokers
beiwei30 Aug 10, 2020
a84e17b
Merge branch 'develop' into bitmap-router
beiwei30 Aug 10, 2020
ef1ddcf
set invokers for router chain in static directory to pass unit test
beiwei30 Aug 10, 2020
fedaae5
fix unit test
beiwei30 Aug 10, 2020
48d713a
correct go fmt
beiwei30 Aug 10, 2020
bc5ad76
update hessian2 pkg
zouyx Aug 10, 2020
a3dcb22
Add: add notify router for tag router
watermelo Aug 10, 2020
d7014ee
update getty pkg
zouyx Aug 10, 2020
316e276
Mod: modify tag router strings compare
watermelo Aug 10, 2020
b8e15bf
fix
Aug 10, 2020
07bf1c4
fix
Aug 10, 2020
bdf48c7
Merge remote-tracking branch 'remotes/upstream/develop' into AddTslSu…
Aug 10, 2020
67abe6b
fix
Aug 10, 2020
ee46d46
split pkg
Aug 10, 2020
350185e
fix travis
zouyx Aug 11, 2020
9aa2bc8
fix review comment
zouyx Aug 11, 2020
5faedba
fix review comment
zouyx Aug 11, 2020
e80c2e4
Merge pull request #709 from zouyx/updatePkg
zouyx Aug 11, 2020
25ddfa5
Merge pull request #707 from williamfeng323/bugfix-application-router
fangyincheng Aug 11, 2020
6c606c1
split pkg
Aug 12, 2020
f2d2ba6
make a comment variable
Aug 12, 2020
6cf2dc8
Mod: move match codes to gost net
watermelo Aug 12, 2020
0121001
use mutex for invokers set and get
beiwei30 Aug 12, 2020
6708d24
Mod: modify comments
watermelo Aug 12, 2020
8458c88
use defer to unlock
beiwei30 Aug 13, 2020
e46939b
code polish for else branch
beiwei30 Aug 13, 2020
9c12919
make sure lock for invokers correctly
beiwei30 Aug 13, 2020
37ebc63
code polish for else branch
beiwei30 Aug 13, 2020
88e097f
fix
Aug 13, 2020
d0345ec
fix
Aug 13, 2020
622e6c5
fix
Aug 13, 2020
c7e0522
fix
Aug 13, 2020
b88d28f
make router.AddrPool with initial size
beiwei30 Aug 14, 2020
7425cd7
correct unlock
beiwei30 Aug 14, 2020
21e572c
rename ch to notify
beiwei30 Aug 14, 2020
0da3151
make map with init size
beiwei30 Aug 14, 2020
0a475bf
Mod: add router tag unit tests scripts
watermelo Aug 14, 2020
aa0ee1c
Merge pull request #685 from aliiohs/AddTslSupport
zouyx Aug 14, 2020
9d8afcd
Merge pull request #703 from watermelo/featrue/tagRouter
AlexStocks Aug 15, 2020
2756d13
upgrade arch png
Isaac-Zhang Aug 15, 2020
69e384e
Merge branch '1.4' into feature/merge1.4
zouyx Aug 16, 2020
a007d32
merge 1.4
zouyx Aug 16, 2020
e3dd46f
Merge pull request #714 from Isaac-Zhang/develop
fangyincheng Aug 16, 2020
f0809f6
add register service instance unit test
Patrick0308 Aug 16, 2020
e4ba8db
register service instance after provider config load
Patrick0308 Aug 5, 2020
b3ab323
modify name
Patrick0308 Aug 5, 2020
52e8a9e
add register service instance unit test
Patrick0308 Aug 16, 2020
066162b
Merge branch 'service-register' of https://github.com/Patrick0308/dub…
Patrick0308 Aug 16, 2020
5a135e6
Merge pull request #716 from zouyx/feature/merge1.4
Aug 16, 2020
ce5751b
when don't has metadataService ignore this error
Patrick0308 Aug 16, 2020
de36a0d
format code
Patrick0308 Aug 17, 2020
5e35cd6
Update: dubbogo/getty -> apache/dubbo-getty
AlexStocks Aug 18, 2020
31194a8
Correct words and Format codes
Howie59 Aug 9, 2020
101e696
fix comment error
AlexStocks Aug 18, 2020
12b6d6a
Fix: comment error
AlexStocks Aug 18, 2020
7c752e8
Fix: format error
AlexStocks Aug 18, 2020
d4336cc
Fix: format test/integrate/dubbo/go-server/server.go
AlexStocks Aug 18, 2020
e361067
foramt go.mod
AlexStocks Aug 18, 2020
fc8d7b0
use NewTicker instead of builtin to avoid of GC pressure.
Aug 18, 2020
70bd933
avoid reflection api
beiwei30 Aug 18, 2020
7f47894
fix typo in comment
beiwei30 Aug 18, 2020
1166752
forbid excuting twice
cvictory Aug 18, 2020
b04224b
Fix: fix tag router rule copy
watermelo Aug 18, 2020
f9fdbeb
Merge branch 'develop', and reimplement dynamic tag rule
beiwei30 Aug 18, 2020
8c4d42e
group var
beiwei30 Aug 18, 2020
f606124
use len(tag) > 0
beiwei30 Aug 18, 2020
c50da85
modify msg
Patrick0308 Aug 18, 2020
5c3f71d
add comment
Patrick0308 Aug 18, 2020
0cb2789
switch to use sync.Mutex instead of atomic.Value.
beiwei30 Aug 18, 2020
066629b
new impl for address cache lifecycle
beiwei30 Aug 19, 2020
fd183d8
switch back to atomic value, I believe this is the best solution come…
beiwei30 Aug 19, 2020
c167842
avoid of copying and comparing invokers as much as possible
beiwei30 Aug 19, 2020
43a3059
asynchronous subscribe nacos service info
lzp0412 Aug 19, 2020
cadae7b
format
Aug 19, 2020
7442ec3
fix imports
Patrick0308 Aug 20, 2020
941e69d
format
Aug 20, 2020
1708b41
fix bug
Aug 20, 2020
8a7a104
Merge pull request #720 from watermelo/Fix/tagRouterCopy
pantianying Aug 20, 2020
e21a257
Merge pull request #721 from lzp0412/develop
zouyx Aug 20, 2020
60f9822
format
Aug 20, 2020
9e1b4d1
fix imports
Patrick0308 Aug 20, 2020
d58e4fa
modify comment
Patrick0308 Aug 20, 2020
6657d27
Merge pull request #694 from Patrick0308/service-register
pantianying Aug 20, 2020
6835365
fix subscribe url wrong
Patrick0308 Aug 21, 2020
b7ae2ce
revert commit "fix subscribe url wrong"
Patrick0308 Aug 21, 2020
bb39786
fix subscribe url wrong
Patrick0308 Aug 21, 2020
0b81ef4
Merge pull request #724 from Patrick0308/1.5.1
zouyx Aug 21, 2020
6ccbc6c
Merge pull request #719 from cvictory/log_opt
AlexStocks Aug 22, 2020
1e0bf87
Merge commit '6ccbc6cc' into develop
AlexStocks Aug 22, 2020
aa796a8
forbid excuting twice
cvictory Aug 18, 2020
3c30353
Merge branch '1.5.1' into develop
Aug 22, 2020
3ed9f66
modify changes.md
zouyx Aug 22, 2020
457dc32
Merge pull request #725 from zouyx/addChange
zouyx Aug 22, 2020
7d1f424
Change file name to the same as interface name
zouyx Aug 22, 2020
489e795
Merge pull request #726 from zouyx/addChange
Patrick0308 Aug 23, 2020
2928502
Update README.md
zouyx Aug 23, 2020
d0bfafb
Merge branch '1.5' into develop
zouyx Aug 23, 2020
811f4f1
Merge branch '1.5'
zouyx Aug 23, 2020
ace8f6b
use defer for wg.Done()
Aug 25, 2020
62a7e88
Merge branch 'develop' into bitmap-router
beiwei30 Aug 25, 2020
6dc2295
fix getProviderConfig in initHystrixConfigProvider
YGrylls Aug 26, 2020
a0053d4
remove outdated comments
YGrylls Aug 26, 2020
96d0f79
format
Aug 27, 2020
09fa354
format
Aug 28, 2020
e6205de
Merge pull request #708 from beiwei30/bitmap-router
AlexStocks Aug 28, 2020
a111829
add detailed comment
YGrylls Aug 28, 2020
8b6e61e
Merge branch 'develop' of https://github.com/apache/dubbo-go into fix…
YGrylls Aug 28, 2020
d542f62
Add: import code rule
AlexStocks Aug 28, 2020
7e4e7fd
chore: Remove unnecessary return and judgement.
atlas-comstock Aug 29, 2020
d862270
Merge pull request #731 from YGrylls/fix/hystrix
hxmhlt Aug 29, 2020
4c483e0
Merge pull request #730 from YongHaoWu/remove-unnecessary-statement
AlexStocks Aug 31, 2020
f8434c3
format
Sep 1, 2020
6707cdc
Merge branch 'develop' into read
Sep 1, 2020
c1e9b84
format
Sep 1, 2020
763b436
fix bug
Sep 3, 2020
6dfac02
try to fix error log prints issue
wenxuwan Sep 4, 2020
6388c4a
Merge pull request #722 from dubbo-x/read
AlexStocks Sep 5, 2020
bb197cc
Merge pull request #735 from wenxuwan/master
AlexStocks Sep 6, 2020
f11bc6d
improve map access concurrency
skyao Sep 7, 2020
49c005a
Ftr: [refer dubbo 2.7.6] attachment type from map[string]stiring to m…
cvictory Sep 7, 2020
aa4d36a
Fix: integration testing problems
zouyx Sep 7, 2020
94fe6c6
Fix: integration testing problems
zouyx Sep 7, 2020
93cb0ac
Fix: integration testing problems
zouyx Sep 7, 2020
bff2cd6
Fix: integration testing problems
zouyx Sep 7, 2020
4cd2487
Fix: integration testing problems
zouyx Sep 7, 2020
a192291
address batch mode notification
beiwei30 Sep 7, 2020
27a8dc7
Fix: integration testing problems
zouyx Sep 7, 2020
c3adeae
Fix: integration testing problems
zouyx Sep 7, 2020
a15d6af
Fix: integration testing problems
zouyx Sep 7, 2020
04b35ea
Fix: integration testing problems
zouyx Sep 7, 2020
a76745f
fix review comment
Sep 7, 2020
9f50dc2
delete useless file
zouyx Sep 7, 2020
a87b814
enhance comments
beiwei30 Sep 8, 2020
837f41f
Merge pull request #740 from zouyx/feature/fixTestProblmes
Patrick0308 Sep 8, 2020
f146507
Revert "Fix: integration testing problems"
zouyx Sep 8, 2020
6209b52
move debug() into refreshInvokers and remove update method
beiwei30 Sep 8, 2020
99f2c3a
Merge remote-tracking branch 'upstream/develop' into improve/map-acce…
skyao Sep 8, 2020
51f4bc3
Merge pull request #744 from apache/revert-740-feature/fixTestProblmes
fangyincheng Sep 8, 2020
6299ce4
Merge branch 'develop' into improve/map-access-concurreny
skyao Sep 8, 2020
fe8e2f8
Merge pull request #739 from skyao/improve/map-access-concurreny
zouyx Sep 9, 2020
8ac1f91
Fix: rename SethealthChecker to SetHealthChecker
watermelo Sep 9, 2020
c9726e4
Fix: syntax error
watermelo Sep 9, 2020
e7d38aa
Merge pull request #741 from beiwei30/address-batch-mode
zouyx Sep 10, 2020
7bb924a
Merge pull request #746 from watermelo/Fix/rename_health_checher
AlexStocks Sep 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol/rest/client/client_impl/resty_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewRestyClient(restOption *client.RestOptions) client.RestClient {
}
}

func (rc *RestyClient) Do(restRequest *client.RestRequest, res interface{}) error {
func (rc *RestyClient) Do(restRequest *client.RestClientRequest, res interface{}) error {
r, err := rc.client.R().
SetHeader("Content-Type", restRequest.Consumes).
SetHeader("Accept", restRequest.Produces).
Expand Down
4 changes: 2 additions & 2 deletions protocol/rest/client/rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RestOptions struct {
ConnectTimeout time.Duration
}

type RestRequest struct {
type RestClientRequest struct {
Location string
Path string
Produces string
Expand All @@ -39,5 +39,5 @@ type RestRequest struct {
}

type RestClient interface {
Do(request *RestRequest, res interface{}) error
Do(request *RestClientRequest, res interface{}) error
}
3 changes: 1 addition & 2 deletions protocol/rest/rest_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func (ri *RestInvoker) Invoke(ctx context.Context, invocation protocol.Invocatio
if len(inv.Arguments()) > methodConfig.Body && methodConfig.Body >= 0 {
body = inv.Arguments()[methodConfig.Body]
}

req := &client.RestRequest{
req := &client.RestClientRequest{
Location: ri.GetUrl().Location,
Produces: methodConfig.Produces,
Consumes: methodConfig.Consumes,
Expand Down
4 changes: 3 additions & 1 deletion protocol/rest/rest_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ func (rp *RestProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
}
rp.SetExporterMap(serviceKey, exporter)
restServer := rp.getServer(url, restServiceConfig.Server)
restServer.Deploy(invoker, restServiceConfig.RestMethodConfigsMap)
for _, methodConfig := range restServiceConfig.RestMethodConfigsMap {
restServer.Deploy(methodConfig, server.GetRouteFunc(invoker, methodConfig))
}
return exporter
}

Expand Down
261 changes: 258 additions & 3 deletions protocol/rest/server/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,270 @@

package server

import (
"context"
"net/http"
"reflect"
"strconv"
"strings"
)

import (
perrors "github.com/pkg/errors"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/rest/config"
"github.com/apache/dubbo-go/protocol/invocation"
rest_config "github.com/apache/dubbo-go/protocol/rest/config"
)

type RestServer interface {
Start(url common.URL)
Deploy(invoker protocol.Invoker, restMethodConfig map[string]*config.RestMethodConfig)
UnDeploy(restMethodConfig map[string]*config.RestMethodConfig)
Deploy(restMethodConfig *rest_config.RestMethodConfig, routeFunc func(request RestServerRequest, response RestServerResponse))
UnDeploy(restMethodConfig *rest_config.RestMethodConfig)
Destroy()
}

// RestServerRequest interface
type RestServerRequest interface {
PathParameter(name string) string
PathParameters() map[string]string
QueryParameter(name string) string
QueryParameters(name string) []string
BodyParameter(name string) (string, error)
HeaderParameter(name string) string
ReadEntity(entityPointer interface{}) error
}

// RestServerResponse interface
type RestServerResponse interface {
WriteError(httpStatus int, err error) (writeErr error)
WriteEntity(value interface{}) error
}

func GetRouteFunc(invoker protocol.Invoker, methodConfig *rest_config.RestMethodConfig) func(req RestServerRequest, resp RestServerResponse) {
return func(req RestServerRequest, resp RestServerResponse) {
var (
err error
args []interface{}
)
svc := common.ServiceMap.GetService(invoker.GetUrl().Protocol, strings.TrimPrefix(invoker.GetUrl().Path, "/"))
// get method
method := svc.Method()[methodConfig.MethodName]
argsTypes := method.ArgsType()
replyType := method.ReplyType()
if (len(argsTypes) == 1 || len(argsTypes) == 2 && replyType == nil) &&
argsTypes[0].String() == "[]interface {}" {
args = getArgsInterfaceFromRequest(req, methodConfig)
} else {
args = getArgsFromRequest(req, argsTypes, methodConfig)
}
result := invoker.Invoke(context.Background(), invocation.NewRPCInvocation(methodConfig.MethodName, args, make(map[string]string)))
if result.Error() != nil {
err = resp.WriteError(http.StatusInternalServerError, result.Error())
if err != nil {
logger.Errorf("[Go Restful] WriteError error:%v", err)
}
return
}
err = resp.WriteEntity(result.Result())
if err != nil {
logger.Errorf("[Go Restful] WriteEntity error:%v", err)
}
}
}

// when service function like GetUser(req []interface{}, rsp *User) error
// use this method to get arguments
func getArgsInterfaceFromRequest(req RestServerRequest, methodConfig *rest_config.RestMethodConfig) []interface{} {
argsMap := make(map[int]interface{}, 8)
maxKey := 0
for k, v := range methodConfig.PathParamsMap {
if maxKey < k {
maxKey = k
}
argsMap[k] = req.PathParameter(v)
}
for k, v := range methodConfig.QueryParamsMap {
if maxKey < k {
maxKey = k
}
params := req.QueryParameters(v)
if len(params) == 1 {
argsMap[k] = params[0]
} else {
argsMap[k] = params
}
}
for k, v := range methodConfig.HeadersMap {
if maxKey < k {
maxKey = k
}
argsMap[k] = req.HeaderParameter(v)
}
if methodConfig.Body >= 0 {
if maxKey < methodConfig.Body {
maxKey = methodConfig.Body
}
m := make(map[string]interface{})
// TODO read as a slice
if err := req.ReadEntity(&m); err != nil {
logger.Warnf("[Go restful] Read body entity as map[string]interface{} error:%v", perrors.WithStack(err))
} else {
argsMap[methodConfig.Body] = m
}
}
args := make([]interface{}, maxKey+1)
for k, v := range argsMap {
if k >= 0 {
args[k] = v
}
}
return args
}

// get arguments from server.RestServerRequest
func getArgsFromRequest(req RestServerRequest, argsTypes []reflect.Type, methodConfig *rest_config.RestMethodConfig) []interface{} {
argsLength := len(argsTypes)
args := make([]interface{}, argsLength)
for i, t := range argsTypes {
args[i] = reflect.Zero(t).Interface()
}
assembleArgsFromPathParams(methodConfig, argsLength, argsTypes, req, args)
assembleArgsFromQueryParams(methodConfig, argsLength, argsTypes, req, args)
assembleArgsFromBody(methodConfig, argsTypes, req, args)
assembleArgsFromHeaders(methodConfig, req, argsLength, argsTypes, args)
return args
}

// assemble arguments from headers
func assembleArgsFromHeaders(methodConfig *rest_config.RestMethodConfig, req RestServerRequest, argsLength int, argsTypes []reflect.Type, args []interface{}) {
for k, v := range methodConfig.HeadersMap {
param := req.HeaderParameter(v)
if k < 0 || k >= argsLength {
logger.Errorf("[Go restful] Header param parse error, the args:%v doesn't exist", k)
continue
}
t := argsTypes[k]
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
if t.Kind() == reflect.String {
args[k] = param
} else {
logger.Errorf("[Go restful] Header param parse error, the args:%v of type isn't string", k)
}
}
}

// assemble arguments from body
func assembleArgsFromBody(methodConfig *rest_config.RestMethodConfig, argsTypes []reflect.Type, req RestServerRequest, args []interface{}) {
if methodConfig.Body >= 0 && methodConfig.Body < len(argsTypes) {
t := argsTypes[methodConfig.Body]
kind := t.Kind()
if kind == reflect.Ptr {
t = t.Elem()
}
var ni interface{}
if t.String() == "[]interface {}" {
ni = make([]map[string]interface{}, 0)
} else if t.String() == "interface {}" {
ni = make(map[string]interface{})
} else {
n := reflect.New(t)
if n.CanInterface() {
ni = n.Interface()
}
}
if err := req.ReadEntity(&ni); err != nil {
logger.Errorf("[Go restful] Read body entity error:%v", err)
} else {
args[methodConfig.Body] = ni
}
}
}

// assemble arguments from query params
func assembleArgsFromQueryParams(methodConfig *rest_config.RestMethodConfig, argsLength int, argsTypes []reflect.Type, req RestServerRequest, args []interface{}) {
var (
err error
param interface{}
i64 int64
)
for k, v := range methodConfig.QueryParamsMap {
if k < 0 || k >= argsLength {
logger.Errorf("[Go restful] Query param parse error, the args:%v doesn't exist", k)
continue
}
t := argsTypes[k]
kind := t.Kind()
if kind == reflect.Ptr {
t = t.Elem()
}
if kind == reflect.Slice {
param = req.QueryParameters(v)
} else if kind == reflect.String {
param = req.QueryParameter(v)
} else if kind == reflect.Int {
param, err = strconv.Atoi(req.QueryParameter(v))
} else if kind == reflect.Int32 {
i64, err = strconv.ParseInt(req.QueryParameter(v), 10, 32)
if err == nil {
param = int32(i64)
}
} else if kind == reflect.Int64 {
param, err = strconv.ParseInt(req.QueryParameter(v), 10, 64)
} else {
logger.Errorf("[Go restful] Query param parse error, the args:%v of type isn't int or string or slice", k)
continue
}
if err != nil {
logger.Errorf("[Go restful] Query param parse error, error is %v", err)
continue
}
args[k] = param
}
}

// assemble arguments from path params
func assembleArgsFromPathParams(methodConfig *rest_config.RestMethodConfig, argsLength int, argsTypes []reflect.Type, req RestServerRequest, args []interface{}) {
var (
err error
param interface{}
i64 int64
)
for k, v := range methodConfig.PathParamsMap {
if k < 0 || k >= argsLength {
logger.Errorf("[Go restful] Path param parse error, the args:%v doesn't exist", k)
continue
}
t := argsTypes[k]
kind := t.Kind()
if kind == reflect.Ptr {
t = t.Elem()
}
if kind == reflect.Int {
param, err = strconv.Atoi(req.PathParameter(v))
} else if kind == reflect.Int32 {
i64, err = strconv.ParseInt(req.PathParameter(v), 10, 32)
if err == nil {
param = int32(i64)
}
} else if kind == reflect.Int64 {
param, err = strconv.ParseInt(req.PathParameter(v), 10, 64)
} else if kind == reflect.String {
param = req.PathParameter(v)
} else {
logger.Warnf("[Go restful] Path param parse error, the args:%v of type isn't int or string", k)
continue
}
if err != nil {
logger.Errorf("[Go restful] Path param parse error, error is %v", err)
continue
}
args[k] = param
}
}
Loading