当前位置:网站首页>Gin framework: implementing service end flow limiting Middleware
Gin framework: implementing service end flow limiting Middleware
2022-06-24 01:47:00 【Trespass 】
Introduce
Through a complete example , Based on Gin Framework in microservices 【 Current limiting 】 middleware .
We will use rk-boot To start up Gin Microservices of the framework .
Please visit the following address for a complete tutorial :https://rkdocs.netlify.app/cn
install
go get github.com/rookie-ninja/rk-boot go get github.com/rookie-ninja/rk-gin
Quick start
1. establish boot.yaml
In order to verify , We launched the following options :
- commonService:commonService It contains a series of general API. details
We aim at /rk/v1/healthy Carry out current limiting treatment , Set to 0, other API Set to 100.
---
gin:
- name: greeter # Required
port: 8080 # Required
enabled: true # Required
commonService:
enabled: true # Optional, default: false
interceptors:
rateLimit:
enabled: true
reqPerSec: 100
paths:
- path: "/rk/v1/healthy"
reqPerSec: 02. establish main.go
// Copyright (c) 2021 rookie-ninja
//
// Use of this source code is governed by an Apache-style
// license that can be found in the LICENSE file.
package main
import (
"context"
"github.com/rookie-ninja/rk-boot"
_ "github.com/rookie-ninja/rk-gin/boot"
)
// Application entrance.
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Bootstrap
boot.Bootstrap(context.Background())
// Wait for shutdown sig
boot.WaitForShutdownSig(context.Background())
}3. Folder structure
$ tree . ├── boot.yaml ├── go.mod ├── go.sum └── main.go 0 directories, 4 files
4. start-up main.go
$ go run main.go
5. verification
- send out /rk/v1/healthy request , Will be restricted
$ curl -X GET localhost:8080/rk/v1/healthy
{
"error":{
"code":429,
"status":"Too Many Requests",
"message":"",
"details":[
"slow down your request"
]
}
}- send out /rk/v1/info request , normal
$ curl -X GET localhost:8080/rk/v1/info
{
"appName":"rk-demo",
"version":"master-2c9c6fd",
"description":"Internal RK entry which describes application with fields of appName, version and etc.",
"keywords":[],
"homeUrl":"",
"iconUrl":"",
"docsUrl":[],
"maintainers":[],
"uid":"501",
"gid":"20",
"username":"Dongxun Yin",
"startTime":"2021-11-14T00:32:09+08:00",
"upTimeSec":123,
"upTimeStr":"2 minutes",
"region":"",
"az":"",
"realm":"",
"domain":""
}YAML Options
name | describe | type | The default value is |
|---|---|---|---|
gin.interceptors.rateLimit.enabled | Start the current limiting middleware | boolean | false |
gin.interceptors.rateLimit.algorithm | Current limiting algorithm , Support tokenBucket and leakyBucket | string | tokenBucket |
gin.interceptors.rateLimit.reqPerSec | Global current limit | int | 0 |
gin.interceptors.rateLimit.paths.path | HTTP route | string | "" |
gin.interceptors.rateLimit.paths.reqPerSec | be based on HTTP The current limit of the path | int | 0 |
边栏推荐
- Coding compass -- creating a software factory like a flowing cloud
- [tcapulusdb knowledge base] how to rebuild tables in tcapulusdb table management?
- Collation of commonly used glusterfs commands
- Batch generation of 2D codes from txt files
- Spatial4j introduction practice
- Application analysis of video edge computing gateway easynvr in video overall monitoring solution
- Best practices cloud development cloudbase multi environment management practices
- What are the selected CDN content acceleration scenarios of Tencent cloud?
- Security | how does Tencent virtual machine realize tamper proof of web pages?
- [tcapulusdb knowledge base] how does tcapulusdb add a business cluster cluster?
猜你喜欢
![[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)](/img/b5/a8c4bbaf868dd20b7dc9449d2a4378.jpg)
[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)
![[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)](/img/c8/f6c2a62b8ab8fa88bd2b3d8f35f592.jpg)
[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)

It's too difficult for me. Ali has had 7 rounds of interviews (5 years of experience and won the offer of P7 post)

I, a 27 year old female programmer, feel that life is meaningless, not counting the accumulation fund deposit of 430000
随机推荐
Moment. JS how to use epoch time to construct objects
[dry goods] configure failover active/acitve in transparent mode on Cisco ASA firewall
Railway patrol system - Railway Intelligent Patrol communication system
Digital case show ‖ made in China for the first time! Tencent cloud tdsql landed in Zhangjiagang bank and worked together to build financial business
[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)
[official time limit activity] in November, if you dare to write, you will get a prize
2、 Shell position variable
Build your own DSL with go and HCl
Tke cluster setup linkerd2
"Cross border" layout photovoltaic circle Green Island wind invested 4.6 million to layout distributed photovoltaic power generation
Web user experience design promotion practice
What is "data" in data analysis- Cassie Kozyrkov
Ppt layout design how to make pages not messy
What is the relationship between the Internet of things and artificial intelligence?
Build fiora chat room with Tencent lightweight cloud
Clubhouse online supports replay function; Webobs live streaming tools are going to be popular |w
Application analysis of video edge computing gateway easynvr in video overall monitoring solution
SAP mm Migo 411k error - correct the customizing settings for the unique
6、 Symbols and commands for numerical calculation of variables
[tcapulusdb knowledge base] tcapulusdb introduction Questions Summary