From c8a3ec4b04f8f7a3d4d6059f8e45600351bcb940 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 21 Oct 2016 22:10:05 +0900 Subject: [PATCH] Minor changes --- .gitignore | 5 ++++- pages/anime.pug | 2 ++ pages/layout.pug | 8 ++++++++ src/main.go | 22 ++++++++++++++++------ styles/.gitignore | 1 + styles/base.styl | 3 +++ styles/layout.styl | 3 +++ 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 pages/anime.pug create mode 100644 pages/layout.pug create mode 100644 styles/.gitignore create mode 100644 styles/base.styl create mode 100644 styles/layout.styl diff --git a/.gitignore b/.gitignore index fb069f89..5f99acbf 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,7 @@ _testmain.go *.out # external packages folder -vendor/ \ No newline at end of file +vendor/ + +# debugger +debug \ No newline at end of file diff --git a/pages/anime.pug b/pages/anime.pug new file mode 100644 index 00000000..bef663e1 --- /dev/null +++ b/pages/anime.pug @@ -0,0 +1,2 @@ +h1 {{.Title.Romaji}} +p {{.Description}} \ No newline at end of file diff --git a/pages/layout.pug b/pages/layout.pug new file mode 100644 index 00000000..cf2daf74 --- /dev/null +++ b/pages/layout.pug @@ -0,0 +1,8 @@ +doctype html +html + head + title Test + link(href='/styles/base.css', rel='stylesheet') + link(href='/styles/layout.css', rel='stylesheet') + body + {{ yield }} \ No newline at end of file diff --git a/src/main.go b/src/main.go index fd5067b2..f3032fbf 100644 --- a/src/main.go +++ b/src/main.go @@ -4,26 +4,36 @@ import ( "fmt" "time" - web "github.com/kataras/iris" + "github.com/kataras/go-template/pug" + "github.com/kataras/iris" ) func main() { InitDatabase() - web.Get("/", func(ctx *web.Context) { + iris.Config.Gzip = true + iris.Config.IsDevelopment = true + + cfg := pug.DefaultConfig() + cfg.Layout = "layout.pug" + + iris.UseTemplate(pug.New(cfg)).Directory("pages", ".pug") + + iris.Static("/styles", "./styles", 1) + + iris.Get("/", func(ctx *iris.Context) { ctx.Response.Header.Set("Content-Type", "text/html;charset=utf-8") ctx.Write(ctx.Request.URI().String()) }) - web.Get("/anime/:id", func(ctx *web.Context) { + iris.Get("/anime/:id", func(ctx *iris.Context) { start := time.Now() id, _ := ctx.ParamInt("id") anime := GetAnime(id) - ctx.Write(anime.Title.Romaji + "\n") - ctx.Write(anime.Description) + ctx.MustRender("anime.pug", anime) fmt.Println(time.Since(start)) }) - web.Listen(":8082") + iris.Listen(":8082") } diff --git a/styles/.gitignore b/styles/.gitignore new file mode 100644 index 00000000..23188627 --- /dev/null +++ b/styles/.gitignore @@ -0,0 +1 @@ +*.css \ No newline at end of file diff --git a/styles/base.styl b/styles/base.styl new file mode 100644 index 00000000..2aaf0275 --- /dev/null +++ b/styles/base.styl @@ -0,0 +1,3 @@ +body + background-color rgb(128, 128, 128) + color white \ No newline at end of file diff --git a/styles/layout.styl b/styles/layout.styl new file mode 100644 index 00000000..7532a8be --- /dev/null +++ b/styles/layout.styl @@ -0,0 +1,3 @@ +* + padding 0 + margin 0 \ No newline at end of file