Separated route handlers into a separate module
This commit is contained in:
parent
64fc6fd8fc
commit
b9560f01e7
21
colossus.go
21
colossus.go
@ -1,12 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/flamego/flamego"
|
||||
"github.com/flamego/template"
|
||||
|
||||
"git.metaunix.net/BitGoblin/colossus/models"
|
||||
"git.metaunix.net/BitGoblin/colossus/routes"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -29,23 +28,7 @@ func main() {
|
||||
}))
|
||||
|
||||
// register route handlers
|
||||
f.Get("/", func(t template.Template, data template.Data) {
|
||||
var hardware []models.Component
|
||||
models.DB.Find(&hardware)
|
||||
data["hardware"] = hardware
|
||||
|
||||
data["title"] = "Dashboard"
|
||||
t.HTML(http.StatusOK, "index")
|
||||
})
|
||||
|
||||
f.Get("/hardware/add", func(c flamego.Context) {
|
||||
models.DB.Create(&models.Component{
|
||||
Name: "PowerColor RX 570 4GB",
|
||||
Manufacturer: "PowerColor",
|
||||
Type: "Graphics Card",
|
||||
})
|
||||
c.Redirect("/")
|
||||
})
|
||||
routes.InitRoutes(f)
|
||||
|
||||
f.Run()
|
||||
}
|
||||
|
16
routes/hardware.go
Normal file
16
routes/hardware.go
Normal file
@ -0,0 +1,16 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/flamego/flamego"
|
||||
|
||||
"git.metaunix.net/BitGoblin/colossus/models"
|
||||
)
|
||||
|
||||
func getHardwareAdd(c flamego.Context) {
|
||||
models.DB.Create(&models.Component{
|
||||
Name: "PowerColor RX 570 4GB",
|
||||
Manufacturer: "PowerColor",
|
||||
Type: "Graphics Card",
|
||||
})
|
||||
c.Redirect("/")
|
||||
}
|
18
routes/index.go
Normal file
18
routes/index.go
Normal file
@ -0,0 +1,18 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/flamego/template"
|
||||
|
||||
"git.metaunix.net/BitGoblin/colossus/models"
|
||||
)
|
||||
|
||||
func getIndex(t template.Template, data template.Data) {
|
||||
var hardware []models.Component
|
||||
models.DB.Find(&hardware)
|
||||
data["hardware"] = hardware
|
||||
|
||||
data["title"] = "Dashboard"
|
||||
t.HTML(http.StatusOK, "index")
|
||||
}
|
11
routes/init.go
Normal file
11
routes/init.go
Normal file
@ -0,0 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/flamego/flamego"
|
||||
)
|
||||
|
||||
func InitRoutes(f *flamego.Flame) {
|
||||
f.Get("/", getIndex)
|
||||
|
||||
f.Get("/hardware/add", getHardwareAdd)
|
||||
}
|
Loading…
Reference in New Issue
Block a user