Using arn and aero package now

This commit is contained in:
Eduard Urbach 2016-10-22 01:25:35 +09:00
parent c8a3ec4b04
commit fb4dba31bc
10 changed files with 42 additions and 87 deletions

6
layout/layout.pug Normal file
View File

@ -0,0 +1,6 @@
doctype html
html
head
title Test
body
{{ yield }}

1
layout/raw.pug Normal file
View File

@ -0,0 +1 @@
{{ yield }}

34
main.go Normal file
View File

@ -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()
}

View File

@ -0,0 +1 @@
h1 notify.moe

View File

@ -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 }}

View File

@ -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"`
}

View File

@ -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
}

View File

@ -1,6 +0,0 @@
package main
// User ...
type User struct {
ID int
}

View File

@ -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")
}