Files
learngo/02-write-your-first-program/README.md
T

79 lines
1.7 KiB
Markdown
Raw Normal View History

2018-10-30 23:19:29 +03:00
# Cheatsheet: Write your First Go Program
2019-05-15 23:39:54 +03:00
Hi!
For reference, you can store this cheatsheet after you take the lectures in this section.
2018-10-30 23:19:29 +03:00
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`
2019-05-15 23:39:54 +03:00
## BUILDING & RUNNING GO PROGRAMS:
2018-10-30 23:19:29 +03:00
* **Build a Go program:**
* While inside a program directory, type:
2021-07-14 22:56:06 +08:00
* `go build main.go`
2018-10-30 23:19:29 +03:00
* **Run a Go program:**
* While inside a program directory, type:
* `go run main.go`
## WHERE YOU SHOULD PUT YOUR SOURCE FILES?
2021-03-23 16:47:38 +03:00
* In any directory you like.
2018-10-30 23:19:29 +03:00
## FIRST PROGRAM
2021-03-23 16:47:38 +03:00
### Create a directory
* Create a new directory:
* `mkdir myDirectoryName`
* Go to that directory:
* `cd myDirectoryName`
2018-10-30 23:32:05 +03:00
2021-03-23 16:47:38 +03:00
### 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.
2018-10-30 23:32:05 +03:00
* And add the following code to it and save it.
2018-10-30 23:19:29 +03:00
```go
package main
import "fmt"
func main() {
fmt.Println("Hi! I want to be a Gopher!")
}
```
2021-03-23 16:47:38 +03:00
### 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 .`
2018-10-30 23:19:29 +03:00
That's all! Enjoy!
> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)
2018-11-18 05:03:43 +08:00
>
2018-10-30 23:19:29 +03:00
> Copyright © 2018 Inanc Gumus
2018-11-18 05:03:43 +08:00
>
2018-10-30 23:19:29 +03:00
> Learn Go Programming Course
2018-11-18 05:03:43 +08:00
>
> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)