1 00:00:01,100 --> 00:00:05,900 It's obviously been writing go programs, you've been using go build, go run, go test, 2 00:00:05,900 --> 00:00:09,900 but there's a bunch of other little tools, some, which you need to install, which 3 00:00:09,900 --> 00:00:13,700 are very useful. When you get to writing large amounts of code, you will 4 00:00:13,700 --> 00:00:17,900 also views go format for meeting the standard go format, but 5 00:00:18,000 --> 00:00:22,600 there are some other tools in particular, go vet, go list and go lint, which can be super 6 00:00:22,600 --> 00:00:26,500 useful. So, just to illustrate how they operate, and I've got my little program here, 7 00:00:26,700 --> 00:00:29,700 which looks perfectly reasonable. Although you might spot that there's a 8 00:00:30,000 --> 00:00:34,900 Return in the middle of Maine. Which means there's some unreachable code, and there's a printf 9 00:00:34,900 --> 00:00:37,900 function. It looks looks reasonable. So let's just run it 10 00:00:39,600 --> 00:00:43,700 and it says hello world centers. It works fine, there's no obvious errors, 11 00:00:44,100 --> 00:00:48,800 the go compiler, doesn't complain about it. And if I were to format It Go for Matt wouldn't complain about it. But 12 00:00:48,800 --> 00:00:52,800 there's actually a few problems with this. Obviously, there's some unreachable code. I haven't 13 00:00:52,800 --> 00:00:56,400 documented what this printf function does and it's got a capital P, so it is 14 00:00:56,400 --> 00:00:59,400 exported. And so really, it could do some documentation 15 00:01:00,300 --> 00:01:04,900 And the something a bit weird about that printf function. If you notice, there's a percent s here, it looks like 16 00:01:04,900 --> 00:01:08,600 I'm expecting this printf function to be a printf 17 00:01:08,600 --> 00:01:12,800 style to have a format and something to print out and actually the tools will 18 00:01:12,800 --> 00:01:16,600 help us out with this. So I'm going to run go vet on this code 19 00:01:17,100 --> 00:01:21,900 and it's going to tell me a couple of things. It's going to say, okay, look line 16. This is unreachable. So 20 00:01:21,900 --> 00:01:25,900 that's very useful. And it's also going to take a look and say, oh well, this thing looks 21 00:01:25,900 --> 00:01:29,800 like it's meant to be a printf and you've got some format thing. 22 00:01:29,900 --> 00:01:33,600 But it doesn't seem to work. And so it all spot 23 00:01:33,600 --> 00:01:37,900 problems that the compiler might not spot and it has a whole list of things. It will do around 24 00:01:37,900 --> 00:01:41,900 variables that you don't seem to be using around Assembly Language. There's a 25 00:01:41,900 --> 00:01:45,900 great list of things that it will vet in the code. And it's one of those things that's good to run 26 00:01:45,900 --> 00:01:49,600 as part of your build process to say, you know, here are the things that are silly. 27 00:01:50,200 --> 00:01:54,800 Now another tools or tool called go lint and what go limp does is it tries to 28 00:01:54,800 --> 00:01:58,700 enforce a certain style beyond what go format does 29 00:01:59,200 --> 00:01:59,800 for? 30 00:02:00,500 --> 00:02:04,800 This printf that is undocumented and exported is going to spot that. So if I just run 31 00:02:05,400 --> 00:02:09,800 go lint on this, it's going to tell me 32 00:02:09,800 --> 00:02:13,800 look line 7 of this thing. You've got this exported function and you haven't commented on 33 00:02:13,800 --> 00:02:17,900 it and so that also will help you. Make sure that your code is really clean and both of 34 00:02:17,900 --> 00:02:21,900 these tools are very good ways of making go code look like the sort 35 00:02:21,900 --> 00:02:25,800 of go code. You're used to raising on GitHub and in the golang packages, 36 00:02:26,900 --> 00:02:30,400 Now there's another rather interesting tool called go list which gives you 37 00:02:30,400 --> 00:02:34,900 information about packages now in its most basic form. It doesn't tell you anything, particularly 38 00:02:34,900 --> 00:02:38,800 exciting, let's just go and look at. If you remember, I wrote that thing called 39 00:02:38,800 --> 00:02:42,900 shouter, which was for shouting, for making strings uppercase 40 00:02:42,900 --> 00:02:46,700 and it's a package. And if I go into here and I say go list, 41 00:02:47,200 --> 00:02:51,700 shelter is going to say, okay, you've got a package called shouter, which is great. It doesn't tell you much more 42 00:02:51,700 --> 00:02:55,900 information. However, go list itself has a whole bunch of 43 00:02:55,900 --> 00:02:56,500 additional 44 00:02:56,600 --> 00:03:00,500 Unit can tell you and you can actually ask for these things. So 45 00:03:00,500 --> 00:03:04,700 for example, if I want to find out what packages, shout it 46 00:03:04,700 --> 00:03:07,600 Imports, I can do that. So let me just do that. 47 00:03:08,100 --> 00:03:12,600 So I'm going to use this import. So if I do this I use a 48 00:03:12,600 --> 00:03:16,700 dash f 1 here. And I say, give me the Imports of this thing. 49 00:03:16,700 --> 00:03:20,900 It's going to tell me. Okay, that is thing, import strings and even more so I can 50 00:03:20,900 --> 00:03:24,800 go in here and say okay what is this thing to depend on? And so in fact, this 51 00:03:24,800 --> 00:03:26,400 depends on what's it goes up the tree. 52 00:03:26,600 --> 00:03:30,800 Three errors, Aya, runtime, strings. All these different things are needed for this 53 00:03:30,800 --> 00:03:34,900 particular package and as I was saying, there's a great list of other 54 00:03:34,900 --> 00:03:38,500 bits of information so I could find out where something is. So let's just go and do 55 00:03:38,500 --> 00:03:39,000 that. 56 00:03:40,900 --> 00:03:44,300 So that's extremely useful if you're trying to figure out where ticket packages, if you have a very 57 00:03:44,300 --> 00:03:48,900 complicated workspace, you can find out what import or import 58 00:03:48,900 --> 00:03:52,900 path. It should have. And if we go down and here, 59 00:03:52,900 --> 00:03:56,900 you can actually get information about all the source files that are part of it. So if I go in here and I say 60 00:03:57,400 --> 00:03:58,500 go files 61 00:04:00,200 --> 00:04:04,600 Then. Okay, when this case is only one particular package but I should be able to ask about something more 62 00:04:04,600 --> 00:04:08,900 complex and so for example the standard strings package consists 63 00:04:08,900 --> 00:04:12,900 of all these individual files. So what go list will allow you to do 64 00:04:12,900 --> 00:04:16,700 is to find out information. There's a little bit hard to find just by looking at the source code 65 00:04:16,700 --> 00:04:20,800 itself directly. So I highly recommend using covet and go lint 66 00:04:20,900 --> 00:04:24,900 as part of your build process and when you're developing, it can be very handy to use go list. 67 00:04:24,900 --> 00:04:27,400 Find information that can be otherwise difficult to find.