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

feat(goframe): add sentinel adapter for goframe #587

Closed
wants to merge 9 commits into from

Conversation

tangfc
Copy link
Contributor

@tangfc tangfc commented Dec 18, 2024

Describe what this PR does / why we need it

这个 PR 为 Sentinel 添加了 goframe 框架的适配器。通过这个适配器,开发者可以在 goframe 项目中方便地使用 Sentinel 的限流和
熔断功能,提高系统的稳定性和可靠性。

Does this pull request fix one issue?

NONE

Describe how you did it

1.实现了 SentinelMiddleware 函数,用于在 goframe 框架中集成 Sentinel。
2.添加了withResourceExtractor 选项,允许开发者自定义资源提取逻辑。
3.添加了WithBlockFallback 选项,允许开发者自定义阻塞时的回退逻辑。
4.编写了相应的测试用例,确保适配器的正确性和稳定性。

Describe how to verify it

1.运行测试用例:

  • go test -run ^TestSentinelMiddlewareDefault -v
  • go test -run ^TestSentineIMiddlewareExtractor -v
  • go test -run ^TestSentinelMiddlewareFallback -v

2.手动测试:

  • 启动一个 goframe应用,集成SentinelMiddleware。
  • 发送请求并观察限流和熔断效果。
  • 测试 WithBlockFallback 选项的回退逻辑。

Special notes for reviews

@@ -0,0 +1,54 @@
module github.com/alibaba/sentinel-golang/pkg/adapters/goframe

go 1.20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz downgrade the go version to no higher than 1.18 to keep it consistent with main package, so as to avoid introducing new features now or in the future and support more go versions

if extractedName == "" {
extractedName = resourceName
}
resourceName = extractedName

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if extractedName := options.resourceExtract(r); extractedName != "" {
resourceName = extractedName
}
It looks the same as the code logic above? But readability will be improved

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ tangfc
❌ tangfangchun


tangfangchun seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@tangfc tangfc closed this by deleting the head repository Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants