Initial setup of an admin page that dynamically reflects the DB to create the CRUD stuff.
This commit is contained in:
parent
02910b8b93
commit
859e3ad0e3
6 changed files with 46 additions and 3 deletions
4
Makefile
4
Makefile
|
@ -15,6 +15,10 @@ test: site
|
|||
go test zedshaw.games/webapp/tests -c -o runtests$(GO_IS_STUPID_EXE)
|
||||
./runtests$(GO_IS_STUPID_EXE)
|
||||
|
||||
test_only:
|
||||
go test zedshaw.games/webapp/tests -c -o runtests$(GO_IS_STUPID_EXE)
|
||||
./runtests$(GO_IS_STUPID_EXE) -test.run TestAdminIndexPage
|
||||
|
||||
migrate_up:
|
||||
go tool goose sqlite3 db.sqlite3 -dir migrations up
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func GetPageIndex(c *fiber.Ctx) error {
|
||||
c.Render("admin/index", fiber.Map{})
|
||||
return c.Render("admin/index", fiber.Map{})
|
||||
}
|
||||
|
||||
func Setup(app *fiber.App) {
|
||||
app.Get("/admin/", GetIndex);
|
||||
app.Get("/admin/", GetPageIndex);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package data
|
||||
|
||||
import "reflect"
|
||||
|
||||
type Login struct {
|
||||
Username string `db:"username" validate:"required,max=30"`
|
||||
Password string `db:"password" validate:"required,max=128"`
|
||||
|
@ -23,3 +25,11 @@ type Stream struct {
|
|||
Title string `db:"title" json:"title"`
|
||||
Description string `db:"description" json:"description"`
|
||||
}
|
||||
|
||||
func Models() map[string]reflect.Type {
|
||||
return map[string]reflect.Type{
|
||||
"stream": reflect.TypeFor[Stream](),
|
||||
"stream_link": reflect.TypeFor[Link](),
|
||||
"user": reflect.TypeFor[User](),
|
||||
}
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -15,6 +15,7 @@ import (
|
|||
"zedshaw.games/webapp/api"
|
||||
"zedshaw.games/webapp/data"
|
||||
"zedshaw.games/webapp/config"
|
||||
"zedshaw.games/webapp/admin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -36,8 +37,9 @@ func main() {
|
|||
app.Use(logger.New())
|
||||
app.Use(recov.New())
|
||||
|
||||
api.Setup(app)
|
||||
data.Setup(config.Settings.Database.Driver, config.Settings.Database.Url)
|
||||
api.Setup(app)
|
||||
admin.Setup(app)
|
||||
|
||||
// this sets up graceful shutdown
|
||||
go func() {
|
||||
|
|
23
tests/admin_test.go
Normal file
23
tests/admin_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"zedshaw.games/webapp/data"
|
||||
// _ "github.com/mattn/go-sqlite3"
|
||||
// "github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
func TestAdminIndexPage(t *testing.T) {
|
||||
models := data.Models()
|
||||
|
||||
for table, model := range models {
|
||||
fmt.Printf("\n------\ntable=%s; model=%s\n", table, model.Name())
|
||||
fields := reflect.VisibleFields(model)
|
||||
|
||||
for _, field := range fields {
|
||||
fmt.Println("\t", field.Name, field.Type, field.Tag)
|
||||
}
|
||||
}
|
||||
}
|
1
views/admin/index.html
Normal file
1
views/admin/index.html
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Admin!</h1>
|
Loading…
Add table
Add a link
Reference in a new issue