Golang 1.19: What is new?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is mario go 1.19 was released a few days ago what is new go 1.19 was released on august 2nd 2022 there are a few ways to install this new version depending on the operating system that you have and the way you like using go typically you can download the files from the official website that include binaries for mac os windows previously and linux if you use macos and you happen to use homebrew the version is still not available however i'm going to be leaving the pr in the description as well typically takes a few weeks to make it available for everybody so you can download that version officially from homebrew so what was included in 1.19 compared to 1.18 there are no major changes to the language only changes to the tool chain runtime and libraries i want to call out four specific changes that i think are really valuable so let's get that started the first one is how we can create documentation go using comments in the source code typically this is really basic but with this new version 1.19 we can use something similar to markdown not everything but there are some features that are applicable and really look similar to the way it's implemented in markdown specifically links lists and also headers let me show you how this looks as usual the link to the examples are in the description so feel free to check that out the first one will be using the new changes when implementing the documentation in go now the way we have documented in go previously is just adding comments and that doesn't change the way it changes is that now pkg called dev or godot rather now supports understanding a few different extra elements that allow you to render your documentation in different ways this is the super similar to what markdown typically uses so for example we have right here a new element it looks like a you know hash and what this does is render a header in the documentation another one will be using these lists that we have right here so we have one and two the render number number list this is a small space that you can refer right here if a tiny thing is a small space to indicate that that is a list and the other cool thing about this one is that you can also render links and an example will be this one that we have right here for linking to google and is similar to markdown you can refer to the link itself right here and talking about links as well you will notice that there is another one right here and what this does is refer to types inside your same package so in this case what is going to happen is when the user clicks hello world what is going to do between is linking or jumping to the hello world function on the page now this also can be used for linking to specific packages outside of your own package maybe in the standard library or methods or different types along those lines so pretty cool really useful if you like documenting your packages and your code properly this is going to be really useful for everybody for your users for you and for everybody else and let's see the second one another change was adding a new validation to the tool called vet when using errors as which typically there is a common issue with the error when you are using as and when you are passing in the second argument in this method let me show you what i mean okay so we open up this main dot go you will notice that my editor is already printing out that for me but it's actually right here if you notice right is saying hey the second argument that errors as should not be error and this is something that is actually not executed when you run the govet manually so let me see i will show you see if i run go fit main.go and right now i'm using go 1.18 the most recent version to date if i run my local version 4.1.19 you will notice that now it will be printing out the the warning that we're expecting so in this case it's going to be saying hey the second error should not be a pointer to an error this is a typical common error and i will show you the code one more time so you can see that you may be having this error in your code and you may never have noticed that before now obviously if you have a linter that is already detecting this for you go fed will be sort of like redundant but it still is really useful third one will be the addition of atomic types in the zinc atomic package let's see so these new types are added in the sink atomic package like i mentioned a while ago you will see that right here what i have is for 1.18 and before or rather everything before of 1.19 and the other important bit will be the one that is right here now in practice the code looks more or less similar there are not too many big differences but it sort of like simplifies the way we're accessing the atomic types using the atomic package now if i go and modify and enable this code you will see that i'm getting a few errors and that's because my editor is still referring to go 1.18 but if i go to again i show you the version you will see that this won't compile because it doesn't exist but if i do 1.18 you will see that now it's working and it's doing what it's supposed to be doing it's just a simplification of what the code was how we implemented the code before i kind of like this one it's kind of nice and the fourth one and finally that i want to call out will be the flag text bar function that allows you to pass in and specify types that support an interface type that allow you to parse those types automatically behind the scenes a few examples will be the ipv4 there is also time a few orders also included in the standard library let me show you a concrete example last one would be this new type added to flag to the flag package specifically called text bar that supports and parsing types that implement this concrete interface encoding text marshaller in this case net ipv4 already implements that for us so it works right away if i run this with go 1.18 it will fail because it's a new type it's a new method but if i run this with 1.18 and if i run dot main go ip let's put a block which is an incorrect ip value it will return an error which is right here right it says invalid address vla but if i change that and say i do something that makes sense and i do one 101.97001 will be printing out that as well like i said this supports i i believe time in the standard library but like like i told you if you go back and implement the requirements of this text bar you will notice that you just have to implement this new package or rather this new type called define in in encoding text marshaller which is basically a new method that's it for this one and that's it those are the four new features that i wanted to call out those are not the only ones for sure please read the release notes as usual take care stay safe and see you next time
Info
Channel: Mario Carrion
Views: 8,293
Rating: undefined out of 5
Keywords: golang tutorial for beginners, golang tutorial, golang tutorial for begginers, golang, golang generics, golang workspaces, golang fuzzing, golang 1.18 fuzzing, golang netip, golang 1.18 tutorial, learn golang, golang for beginners, golang strings cut, go 1.19, go lang 1.19, golang 1.19, golang 1.19 alpine, golang 1.19 changes
Id: Wh8VuF34JDo
Channel Id: undefined
Length: 7min 37sec (457 seconds)
Published: Fri Aug 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.