Separated route handlers into a separate module
This commit is contained in:
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)
|
||||
}
|
Reference in New Issue
Block a user