1 00:00:00,340 --> 00:00:03,900 There's one last thing we should cover before we move onto the next stage, and 2 00:00:03,900 --> 00:00:05,920 that's the Go-Format Tool. 3 00:00:05,920 --> 00:00:08,740 Here we have a file whose formatting isn't ideal. 4 00:00:08,740 --> 00:00:13,740 Things aren't indented correctly, there's odd spacing in the function calls and 5 00:00:13,740 --> 00:00:15,070 things like that. 6 00:00:15,070 --> 00:00:18,140 Let's try running the Go-Format tool on this file. 7 00:00:18,140 --> 00:00:19,910 So, I'm gonna go down here to the console. 8 00:00:19,910 --> 00:00:25,750 I'll type go, I'll run the format sub-command which is just fmt for short. 9 00:00:26,940 --> 00:00:29,740 And I'll specify the name of the file that I want it to update. 10 00:00:29,740 --> 00:00:31,616 So that's temp.go. 11 00:00:31,616 --> 00:00:35,300 Run that and it'll print out the name of the file that it updated. 12 00:00:35,300 --> 00:00:38,690 Then if I switch back up here to the editor, it will reload. 13 00:00:38,690 --> 00:00:41,640 And you can see that even though the code looks much the same, 14 00:00:41,640 --> 00:00:43,710 it's been substantially reformatted. 15 00:00:43,710 --> 00:00:45,880 Our import statement's been cleaned up. 16 00:00:45,880 --> 00:00:48,470 The indentation on everything has been fixed. 17 00:00:48,470 --> 00:00:51,050 The comments are all aligned with each other and 18 00:00:51,050 --> 00:00:54,320 even the spacing inside each line has been fixed. 19 00:00:54,320 --> 00:00:57,490 This was done for us automatically by the Go Format tool. 20 00:00:57,490 --> 00:00:59,990 It analyzed the structure of our source code and 21 00:00:59,990 --> 00:01:04,880 then indented everything appropriately for us, and it makes other fixes as well. 22 00:01:04,880 --> 00:01:08,310 Most people don't like all the formatting changes that Go Format makes. 23 00:01:08,310 --> 00:01:11,340 But the point is that you don't have to argue about those changes. 24 00:01:11,340 --> 00:01:14,110 Go Format is the standard for formatting Go code. 25 00:01:14,110 --> 00:01:17,930 The standard format is easier to read once you're used to it. 26 00:01:17,930 --> 00:01:21,180 And you don't have to manually make changes anymore to match some 27 00:01:21,180 --> 00:01:22,830 arbitrary style guide. 28 00:01:22,830 --> 00:01:27,270 You should run Go Format on all your Go code, especially if you're sharing it. 29 00:01:27,270 --> 00:01:31,830 And it's easy to do, sublime text, then and all the other major text editors can 30 00:01:31,830 --> 00:01:36,130 be set up to automatically run Go Format on files each time you save them. 31 00:01:36,130 --> 00:01:39,660 So get in the habit, Go Format can save you a lot of time and trouble