GoLang Workshop #1

This is show you how to build a simple Hello World Program and build/deploy the executable on your machine. This is how you would build and test applications on your own that you would then share.

I love this tutorial and it's everything you need to get started using Go

Build a binary and execute it on your machine

You want to distribute your code. You are ready to deploy your project. In order to do that, you must know how to make a 'binary executable' which is the one file that has all the byte & machine code to run your application effectively.

Step 1 - Download Go

A. you need to set up GoLang --> HERE

Once you have Go Installed, you can jump into this workshop. It will be very easy. This is to show you how Go is used when executing

B. open visual Studio code and make sure to download all plugin's for using Golang. you can find articles here--> to figure out how to do this.

Step 2 - set up dependencies, directories and files of your project

B. Then, I like to drag it into visual studio code

A. Make a directory 'src' for your source files

B. make a directory within 'src', and name it 'greeter'.

C. make a file and name it 'main.go'

Step 3 - running & testing your program

A. Go to the Terminal in VS code, (ctrl+~) and then change the directory to greeter by going through your source directory first. and then run the go run main.go command to execute a run time build of your Hello World Program.

Congrats, you ran your first ever Golang program! no matter the complexity, the go run command will always be used for executing a project.

Step 4 - Building; generate the executable Binary!

A. You are finished with you program, now we build the real project by running the command go build in the terminal, where we last left off.

B. but first, you have to make the modulus, run $go mod init Binary-Test

of course you will name your project whatever you want, perhaps you named it binary-testing... then you would run $go mod init binary-testing

C. run go build command: this will build every file in the given directory *.go (all files)

Note: On Windows, your executable will be greeter.exe.

D. Move you binary to the parent directory folder, above your src. And then run ./Binary-Test.

What ever you named your go.mod file, will be the name of the executable built if you run the command go build.

...If you named it $go mod init github.com/BridgeBuilder/BBD, then the name of the binary will be BBD and you would execute $./BBD

E. Changing the name of the binary is easy, run these commands in order at the directory level of you program in greeter directory.

Last updated