当前位置:网站首页>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 |
边栏推荐
- Tcapulusdb Jun · industry news collection (November 22)
- SAP mm maintains inter company sto error -no delivery type defined for supplying
- Behind the 1.6 trillion requests per day, the secret of DNSPod - state secret DOH
- Digital case show ‖ made in China for the first time! Tencent cloud tdsql landed in Zhangjiagang bank and worked together to build financial business
- Gin framework: implementing distributed log tracing
- Note 3 of disruptor: basic operation of ring queue (without disruptor class)
- What you don't know about traifik
- [SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)
- How to implement NSQ delay streaming technology in easycvr?
- A marriage app_ T signature analysis
猜你喜欢
![[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
随机推荐
What is function point analysis - FPA
How is the national standard easygbs video technology applied in the comprehensive supervision scenario of the power supply business hall?
What are the selected CDN content acceleration scenarios of Tencent cloud?
Application analysis of video edge computing gateway easynvr in video overall monitoring solution
Tcapulusdb Jun · industry news collection
[tcapulusdb knowledge base] common problems of tcapulusdb local deployment
4、 Variable assignment method
How to restart the server through the fortress machine how to log in to the fortress machine
Logistics industry supplier collaborative management platform supplier life cycle management to optimize logistics costs
Tcapulusdb database: the king behind the "Tianya Mingyue swordsman Tour"
Web user experience design promotion practice
[combat power upgrade] Tencent cloud's first arm architecture instance was launched! Experience the new architecture computing power!
How to access the server through the fortress machine? What if the fortress cannot access the server?
Flink weapon: introduction to the open source platform streamx
AES encryption analysis of CNKI academic translation
8、 Pipeline pipeline construction project
Online and offline integrated operation of channel sales system in the home furnishing industry to promote product update and iteration
Gin framework: implementing timeout Middleware
[dry goods] configure failover active/acitve in transparent mode on Cisco ASA firewall
Interviewer: let's talk about the snowflake algorithm. The more detailed, the better