Web handlers can return a variety of content types; for example, they can return JSON, plain text, images, and more. Frequently, when communicating with APIs, it's possible to specify and accept a content type to clarify what format you'll pass data in as and what data you want to receive back out.
This recipe will explore using unrolled/render and a custom function to negotiate the content type and respond accordingly.
How to do it...
The following steps cover the writing and running of your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter8/negotiate, and navigate to this directory.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter8/negotiate
You should see a file calledgo.modthat...