sentinel-golang
sentinel-golang copied to clipboard
Add adapter for Kratos
Describe what this PR does / why we need it
#450
Does this pull request fix one issue?
#450
Describe how you did it
The implementation is based on Kratos unified middleware abstractions for http/grpc servers/clients.
Tests on HTTP servers/clients are provided in server_test.go
and client_test.go
.
Describe how to verify it
The implementation can be verified via go test
.
Special notes for reviews
Codecov Report
Merging #459 (9a929d9) into master (89ef54d) will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #459 +/- ##
=======================================
Coverage 53.14% 53.14%
=======================================
Files 91 91
Lines 5897 5897
=======================================
Hits 3134 3134
Misses 2415 2415
Partials 348 348
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 89ef54d...9a929d9. Read the comment docs.
Why fallback only return error without response?
Why fallback only return error without response?
- I found all other adapters in Sentinel only return an
error
in their fallback options. I don't know if a response return value would be useful. Of course, it is more flexible :) - I found
reply
anderror
are mutually exclusive in some Kratos examples. Thus, I assume that thereply
isnil
whenblockFallback
is called in Sentinel middleware. - If necessary, the
kratos/errors
contains statuscode
,reason
andmessage
fields. Informative responses can be appended in themessage
field.
Why fallback only return error without response?
- I found all other adapters in Sentinel only return an
error
in their fallback options. I don't know if a response return value would be useful. Of course, it is more flexible :)- I found
reply
anderror
are mutually exclusive in some Kratos examples. Thus, I assume that thereply
isnil
whenblockFallback
is called in Sentinel middleware.- If necessary, the
kratos/errors
contains statuscode
,reason
andmessage
fields. Informative responses can be appended in themessage
field.
Hi~Thanks for reply. The reason that reply
is nil
in kratos middleware is because those middleware doesnt invoke business logic. So they only need to report error.
But in practice, the fallback would invoke some business logic. Such as return previous value.
And I dont think return a reply within an error is a good idea. This require client to process special error with same business logic. At the same time, it couple results and errors. It make me confused that some other adapters only return an error
.
Why fallback only return error without response?
- I found all other adapters in Sentinel only return an
error
in their fallback options. I don't know if a response return value would be useful. Of course, it is more flexible :)- I found
reply
anderror
are mutually exclusive in some Kratos examples. Thus, I assume that thereply
isnil
whenblockFallback
is called in Sentinel middleware.- If necessary, the
kratos/errors
contains statuscode
,reason
andmessage
fields. Informative responses can be appended in themessage
field.Hi~Thanks for reply. The reason that
reply
isnil
in kratos middleware is because those middleware doesnt invoke business logic. So they only need to report error. But in practice, the fallback would invoke some business logic. Such as return previous value. And I dont think return a reply within an error is a good idea. This require client to process special error with same business logic. At the same time, it couple results and errors. It make me confused that some other adapters only return anerror
.
Thanks, got it, I'll add the reply to this adapter :) For other adapters, maybe a new issue should be open.
You can consider submitting directly to Kratos contrib.
You can consider submitting directly to Kratos contrib.
👍 I'll test it on the latest Kratos in these days and try to submit there