iris icon indicating copy to clipboard operation
iris copied to clipboard

Is there a way to dynamically add routes?

Open tuhao1020 opened this issue 3 years ago • 4 comments

I need to serve a static directory which passed by users after the program starts, I tried CreateRoutes but it didn't work. Is there any way to achieve this requirement?

tuhao1020 avatar Feb 23 '21 10:02 tuhao1020

it works with below code

app.Get("/mapping/{name}/{dir}", func(ctx iris.Context) {
  app.HandleDir("/static/" + ctx.Params().Get("name"), iris.Dir("../" + ctx.Params().Get("dir")), iris.DirOptions{
	  ShowList:          true,
	  SPA:               false,
  })
  app.RefreshRouter()
  ctx.Text("OK")
})

another question is: how can I delete the routes? There is a method named SetStatusOffline, but it doesn't delete the route.

tuhao1020 avatar Feb 24 '21 04:02 tuhao1020

@kataras Do you have time to look at my questions? 😃

tuhao1020 avatar Mar 04 '21 01:03 tuhao1020

Yes @tuhao1020 through the AddRouteUnsafe. Example can be found at the configuration.go file

kataras avatar Mar 18 '21 18:03 kataras

@kataras now I need a function like RemoveRoute(path string) 😄

tuhao1020 avatar Mar 19 '21 02:03 tuhao1020