package main import ( "net/http" "github.com/hoisie/web" ) func main() { web.Get("/data", func(ctx *web.Context) { ctx.SetContentType("application/json") // write some JSON data }) http.ListenAndServe(":8080", nil) }
package main import ( "net/http" "github.com/hoisie/web" ) func main() { web.Get("/", func(ctx *web.Context) { ctx.SetContentType("text/html") // write some HTML data }) http.ListenAndServe(":8080", nil) }In this example, we are setting the content type of the response to "text/html" using the SetContentType method. This is useful when returning HTML pages from a web application. The Context ContentType package is part of the hoisie/web library for Go, which provides a simple and efficient framework for building web applications. It provides a number of useful tools, including routing, middleware, and template rendering.