2022-11-25 13:33:27 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/flamego/flamego"
|
|
|
|
"github.com/flamego/template"
|
2022-11-25 15:13:32 -05:00
|
|
|
|
|
|
|
"git.metaunix.net/BitGoblin/colossus/models"
|
2022-11-25 13:33:27 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-11-25 15:13:32 -05:00
|
|
|
// initialize database connection
|
|
|
|
models.InitDB()
|
|
|
|
|
|
|
|
// start initialize Flamego router
|
2022-11-25 13:33:27 -05:00
|
|
|
f := flamego.Classic()
|
|
|
|
|
|
|
|
// serve static files from ./public/
|
|
|
|
f.Use(flamego.Static(
|
|
|
|
flamego.StaticOptions{
|
|
|
|
Directory: "public",
|
|
|
|
},
|
|
|
|
))
|
|
|
|
|
|
|
|
// initialize template engine
|
|
|
|
f.Use(template.Templater(template.Options{
|
|
|
|
Directory: "./views",
|
|
|
|
}))
|
|
|
|
|
|
|
|
// register route handlers
|
|
|
|
f.Get("/", func(t template.Template, data template.Data) {
|
2022-11-25 15:13:32 -05:00
|
|
|
var hardware []models.Component
|
|
|
|
models.DB.Find(&hardware)
|
|
|
|
data["hardware"] = hardware
|
|
|
|
|
2022-11-25 13:33:27 -05:00
|
|
|
data["title"] = "Dashboard"
|
|
|
|
t.HTML(http.StatusOK, "index")
|
|
|
|
})
|
|
|
|
|
2022-11-25 15:13:32 -05:00
|
|
|
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("/")
|
|
|
|
})
|
2022-11-25 14:00:28 -05:00
|
|
|
|
2022-11-25 13:33:27 -05:00
|
|
|
f.Run()
|
|
|
|
}
|