All right, before we can actually start writing any code, we need to get a development environment
set up and I'm going to walk you through the steps necessary to make this happen.
So the first thing we need to do is to get go and install it.
And it is a really simple process.
So I'm going to fire up a Web browser here and I'm going to go to this site, go langue.
So go to go langue.
And it doesn't matter if you're on Windows or a Mac or Linux.
I happen to be on a Mac.
The process is pretty much the same.
So click on the big button that says download go.
And I'm going to do that because I have an old version of Google installed and I'm on a Mac, so I'm
going to choose Apple Mac OS.
If you run Windows, choose Windows.
If you're on Linux, choose Linux.
If you're feeling really adventurous, I suppose you could install from source and compile it.
I don't recommend that there's no benefit to doing it.
So just click on the one appropriate for your operating system and download it.
So I'm going to open have it open automatically when it downloads.
It's working together and.
It's done so on a market fires south up on a windows, you might have to double click on it, but find
it and install it.
If you already had go installed, you might see previous installation detected.
If you don't, you won't.
So just click through and accept the defaults.
So I'm going to install it and it's trying to install it and I will allow it to do so.
And off it goes.
And it doesn't take long to install.
So there it's all installed and I can verify it's installed by firing up a terminal, which I will do,
I happen to use one called I term, but if you're on Windows, fire up a command prompt and just type
go version.
I think it is.
No, Ashvin.
Go version.
There it is, go version one point fifteen point three.
Now, when you're taking this course, you might be in a later version.
Don't worry, always install the latest version.
So that's simple enough.
Good.
Now let's go and find an integrated development environment and ID and I'm going to show you one that
is free and relatively easy to use.
It's probably not the one I'm going to use in this course, but I'll show you the one I'm using in a
moment.
This one is free, which is why I'm showing you how to install it.
So let's go to Google or your favorite search engine and type in visual studio code.
And it's the first one.
I want to download it.
So let's click on the download link and again, download it for your operating system.
I'm on a Mac, so I'm choosing Mac.
If you're on Linux, you can use this one.
If you're on Windows, you can use this one.
But I'm on a Mac so often comes and I'm going to save the file and I will watch the download.
I sometimes wish I could reclaim the time I spend waiting for computers, I'd have a lot of free time
if I could do that.
And there it is, all downloaded.
Now, we're not finished yet.
We have to set it up.
So I'm going to take the zip file on windows.
You just unzip it.
However, you normally unzip files on a Mac.
I happened to use this one.
The our but again, you can just double click on it and it will extract it.
So it's extracted.
Now I'm going to put that in my applications folder.
So let's find here and find my home.
I guess I want to go to the top level and find applications and I will drag it into my applications
folder.
You can put it wherever you want and start it up.
Let's open it.
Visual studio code.
Yes, I do want you to open this up it comes and we're not quite done, we need to tell it about go.
So I'm going to make this bigger.
I'm going to go to code and preferences and find Extension's.
So find your settings in your extension's.
Open that up and we're going to look for gold.
There it is right there, so let's install this.
And it should be installed.
OK.
And I have to restart, so I'll quit and restart and it becomes SMIC shirts, installed preferences,
extensions.
Go.
There we are, it's installed.
OK, don't go, let's go nightly, go with the go one.
Now, the first time you install this and I had it installed before, so I'm not seeing it, you're
going to see a bunch of alerts show up here in the lower right hand corner asking you to install things,
install those.
OK, so how did this bring this up?
Close that welcome screen.
Now, let's open this up.
I have no open folders, so I'm going to open a folder.
So I'm going to open a folder and I can put this anywhere.
I'll come in here and create a new folder called Visual Studio Projects Create.
Inside of that, I'll create a new folder called Hello World.
You probably saw this company coming up.
The conventional and traditional way of of learning a new language is to create a very simple Hello
World project.
So let's create a new file.
I roll over my folder.
I've just opened in, say, new file, and I'm going to create a file called Main Dot.
Go and Dot Go is the extension you have to give go file.
So I'm creating a new empty file called Mango and I'm going to create a simple program that does nothing
more than write Hello World to the screen and I'll write it to the terminal window.
So let's start with really simple things.
Every file in goal has to have a package.
The first line in your file is going to be a package declaration.
And I'm going to call this main I can call it whatever I wanted, but because this is the main part
of my program and this is a simple program that's going to have one file, I want to give it the name
main.
Underneath that, I'm going to have a function.
And that function is also called main.
And there can only be one main function in an application.
And the way you write functions and go and you're going to get very, very used to this as time goes
on, is with this keyword func that says I'm a funk.
Oh, look, there's the install things, so I'm going to install the first one is go code command is
not available, so let's install and the second one is go packages.
Let's install that and off it goes is installing them.
I'll wait for that to finish all tools successfully installed.
Perfect.
All right.
What's my problem.
Expected package found EAFE.
I know.
So I've got that done.
Let's call this funk main and I'll just get rid of this error message.
It's only there because I wasn't finished typing my function func main and then I have curly brackets
inside of that.
I'm going to do a simple write to the screen and use that.
You do that and go using a package called FMT or format is what I call it.
Some people call it font, but I can't bring myself to say that regularly.
So I call it format FMT Dot.
And this is the nice thing about the ID is it gives me all of the auto completions.
I'm looking for print line Primanti L.N..
There it is, function of format, print line.
And then inside of that I'll write Hello World.
Now you'll notice that I have an error here.
Still, I'm using this format function but it I need an import statement now.
I could come up here and type in import format, but I really want this to happen automatically.
So I'm going to go to preferences here.
I need to find somewhere and preferences under settings I have go so I type and go.
There it is.
And do I have any code completion stuff.
Um, there's go again, I guess I get out of there.
Build flags, flags to go build no, no.
I'm looking for the.
The auto import.
Where is that footpath?
Watlington PSUV.
Use the language server, that's what I want.
So let's do that.
I don't know, I need to install the go please tools, which is what I want, it installs it.
This is an important step that will save you a lot of time, and I always have to look for it every
time I use this because I don't regularly use this package.
This is OK, I've got it done.
Let's quit out of it just to make sure it's working properly.
Started back up.
And good, let's close the settings, go back to Main, I'm going to delete this line and I'm a FMT
return print line and hopefully it will automatically do the part for me.
And it did.
It put import format in one format, print line and now hello, world.
All right.
So let's save this.
There it is.
My program is now done.
Now I want to run this program.
So I've written a very simple program.
Let's just go through the things.
First of all, every go file has to have a package declaration.
And since we only have one file and it's the main file, the package is main.
The import section tells the code, I am using certain packages and these could be packages in the standard
library, which is all we're going to be using for the next little while.
But eventually we'll go to external packages and then we have at least one function.
And that function, if there's only one, has to be called main.
I can have other functions and we'll do some of those in a little while.
But right now we're just doing a very simple thing.
So how do I run this program, this package main, which uses Fanti format from the standard library
and all it does in the main function is write Hello World to the terminal.
Well, I open a terminal window and in visual studio code you have a built in terminal.
So there it is.
And I'm going to run this now by default.
When I open up the terminal, you can see where I am.
I'm in my users, my name, the visual studio projects folder that I created, and then the Hello world
folder that I created to hold this one file to run this I type.
Go, run, maeng, go.
And when I do that, what should happen is it should print Hello world to the screen and it does.
Hello world.
That's great.
OK, now if I do, unless you see there's only one file in there.
What if I wanted to build an executable.
That's pretty simple.
Go build D'Ascenzo for out.
I want to call it HSW for Low World and what I want to compile is mango.
So go is the command.
You're going to get very used to using the go command.
I want it to build and I want it to output.
That's what the dashboard means to a file called H.W. and I want to compile mango.
And when I do that it looks like nothing happened.
And yet you notice up here I have a new a new file called H.W. And if I do an LS here, I have an H
w and I can run that by doing dot slash, which says run in the current directory H.W. And all that
does is print Hello World.
So that is our basic setup and this is everything you need to use.
This course you may want to install get.
When I get to that I'll talk about that.
But all you need to write go programs is something to create text files.
I like an idea like Visual Studio Code and I'm going to show you the one I'm going to use momentarily.
But Visual Studio Code is free and will do everything you want.
You have to install the go package for Visual Studio Code and you need the go the go programming language.
So once you install go at an idea and the necessary plug ins, you're all set.
Now compare this to something like P, where you have to install a runtime, you have to install all
the packages, you have to have composer, you have to have all kinds of things and keep them up to
date.
All you really need to write go programs is this.
Now, there are other things we're going to use like a database later on and we'll install that.
And it's a very simple process to do it, but it's very, very straightforward and very, very clean
to run go code.
Now, as I said, I don't use visual studio code and if I use it in this course, I'm going to look
like I don't know what I'm doing because I'm just not familiar with it.
ID nor do I want to be.
The one I actually use is by a company called Jet Brains.
But it's commercial software.
You have to buy it.
So I've got a jet Breen's dotcom.
Up it comes, and I want to use go, I want to write, I want to write things in goes.
I'm going to scroll down to find gold and click on that.
And it becomes it says Goaland.
This is exactly the one that I use.
And it's it's just another idy.
The only reason I use it is because I'm familiar with it.
You can get it free if you happen to be a student in an educational institution, you can get it free
if you're using it for an open source project.
But of course you actually have to have a project that is open source that they can look at, or you
can download the three day trial and try it out if you like it by it.
If you don't like it, go back and learn and use visual studio code.
It's entirely up to you.
This is what I'm probably going to use as we go through this course just because I'm so much more familiar
with it.
But the differences really are pretty straightforward.
You're still going to have go files.
You're still going to have a terminal.
Everything will be almost the same.
I'm just going to have a slightly different interface than you are.
But anyway, we've now got a one functional go program.
Let's get started and do something that's actually useful.