Skip to content

Instantly share code, notes, and snippets.

@robertwe
Created June 26, 2018 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertwe/e19e4ea2767c6ea7852d3160b56bd20a to your computer and use it in GitHub Desktop.
Save robertwe/e19e4ea2767c6ea7852d3160b56bd20a to your computer and use it in GitHub Desktop.
fasthttp and html
package main
import (
"bytes"
"log"
"github.com/shiyanhui/hero/examples/app/template"
"github.com/valyala/fasthttp"
)
func main() {
requestHandler := func(ctx *fasthttp.RequestCtx) {
var userList = []string{
"Alice",
"Bob",
"Tom",
}
buffer := new(bytes.Buffer)
template.UserList(userList, buffer)
if _, err := ctx.Write(buffer.Bytes()); err != nil {
log.Printf("ERR: %s\n", err)
}
ctx.SetContentType("text/html; charset=utf8")
}
log.Fatal(fasthttp.ListenAndServe(":8081", requestHandler))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment