Hello everyone.
In this video we will be creating a hell of work program ahead of our program is a very basic program.
We will write just to understand how go programs works so that first thing we need to know is what are
we going to store.
This program usually goes SHEELER You say the goal path environment variable but if you haven't defined
it yet you can just use the go directory.
So in my case after going to my home directory is going to be go let's go there.
And if you list the content there you will see three different directories.
But being what the binaries are stored packaged where your packages are going to be stored and serves
where your source is going to get stored in this case we're going to go into the search directory to
create our program and then we need to create a directory with the problem name we're gonna use head
on.
So we created recreating it.
We go there now from this directory it's going to hold all the files that we want to create.
We're gonna start by creating a main go program and we go programs are divided to sort of different
sections.
The first section is the package name you need to know that every go program belongs to some sort of
package.
The packages are collections of functions and methods for executive tools.
The package has to be called Main.
So we're going to do that.
Our priority is called Main.
If we're creating a library our package name could be something different.
But as we're building an executable file the package name has to be main then the next section of the
program is my inputs.
So every go program requires some libraries to operate.
We will import in this case just a single package called F.A. F.A. package holds different functions
to format messages into the input output system and that's it.
And now the most important part is the main function.
The main function is the entry point of every call program.
So here we are we have a very basic program that doesn't do pretty much anything.
So we want to do something and what we want to do is to print a message.
So we're gonna call the Green Line function from the F.A. package and we're going to add some text in
this case we're gonna say hello world.
OK.
So let's review as we define the main package which is our own package.
Then we import some other dependencies.
In this case F.A. AND WE define the main function.
Let's say this and see how to run in this.
There is two ways to run it.
The first one is to use this runs up common.
So we will type go run main that go and there we are.
We've already run compiler program right.
And we've got the output which has had a word but there is a different way to execute programs which
is that builds upcoming if we're Goldfield made a go.
Nothing happens because the program hasn't been run.
What we did is to just compile it.
So if we take a look at the contents of this directory we will see two files made the go which is the
file we've created to write our program in Maine.
If you take a closer you will see that the main the Go program is very very tiny compared to Maine because
Maine.
It's a binary it's the compile program.
And if we want to run it we just type this it will get the same output.
So as you can see.
Goal is to compile language with a dynamic workflow which means that I can go my program without even
compile it and it feels like we're a dynamic programming language.
But it isn't under the hood run compose a program and execute it.
So this is the very very basic program that we can run.
Remember it's inside a goal path slash service slash our directory.
And what I want to do now is to customize a little bit this program.
So let's say what we want to do instead of say hello world we want to do this.
Hello.
Name the name of somebody.
Anyway so how do we do this.
Well we need to do here is to create a function.
And we're going to do it this way.
Let's create a function called Hello.
In terms of shape is pretty similar to main verb we will set some parameters so that we can use them
to do some different stuff.
So the definition of this is as follows inside the parentheses I can define my arguments and between
the parentheses and the curly brackets I can define the return value of that function to make it simpler.
We're not going to return anything.
We're just going to set parameters.
In this case let's say I'm want to accept a name parameter which is of the type string.
There's different types in say the goal line which which we will cover and further sections.
But just for this I assume that string is a.
Now I want to do the same that I did before.
So I need to create this and what I'm going to do here is do this.
So what I'm doing is I'm defining in a function called Hello which accepts a parameter called name of
type String.
And what I'm doing with the name is that I'm passing it as an argument to the print line function.
Right.
Which is here.
Now I need to call this function.
How do I do that.
Pretty simple.
I just type below and I can pass on names like my name and I also want to say hello to the golfers.
Right.
So what I'm doing here is I'm calling the head of functional twice but with different arguments meaning
that every time I call this function pretty light is going to be executed with a different argument.
What it should happen is that it should print Hello style and hello golfers.
Let's try it out so let's build this program out with a previously great.
We've already built the program and let execute it and see if it has what we thought it was going to
happen and how we're grading hello with style and her golfer.
So I hope you understand how to write our hello world program.
Remember this is the foundation for every other program that we will write in the future.
By.