colossus/colossus.go

52 lines
1021 B
Go
Raw Normal View History

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"
)
func main() {
2022-11-25 15:13:32 -05:00
// initialize database connection
models.InitDB()
// start initialize Flamego router
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
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("/")
})
f.Run()
}