Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Go Language Overview!
You have completed Go Language Overview!
Preview
Run the "go fmt" tool on your source code files, and it will fix indentation, fix spacing issues, align comments, and more, automatically.
-
go fmt- Fixes indentation
- Fixes spacing issues
- Aligns comments
- And more
Before:
package main
import ("fmt")
func main() {
var myInt int
var myString string
var myBool bool
fmt.Println("myInt", myInt) // 0
fmt.Println("myString", myString) //""
fmt.Println("myBool",myBool) //false
}
After:
package main
import (
"fmt"
)
func main() {
var myInt int
var myString string
var myBool bool
fmt.Println("myInt", myInt) // 0
fmt.Println("myString", myString) //""
fmt.Println("myBool", myBool) //false
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Things aren't indented correctly, there's
odd spacing in the function calls and
0:00
things like that.
0:04
Let's try running the Go-Format
tool on this file.
0:06
So, I'm gonna go down here to the console.
0:09
I'll type go, I'll run the format
sub-command which is just fmt for short.
0:10
And I'll specify the name of
the file that I want it to update.
0:17
So that's temp.go.
0:20
Run that and it'll print out the name
of the file that it updated.
0:22
Then if I switch back up here
to the editor, it will reload.
0:26
And you can see that even though
the code looks much the same,
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up