简体   繁体   中英

Stop request execution at certain point on Golang iris

I have written a service I'm currently facing an issue where I want to stop the request cycle at a certain point and a return something to client side. I have used methods like ctx.EndRequest() ctx.StopExecution() but it keeps execute until the handler method finishes.

if aff.Status != StatActive {
        //Affiliate Not active exception
        err := errors.NewAffiliateNotActiveError(ctx)
        pc, fn, line, _ := runtime.Caller(1)
        log.Printf("[error] in %s[%s:%d] %v", runtime.FuncForPC(pc).Name(), fn, line, err)
        ctx.Write([]byte(err.Error()))
        ctx.StopExecution()

    }

Like above when that condition triggered I want to stop execution equivalent of a throw exception. How can I achieve that?

如果您希望处理程序执行停止,您需要一个 return 语句。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM