go-iris

Goroutine Timeout

若如初见. 提交于 2021-02-05 11:30:35
问题 type Response struct { data interface{} status bool } func Find() (interface{}, bool) { ch := make(chan Response, 1) go func() { data, status := findCicCode() ch <- Response{data: data, status: status} }() select { case response := <-ch: return response.data, response.status case <-time.After(50 * time.Millisecond): return "Request timed out", false } } So, I have above function. Basically findCicCode() function call makes 3 http calls internally to external services. I have added combined

Fetching Logged in User Info for display

一个人想着一个人 提交于 2019-12-25 13:08:06
问题 I am using https://github.com/kataras/iris Go web framework. I have: User Registered User Verified & Logged in Session created and set with key username with user (table & struct) username Now, here is my code for logged in user: // Loaded All DB and other required value above allRoutes := app.Party("/", logThisMiddleware, authCheck) { allRoutes.Get("/", func(ctx context.Context) { ctx.View("index.html"); }); } In authcheck middleware func authcheck(ctx context.Context) { // Loaded session. /

Fetching Logged in User Info for display

我们两清 提交于 2019-12-25 13:07:53
问题 I am using https://github.com/kataras/iris Go web framework. I have: User Registered User Verified & Logged in Session created and set with key username with user (table & struct) username Now, here is my code for logged in user: // Loaded All DB and other required value above allRoutes := app.Party("/", logThisMiddleware, authCheck) { allRoutes.Get("/", func(ctx context.Context) { ctx.View("index.html"); }); } In authcheck middleware func authcheck(ctx context.Context) { // Loaded session. /

Stop goroutine execution on timeout

纵饮孤独 提交于 2019-12-19 19:38:45
问题 I want to stop goroutine execution on timeout. But it seems like it is not working for me. I am using iris framework. type Response struct { data interface{} status bool } func (s *CicService) Find() (interface{}, bool) { ch := make(chan Response, 1) go func() { time.Sleep(10 * time.Second) fmt.Println("test") fmt.Println("test1") ch <- Response{data: "data", status: true} }() select { case <-ch: fmt.Println("Read from ch") res := <-ch return res.data, res.status case <-time.After(50 * time

Stop goroutine execution on timeout

 ̄綄美尐妖づ 提交于 2019-12-01 19:57:07
I want to stop goroutine execution on timeout. But it seems like it is not working for me. I am using iris framework. type Response struct { data interface{} status bool } func (s *CicService) Find() (interface{}, bool) { ch := make(chan Response, 1) go func() { time.Sleep(10 * time.Second) fmt.Println("test") fmt.Println("test1") ch <- Response{data: "data", status: true} }() select { case <-ch: fmt.Println("Read from ch") res := <-ch return res.data, res.status case <-time.After(50 * time.Millisecond): return "Timed out", false } } Output: Timed out test test1 Expected Output: Timed out Can