Files
2021-09-23 17:32:38 +03:00

79 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Cheatsheet: Write your First Go Program
Hi!
For reference, you can store this cheatsheet after you take the lectures in this section.
You can also print this cheatsheet and then follow the video lectures in this section along with it.
Enjoy!
---
## COMMAND LINE COMMANDS:
* Enter into a directory: `cd directoryPath`
* **WINDOWS:**
* List files in a directory: `dir`
* **OS X & LINUXes:**
* List files in a directory: `ls`
## BUILDING & RUNNING GO PROGRAMS:
* **Build a Go program:**
* While inside a program directory, type:
* `go build main.go`
* **Run a Go program:**
* While inside a program directory, type:
* `go run main.go`
## WHERE YOU SHOULD PUT YOUR SOURCE FILES?
* In any directory you like.
## FIRST PROGRAM
### Create a directory
* Create a new directory:
* `mkdir myDirectoryName`
* Go to that directory:
* `cd myDirectoryName`
### Add the source code files
* Create a new `code main.go` file.
* This is going to the create the file in the folder, and open up it in the Visual Studio Code.
* And add the following code to it and save it.
```go
package main
import "fmt"
func main() {
fmt.Println("Hi! I want to be a Gopher!")
}
```
### Run the program
* Finally, return back to the command-line.
* Run it like this: `go run main.go`
* If you create other files and run them all, you can use this command:
* `go run .`
That's all! Enjoy!
> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)
>
> Copyright © 2018 Inanc Gumus
>
> Learn Go Programming Course
>
> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)