Routing
I want complete control. I want to be able to do some odd things to handle edge cases and I want all the logic in normal if else golang statements.
if second == "routing" && third == "" && c.Method == "GET" {
  handleFrameRouting(c)
  return
}
The var second and the var third are the 2nd the 3rd tokens from the url path like: /first/second/third
A common case is something like https://www.reddit.com/r/golang/f9a0919a-346e-4bc4-b6b7-c94cfa049cc9 where first is "r" and second is "golang" and third is that guid.
if second == "golang" && third != "" && c.Method == "GET" {
  handleSubredditShow(c, third)
  return
}
func handleSubredditShow(c *router.Context, guid string) {
// send html see templates
}
You can decide where to make sure you have a logged in user.
if router.NotLoggedIn(c) {
  return // will send redirect to root path /
}
If you reach the end of all your if statements and c.NotFound = true is set the user will get a 404 and 404.html will render.
See more in the example app:
Remember you also can change what http verbs you need:
if second == "routing" && third == "" && c.Method == "POST" {
}
if second == "routing" && third == "" && c.Method == "PATCH" {
}
if second == "routing" && third == "" && c.Method == "PUT" {
}
if second == "routing" && third == "" && c.Method == "DELETE" {
}
Email us:
apps@andrewarrow.dev
Copyright © 2024
All right reserved by andrewarrow.dev
Terms of Service     Privacy Policy