WEBVTT 00:00.980 --> 00:02.050 Hello everyone. 00:02.180 --> 00:09.040 In this video we will be creating a hell of work program ahead of our program is a very basic program. 00:09.050 --> 00:18.750 We will write just to understand how go programs works so that first thing we need to know is what are 00:18.750 --> 00:19.440 we going to store. 00:19.440 --> 00:27.230 This program usually goes SHEELER You say the goal path environment variable but if you haven't defined 00:27.230 --> 00:31.000 it yet you can just use the go directory. 00:31.010 --> 00:39.150 So in my case after going to my home directory is going to be go let's go there. 00:39.280 --> 00:43.070 And if you list the content there you will see three different directories. 00:43.370 --> 00:50.240 But being what the binaries are stored packaged where your packages are going to be stored and serves 00:50.600 --> 00:55.940 where your source is going to get stored in this case we're going to go into the search directory to 00:55.940 --> 01:01.800 create our program and then we need to create a directory with the problem name we're gonna use head 01:01.800 --> 01:02.180 on. 01:02.720 --> 01:04.100 So we created recreating it. 01:04.100 --> 01:11.300 We go there now from this directory it's going to hold all the files that we want to create. 01:11.300 --> 01:21.530 We're gonna start by creating a main go program and we go programs are divided to sort of different 01:21.530 --> 01:22.400 sections. 01:22.400 --> 01:31.050 The first section is the package name you need to know that every go program belongs to some sort of 01:31.050 --> 01:31.640 package. 01:31.650 --> 01:37.870 The packages are collections of functions and methods for executive tools. 01:37.890 --> 01:40.520 The package has to be called Main. 01:40.530 --> 01:42.210 So we're going to do that. 01:42.240 --> 01:44.490 Our priority is called Main. 01:44.490 --> 01:48.830 If we're creating a library our package name could be something different. 01:48.930 --> 01:56.840 But as we're building an executable file the package name has to be main then the next section of the 01:56.840 --> 01:59.080 program is my inputs. 01:59.630 --> 02:04.660 So every go program requires some libraries to operate. 02:04.820 --> 02:13.460 We will import in this case just a single package called F.A. F.A. package holds different functions 02:13.990 --> 02:20.070 to format messages into the input output system and that's it. 02:20.120 --> 02:23.860 And now the most important part is the main function. 02:23.860 --> 02:28.750 The main function is the entry point of every call program. 02:28.750 --> 02:34.810 So here we are we have a very basic program that doesn't do pretty much anything. 02:34.810 --> 02:38.500 So we want to do something and what we want to do is to print a message. 02:38.830 --> 02:47.280 So we're gonna call the Green Line function from the F.A. package and we're going to add some text in 02:47.280 --> 02:49.830 this case we're gonna say hello world. 02:49.970 --> 02:50.330 OK. 02:50.730 --> 02:56.840 So let's review as we define the main package which is our own package. 02:56.840 --> 02:59.550 Then we import some other dependencies. 02:59.570 --> 03:03.480 In this case F.A. AND WE define the main function. 03:03.500 --> 03:06.500 Let's say this and see how to run in this. 03:06.630 --> 03:08.110 There is two ways to run it. 03:08.150 --> 03:11.580 The first one is to use this runs up common. 03:11.630 --> 03:16.730 So we will type go run main that go and there we are. 03:17.330 --> 03:20.270 We've already run compiler program right. 03:20.300 --> 03:27.020 And we've got the output which has had a word but there is a different way to execute programs which 03:27.020 --> 03:32.760 is that builds upcoming if we're Goldfield made a go. 03:32.840 --> 03:36.440 Nothing happens because the program hasn't been run. 03:36.440 --> 03:39.040 What we did is to just compile it. 03:39.110 --> 03:45.560 So if we take a look at the contents of this directory we will see two files made the go which is the 03:45.560 --> 03:48.810 file we've created to write our program in Maine. 03:49.430 --> 03:59.000 If you take a closer you will see that the main the Go program is very very tiny compared to Maine because 03:59.000 --> 03:59.590 Maine. 03:59.660 --> 04:02.820 It's a binary it's the compile program. 04:02.840 --> 04:08.390 And if we want to run it we just type this it will get the same output. 04:10.630 --> 04:11.860 So as you can see. 04:11.860 --> 04:21.070 Goal is to compile language with a dynamic workflow which means that I can go my program without even 04:21.070 --> 04:26.200 compile it and it feels like we're a dynamic programming language. 04:26.200 --> 04:29.680 But it isn't under the hood run compose a program and execute it. 04:30.010 --> 04:34.360 So this is the very very basic program that we can run. 04:34.360 --> 04:40.660 Remember it's inside a goal path slash service slash our directory. 04:40.660 --> 04:45.670 And what I want to do now is to customize a little bit this program. 04:45.910 --> 04:51.570 So let's say what we want to do instead of say hello world we want to do this. 04:51.620 --> 04:52.930 Hello. 04:53.050 --> 04:55.030 Name the name of somebody. 04:55.070 --> 04:57.510 Anyway so how do we do this. 04:57.520 --> 04:59.710 Well we need to do here is to create a function. 04:59.830 --> 05:01.720 And we're going to do it this way. 05:01.870 --> 05:04.650 Let's create a function called Hello. 05:04.720 --> 05:13.420 In terms of shape is pretty similar to main verb we will set some parameters so that we can use them 05:14.480 --> 05:16.040 to do some different stuff. 05:17.170 --> 05:28.030 So the definition of this is as follows inside the parentheses I can define my arguments and between 05:28.030 --> 05:34.220 the parentheses and the curly brackets I can define the return value of that function to make it simpler. 05:34.240 --> 05:36.380 We're not going to return anything. 05:36.670 --> 05:38.800 We're just going to set parameters. 05:38.860 --> 05:45.310 In this case let's say I'm want to accept a name parameter which is of the type string. 05:45.520 --> 05:51.560 There's different types in say the goal line which which we will cover and further sections. 05:51.860 --> 05:56.050 But just for this I assume that string is a. 05:56.080 --> 05:58.710 Now I want to do the same that I did before. 05:58.720 --> 06:04.270 So I need to create this and what I'm going to do here is do this. 06:04.330 --> 06:13.650 So what I'm doing is I'm defining in a function called Hello which accepts a parameter called name of 06:13.650 --> 06:15.180 type String. 06:15.210 --> 06:22.830 And what I'm doing with the name is that I'm passing it as an argument to the print line function. 06:22.830 --> 06:23.440 Right. 06:23.580 --> 06:25.050 Which is here. 06:25.050 --> 06:26.710 Now I need to call this function. 06:26.760 --> 06:28.480 How do I do that. 06:28.650 --> 06:29.460 Pretty simple. 06:29.460 --> 06:38.080 I just type below and I can pass on names like my name and I also want to say hello to the golfers. 06:38.160 --> 06:39.470 Right. 06:39.480 --> 06:46.080 So what I'm doing here is I'm calling the head of functional twice but with different arguments meaning 06:46.080 --> 06:52.920 that every time I call this function pretty light is going to be executed with a different argument. 06:53.140 --> 07:00.790 What it should happen is that it should print Hello style and hello golfers. 07:01.370 --> 07:07.330 Let's try it out so let's build this program out with a previously great. 07:07.620 --> 07:14.090 We've already built the program and let execute it and see if it has what we thought it was going to 07:14.090 --> 07:18.890 happen and how we're grading hello with style and her golfer. 07:19.010 --> 07:23.660 So I hope you understand how to write our hello world program. 07:23.810 --> 07:28.780 Remember this is the foundation for every other program that we will write in the future. 07:29.030 --> 07:29.450 By.