Comments (2)
Please see the FAQ in our main README.md before submitting your issue.
This is my solution, you can refer to it
// Detach returns a detached context
func Detach(ctx context.Context) context.Context { return detachedContext{ctx} }
type detachedContext struct{ parent context.Context }
func (v detachedContext) Deadline() (time.Time, bool) { return time.Time{}, false }
func (v detachedContext) Done() <-chan struct{} { return nil }
func (v detachedContext) Err() error { return nil }
func (v detachedContext) Value(key interface{}) interface{} { return v.parent.Value(key) }
// SayHello implements helloworld.GreeterServer.
func (s *GreeterService) SayHello(ctx context.Context, in *v1.HelloRequest) (*v1.HelloReply, error) {
// Detach the service ctx and reset the timeout
ctx, cancel := context.WithTimeout(Detach(ctx), time.Second*3)
defer cancel()
// ....
}
from kratos.
Please see the FAQ in our main README.md before submitting your issue.
This is my solution, you can refer to it
// Detach returns a detached context func Detach(ctx context.Context) context.Context { return detachedContext{ctx} } type detachedContext struct{ parent context.Context } func (v detachedContext) Deadline() (time.Time, bool) { return time.Time{}, false } func (v detachedContext) Done() <-chan struct{} { return nil } func (v detachedContext) Err() error { return nil } func (v detachedContext) Value(key interface{}) interface{} { return v.parent.Value(key) } // SayHello implements helloworld.GreeterServer. func (s *GreeterService) SayHello(ctx context.Context, in *v1.HelloRequest) (*v1.HelloReply, error) { // Detach the service ctx and reset the timeout ctx, cancel := context.WithTimeout(Detach(ctx), time.Second*3) defer cancel() // .... }
@dobet
You can also set timeout times for routes separately in middleware
from kratos.
Related Issues (20)
- [Question] How to log Http method? HOT 3
- [Question] How to install a specific version of kratos ? HOT 1
- [Question] why trace_id and span_id in logger ctx? HOT 1
- [Feature] allow custom signal to do some handle logic HOT 1
- [Feature] Some specification issues when Kratos registers services on Polaris HOT 9
- I have a question about proto. HOT 2
- apollo settings Watch cannot hot update configuration normally
- http.NewClient results in NODE_NOT_FOUND HOT 2
- load apollo config yml format panic HOT 5
- [Question] 如何使用json.Marshal 作为http server 返回的序列化工具 HOT 2
- [Question] The middleware is Executed at the end of the request? HOT 7
- [Question] trace.id is not passed HOT 5
- [Question] How to limit HTTP request size? HOT 6
- The trace_id between requests is getting mixed up HOT 4
- [Question] How should I create a kratos project HOT 1
- net: lookupIPAddr dns resolving panic by data race. HOT 4
- [Question] The pprof profile is not valid HOT 4
- [Feature] Replace `PGV` by `protovalidate` HOT 7
- [Question] Pubsub Implementation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kratos.