Golang Tutorial #1 - Introduction to Go

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to this first tutorial on getting started with go firstly i just want to congratulate everyone who is taking the time to watch this video uh while i think teaching yourself programming is probably easier than most people realize taking the initiative to get started is often the most challenging part so i want to congratulate you on that if you'd like to learn more about the go programming language in general i encourage you to check out my first video on why go is the best programming language to learn in 2021 but let's go ahead and hop right into it this is kind of the agenda or the outline for this particular video everywhere that you see a star is an area that i intend to cover that is often omitted by other tutorials when i look at other tutorials i see that they often leave out parts that i think are essential to kind of forming a complete picture of the gold language and the go tools so i encourage you to pay attention especially during those sections of the videos uh because it's those small details that are going to take you from being a good developer to a great developer the first thing i'm going to do is open up the command prompt and i'm just going to type go version into here go version is the command that you would use to see if you have go installed and if you do it will show you the version of the sdk i do not have it installed which is why i'm getting an error saying that the go command is not recognized in order to install go go ahead and open up your browser and go to golane.org now this here is the page for the golang language it has your documentation your search your source code packages information on the go open source project so go ahead and click on the downloads button uh what it immediately presents is a number of different options based on your operating system you can also choose the semantic version of the sdk that you want to download uh you can pretty much see here that you can really download any version of go that you want the most recent version is 1.15.6 and i'm on windows so i'm going to select that you should obviously select what is best for your operating system once the download is complete you can go ahead and run the installer of course you need to accept the license agreement and then you can click next and pretty much select all of the default options and click install once your installation is complete you can go ahead and hit finish to close out of the dialog window and you should be all set and ready to go in order to verify our installation we can open the command prompt back up and it is important that you open a new command prompt you can't use the same one that you open at the beginning open that up and just try that go version command again now you can see that i have version 1.15.6 installed if you do still get an error message as i said make sure you opened up a new command prompt and if you're still getting it i would advise that you restart or i'm sorry reinstall go then come back to the screen and try it again before i close out of this window there's just some additional information or functionality that i'd like to share with you guys behind the go tooling if you just type go into the prompt and hit enter it will provide you with a list of options that you can use in conjunction with the go command a lot of these options have to be followed up with a specific file name a specific go file but not all of them as you can see we have go version on the list which we've already used the go build command would be followed by a file name so you type go build and then the name of the file and that would compile your go program go format is one that i use often because it auto indents your code and makes it look like you know what you're doing and then go run which will use in a minute actually compiles your code and then runs your go program for you so it actually runs go build before it actually runs your program you can use the help command to find out additional information on any one of these individual options for example one of the more useful help sections is the section that covers the documentation so i can type go help doc here and it immediately provides me with examples uh usage examples for how i can use the documentation command and what it says at the top here is basically that you can use the documentation command to find out the details of any specific package within the go sdk so you can find out the functions the methods uh the interfaces the structs so it's just useful to learn more about a specific package so i'll take a look at this one uh the encoding slash json package is saying that you can use go.json so i'll type that in here like i said it shows you the interfaces and structs of this package that's just kind of a useful command and there's a lot more i could get into with the tooling but it's just good to know that go provides you with a number of different ways to interact with the sdk through the command line interface the next thing i'll demonstrate is how to install your ide and get that setup to start programming with go when it comes to your ide you have a number of different options one of the more popular options is visual studio code this is a code editor not for just go but for a number of different programming languages and it allows you to install extensions that provide some additional functionality for whatever program you're working with so things like syntax highlighting suggestions things of that nature so this is a popular code editor and one of the perks of it is that it's free so you don't have to worry about paying a dime for this although this is a popular code editor i typically don't use this one when i'm programming with go actually i prefer to use one that is called go land and this is a ide that is developed by jetbrains and i prefer to use this one because it's an editor that is specifically made for go i use visual studio when i first started programming with go and it worked okay but um i felt like i found myself messing around with the configurations and the plugins and extensions um just a little bit too much i felt like i was spending too much time having to update those things and when i switched to golan i felt like it saved me quite a bit of time i guess you could say one of the downsides of golan is that it's not free you do have to pay for it although you do get a free 30-day trial which i think is long enough to determine if you actually like the software or not and if not obviously you can always go back to visual studio code but there are special offers that allow you to get it for free or at least at a discount for example if you're a student or teacher and you get it completely for free which is what i did also if you're part of a non-profit organization you can get it for up to 50 off so it's really personal preference within this course i'll show you guys how to install both visual studio and go land and you guys can kind of make the decision for yourselves but i would advise that you at least give go land a try like i said it will save you a bunch of time and i'm not affiliated with with jetbrains so i don't get a cent for recommending that but the first thing i'll do is show you guys how to install visual studio code so you can skip to the part that applies to you and then the next section will be setting up our go program in this section of the video i'll show you guys how to install visual studio code if you prefer to use golan or another ide you can go ahead and skip this section and fast forward to the part where we set up our first go project but to install visual studio if you just search for it in your search engine it should be pretty easy to find click on the download section and it presents you with options as far as your operating system so i'll click the one that works for me after it's finished downloading you can go ahead and run the installer of course you have to accept the license agreement i would advise selecting the default installation options just click through and the installation shouldn't take too long once the installation is complete it should automatically launch visual studio for you and i'll give just a brief overview of the ui here to the left at the top you have uh your file or directory explorer so that allows you to kind of look at the hierarchy and the folders within your projects this here is the search icon it allows you to find specific text or files in your project this is the source control icon it allows you to connect to a remote repository then you have your debugging and then you have the tool or the search option for extensions so we're going to go ahead and type go in here in the extension that we want to install is this first one here when i click it you can see that it's got just over four million downloads so it's probably the most popular go extension and it's by golane.go mine is already installed because i did have visual studio installed before but go ahead and click the install button and that may take just a little bit if you want to see the actual features that this extension is providing you can click on the feature contributions tab and it will show you a brief description of the functionality provided by this extension once your extension is finished installing you can go ahead and exit out of this you just have one more step in order to enable the full functionality of this extension we actually have to install some tools on top of it so go ahead and hit ctrl shift and p on your keyboard or command shift p if you're on mac and that should bring up a prompt at the top we want to type in go install slash update tools this is the option that we want once you select it it will bring up a list of tools that can be installed on top of the extension select the box at the top and that will select all of them and then you can go ahead and click ok this installation will take probably around five minutes but once it's complete you should be all set and ready to code with go in visual studio in this section of the tutorial i'll show you guys how to install golan if you already have an ide installed you can go ahead and skip past this section of the video to the part where we set up our first go project to install golan it's pretty straightforward just search for it in your search engine click the download option there i'm actually not going to click download because i already have it installed but once you click download it will download the installer click the installer to run it uh all of the questions are pretty straightforward um it's just asking you things like the you know installation location and some other options i would advise clicking all of the default options and then once the installation is complete it will actually present you with this screen here it's asking you to either activate a license or evaluate for free if you somehow got a license by either paying or through one of the free membership options go ahead and select that and enter your information to activate that license or you can select evaluate for free and you will be able to use the software for 30 days with no license after you've done that go ahead and exit out of golan and in the next section we'll create our first go project at this point regardless of what ide you have chosen to use you should be ready to set up your first go project but before we get into that i want to briefly cover a topic that i often see omitted in other gold lane tutorials and that relates to go modules as of go 1.13 go modules is the correct way to set up your go project prior to the existence of go modules programmers needed to set up their project using something called go workspaces and modules was introduced to solve some issues around uh dependency management and versioning uh which is maybe a little bit too detailed and outside of the scope of this course but one of the benefits of go modules is that it allows you to set up your go project in any directory you want to in any place on your operating system with workspaces you have to set up your project in a very specific folder alongside the go sdk installation and even now in 2020 i see new go lane tutorials instructing people to set up a go workspace that is incorrect that is an outdated way of setting up your go project and so this course will certainly be taking advantage of go modules but i just want to point that out because that is an important distinction and i do encourage you to google that and read up on the difference between workspaces and modules when you get a chance alright we have officially made it to the last section of this course where we will create our own go project and run it as i just mentioned go modules allows you to install a go project in any location you want to on your operating system so go ahead and select your directory of choice and create a folder i'm going to create one here in my documents directory and just name it a first go project and just save that there then open your ide shouldn't matter what ide you use at this point and i want you to navigate to the spot where you saved that directory and open it when you first open that folder in your ide you'll notice that there's of course nothing in it so the next thing that we're going to do is initialize our go modules and you do that with this command go mod init followed by the module name if you plan to only store your modules on your computer it really doesn't matter what name you give the modules but if you plan to store it in a repository it's common practice to follow this naming pattern and that pattern is the repository followed by the username followed by the name of the project and that as i mentioned is called module initialization now if i go to the directory you see that it's created a go.nod file for me so this is officially a module and just so you know a module is really any directory that has a collection of go files with a go.mod file in it when i open that file there's not much in here all you see is the module name and current version of go that i'm using but as we add dependencies and packages to our project they will automatically be populated here and they're populated under what's called directives i won't go into detail on those but um the most basic directive is called a required directive and that simply lists out all of the minimum required versions of any given dependency within your project so now that we've got a go.mod file let's go ahead and create our first go file go ahead and create a file and name it main.go if you're in visual studio code it may not automatically create this package declaration at the top but in any case what we want to do is actually name this package main in order to run any executable program in go at the very least you have to have a package made and you must have a funct main the font main or function card made is the entry point for an executable program in go so these are the basic parts of a go program there's a third part which is the imports but as we'll see in a moment that part will actually automatically be included whenever you make a call to another package so as you can see when i make a call to the format package it automatically imports and the format package is the library you use to do any type of printing to the console or any type of string interpolation but i'll just keep it simple here i'll type in of course the standard hello world string there and at this point you should be able to run your go program so open your terminal if it's not already open make sure that you have cd into the project directory and you can now run go run main dot go and you can see that it prints out hello world earlier i mentioned that whenever you execute the go run command it first builds the program for you so it's possible for us to just run the build command by itself the result is an executable file that you can run just by typing the name of the file and you see i get the same result that does it for this tutorial video if you have any questions feel free to leave them in the comments please subscribe to be updated as i release new videos throughout this series and if you enjoyed the content please give the video a like thanks for watching esoteric tech i'll see you in the next tutorial
Info
Channel: Esoteric Tech
Views: 3,117
Rating: undefined out of 5
Keywords: golang, golang introduction, Golang Tutorial, Golang For Beginners, Golang Programming, Go Tutorial, golang programming language, golang tutorial for beginners, learn golang, golang beginner tutorial, go language introduction, golang tutorials, Golang SDK, Install Go, Go Installation, programming tutorial, introduction to go, Learn go, golang installation, go programming tutorial for beginners
Id: bt3xrM3sUck
Channel Id: undefined
Length: 19min 15sec (1155 seconds)
Published: Mon Dec 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.