It's obviously been writing go programs, you've been using go build, go run, go test,
but there's a bunch of other little tools, some, which you need to install, which
are very useful. When you get to writing large amounts of code, you will
also views go format for meeting the standard go format, but
there are some other tools in particular, go vet, go list and go lint, which can be super
useful. So, just to illustrate how they operate, and I've got my little program here,
which looks perfectly reasonable. Although you might spot that there's a
Return in the middle of Maine. Which means there's some unreachable code, and there's a printf
function. It looks looks reasonable. So let's just run it
and it says hello world centers. It works fine, there's no obvious errors,
the go compiler, doesn't complain about it. And if I were to format It Go for Matt wouldn't complain about it. But
there's actually a few problems with this. Obviously, there's some unreachable code. I haven't
documented what this printf function does and it's got a capital P, so it is
exported. And so really, it could do some documentation
And the something a bit weird about that printf function. If you notice, there's a percent s here, it looks like
I'm expecting this printf function to be a printf
style to have a format and something to print out and actually the tools will
help us out with this. So I'm going to run go vet on this code
and it's going to tell me a couple of things. It's going to say, okay, look line 16. This is unreachable. So
that's very useful. And it's also going to take a look and say, oh well, this thing looks
like it's meant to be a printf and you've got some format thing.
But it doesn't seem to work. And so it all spot
problems that the compiler might not spot and it has a whole list of things. It will do around
variables that you don't seem to be using around Assembly Language. There's a
great list of things that it will vet in the code. And it's one of those things that's good to run
as part of your build process to say, you know, here are the things that are silly.
Now another tools or tool called go lint and what go limp does is it tries to
enforce a certain style beyond what go format does
for?
This printf that is undocumented and exported is going to spot that. So if I just run
go lint on this, it's going to tell me
look line 7 of this thing. You've got this exported function and you haven't commented on
it and so that also will help you. Make sure that your code is really clean and both of
these tools are very good ways of making go code look like the sort
of go code. You're used to raising on GitHub and in the golang packages,
Now there's another rather interesting tool called go list which gives you
information about packages now in its most basic form. It doesn't tell you anything, particularly
exciting, let's just go and look at. If you remember, I wrote that thing called
shouter, which was for shouting, for making strings uppercase
and it's a package. And if I go into here and I say go list,
shelter is going to say, okay, you've got a package called shouter, which is great. It doesn't tell you much more
information. However, go list itself has a whole bunch of
additional
Unit can tell you and you can actually ask for these things. So
for example, if I want to find out what packages, shout it
Imports, I can do that. So let me just do that.
So I'm going to use this import. So if I do this I use a
dash f 1 here. And I say, give me the Imports of this thing.
It's going to tell me. Okay, that is thing, import strings and even more so I can
go in here and say okay what is this thing to depend on? And so in fact, this
depends on what's it goes up the tree.
Three errors, Aya, runtime, strings. All these different things are needed for this
particular package and as I was saying, there's a great list of other
bits of information so I could find out where something is. So let's just go and do
that.
So that's extremely useful if you're trying to figure out where ticket packages, if you have a very
complicated workspace, you can find out what import or import
path. It should have. And if we go down and here,
you can actually get information about all the source files that are part of it. So if I go in here and I say
go files
Then. Okay, when this case is only one particular package but I should be able to ask about something more
complex and so for example the standard strings package consists
of all these individual files. So what go list will allow you to do
is to find out information. There's a little bit hard to find just by looking at the source code
itself directly. So I highly recommend using covet and go lint
as part of your build process and when you're developing, it can be very handy to use go list.
Find information that can be otherwise difficult to find.