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-28 16:11:25 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
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
|
|
|
|
2016-10-28 16:11:25 +00:00
|
|
|
cssBytes, _ := ioutil.ReadFile("layout.css")
|
|
|
|
css := string(cssBytes)
|
|
|
|
css = css
|
2016-10-22 17:03:16 +00:00
|
|
|
|
2016-10-23 15:45:37 +00:00
|
|
|
app.Get("/", func(ctx *aero.Context) {
|
2016-10-28 16:11:25 +00:00
|
|
|
ctx.Respond(Stream.Dashboard())
|
2016-10-22 17:03:16 +00:00
|
|
|
})
|
|
|
|
|
2016-10-23 15:45:37 +00:00
|
|
|
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)
|
2016-10-28 16:11:25 +00:00
|
|
|
anime = anime
|
2016-10-21 16:25:35 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2016-10-23 15:45:37 +00:00
|
|
|
ctx.Respond("Anime not found")
|
2016-10-21 16:25:35 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:11:25 +00:00
|
|
|
stream := fasthttp.AcquireByteBuffer()
|
|
|
|
Stream.Layout(stream, anime, css)
|
|
|
|
ctx.RespondBytes(stream.Bytes())
|
|
|
|
Stream.Release(stream)
|
|
|
|
// ctx.Respond(Render.Layout(Render.Anime(anime), css))
|
2016-10-21 16:25:35 +00:00
|
|
|
})
|
|
|
|
|
2016-10-28 16:11:25 +00:00
|
|
|
// layout := aero.NewTemplate("layout.pug")
|
|
|
|
// template := aero.NewTemplate("anime.pug")
|
|
|
|
|
|
|
|
// app.Get("/anime/:id", func(ctx *aero.Context) {
|
|
|
|
// id, _ := strconv.Atoi(ctx.Params.ByName("id"))
|
|
|
|
// anime, err := arn.GetAnime(id)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
// ctx.Respond("Anime not found")
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
|
|
|
|
// content := template.Render(map[string]interface{}{
|
|
|
|
// "anime": anime,
|
|
|
|
// })
|
|
|
|
|
|
|
|
// final := layout.Render(map[string]interface{}{
|
|
|
|
// "content": content,
|
|
|
|
// })
|
|
|
|
|
|
|
|
// final = strings.Replace(final, cssSearch, cssReplace, 1)
|
|
|
|
|
|
|
|
// ctx.Respond(final)
|
|
|
|
// })
|
|
|
|
|
|
|
|
// app.Get("/t", func(ctx *aero.Context) {
|
|
|
|
// ctx.Respond(templates.Hello("abc"))
|
|
|
|
// })
|
|
|
|
|
2016-10-21 16:25:35 +00:00
|
|
|
app.Run()
|
|
|
|
}
|