-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from askuy/feature/ginserverandctxtimeout
support gin server and context read timeout
- Loading branch information
Showing
15 changed files
with
399 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[server.http] | ||
host = "0.0.0.0" | ||
port = 12345 | ||
enableAccessInterceptorReq = true | ||
enableAccessInterceptorRes = true | ||
contextTimeout = "1s" | ||
serverRriteTimeout = "1s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/gotomicro/ego" | ||
"github.com/gotomicro/ego/client/ehttp" | ||
"github.com/gotomicro/ego/core/elog" | ||
"github.com/gotomicro/ego/server/egin" | ||
) | ||
|
||
// export EGO_DEBUG=true && go run main.go --config=config.toml | ||
// curl -i 'http://localhost:9006/hello?q=query' -X POST -H 'X-Ego-Uid: 9999' --data '{"id":1,"name":"lee"}' | ||
func main() { | ||
if err := ego.New().Invoker(func() error { | ||
go func() { | ||
time.Sleep(1 * time.Second) | ||
startTime := time.Now() | ||
ehttp.DefaultContainer().Build().R().Get("http://127.0.0.1:12345/hello") | ||
fmt.Println("cost: ", time.Now().Sub(startTime)) | ||
}() | ||
|
||
return nil | ||
}).Serve(func() *egin.Component { | ||
server := egin.Load("server.http").Build() | ||
server.GET("/hello", func(c *gin.Context) { | ||
time.Sleep(10 * time.Second) | ||
//startTime := time.Now() | ||
//ehttp.DefaultContainer().Build().R().SetContext(c.Request.Context()).Get("http://127.0.0.1:12345/longtime") | ||
//fmt.Println("cost: ", time.Now().Sub(startTime)) | ||
c.JSON(200, "Hello EGO") | ||
return | ||
}) | ||
|
||
server.GET("/longtime", func(c *gin.Context) { | ||
time.Sleep(10 * time.Second) | ||
c.JSON(200, "Hello longtime") | ||
return | ||
}) | ||
return server | ||
}()).Run(); err != nil { | ||
elog.Panic("startup", elog.FieldErr(err)) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.