How can I redirect from a middleware in go?

Viewed 59

I have the following case.

how can i address from handlev1 to handle2, using middleware? that depends on IsActiveBypass

Or what do you suggest?

func Handlev1(sw echoswagger.ApiRoot, itemUseCase usecase.ItemFileUseCase) {
    g := sw.Group("V2", "/v2/items")
    h := &itemHandler{itemUseCase: itemUseCase}
    g.SetDescription("item information")

    sw.Echo().Use(Bypass(sw))

    g.POST("/page1", func(c echo.Context) (err error) {
        ...
    })

    
}

func Handlev2(sw echoswagger.ApiRoot, version string) {
    path := version
    g := sw.Group("GTP", version+"/items")
    g.SetDescription("item information")

    g.POST("/page2", func(c echo.Context) (err error) {
        ...
    })

}

func IsActiveBypass() (clatlasitemapiapi bool) {
    clatlasitemapiapi = true
    return clatlasitemapiapi
}


func Bypass(sw echoswagger.ApiRoot) echo.MiddlewareFunc {
    return func(next echo.HandlerFunc) echo.HandlerFunc {
        if IsActiveBypass() {
            return next(Handlev2(sw, "v2"))
        }
        return nil
    }
}

If IsActiveBypass is true I call handlev2

0 Answers
Related