51 lines
1.0 KiB
Go
Raw Normal View History

2016-10-21 16:25:35 +00:00
package main
import (
2016-10-22 17:03:16 +00:00
"io/ioutil"
2016-10-21 16:25:35 +00:00
"strconv"
"github.com/aerojs/aero"
2016-10-22 17:03:16 +00:00
"github.com/blitzprog/arn"
2016-10-21 16:25:35 +00:00
)
2016-10-22 17:03:16 +00:00
const (
gzipThreshold = 1450
contentTypeHeader = "content-type"
contentType = "text/html;charset=utf-8"
contentEncodingHeader = "content-encoding"
contentEncoding = "gzip"
hello = "Hello World"
)
2016-10-21 16:25:35 +00:00
2016-10-22 17:03:16 +00:00
func main() {
2016-10-21 16:25:35 +00:00
app := aero.New()
2016-10-22 17:03:16 +00:00
example, _ := ioutil.ReadFile("security/frontpage.html")
app.Get("/", func(ctx *aero.Context) {
ctx.RespondBytes(example)
2016-10-22 17:03:16 +00:00
})
template := aero.NewTemplate("pages/anime/anime.pug")
2016-10-21 16:25:35 +00:00
// app.Get("/hello", func(ctx *fasthttp.RequestCtx, _ fasthttprouter.Params) {
// aero.Respond(ctx, "Hello World")
// })
app.Get("/anime/:id", func(ctx *aero.Context) {
id, _ := strconv.Atoi(ctx.Params.ByName("id"))
2016-10-21 16:25:35 +00:00
anime, err := arn.GetAnime(id)
if err != nil {
ctx.Respond("Anime not found")
2016-10-21 16:25:35 +00:00
return
}
2016-10-23 04:15:47 +00:00
templateParams := make(map[string]interface{})
templateParams["anime"] = anime
ctx.Respond(template.Render(templateParams))
2016-10-21 16:25:35 +00:00
})
app.Run()
}