当前位置:网站首页>Gin framework: implementing timeout Middleware
Gin framework: implementing timeout Middleware
2022-06-24 01:34:00 【Trespass 】
Introduce
Through a complete example , Based on Gin Framework in microservices 【 Overtime 】 middleware .
We will use rk-boot To start up Gin Microservices of the framework .
Please visit the following address for a complete tutorial :
install
go get github.com/rookie-ninja/rk-boot go get github.com/rookie-ninja/rk-gin
Quick start
Support global timeout and API Timeout settings .
1. establish boot.yaml
boot.yaml File tell rk-boot How to start Gin service .
In order to verify , We launched the following options :
- commonService:commonService It contains a series of general API. details
Set the global timeout to 5 second , Give Way GC The timeout for is 1 millisecond ,GC Usually more than 1 millisecond .
---
gin:
- name: greeter # Required
port: 8080 # Required
enabled: true # Required
commonService:
enabled: true # Optional, Enable common service for testing
interceptors:
timeout:
enabled: true # Optional, default: false
timeoutMs: 5000 # Optional, default: 5000
paths:
- path: "/rk/v1/gc" # Optional, default: ""
timeoutMs: 1 # Optional, default: 50002. 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. start-up main.go
$ go run main.go
4. verification
send out GC request .
$ curl -X GET localhost:8080/rk/v1/gc
{
"error":{
"code":408,
"status":"Request Timeout",
"message":"Request timed out!",
"details":[]
}
}边栏推荐
- How to choose a website construction company self-study website or website construction company
- Cloud computing "keeping the promise"
- Istio practice manual | meeting the new generation of microservice architecture
- Build a smart drug supervision platform based on easycvr video technology and build a drug safety firewall
- Openstack
- jdbc
- "Ai+ education" and "Ai education": one for education and the other for Education
- Leetcode lecture on algorithm interview for large factories 2 Time space complexity
- 什么是养老理财?养老理财产品有哪些?
- An error is reported when easynvr uploads the SSL certificate: the network request fails. How to handle it?
猜你喜欢
随机推荐
jdbc
Qu'est - ce que le financement des pensions? Quels sont les produits financiers pour les personnes âgées?
What is the website construction process? What details need to be valued?
Tencent cloud Weibo was selected into the analysis report on the status quo of China's low code platform market in 2021 by Forrester, an international authoritative research institution
Virtual currency mining detection and defense
What you don't know about traifik
Common e-commerce data index system
Salesforce batch apex batch processing (I)
Interviewer: why does the new generation memory need two survivor zones?
Openstack
[technology planting grass] talk about the system design and architecture of large-scale shopping platform
Talk about 11 tips for interface performance optimization
Dart series part: asynchronous programming in dart
Logistics industry supplier collaborative management platform supplier life cycle management to optimize logistics costs
Eight common errors in programming
Activity Registration - Tencent cloud digital intelligence driven SME transformation and upgrading series salon · Zhuhai station
How to realize court face recognition / flow statistics based on easycvr technology?
Server performance monitoring: Best Practices for server monitoring
Build a smart pole visual intercom system through an intelligent gateway
How to build a high-quality website

