// create a new context ctx := context.Background() // set a value in the context ctx = context.WithValue(ctx, "foo", "bar") // get the value from the context val := ctx.Value("foo").(string) fmt.Println(val) // outputs "bar"
// create an http handler function func helloHandler(w http.ResponseWriter, r *http.Request) { // write a response body fmt.Fprintf(w, "Hello, World!") } // register the handler function with an http server http.HandleFunc("/hello", helloHandler)Overall, this package provides useful types for working with HTTP requests and responses in Go web applications.