Go experiments
This commit is contained in:
51
main.go
51
main.go
@ -6,36 +6,65 @@ import (
|
||||
|
||||
"github.com/aerojs/aero"
|
||||
"github.com/blitzprog/arn"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := aero.New()
|
||||
|
||||
example, _ := ioutil.ReadFile("security/frontpage.html")
|
||||
cssBytes, _ := ioutil.ReadFile("layout.css")
|
||||
css := string(cssBytes)
|
||||
css = css
|
||||
|
||||
app.Get("/", func(ctx *aero.Context) {
|
||||
ctx.RespondBytes(example)
|
||||
ctx.Respond(Stream.Dashboard())
|
||||
})
|
||||
|
||||
app.Get("/hello", func(ctx *aero.Context) {
|
||||
ctx.Respond("Hello World")
|
||||
})
|
||||
|
||||
template := aero.NewTemplate("pages/anime/anime.pug")
|
||||
|
||||
app.Get("/anime/:id", func(ctx *aero.Context) {
|
||||
id, _ := strconv.Atoi(ctx.Params.ByName("id"))
|
||||
anime, err := arn.GetAnime(id)
|
||||
anime = anime
|
||||
|
||||
if err != nil {
|
||||
ctx.Respond("Anime not found")
|
||||
return
|
||||
}
|
||||
|
||||
templateParams := make(map[string]interface{})
|
||||
templateParams["anime"] = anime
|
||||
ctx.Respond(template.Render(templateParams))
|
||||
stream := fasthttp.AcquireByteBuffer()
|
||||
Stream.Layout(stream, anime, css)
|
||||
ctx.RespondBytes(stream.Bytes())
|
||||
Stream.Release(stream)
|
||||
// ctx.Respond(Render.Layout(Render.Anime(anime), css))
|
||||
})
|
||||
|
||||
// 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"))
|
||||
// })
|
||||
|
||||
app.Run()
|
||||
}
|
||||
|
Reference in New Issue
Block a user