Problem integrating hero template with fasthttp

i am integrating hero template to fasthttp but localhost:8080 shows just like this


but i need localhost:8080 shows just like this


problem is html code is shown. My app.go is

package main
import (
func main() {
requestHandler := func(ctx *fasthttp.RequestCtx) {
var userList = []string{
buffer := new(bytes.Buffer)
template.UserList(userList, buffer)
if _, err := ctx.Write(buffer.Bytes()); err != nil {
log.Printf("ERR: %s\n", err)
log.Fatal(fasthttp.ListenAndServe(":8080", requestHandler))

Just a guess as I do not know fasthttp, but I think you need to set an appropriate content type.


PS: You are generating three lists with a single item each, is this really the expected behaviour?

the browser needs an info what type of content you will serve.
In you case before you set the buffer you need to set the proper header:
ctx.SetContentType("text/html; charset=utf8")
After that it should work.

here you can find more complex example:

Wow really thanks a lot

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.