From fb4dba31bc4140960b0c15416396413346c95c0e Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 22 Oct 2016 01:25:35 +0900 Subject: [PATCH] Using arn and aero package now --- layout/layout.pug | 6 ++++++ layout/raw.pug | 1 + main.go | 34 ++++++++++++++++++++++++++++++ pages/{ => anime}/anime.pug | 0 pages/dashboard/dashboard.pug | 1 + pages/layout.pug | 8 ------- src/Anime.go | 15 -------------- src/Database.go | 19 ----------------- src/User.go | 6 ------ src/main.go | 39 ----------------------------------- 10 files changed, 42 insertions(+), 87 deletions(-) create mode 100644 layout/layout.pug create mode 100644 layout/raw.pug create mode 100644 main.go rename pages/{ => anime}/anime.pug (100%) create mode 100644 pages/dashboard/dashboard.pug delete mode 100644 pages/layout.pug delete mode 100644 src/Anime.go delete mode 100644 src/Database.go delete mode 100644 src/User.go delete mode 100644 src/main.go diff --git a/layout/layout.pug b/layout/layout.pug new file mode 100644 index 00000000..b4186685 --- /dev/null +++ b/layout/layout.pug @@ -0,0 +1,6 @@ +doctype html +html + head + title Test + body + {{ yield }} \ No newline at end of file diff --git a/layout/raw.pug b/layout/raw.pug new file mode 100644 index 00000000..3eedbd7d --- /dev/null +++ b/layout/raw.pug @@ -0,0 +1 @@ +{{ yield }} \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 00000000..440cf9e2 --- /dev/null +++ b/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "strconv" + + "github.com/aerojs/aero" + "github.com/animenotifier/arn" + "github.com/buaazp/fasthttprouter" + "github.com/valyala/fasthttp" +) + +func main() { + arn.Init() + + app := aero.New() + + app.Get("/", func(ctx *fasthttp.RequestCtx, _ fasthttprouter.Params) { + ctx.Write(ctx.RequestURI()) + }) + + app.Get("/anime/:id", func(ctx *fasthttp.RequestCtx, params fasthttprouter.Params) { + id, _ := strconv.Atoi(params.ByName("id")) + anime, err := arn.GetAnime(id) + + if err != nil { + ctx.WriteString("Anime not found") + return + } + + ctx.WriteString(anime.Description) + }) + + app.Run() +} diff --git a/pages/anime.pug b/pages/anime/anime.pug similarity index 100% rename from pages/anime.pug rename to pages/anime/anime.pug diff --git a/pages/dashboard/dashboard.pug b/pages/dashboard/dashboard.pug new file mode 100644 index 00000000..9dfd90ef --- /dev/null +++ b/pages/dashboard/dashboard.pug @@ -0,0 +1 @@ +h1 notify.moe \ No newline at end of file diff --git a/pages/layout.pug b/pages/layout.pug deleted file mode 100644 index cf2daf74..00000000 --- a/pages/layout.pug +++ /dev/null @@ -1,8 +0,0 @@ -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/Anime.go b/src/Anime.go deleted file mode 100644 index aca49095..00000000 --- a/src/Anime.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -// Anime ... -type Anime struct { - ID int `as:"id"` - Title AnimeTitle `as:"title"` - Description string `as:"description"` -} - -// AnimeTitle ... -type AnimeTitle struct { - Romaji string `as:"romaji"` - English string `as:"english"` - Japanese string `as:"japanese"` -} diff --git a/src/Database.go b/src/Database.go deleted file mode 100644 index f2077c7d..00000000 --- a/src/Database.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import as "github.com/aerospike/aerospike-client-go" - -// Client ... -var client *as.Client - -// InitDatabase ... -func InitDatabase() { - client, _ = as.NewClient("127.0.0.1", 3000) -} - -// GetAnime ... -func GetAnime(id int) *Anime { - key, _ := as.NewKey("arn", "Anime", id) - anime := new(Anime) - client.GetObject(nil, key, anime) - return anime -} diff --git a/src/User.go b/src/User.go deleted file mode 100644 index cdef1028..00000000 --- a/src/User.go +++ /dev/null @@ -1,6 +0,0 @@ -package main - -// User ... -type User struct { - ID int -} diff --git a/src/main.go b/src/main.go deleted file mode 100644 index f3032fbf..00000000 --- a/src/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/kataras/go-template/pug" - "github.com/kataras/iris" -) - -func main() { - InitDatabase() - - 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()) - }) - - iris.Get("/anime/:id", func(ctx *iris.Context) { - start := time.Now() - id, _ := ctx.ParamInt("id") - anime := GetAnime(id) - - ctx.MustRender("anime.pug", anime) - fmt.Println(time.Since(start)) - }) - - iris.Listen(":8082") -}