Using arn and aero package now
This commit is contained in:
parent
c8a3ec4b04
commit
fb4dba31bc
6
layout/layout.pug
Normal file
6
layout/layout.pug
Normal file
@ -0,0 +1,6 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
title Test
|
||||
body
|
||||
{{ yield }}
|
1
layout/raw.pug
Normal file
1
layout/raw.pug
Normal file
@ -0,0 +1 @@
|
||||
{{ yield }}
|
34
main.go
Normal file
34
main.go
Normal 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()
|
||||
}
|
1
pages/dashboard/dashboard.pug
Normal file
1
pages/dashboard/dashboard.pug
Normal file
@ -0,0 +1 @@
|
||||
h1 notify.moe
|
@ -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 }}
|
15
src/Anime.go
15
src/Anime.go
@ -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"`
|
||||
}
|
@ -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
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package main
|
||||
|
||||
// User ...
|
||||
type User struct {
|
||||
ID int
|
||||
}
|
39
src/main.go
39
src/main.go
@ -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")
|
||||
}
|
Loading…
Reference in New Issue
Block a user