package main import ( "github.com/hoisie/web" "net/http" ) func main() { web.Get("/hello", func(ctx *web.Context) { ctx.WriteHeader(http.StatusOK) ctx.WriteString("Hello, World!") }) web.Run("localhost:8080") }
package main import ( "github.com/hoisie/web" "net/http" ) func main() { web.Get("/notfound", func(ctx *web.Context) { ctx.WriteHeader(http.StatusNotFound) ctx.WriteString("Page not found!") }) web.Run("localhost:8080") }This example sets the response header to indicate a HTTP 404 Not Found status code before writing the message "Page not found!" to the response body. In both examples, the "github.com.hoisie.web" package library is used to create and manage a web server endpoint with the "web.Run" function. The "web.Get" function is used to specify the HTTP route and associated handler function with a "web.Context" parameter for setting response headers and writing messages to the response body.