DEV Community

Cover image for Building my first Go App with Github Copilot
rachelle palmer
rachelle palmer

Posted on

Building my first Go App with Github Copilot

It's been just a few months since Github made Copilot, and yet the new Github Copilot extension for VS Code already has more than 2 million downloads. This is a huge amount of people, and I wanted to see if the hype is real. I decided to try and build a few apps with a programming language that I don't know - Golang - and see how successful it might be.

My Ground Rules

  • Don't read a lot of Go docs. If I'm the one writing most of the code, or spending time in the docs, that would be a fail
  • Don't try anything TOO fancy... but don't go easy on Copilot either. This is not a marketing puff piece. I really want to know what's possible.

Experiment 1: Hello World

After installing go, the VS Code go extension, and the Github Copilot extension, I created a new file, skimmed one tutorial, and typed
package main
import
Github Copilot then suggested fmt
Github then suggested func main()
once I accepted this suggestion, GC replied with
{fmt.PrintIn("Hello World!")
}

Verdict: Hell yea, this works!

Experiment 2: Build Your Own Container

For something a little more difficult, I turned to this Build Your Own Container tutorial. I typed
package main
import(
and Copilot suggested fmt.
After accepting this suggestion, I typed os, and Copilot suggested os/exec.
Then, I typed func... and Copilot veered off course with this:
main() {
binary, lookErr := exec.LookPath("ls")
if lookErr != nil {
panic(lookErr)
}
args := []string{"ls", "-a", "-l", "-h"}
env := os.Environ()
execErr := syscall.Exec(binary, args, env)
if execErr != nil {
panic(execErr)
}

Verdict: No.

I typed switch os.Args[1]{
and from there Copilot helpfully offers:

case "run":
parent()
case "child":
child()
default:
panic("what?")
}

And we're back on track!

I continue on with this tutorial and the verdict is that although Copilot sometimes offers wrong suggestions for what I want, the code itself is great. If I give it just a tiny hit, it can give me entire blocks of code that are more than 90% accurate.

Final code matches the tutorial almost exactly.

Image description

Verdict:...
Image description

Ultimately I was pretty impressed by what is possible. I still don't know golang and I'm unlikely to learn, but I did feel like I'd be capable of building an application within a matter of weeks with something like Gopilot as a sort of 'uber linter`.

Top comments (0)