github.com/hduhelp/go-zero@v1.4.3/gateway/internal/timeout.go (about) 1 package internal 2 3 import ( 4 "net/http" 5 "time" 6 ) 7 8 const grpcTimeoutHeader = "Grpc-Timeout" 9 10 // GetTimeout returns the timeout from the header, if not set, returns the default timeout. 11 func GetTimeout(header http.Header, defaultTimeout time.Duration) time.Duration { 12 if timeout := header.Get(grpcTimeoutHeader); len(timeout) > 0 { 13 if t, err := time.ParseDuration(timeout); err == nil { 14 return t 15 } 16 } 17 18 return defaultTimeout 19 }