🚀 Get 25% off access to all my premium courses - use discount code FUNCMAIN at checkout - view the pricing page now!


Writing Your First Go App

May 6, 2021

Course Instructor: Elliot Forbes

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

Now that we have Go successfully installed on our machine, Let’s try and write our first go application.

Now I have created the directory under which this application is going to live. I’m going to create a new file called main.go in this directory.

The first thing I’m going to do here is to define a package main and a func main I’m then going to do println("Hello World") Like so.

package main

func main() {
	println("Hello World")

So let’s dive into what this means. Well, the package main and the func main are a special combination, that effectively act as the entry point or the starting point for any Go application.

Now, if we wanted to run this application, we could do so using the go run command and passing into the name of the file.

$ go run main.go
Hello World

And as you can see, it has printed out hello world.

Now, in this instance, we are running this through the go command-line tool. If we wanted to execute this as a binary executable, we could build it using the same tool.

$ go build -o main main.go 

So that’s going to go away, take all of this source code here and compile it as a binary executable. And if we print out the contents of directory, you can see the executable here and the main.go file, which we built this executable from.

Let’s try it run our application.

$ ./main
Hello World

And as you can see, our application has printed out hello world.

So while this application isn’t the most complex, this does represent the first and arguably the most important step and your journey towards learning Go. You have created your first application.

Now in the next videos in this course, we are going to start to add complexity to our application. We’ll start to introduce some of the basic syntax that you’ll need an order to write more advanced Go applications.