diff --git a/app/web/routes.go b/app/web/routes.go new file mode 100644 index 0000000..12ba5b1 --- /dev/null +++ b/app/web/routes.go @@ -0,0 +1,17 @@ +package web + +import ( + "net/http" + + "github.com/flamego/flamego" + "github.com/flamego/template" +) + +func RegisterRoutes(f *flamego.Flame) { + // index route - landing page for the user + f.Get("/", func(t template.Template, data template.Data) { + t.HTML(http.StatusOK, "index") + }) + + // item list route - lists all of the items in the database +} diff --git a/go.mod b/go.mod index 1336eea..1eb4b90 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/alecthomas/participle/v2 v2.0.0-beta.5 // indirect github.com/fatih/color v1.13.0 // indirect github.com/flamego/flamego v1.7.0 // indirect + github.com/flamego/template v1.1.0 // indirect github.com/mattn/go-colorable v0.1.9 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/go.sum b/go.sum index 7dfb254..0b79092 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/flamego/flamego v1.7.0 h1:c1Lu16PBAZKkpsjHw42vwotdoQnMMpUi60ITP41W12w= github.com/flamego/flamego v1.7.0/go.mod h1:dnVMBJyHKaxjcqRVN93taSK+YB/9p+Op1GdLIuA1hFQ= +github.com/flamego/template v1.1.0 h1:iYtCzY3TeYpsoQiGApFXw2qycKdMzimz2gkO/SlcksM= +github.com/flamego/template v1.1.0/go.mod h1:bgnmEXNumarhQIUzFgn18CDG6u8cM6X09c7UOTwZcxM= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= diff --git a/raven.go b/raven.go index 8545d24..34df654 100644 --- a/raven.go +++ b/raven.go @@ -2,12 +2,26 @@ package main import ( "github.com/flamego/flamego" + "github.com/flamego/template" + + "git.metaunix.net/metaunix/raven/app/web" ) func main() { - f := flamego.Classic() - f.Get("/", func() string { - return "Hello, Flamego!" - }) + f := flamego.New() + + // Initialize template engine + f.Use(template.Templater(template.Options{ + Directory: "views", + })) + + f.Use(flamego.Static( + flamego.StaticOptions{ + Directory: "public", + }, + )) + + web.RegisterRoutes(f) + f.Run() } diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..eeaa229 --- /dev/null +++ b/views/index.html @@ -0,0 +1,7 @@ +{{ template "layout" . }} + +{{ define "title" }}Dashboard{{ end }} + +{{ define "content" }} +
This is a test.
+{{ end }} diff --git a/views/layout/layout.html b/views/layout/layout.html new file mode 100644 index 0000000..cb3fb75 --- /dev/null +++ b/views/layout/layout.html @@ -0,0 +1,16 @@ +{{ define "layout" }} + + + + + + +