ChatGPT Part 2
The previous part in this series introduced ChatGPT and explained my motivations for testing it out. One of the coolest features of the tool is that it will remember previous topics in the conversation and apply them in future prompts. So you don’t need to get it right the first try, you can rephrase and try again. Since I learn best when the knowledge is applied, I asked ChatGPT to help me with a problem I was struggling with for the past 4 days. I was trying to come up with an elegant solution to using AWS application load balancers to process HTTP requests with Lambda functions, and I wanted to use the Go programming language. However, doing HTTP path multiplexing is something that the standard Go muxer is not good or performant at. For instance, the default muxer can handle GET /blog perfectly, but it cannot handle GET /blog/:id because it doesn’t know how to parse path parameters. I could start parsing those path parameters with regex, but then I’d start having regex problems, and I’m certain it wouldn’t be performant or battle-tested. That’s where muxers like Gin or Chi or Gorilla come in. I wanted to write the Lambda function to pass the ALB request to a Gin backend and have it mux for me. The problem was that constructing an HTTP response struct by hand is not something people do, and I was struggling to write it properly. I tried using net/http/httptest/ResponseRecorder and it worked, but that struct is for unit testing and it felt wrong to adapt it for – what I would expect to be – production code. None of my solutions worked, so I asked ChatGPT to help me. ...