From 2f920b497ce9615f0bc77e48c0cfba7e99324989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 23 Mar 2021 16:47:38 +0300 Subject: [PATCH] update: write your first program gopath is no longer used. --- 02-write-your-first-program/README.md | 63 +++++++-------------------- 1 file changed, 15 insertions(+), 48 deletions(-) diff --git a/02-write-your-first-program/README.md b/02-write-your-first-program/README.md index 09aee37..3a92b5a 100644 --- a/02-write-your-first-program/README.md +++ b/02-write-your-first-program/README.md @@ -34,57 +34,22 @@ Enjoy! * While inside a program directory, type: * `go run main.go` -## WHAT IS $GOPATH? - -* _$GOPATH_ is an environment variable which points to a directory where the downloaded and your own Go files are stored. - - * **On Windows**, it's in: `%USERPROFILE%\go` - - * **On OS X & Linux**, it's in: `~/go` - - * **NOTE:** Never set your GOPATH manually. It's by default under your users directory. - -* **GOPATH has 3 directories:** - - * **src:** Contains the source files for your own or other downloaded packages. You can build and run programs while in a program directory under this directory. - - * **pkg:** Contains compiled package files. Go uses this to make the builds (compilation & linking) faster. - - * **bin:** Contains compiled and executable Go programs. When you call go install on a program directory, Go will put the executable under this folder. - - * _You might want to add this to your `PATH` environment variable if it's not there already._ - ## WHERE YOU SHOULD PUT YOUR SOURCE FILES? -* `$GOPATH/src/github.com/yourUsername/programDirectory` - -* **Example:** - - * My GitHub username is: inancgumus - - * So, I put all my programs under: `~/go/src/github.com/inancgumus/` - - * And, let's say that I've a program named hello, then I put it under this directory: `~/go/src/github.com/inancgumus/hello` +* In any directory you like. ## FIRST PROGRAM -* **Create directories:** - * **OS X & Linux (or git bash):** - * Create a new directory: - * `mkdir -p ~/go/src/yourname/hello` - * Go to that directory: - * `cd ~/go/src/yourname/hello` +### Create a directory +* Create a new directory: + * `mkdir myDirectoryName` +* Go to that directory: + * `cd myDirectoryName` - * **Windows:** - * Create a new directory: - * `mkdir c:\Go\src\yourname\hello` - * Go to that directory: - * `cd c:\Go\src\yourname\hello` - -* Create a new `code main.go` file under Visual Studio Code. +### 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. -* Then, return back to the command-line. - * Run it like this: `go run main.go` ```go package main @@ -96,12 +61,14 @@ func main() { } ``` +### 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! -## NOTE: - -* There is a new *Go Modules* support that allows you to run your programs in any directory that you want. It's still an experimental feature, when it stabilizes, I'll update the course and include Go Modules as well. - > For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com) > > Copyright © 2018 Inanc Gumus