Go – Function that gets a website and returns its title – With ChatGPT

I took a look at that new ChatGPT and I can officially say – the future is now. Take a look at what it does, after writing it a simple nice request:

The first result did not work, as it had unused variable and golang does not allow it, but then it started giving working results:

Then I asked it to try to do it without the github libraries and after only 8 wrong tries, it returned this working beauty:

Then I asked it to do it with less libraries and with less lines and both times it produced a working code. I asked it to do it without a loop, and it gave a working solution as well (after a few corrections from my site):

Asked for meaningful names of the variables and it agreed that meaningful names was a good idea:

I asked it a few times to optimize it, and once the optimization was even passing the website argument like this:

Really, this is no doubt faster! 🙂 And some kind of strange creativity, for not needing to access the site at all.

That’s not all!

I asked it to make a library with useful webfunctions, and it created one with the GetTitle() function and then proposed to add two more functions. These are its words:

You can expand this library by adding more functions that are commonly used in web development, such as functions to make HTTP requests, parse HTML or JSON, and so on. Please let me know if you have any other questions or concerns.

Well, it created the libraries. Then I asked it to create tests for them… and it did. Now the funny part – I could not run the tests correctly, as I was not that familiar with the Go syntax and asked it how to run these. It told me nicely:

And ChatGPT was correct! So, long story short, this is the small library it created, named web:

And these are the tests it wrote:

The future is now!

Tagged with: , , , , ,