[
  {
    "path": ".gitignore",
    "content": "*.DS_Store\n\n# Binaries for programs and plugins\n*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n\n# Test binary, build with `go test -c`\n*.test\n\n# Output of the go coverage tool, specifically when used with LiteIDE\n*.out\n\n.vscode/*\n"
  },
  {
    "path": "01-get-started/README.md",
    "content": "# GO INSTALLATION GUIDES\n\nPlease select your operating system below for the detailed installation instructions:\n\n* [OS X](osx-installation.md)\n* [Windows](windows-installation.md)\n* [Linux (Ubuntu)](ubuntu-installation.md)\n"
  },
  {
    "path": "01-get-started/osx-installation.md",
    "content": "# OS X INSTALLATION CHEATSHEET\n\n## NOTE\n\nIf you have [homebrew](https://brew.sh) installed, you can easily install Go like so:\n\n```\n# if you don't have git install it like so:\nbrew install git\n\n# then install go\nbrew install go\n\n# add GOBIN path to your PATH in ~/.bash_profile\nexport PATH=${HOME}/go/bin:$PATH\n```\n\n## 1- Install Visual Studio Code Editor\n\n1. Install it but don't open it yet.\n2. Go to: [https://code.visualstudio.com](https://code.visualstudio.com)\n3. Select OS X (Mac) and start downloading\n4. Uncompress the downloaded file and move it to your `~/Applications` directory.\n\n## 2- Install Git\n\n1. Grab and run the installer. Go to: [https://git-scm.com/downloads](https://git-scm.com/downloads)\n2. Select VSCode as the default editor\n\n## 3- Install Go\n\n1. Go to [https://golang.org/dl](https://golang.org/dl)\n2. Select OS X (Mac)\n3. Start the installer\n\n## 4- Configure VS Code\n\n1. Open VS Code; from the extensions tab at the left, search for \"go\" and install it\n2. Close VS Code completely and open it up again\n\n3. Go to View menu; select **Command Palette**\n    1. Or just press `cmd+shift+p`\n    2. Type: `go install`\n    3. Select _\"Go: Install/Update Tools\"_\n    4. Check all the checkboxes\n\n4. After it's done, open the **Command Palette** again\n    1. Type: `shell`\n    2. Select: _\"Install 'code' command in PATH\"_\n        1. **NOTE:** You don't have to do this if you're on Windows.\n\n## That's all! Enjoy! 🤩\n\n<div style=\"page-break-after: always;\"></div>\n\n> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n> \n> Copyright © 2018 Inanc Gumus\n> \n> Learn Go Programming Course\n> \n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "01-get-started/programmers-roadmap.md",
    "content": "# PROGRAMMER'S ROADMAP\n\nHi!\n\nIf you're an experienced developer, you may want to watch only the following lectures. If you follow this roadmap, you will need to watch about 50 lectures instead of 180 lectures.\n\nThis course starts from the most basics than advances toward the end, step by step. So, the complexity of the topics increases on each level. I've intentionally designed it so to make it easy for everyone. \n\nIf you think some of the topics are easy for you, then watch the recap lectures, take the quizzes and exercises, and even skip the lectures in that section altogether, you can always come back to them later.\n\nEnjoy!\n\n## LECTURES\n\n* **Write Your First Go Program**\n  * Please watch all the lectures.\n  * What is Go Doc?\n  * The lectures under \"Write a Library Package\".\n\n* **Master the Type System of Go**\n  * Every Go type has a zero value\n  * What is a blank identifier?\n  * Let's declare a couple of variables!\n  * What is type inference?\n  * How to short declare multiple variables?\n  * Why can't you short declare a variable in the package-level?\n  * What is redeclaration?\n  * When to use a short declaration?\n  * Get input from command-line and learn about slices\n  * Learn the basics of os.Args\n  * Greet people using os.Args\n  * The lectures under \"Print Formatted Output Using Printf\".\n  * Convert Celsius to Fahrenheit\n  * Convert Feet to Meters\n  * What is a Raw String Literal?\n  * How to get the length of a string?\n  * The lectures after \"What is a Predeclared Type?\" and to the end of the section.\n  * The following lectures under \"Understand Untyped Constants\"\n    * Learn the rules of constants\n    * Recap: Constants\n    * How untyped constants work under the hood?\n    * What is a Default Type?\n    * Example: time.Duration\n    * What is iota?\n    * Naming Things: Recommendations\n\n* **Control Flow and Error Handling**\n  * Watch all the lectures under \"Pass Me: Create a Password-Protected Program\"\n  * Watch all the lectures under \"Understand Go's Error Handling\"\n  * Use multiple values in case conditions\n  * How does the fallthrough statement work?\n  * Solution: Parts of a Day\n  * Recap: Switch Statement\n  * How to continue a loop? (+BONUS: Debugging)\n  * Create a multiplication table\n  * How to loop over a slice?\n  * For Range: Learn the easy way!\n\n* **Projects: For Beginners**\n  * Please watch all the lectures.\n\n* **Remaining Sections**\n  * You may watch all the remaining lectures from this point. They are intermediate to advanced level lectures.\n\n## That's all! Enjoy! 🤩\n\n---\n\n# BONUS: Why should you learn Go?\n\n**In summary:** Go is easy as Python and Javascript , and it's as fast as C/C++. It's more enjoyable to work with Go than C/C++. You can go low-level, or you can stay high-level.\n\n## What Go is used for?\n\nGo is used mostly by web companies: Google, Facebook, Twitter, Uber, Apple, Dropbox, Soundcloud, Medium, Mozilla Firefox, Github, Docker, Kubernetes, and Heroku.\n\n**Go is best for:** Cross-Platform Command-line Tools, Distributed Network Applications, Cloud technologies like Microservices and Serverless, Web APIs, Database Engines, Big-Data Processing Pipelines, Embedded Development, and so on.\n\n**Go is not best for (but doable):** Desktop Apps, Writing Operating Systems, Kernel Drivers, Game Development, etc.\n\n## Who Designed Go?\n\nGo designed by one of the most influential people in the industry:\n\n* Unix: Ken Thompson\n* UTF-8, Plan 9: Rob Pike\n* Hotspot JVM (Java Virtual Machine): Robert Griesemer\n\n## HOW MUCH CAN YOU EARN?\n\n* [Go Salaries](https://www.payscale.com/research/US/Skill=Go_(Golang)_Programming_Language/Salary)\n\n## [From Eight years of Go post](https://blog.golang.org/8years):\n\n> Today, **every single cloud company has critical components of their cloud infrastructure implemented in Go** including Google Cloud, AWS, Microsoft Azure, Heroku, and many others. Go is a key part of cloud companies like Alibaba, Cloudflare, and Dropbox. Go is a critical part of open infrastructure including Kubernetes, Cloud Foundry, Openshift, NATS, Docker, Istio, Etcd, Consul, Juju, and many more. Companies are increasingly choosing Go, to build cloud infrastructure solutions.\n\n## What Can You Accomplish with Go?\n\n* [A network Driver written in Go](https://www.net.in.tum.de/fileadmin/bibtex/publications/theses/2018-ixy-go.pdf) (_only 10% penalty compared to C driver_)\n* [Google gVisor](https://cloud.google.com/blog/products/gcp/open-sourcing-gvisor-a-sandboxed-container-runtime) (_Userspace kernel written in Go_)\n* [Multi-platform Nintendo emulator](https://humpheh.github.io/goboy/)\n* [Docker: Container system](https://github.com/moby/moby)\n* [Kubernetes: Container scheduling and management](https://github.com/kubernetes/kubernetes)\n* VM image deduplication utility\n* Chat server\n* RUM beacon collector\n* Time-series database engine, a client for it, command-line tools, etc.\n* Map-reduce library\n* Clustered front-end-optimizing reverse proxy with on the fly content rewriting, image resizing, caching, Lua event handler execution (all multi-tenant)\n* Geographically distributed reverse proxy CDN nodes\n* Health management daemon with event handlers and peer to peer reporting\n* Pure Go DNS server\n* API backend that interfaces with MySQL\n* Linux process capture/restore utility\n* Reverse Proxy to mask our asset server from clients.\n* HTML -> PDF converter for invoice generation.\n* URL shortener like tinyurl.com and goo.gl\n* SMS messaging service.\n* Credit Card payment gateway\n* JSON Web Token package\n* On the fly image processing services\n* 3d render farm/content production pipeline (pretty large project)\n* Production lxc container deployment\n* Automated testing management\n\nReference: [This Reddit post](https://www.reddit.com/r/golang/comments/5nac2b/what_have_you_used_go_for_in_your_professional/).\n\n## CHECK OUT FOR MORE INFORMATION:\n\n* [About Go: An Overview](https://blog.learngoprogramming.com/about-go-language-an-overview-f0bee143597c)\n* [Why should you learn Go?](https://medium.com/@kevalpatel2106/why-should-you-learn-go-f607681fad65)\n* [Emerging language of cloud Infrastructure](https://redmonk.com/dberkholz/2014/03/18/go-the-emerging-language-of-cloud-infrastructure/)\n* [Companies using Go](https://github.com/golang/go/wiki/GoUsers)\n* [Eight years of Go](https://blog.golang.org/8years)\n* [Twitter: Handling Five Billion Session in a Day with Go](https://blog.twitter.com/engineering/en_us/a/2015/handling-five-billion-sessions-a-day-in-real-time.html)\n* [A C++ developer looks at Go](https://www.murrayc.com/permalink/2017/06/26/a-c-developer-looks-at-go-the-programming-language-part-1-simple-features/)\n\n<div style=\"page-break-after: always;\"></div>\n\n> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n> \n> Copyright © 2019 Inanc Gumus\n> \n> Learn Go Programming Course\n> \n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "01-get-started/ubuntu-installation.md",
    "content": "# Linux Installation Cheatsheet\n\nIf you want to use snap, you can easily install Go like so:\n\n    sudo snap install go --classic\n    \nOtherwise, please follow the steps below:\n\n## 1. Update the local packages\n\n  ```bash\n  sudo apt-get update\n  ```\n\n## 2. Install git\n\n  ```bash\n  sudo apt-get install git\n  ```\n\n## 3. Install Go\n\nThere are two ways:\n\n1- From Web: Select Linux and the download will begin.\n\n  ```bash\n  firefox https://golang.org/dl\n  ```\n\n2- By using snap: If you use this option, skip to the 5th step.\n\n  ```bash\n  sudo snap install go --classic\n  ```\n\n## 4. Copy Go into the proper directory\n\n1. Find out the name of the downloaded file\n\n2. Use that filename to uncompress it\n\n    ```bash\n    gofile=\"DELETE_THIS_AND_TYPE_THE_NAME_OF_THE_DOWNLOADED_FILE_HERE (without its extension)\"\n\n    tar -C /usr/local -xzf ~/Downloads/$gofile\n    ```\n\n## 5. Add Go executables directory to your PATH\n\n1. Add `go/bin` directory to `$PATH` to be able to run the fundamental Go commands.\n\n    ```bash\n    echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile\n    ```\n\n2. Add \"$HOME/go/bin\" directory to $PATH\n\n    ```bash\n    echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.profile\n    ```\n\n## Install Go Tools:\n\n* These are very handy tools to ease the development (like goimports)\n\n* `go get` cannot be used without installing a code versioning program like Git which we already have got it above.\n\n* This will create `~/go` directory and will download go tools into there.\n\n    * This directory is also a place where you should put your code into.\n    (If you're not going to use Go Modules)\n\n    ```bash\n    go get -v -u golang.org/x/tools/...\n    ```\n\n## Install VSCode (Optional)\n\nNote: You may use another coding editor if you like. However, the course uses Visual Studio Code (VSCode).\n\n1. Open \"Ubuntu Software\" application\n\n2. Search for VSCode then click \"Install\"\n\n\n## OPTIONAL STEP:\n\n1. Create a hello.go file in a new directory but anywhere outside of `$GOPATH`\n\n    ```bash\n    cat <<EOF > hello.go\n    package main\n\n    import \"fmt\"\n\n    func main() {\n        fmt.Println(\"hello gopher!\")\n    }\n    EOF\n    ```\n\n2. Run the program\n\n    ```bash\n    go run hello.go\n    It should print: hello gopher!\n    ```\n\n<div style=\"page-break-after: always;\"></div>\n\n> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2018 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "01-get-started/windows-installation.md",
    "content": "# WINDOWS INSTALLATION CHEATSHEET\n\n## NOTE\n\nIf you have [chocolatey.org](https://chocolatey.org/) package manager, you can easily install Go like so:\n\n```\nchoco install golang\n```\n\n## 1- Install Visual Studio Code Editor\n\n1. Install it but don't open it yet.\n2. Go to: [https://code.visualstudio.com](https://code.visualstudio.com)\n3. Select Windows and start downloading\n4. Run the installer\n\n## 2- Install Git\n\n1. Grab and run the installer. Go to: [https://gitforwindows.org](https://gitforwindows.org)\n2. Select VSCode as the default editor\n3. Enable all the checkboxes\n4. Select: _\"Use Git from the Windows Command Prompt\"_\n5. Encodings: Select: _\"Checkout as is...\" option._\n\n## 3- Install Go\n\n1. Go to [https://golang.org/dl](https://golang.org/dl)\n2. Select Windows and download\n3. Start the installer\n\n## 4- Configure VS Code\n\n1. Open VS Code; from the extensions tab at the left, search for \"go\" and install it\n2. Close VS Code completely and open it up again\n\n3. Go to View menu; select **Command Palette**\n    1. Or just press `ctrl+shift+p`\n    2. Type: `go install`\n    3. Select _\"Go: Install/Update Tools\"_\n    4. Check all the checkboxes\n\n## 5- Using Git-Bash\n\n* In this course I'll be using bash commands. Bash is just a command-line interface used in OS X and Linux. It's one of the most popular command-line interfaces. So, if you want to use it too, instead of using the Windows default command-line, you can use git bash that you've installed. With git bash, you can type a command in command-line as you're on OS X or Linux.\n\n* If you don't want to use git bash, it's ok too. It depends on you. But note that, I'll be using bash commands mostly. Because it allows more advanced commands as well.\n\n* You can also prefer to use the more powerful alternative to git bash: [Linux Subsystem for Windows](https://docs.microsoft.com/en-us/windows/wsl/install-win10)\n\n* **So, to use git bash, follow these steps:**\n    1. Just search for git bash from the start bar\n    2. Or, if there's one, click on the icon on your desktop\n\n    3. Also, setup VS Code to use git-bash by default:\n        1. Open VS Code\n        2. Go to Command Palette\n            1. Type: `terminal`\n            2. Select: _\"Terminal: Select Default Shell\"_\n            3. And, Select: _\"Git Bash\"_\n\n    4. **NOTE:** Normally, you can find your files under `c:\\`, however, when you're using git bash, you'll find them under `/c/` directory. It's actually the very same directory, it's just a shortcut.\n\n## That's all! Enjoy! 🤩\n\n<div style=\"page-break-after: always;\"></div>\n\n> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2018 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "02-write-your-first-program/README.md",
    "content": "# Cheatsheet: Write your First Go Program\n\nHi!\n\nFor reference, you can store this cheatsheet after you take the lectures in this section.\n\nYou can also print this cheatsheet and then follow the video lectures in this section along with it.\n\nEnjoy!\n\n---\n\n## COMMAND LINE COMMANDS:\n\n* Enter into a directory: `cd directoryPath`\n\n* **WINDOWS:**\n\n    * List files in a directory: `dir`\n\n* **OS X & LINUXes:**\n\n    * List files in a directory: `ls`\n\n## BUILDING & RUNNING GO PROGRAMS:\n\n* **Build a Go program:**\n\n    * While inside a program directory, type:\n        * `go build main.go`\n\n* **Run a Go program:**\n\n    * While inside a program directory, type:\n        * `go run main.go`\n\n## WHERE YOU SHOULD PUT YOUR SOURCE FILES?\n\n* In any directory you like.\n\n## FIRST PROGRAM\n\n### Create a directory\n* Create a new directory:\n  * `mkdir myDirectoryName`\n* Go to that directory:\n  * `cd myDirectoryName`\n\n### Add the source code files\n* Create a new `code main.go` file.\n  * This is going to the create the file in the folder, and open up it in the Visual Studio Code.\n* And add the following code to it and save it.\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi! I want to be a Gopher!\")\n}\n```\n\n### Run the program\n* Finally, return back to the command-line.\n  * Run it like this: `go run main.go`\n* If you create other files and run them all, you can use this command:\n  * `go run .`\n\nThat's all! Enjoy!\n\n> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2018 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "02-write-your-first-program/annotated-go-program-example.md",
    "content": "# Annotated Example Go Program\n\n```go\n// package main is a special package\n// it allows Go to create an executable file\npackage main\n\n/*\nThis is a multi-line comment.\n\nimport keyword makes another package available\n  for this .go \"file\".\n\nimport \"fmt\" lets you access fmt package's functionality\n  here in this file.\n*/\nimport \"fmt\"\n\n// \"func main\" is special.\n//\n// Go has to know where to start\n//\n// func main creates a starting point for Go\n//\n// After compiling the code,\n// Go runtime will first run this function\nfunc main() {\n\t// after: import \"fmt\"\n\t// Println function of \"fmt\" package becomes available\n\n\t// Look at what it looks like by typing in the console:\n\t//   go doc -src fmt Println\n\n\t// Println is just an exported function from\n\t//   \"fmt\" package\n\n\t// Exported = First Letter is uppercase\n\tfmt.Println(\"Hello Gopher!\")\n\n\t// Go cannot call Println function by itself.\n\t// That's why you need to call it here.\n\t// It only calls `func main` automatically.\n\n\t// -----\n\n\t// Go supports Unicode characters in string literals\n\t// And also in source-code: KÖSTEBEK!\n\t//\n\t// Because: Literal ~= Source Code\n}\n```\n\n<div style=\"page-break-after: always;\"></div>\n\n> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n> \n> Copyright © 2018 Inanc Gumus\n> \n> Learn Go Programming Course\n> \n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
  },
  {
    "path": "02-write-your-first-program/exercises/01-print-names/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print names\n//\n//  Print your name and your best friend's name using\n//  Println twice\n//\n// EXPECTED OUTPUT\n//  YourName\n//  YourBestFriendName\n//\n// BONUS\n//  Use `go run` first.\n//  And after that use `go build` and run your program.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n\t// ?\n}\n"
  },
  {
    "path": "02-write-your-first-program/exercises/01-print-names/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// go run main.go\n\n// go build\n// ./solution\n\nfunc main() {\n\tfmt.Println(\"Nikola\")\n\tfmt.Println(\"Thomas\")\n}\n"
  },
  {
    "path": "02-write-your-first-program/exercises/README.md",
    "content": "1. **Print your name and your best friend's name** using Println twice. [Check out this exercise here](https://github.com/inancgumus/learngo/tree/master/02-write-your-first-program/exercises/01-print-names).\n\n2. **Say hello to yourself.**\n\n    1. Build your program using `go build`\n\n    2. **Send it to your friend**\n\n       S/he should use be using the same operating system.\n\n       For example, if you're using Windows, then hers/his should be Windows as well.\n\n    3. **Send your program to a friend with a different operating system**\n\n       So, you should compile your program for her operating system.\n\n       **Create an OSX executable:**\n       `GOOS=darwin GOARCH=386 go build`\n\n       **Create a Windows executable:**\n       `GOOS=windows GOARCH=386 go build`\n\n       **Create a Linux executable:**\n       `GOOS=linux GOARCH=arm GOARM=7 go build`\n\n       **You can find the full list in here:**\n       https://golang.org/doc/install/source#environment\n\n       **NOTE:** If you're using the command prompt or the PowerShell, you may need to use it like this:\n       `cmd /c \"set GOOS=darwin GOARCH=386 && go build\"`\n\n3. **Call [Print](https://golang.org/pkg/fmt/#Print) instead of [Println](https://golang.org/pkg/fmt/#Println)** to see what happens.\n\n4. **Call [Println](https://golang.org/pkg/fmt/#Println) or [Print](https://golang.org/pkg/fmt/#Print) with multiple values** by separating them using commas.\n\n5. **Remove the double quotes from a string literal** and see what happens.\n\n6. **Move the package and import statement** to the bottom of the file and see what happens.\n\n7. **[Read Go online documentation](https://golang.org/pkg)**.\n\n    1. Take a quick look at the packages and read what they do.\n\n    2. Look at their source-code by clicking on their titles.\n\n    3. You don't have to understand everything, just do it. This will warm you up for the upcoming lectures.\n\n8. Also, **take a tour on**: https://tour.golang.org/\n\n    1. Have a quick look. Check out the language features.\n\n    2. We're going to talk all about them soon.\n\n9. [Follow me on twitter to learn more](https://twitter.com/inancgumus)."
  },
  {
    "path": "02-write-your-first-program/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// package main is a special package\n// it allows Go to create an executable file\npackage main\n\n/*\nThis is a multi-line comment.\n\nimport keyword makes another package available\n  for this .go \"file\".\n\nimport \"fmt\" lets you access fmt package's functionality\n  here in this file.\n*/\nimport \"fmt\"\n\n// \"func main\" is special.\n//\n// Go has to know where to start\n//\n// func main creates a starting point for Go\n//\n// After compiling the code,\n// Go runtime will first run this function\nfunc main() {\n\t// after: import \"fmt\"\n\t// Println function of \"fmt\" package becomes available\n\n\t// Look at what it looks like by typing in the console:\n\t//   go doc -src fmt Println\n\n\t// Println is just an exported function from\n\t//   \"fmt\" package\n\n\t// Exported = First Letter is uppercase\n\tfmt.Println(\"Hello Gopher!\")\n\n\t// Go cannot call Println function by itself.\n\t// That's why you need to call it here.\n\t// It only calls `func main` automatically.\n\n\t// -----\n\n\t// Go supports Unicode characters in string literals\n\t// And also in source-code: KÖSTEBEK!\n\t//\n\t// Because: Literal ~= Source Code\n\n\t// EXERCISE: Remove the comments from below --> //\n\t// fmt.Println(\"Merhaba Köstebek!\")\n\n\t// Unnecessary note:\n\t// \"Merhaba Köstebek\" means \"Hello Gopher\"\n\t// in Turkish language\n}\n"
  },
  {
    "path": "02-write-your-first-program/questions/01-gopath/README.md",
    "content": "## Where should you save your Go source code?\n* Anywhere on my computer\n* Under $GOPATH\n* Under $GOPATH/src *CORRECT*\n\n## What does $GOPATH mean?\n* It's a file for Go runtime\n* Stores Go source code files and compiled packages\n* It's a path for gophers to follow\n\n## Do you need to set $GOPATH?\n* Yes\n* No: It's stored on my desktop\n* No: It's stored under my user path *CORRECT*\n\n## How can you print $GOPATH?\n* Using `ls` command\n* Using `go env GOPATH` command *CORRECT*\n* Using `go environment` command"
  },
  {
    "path": "02-write-your-first-program/questions/02-code-your-first-program/README.md",
    "content": "## Which keyword below that you need use to define a package?\n```go\npackage main\n\nfunc main() {\n}\n```\n1. func\n2. package *CORRECT*\n3. fmt.Println\n4. import\n\n> **1:** func keyword is used to declare a new function.\n>\n>\n> **2:** That's right! package keyword allows you to define a package for a Go file.\n>\n>\n> **3:** It's not a keyword, it's a function of the fmt package.\n>\n>\n> **4:** import keyword is used to import a package.\n>\n>\n\n\n## What is the purpose of using package main in the following program?\n```go\npackage main\n\nfunc main() {\n}\n```\n* To create a library package\n* To properly exit from the program\n* To create an executable Go program *CORRECT*\n\n\n## What is the purpose of func main in the following program?\n```go\npackage main\n\nfunc main() {\n}\n```\n1. It defines a package called main\n2. It allows Go to start executing the program *CORRECT*\n3. It prints a message to the console\n\n> **1:** main function doesn't create a package.\n>\n>\n> **2:** That's right. Go automatically calls the main function to execute a program.\n>\n>\n> **3:** It doesn't print anything (at least directly).\n>\n>\n\n\n## What is the purpose of import \"fmt\" in the following program?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi!\")\n}\n```\n1. It prints \"fmt\" to the console\n2. It defines a new package called \"fmt\"\n3. It imports the `fmt` package; so you can use its functionalities *CORRECT*\n\n> **1:** `fmt.Println` prints a message not the `import \"fmt\"`.\n>\n>\n> **2:** `package` keyword does that, not the `import` keyword.\n>\n>\n> **3:** Yes. For example, after you import the fmt package you can call its Println function to print a message to the console.\n>\n>\n\n\n## Which keyword is used to declare a new function?\n* func *CORRECT*\n* package\n* Println\n* import\n\n\n## What is a function?\n1. It's like a mini-program. It's a reusable and executable block of code. *CORRECT*\n2. It allows Go to execute a program.\n3. It allows Go to import a package called function.\n4. It prints a message to the console.\n\n> **2:** Go looks for package main and func main to do that. A function doesn't do that on its own.\n>\n>\n> **3:** `import` keyword does that.\n>\n>\n> **4:** For example: `fmt.Println` does that.\n>\n>\n\n\n## Do you have to call the main function yourself?\n1. Yes, so that, I can execute my program.\n2. No, Go calls the main function automatically. *CORRECT*\n\n> **1:** No, you don't need to call the main function. Go automatically executes it.\n>\n>\n\n\n## Do you have to call a function to execute it?\n_(except the main func)_\n1. Yes, so that, Go can execute that function. *CORRECT*\n2. Yes, so that, Go can execute my program.\n3. No, Go calls the functions automatically.\n\n> **1:** That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet).\n>\n>\n\n> **2:** That's only the job of the `func main`. There's only one `func main`.\n>\n>\n\n> **3:** Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself.\n>\n\n\n## What does the following program print?\n```go\npackage main\n\nfunc main() {\n}\n```\n1. It prints a message to the console\n2. It's a correct program but it doesn't print anything *CORRECT*\n3. It's an incorrect program\n\n> **1:** It doesn't print a message. To do that you can use fmt.Println function.\n>\n>\n\n> **2:** Yes, it's a correct program, however since it doesn't contain fmt.Println it doesn't print anything.\n>\n>\n\n> **3:** It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program.\n>\n>\n\n\n## What does this program print?\n```go\npackage main\n\nfunc main() {\n    fmt.Println(Hi! I want to be a Gopher!)\n}\n```\n* Hi! I want to be a Gopher!\n* It doesn't print anything\n* This program is incorrect *CORRECT*\n\n> **1:** It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println(\"Hi! I want to be a Gopher\")\n>\n>\n\n> **3:** It doesn't import \"fmt\" package. Also see #1.\n>\n>\n\n\n## What does this program print?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi there!\")\n}\n```\n* Hi there! *CORRECT*\n* fmt\n* This program is incorrect; it imports the wrong package or there isn't a function called `Println`\n\n> **2:** import \"fmt\" imports the `fmt` package; so you can use its functionalities.\n>\n>\n> **3:** Actually, this program is correct.\n>\n>"
  },
  {
    "path": "02-write-your-first-program/questions/03-run-your-first-program/README.md",
    "content": "## What is the difference between `go build` and `go run`?\n1. `go run` just compiles a program; whereas `go build` both compiles and runs it.\n2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT*\n\n> **1:** It's opposite actually.\n>\n>\n> **2:** `go run` compiles your program and puts it in a temporary directory. Then it runs the compiled program in there.\n>\n>\n\n\n## Go saves the compiled code in a directory. What is the name of that directory?\n1. The same directory where you call `go build` *CORRECT*\n2. $GOPATH/src directory\n3. $GOPATH/pkg directory\n4. Into a temporary directory.\n\n> **2:** There only lives Go source-code files\n>\n>\n> **3:** Go only puts your code there when you call `go install`.\n>\n>\n\n\n## Which is true for runtime?\n1. It happens when your program starts running on a computer *CORRECT*\n2. It happens while your program is being compiled\n\n\n## Which is true for the compile-time?\n1. It happens when your program starts running on a computer\n2. It happens while your program is being compiled  *CORRECT*\n\n\n## When can a Go program print a message to the console?\n1. While it's being compiled.\n2. While it runs (after compile-time). *CORRECT*\n3. While it runs (inside the compile-time).\n\n> **1:** In the compilation step your program cannot print a message. In that stage, it's literally dead.\n>\n>\n> **2:** That's right. That's the only time which your program can interact with a computer and instruct it to print a message to the console.\n>\n>\n> **3:** Running can only happen after the compile-time\n>\n>"
  },
  {
    "path": "03-packages-and-scopes/01-packages/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/01-packages/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/01-packages/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// You can access functions from other files\n\t// which are in the same package\n\n\t// Here, `main()` can access `bye()` and `hey()`\n\n\t// It's because bye.go, hey.go and main.go\n\t//   are in the main package.\n\n\tbye()\n\they()\n}\n"
  },
  {
    "path": "03-packages-and-scopes/02-scopes/01-scopes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// file scope\nimport \"fmt\"\n\n// package scope\nconst ok = true\n\n// package scope\nfunc main() { // block scope starts\n\n\tvar hello = \"Hello\"\n\n\t// hello and ok are visible here\n\tfmt.Println(hello, ok)\n\n} // block scope ends\n"
  },
  {
    "path": "03-packages-and-scopes/02-scopes/02-block-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc nope() { // block scope starts\n\n\t// hello and ok are only visible here\n\tconst ok = true\n\tvar hello = \"Hello\"\n\n\t_ = hello\n} // block scope ends\n\nfunc main() { // block scope starts\n\n\t// hello and ok are not visible here\n\n\t// ERROR:\n\t// fmt.Println(hello, ok)\n\n} // block scope ends\n"
  },
  {
    "path": "03-packages-and-scopes/02-scopes/03-nested-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// I didn't talk about this in a lecture\n// As a side-note, I wanted to put it here\n// Please review it.\n\nvar declareMeAgain = 10\n\nfunc nested() { // block scope starts\n\n\t// declares the same variable\n\t// they both can exist together\n\t// this one only belongs to this scope\n\t// package's variable is still intact\n\tvar declareMeAgain = 5\n\tfmt.Println(\"inside nested:\", declareMeAgain)\n\n} // block scope ends\n\nfunc main() { // block scope starts\n\n\tfmt.Println(\"inside main:\", declareMeAgain)\n\n\tnested()\n\n\t// package-level declareMeAgain isn't effected\n\t// from the change inside the nested func\n\tfmt.Println(\"inside main:\", declareMeAgain)\n\n} // block scope ends\n"
  },
  {
    "path": "03-packages-and-scopes/02-scopes/04-package-scope/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/02-scopes/04-package-scope/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/02-scopes/04-package-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// two files belong to the same package\n\t// calling `bye()` of bye.go here\n\tbye()\n}\n\n// EXERCISE: Remove the comments from the below function\n//           And analyze the error message\n\n// func bye() {\n// \tfmt.Println(\"Bye!\")\n// }\n\n// ***** EXPLANATION *****\n//\n// ERROR: \"bye\" function \"redeclared\"\n//        in \"this block\"\n//\n// \"this block\" means = \"main package\"\n//\n// \"redeclared\" means = you're using the same name\n//   in the same scope again\n//\n// main package's scope is:\n// all source-code files which are in the same main package\n"
  },
  {
    "path": "03-packages-and-scopes/03-importing/01-file-scope/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Uncomment below code to see the error\n// (Just remove the // characters for all 3 lines below)\n\n// This file cannot see main.go's imported names (\"fmt\").\n// Because the imported names belong to file scope.\n\n// func bye() {\n// \tfmt.Println(\"Bye!\")\n// }\n"
  },
  {
    "path": "03-packages-and-scopes/03-importing/01-file-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/03-importing/02-renaming/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\nimport f \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\tf.Println(\"There!\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/01-packages/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Use your own package\n//\n//  Create a few Go files and call their functions from\n//  the main function.\n//\n//  1- Create main.go, greet.go and bye.go files\n//  2- In main.go: Call greet and bye functions.\n//  3- Run `main.go`\n//\n// HINT\n//  greet function should be in greet.go\n//  bye function should be in bye.go\n//\n// EXPECTED OUTPUT\n//  hi there\n//  goodbye\n// ---------------------------------------------------------\n\nfunc main() {\n\t// call functions of the other files here\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/01-packages/solution/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"goodbye\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/01-packages/solution/greet.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc greet() {\n\tfmt.Println(\"hi there\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/01-packages/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tgreet()\n\tbye()\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/02-scopes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Try the scopes\n//\n//  1. Create two files: main.go and printer.go\n//\n//  2. In printer.go:\n//     1. Create a function named hello\n//     2. Inside the hello function, print your name\n//\n//  3. In main.go:\n//     1. Create the usual func main\n//     2. Call your function just by using its name: hello\n//     3. Create a function named bye\n//     4. Inside the bye function, print \"bye bye\"\n//\n//  4. In printer.go:\n//     1. Call the bye function from\n//        inside the hello function\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/02-scopes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// as you can see, I don't need to import a package\n\t// and I can call `hello` function here.\n\t//\n\t// this is because, package-scoped names\n\t// are shared in the same package\n\thello()\n\n\t// but here, I can't access the fmt package without\n\t// importing it.\n\t//\n\t// this is because, it's in the printer.go's file scope.\n\t// it imports it.\n\n\t// this main func can also call bye function here\n\t// bye()\n}\n\n// printer.go can call this function\n//\n// this is because, bye function is in the package-scope\n// of the main package now.\n//\n// main func can also call this.\nfunc bye() {\n\tfmt.Println(\"bye bye\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/02-scopes/solution/printer.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hello() {\n\t// only this file can access the imported fmt package\n\t// when others also do so, they can also access\n\t//   their own `fmt` \"name\"\n\n\tfmt.Println(\"hi! this is inanc!\")\n\tbye()\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/03-importing/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Rename imports\n//\n//  1- Import fmt package three times with different names\n//\n//  2- Print a few messages using those imports\n//\n// EXPECTED OUTPUT\n//  hello\n//  hey\n//  hi\n// ---------------------------------------------------------\n\n// ?\n// ?\n// ?\n\nfunc main() {\n\t// ?\n\t// ?\n\t// ?\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/03-importing/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\nimport f \"fmt\"\nimport fm \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"hello\")\n\tf.Println(\"hey\")\n\tfm.Println(\"hi\")\n}\n"
  },
  {
    "path": "03-packages-and-scopes/exercises/README.md",
    "content": "1. **[Use your own package](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/01-packages)**\n\n    Create a few Go files and call their functions from the main function.\n\n\n2. **[Try the scopes](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/02-scopes)**\n\n    Learn the effects of scoping across packages.\n\n\n3. **[Rename imports](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/03-importing)**\n\n    Import the same package using a different name."
  },
  {
    "path": "03-packages-and-scopes/questions/01-packages-A/README.md",
    "content": "## Where to store the source code files that belong to a package?\n1. Each file should go into a different directory\n2. In a single directory *CORRECT*\n\n\n## Why a package clause is used in a Go source-code file?\n1. It's used for importing a package\n2. It's used for letting Go know that the file belongs to a package *CORRECT*\n3. It's used for declaring a new function\n\n> **1:** `import` statement does that.\n>\n>\n> **3:** `func` statement does that.\n>\n>\n\n\n## Where you should put the `package clause` in a Go source-code file?\n1. As the first code in a Go source code file *CORRECT*\n2. As the last code in a Go source code file\n3. You can put it anywhere\n\n\n## How many times you can use `package clause` for a single source code file?\n1. Once *CORRECT*\n2. None\n3. Multiple times\n\n\n## Which one is a correct usage of `package clause`?\n1. `my package`\n2. `package main`\n3. `pkg main`\n\n\n## Which one is correct?\n1. All files belong to the same package cannot call each others' functions\n2. All files belong to the same package can call each others' functions *CORRECT*\n\n\n## How to run multiple Go files?\n1. go run *.*go\n2. go build *go\n3. go run go\n4. go run *.go *CORRECT*\n\n> **4:** You can also call it like (assuming there are file1.go file2.go and file3.go in the same directory): go run file1.go file2.go file3.go\n>\n>\n"
  },
  {
    "path": "03-packages-and-scopes/questions/02-packages-B/README.md",
    "content": "## Which one below is a correct package type in Go?\n* Empty package\n* Executable package *CORRECT*\n* Transferrable package\n* Librarian package\n\n## Which package type `go run` can execute?\n* Empty package\n* Executable package *CORRECT*\n* Transferrable package\n* Library package\n\n## Which package type that `go build` can compile?\n* Empty package\n* Temporary package\n* Both of executable and library packages *CORRECT*\n* Transferrable package\n\n## Which one is an executable package?\n* `package main` with `func main` *CORRECT*\n* `package Main` with `func Main`\n* `package exec` with `func exec`\n\n## Which one is a library package?\n* `main package`\n* `package lib` *CORRECT*\n* `func package`\n* `package main` with `func main`\n\n## Which package is used for an executable Go program?\n* Empty package\n* Executable package *CORRECT*\n* Transferrable package\n* Library package\n\n## Which package is used for reusability and can be imported? \n* Empty package\n* Executable package\n* Transferrable package\n* Library package *CORRECT*\n"
  },
  {
    "path": "03-packages-and-scopes/questions/03-scopes/README.md",
    "content": "## What's a scope?\n* Executable block of code\n* The visibility of the declared names **CORRECT**\n* Determines what to run\n\n```go\npackage awesome\n\nimport \"fmt\"\n\nvar enabled bool\n\nfunc block() {\n    var counter int\n    fmt.Println(counter)\n}\n```\n\n## Which name below is package scoped?\n1. awesome\n2. fmt\n3. enabled **CORRECT**\n4. counter\n\n> **3:** That's right. `enabled` is out of any functions, so it's a package scoped name. `block()` function is also package scoped; it's out of any function too.\n>\n>\n\n\n## Which name below is file scoped?\n1. awesome\n2. fmt **CORRECT**\n3. enabled\n4. block()\n5. counter\n\n> **2:** That's right. Imported package names are file scoped. And they can only be used within the same file.\n>\n>\n\n\n## Which name below is in the scope of the block() func?\n1. awesome\n2. fmt\n3. enabled\n4. block()\n5. counter **CORRECT**\n\n> **5:** That's right. `counter` is declared within the `block()` func, so it's in the scope of the block func. Out of the `block()` func, other code can't see it.\n>\n>\n\n\n## Can `block()` see `enabled` name?\n1. Yes: It's in the package scope **CORRECT**\n2. No: It's in the file scope\n3. No: It's in the block scope of block()\n\n> **1:** All code inside the same package can see all the other package level declared names.\n>\n>\n\n\n## Can other files in `awesome` package see `counter` name?\n1. Yes\n2. No: It's in the package scope\n3. No: It's in the file scope\n4. No: It's in the block scope of block() **CORRECT**\n\n> **4:** That's right. None of the other code can see the names inside the `block()` function. Only the code inside the `block()` function can see them (Only to some extent. For example: Inside the block, the code can only see the variables declared before it.)\n>\n>\n\n\n## Can other files in `awesome` package see `fmt` name?\n1. Yes\n2. No: It's in the package scope\n3. No: It's in the file scope **CORRECT**\n4. No: It's in the block scope of block()\n\n> **3:** Only the same file can see the imported packages, not the other files whether they're in the same package or not.\n>\n>\n\n\n## What happens if you declare the same name in the same scope as this:\n```go\npackage awesome\n\nimport \"fmt\"\n\n// declared twice in the package scope\nvar enabled bool\nvar enabled bool\n\nfunc block() {\n    var counter int\n    fmt.Println(counter)\n}\n```\n1. The newly declared name will override the previous one.\n2. I can't do that. It's already been declared at the package scope. *CORRECT*\n3. I can't do that. It's already been declared at the file scope.\n\n> **2:** That's right. You can't declare the same name in the same scope. If you could do so, then how would you access it again? Or to which one?\n>\n>\n\n\n## What happens if you declare the same name in another scope like this:\n```go\npackage awesome\n\nimport \"fmt\"\n\n// declared at the package scope\nvar enabled bool\n\nfunc block() {\n    // also declared in the block scope\n    var enabled bool\n\n    var counter int\n    fmt.Println(counter)\n}\n```\n1. The newly declared name will override the previous one. *CORRECT*\n2. I can't do that. It's already been declared at the package scope.\n3. I can't do that. It's already been declared at the file scope.\n\n> **1:** Actually, you can declare the same name in the inner scopes like this. `block()`'s scope is inside its package. This means that it can access to its package's scope (but not vice versa). So, `block()`'s scope is under its package's scope. This means that you can declare the same name again. It will override the parent scope's name. They both can be exist together. Check out the example in the course repository to find out.\n>\n>\n"
  },
  {
    "path": "04-statements-expressions-comments/01-statements/01-execution-flow/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// Statements change the execution flow\n\t// Especially the control flow statements like `if`\n\tif 5 > 1 {\n\t\tfmt.Println(\"bigger\")\n\t}\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/01-statements/02-semicolons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello\"); fmt.Println(\"World!\")\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/02-expressions/01-operator/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello!\" + \"!\")\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/02-expressions/02-call-expression/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n)\n\nfunc main() {\n\t// runtime.NumCPU() is a call expression\n\tfmt.Println(runtime.NumCPU() + 1)\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/03-comments/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// Package main makes this package an executable program\npackage main\n\nimport \"fmt\"\n\n/*\nmain function\nGo executes this program using this function.\nThere should be only one main file in the main package.\nExecutable programs are also called \"commands\".\n*/\nfunc main() {\n\tfmt.Println(\"Hello Gopher!\")\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/01-shy-semicolons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Shy Semicolons\n//\n//  1. Try to type your statements by separating them using\n//     semicolons\n//\n//  2. Observe how Go fixes them for you\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/01-shy-semicolons/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// Uncomment the line of code below; then save the file.\n\t//\n\t// You will see that Gofmt tool will format your code automatically.\n\t// https://golang.org/cmd/gofmt/\n\t//\n\t// This is because, for Go, it doesn't matter whether\n\t// you use semicolons between the statements or not.\n\t//\n\t// It adds them automatically after all.\n\n\t/*\n\t\tfmt.Println(\"inanc\"); fmt.Println(\"lina\"); fmt.Println(\"ebru\");\n\t*/\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/02-naked-expression/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Naked Expression\n//\n//  1. Try to type just \"Hello\" on a line.\n//  2. Do not use Println\n//  3. Observe the error\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/02-naked-expression/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// Uncomment the code line below to see the error.\n\n\t/*\n\t\t\"Hello\"\n\t*/\n\n\t// It will say: \"evaluted but not used\"\n\t//\n\t// Because:\n\t// \"Hello\" literal returns a value but there isn't any\n\t// statement which uses it.\n\t//\n\t// So:\n\t// You can't use expressions alone without statements.\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/03-operators-combine/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Operators combine the expressions\n//\n//  Print the expected output below using the string\n//  concatenation operator.\n//\n// HINT\n//  Use + operator multiple times to create \"Hello!!!?\".\n//\n// EXPECTED OUTPUT\n//  \"Hello!!!?\"\n// ---------------------------------------------------------\n\nfunc main() {\n\n\t// fmt.Println(\"Hello!\" + ?)\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/03-operators-combine/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Operators combine multiple expressions together\n\t// as if there's a single expression.\n\tfmt.Println(\"Hello!\" + \"!\" + \"!\" + \"?\")\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/04-print-go-version/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the Go Version\n//\n//  1. Look at the runtime package documentation\n//  2. Find the func that returns the Go version\n//  3. Print the Go version by calling that func\n//\n// HINT\n//  It's here: https://golang.org/pkg/runtime\n//\n// EXPECTED OUTPUT\n//  \"go1.10\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/04-print-go-version/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n)\n\nfunc main() {\n\tfmt.Println(runtime.Version())\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/05-comment-out/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Comment out\n//\n//  Use single and multiline comments to comment Printlns.\n//\n// EXPECTED OUTPUT\n//  You shouldn't see any output after you're done.\n// ---------------------------------------------------------\n\nfunc main() {\n\tfmt.Println(\"hello\")\n\tfmt.Println(\"how\")\n\tfmt.Println(\"are\")\n\tfmt.Println(\"you\")\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/05-comment-out/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// fmt.Println(\"hello\")\n\t/*\n\t\tfmt.Println(\"how\")\n\t\tfmt.Println(\"are\")\n\t\tfmt.Println(\"you\")\n\t*/\n}\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/06-use-godoc/exercise.md",
    "content": "## EXERCISE\n\n- Print the documentation of `runtime.NumCPU` function in the command line\n- Print also its source code using in the command line\n\n## HINT\n\nYou should use correct `go doc` tools\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/06-use-godoc/solution/solution.md",
    "content": "## DOCUMENTATION:\n\n  go doc runtime NumCPU\n\n## SOURCE CODE:\n\n  go doc -src runtime NumCPU\n"
  },
  {
    "path": "04-statements-expressions-comments/exercises/README.md",
    "content": "1. **[Shy Semicolons](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/01-shy-semicolons)**\n\n    Observe how Go fixes semicolons for you.\n\n2. **[Naked Expression](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/02-naked-expression)**\n\n    Observe what happens when you use an expression without a statement.\n\n3. **[Operators Combine](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/03-operators-combine)**\n\n    Try using operators to combine expressions.\n\n4. **[Print Go Version](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/04-print-go-version)**\n\n    Use a package from Go Standard Library to print the current version of Go on your system. Or the system which will run your program.\n\n5. **[Comment Out](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/05-comment-out)**\n\n    Learn how to comment out.\n\n6. **[Use the GoDoc](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/06-use-godoc)**\n\n    Try godoc yourself.\n"
  },
  {
    "path": "04-statements-expressions-comments/questions/01-statements/README.md",
    "content": "## Which one is the correct description for a statement?\n1. A statement instructs Go to do something *CORRECT*\n2. A statement produces a value\n3. A statement can't change the execution flow\n\n> **2:** A statement can't produce a value. However, it can indirectly help to produce a value.\n>\n>\n> **3:** It surely can.\n>\n>\n\n\n## What's the direction of execution in a Go code?\n1. From left to right\n2. From top to bottom *CORRECT*\n3. From right to left\n4. From bottom to top\n\n> **2:** That's right. Go executes the code from top-to-bottom, one statement at a time.\n>\n>\n\n\n## Which one is the correct description for an expression?\n1. An expression instructs Go to do something\n2. An expression produces a value *CORRECT*\n3. An expression can change the execution flow\n\n> **1:** It can't. Only a statement can do that.\n>\n>\n> **3:** It can't. Only a statement can do that.\n>\n>\n\n\n## Which one is the correct description for an operator?\n1. An operator instructs Go to do something\n2. An operator can change the execution flow\n3. An operator can combine expressions *CORRECT*\n\n> **1:** It can't. Only a statement can do that.\n>\n>\n> **2:** It can't. Only a statement can do that.\n>\n>\n\n\n## Why doesn't the following program work?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    \"Hello\"\n}\n```\n\n1. \"Hello\" is an expression and it can't be on its own on a single line of code without a statement. *CORRECT*\n2. By removing the double-quotes surrounding the \"Hello\". Like this: Hello\n3. By moving \"Hello\" out of the func main.\n\n\n## Does the following program work?\n```go\npackage main\nimport (\n    \"fmt\"\n    \"runtime\"\n)\n\nfunc main() {\n    fmt.Println(runtime.NumCPU()); fmt.Println(\"cpus\"); fmt.Println(\"the machine\")\n}\n```\n\n1. It works: Expressions can be typed by separating them using semicolons\n2. It doesn't work: Statements should be on their own on a single line of code\n3. It works: Go adds semicolons behind the scenes for every statement already *CORRECT*\n\n> **1:** It works but that's not the reason. And, expressions can't be typed like that.\n>\n>\n> **2:** Are you sure?\n>\n>\n> **3:** That's right. Whether there's a semicolon or not; Go adds them automatically. Those statements are still assumed as they're on a different code line of their own.\n>\n>\n\n\n## Why does this program work?\n```go\npackage main\nimport (\n    \"fmt\"\n    \"runtime\"\n)\n\nfunc main() {\n    fmt.Println(runtime.NumCPU() + 10)\n}\n```\n\n1. Operators can combine expressions *CORRECT*\n2. Statements can be used with operators\n3. Expressions can return multiple values\n\n> **1:** That's right. + operator combines `runtime.NumCPU()` and `10` expressions.\n>\n>\n> **2:** No, they can't be. For example, you can't do this: `import \"fmt\" + 3`. Some statement can allow expressions. However, this doesn't mean that they can be combined using expressions.\n>\n>\n> **3:** That's right however it's irrelevant to why this code works.\n>\n>\n"
  },
  {
    "path": "04-statements-expressions-comments/questions/02-expressions/README.md",
    "content": "## Please check out the questions inside the statements directory."
  },
  {
    "path": "04-statements-expressions-comments/questions/03-comments/README.md",
    "content": "## Why do you need to use comments sometimes?\n1. To combine different expressions together\n2. To provide explanations or generating automatic documentation for your code *CORRECT*\n3. To make the code look nice and beautiful\n\n\n## Which of the following code is correct?\n1.\n```go\npackage main\n\n/ main function is an entry point /\nfunc main() {\n    fmt.Println(\"Hi\")\n}\n```\n\n2. *CORRECT*\n```go\npackage main\n\n// main function is an entry point /*\nfunc main() {\n    fmt.Println(/* this will print Hi! */ \"Hi\")\n}\n```\n\n3.\n```go\npackage main\n\n/*\nmain function is an entry point\n\nIt allows Go to find where to start executing an executable program.\n*/\nfunc main() {\n    fmt.Println(// \"this will print Hi!\")\n}\n```\n\n> **1:** `/` is not a comment. It should be `//`.\n>\n>\n> **2:** Multiline comments can be put almost anywhere. However, when a comment starts with `/*`, it also needs to end with `*/`. Here, Go doesn't interpret `/* ... */`, it just skips it. And, when Go sees `//` as the first two characters in a code, it skips the whole line.\n>\n>\n> **3:** `//` prevents Go to interpret the rest of the code line. That's why this code doesn't work. Go can't interpret this part because of the comment: `\"this will print Hi!\")`\n>\n>\n\n## How should you name your code so that Go can generate documentation from your code automatically?\n1. By commenting each line of the code; then it will generate the documentation from whatever it sees\n2. By starting the comments using the name of the declared names *CORRECT*\n3. By using multi-line comments\n\n> **1:** This won't help. Sorry.\n>\n>\n> **3:** It doesn't matter whether you type your comments using single-line comments or multi-line comments.\n>\n>\n\n\n## Which tool do you need to use from the command-line to print the documentation?\n1. go build\n2. go run\n3. go doctor\n4. go doc *CORRECT*\n\n\n## What's the difference between `godoc` and `go doc`?\n1. `go doc` is the real tool behind `godoc`\n2. `godoc` is the real tool behind `go doc` *CORRECT*\n3. `go` tool is the real tool behind `go doc`\n4. `go` tool is the real tool behind `godoc`\n\n> **2:** That's right. go doc tool uses godoc tool behind the scenes. go doc is just a simplified version of the godoc tool.\n>\n>\n"
  },
  {
    "path": "05-write-your-first-library-package/exercise/README.md",
    "content": "[Check out the exercise and its solution here.](https://github.com/inancgumus/learngo/tree/master/05-write-your-first-library-package/exercise)\n\n---\n\n# EXERCISE\n1. Create a new library\n2. In it, create a function that returns the Go version\n3. Create a command and import your library\n4. Call your function that returns Go version\n5. Run your program\n\n## HINTS\n**Create your package function like this:**\n\n```go\nfunc Version() string {\n    return runtime.Version()\n}\n```\n\n## EXPECTED OUTPUT\nIt should print the current Go version on your system.\n\n## WARNING\n\nYou should create this package under your own folder, not in github.com/inancgumus/learngo folder. Also, please note that VS Code may automatically import my library which is in github.com/inancgumus/learngo instead of your own library.\n\nSo, if you want VS Code automatically import your own package when you save, just move github.com/inancgumus/learngo out of GOPATH to somewhere else, for example, to your Desktop (of course move it back afterward).\n\nSee [this question](https://www.udemy.com/learn-go-the-complete-bootcamp-course-golang/learn/v4/questions/5518190) in Q&A for more information.\n"
  },
  {
    "path": "05-write-your-first-library-package/exercise/solution/golang/cmd/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\" // You should replace this with your username\n\n\t\"github.com/inancgumus/learngo/05-write-your-first-library-package/exercise/solution/golang\"\n)\n\nfunc main() {\n\tfmt.Println(golang.Version())\n}\n"
  },
  {
    "path": "05-write-your-first-library-package/exercise/solution/golang/go.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage golang\n\nimport (\n\t\"runtime\"\n)\n\n// Version returns the current Go version\nfunc Version() string {\n\treturn runtime.Version()\n}\n"
  },
  {
    "path": "05-write-your-first-library-package/printer/cmd/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Automatically imports!... AWESOME!\nimport \"github.com/inancgumus/learngo/05-write-your-first-library-package/printer\"\n\nfunc main() {\n\tprinter.Hello()\n}\n"
  },
  {
    "path": "05-write-your-first-library-package/printer/printer.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage printer\n\nimport \"fmt\"\n\n// Hello is an exported function\nfunc Hello() {\n\tfmt.Println(\"exported hello\")\n}\n"
  },
  {
    "path": "05-write-your-first-library-package/questions/README.md",
    "content": "## Which one below is correct?\n**NOTE** _There are explanations inside the answers. Even if you know the answer please try to select all of them one by one, so you can read the explanations._\n\n1. You can run a library package.\n2. In a library package, there should be a function named main (func main).\n3. You can compile a library package. *CORRECT*\n4. You have to compile a library package.\n\n> **1:** You can't, but you can import it from other packages.\n>\n> **2:** In a library package, you don't have to include the main function. Because it isn't an executable package. Only in executable packages you need a main func.\n>\n> **4:** You don't have to compile it. When you import it, it will automatically be built by the other program or library when it gets compiled or ran.\n\n\n## What do you need to export a name?\n1. You need to type it in all capital letters\n2. You need to type its first letter as a capital letter *CORRECT*\n3. You need to put it inside a function scope\n4. You need to create a new file for that name\n\n> **1:** When you do so, it will be exported, that's true, but don't do that; so I assume that this answer is not correct :)\n>\n> **2:** That's right. Then the other packages can access it.\n>\n> **3:** It should be in a package scope, not function scope.\n>\n> **4:** You don't have to do that.\n\n\n## How can you use a function from your library from an executable program?\n1. You need to export your library package first; then you can access its imported names\n2. You need to import your library package first; then you can access its exported names *CORRECT*\n3. You can access your library package as if it's in your executable program\n4. You can import it just by using its name\n\n> **1:** You can't export packages. All packages are already exported. Unless you put them in a directory called: \"internal\". But, that's an advanced topic for now.\n>\n> **2:** That's right.\n>\n> **3:** You can't access a package from another package without importing it.\n>\n> **4:** No, you can't. You need to import it using its full directory path after GOPATH. BTW, in the near future, this may change with the Go modules support.\n\n\n## In the following program, which names are exported?\n```go\npackage wizard\n\nimport \"fmt\"\n\nfunc doMagic() {\n    fmt.Println(\"enchanted!\")\n}\n\nfunc Fireball() {\n    fmt.Println(\"fireball!!!\")\n}\n```\n\n1. fmt\n2. doMagic\n3. Fireball *CORRECT*\n4. Println\n\n> **1:** That's just an imported package name.\n>\n> **2:** It starts with a lowercase letter; so, it's not exported.\n>\n> **3:** That's right. It starts with a capital letter.\n>\n> **4:** This isn't your function. It's already been exported in the fmt package. But, it isn't exported here.\n\n\n## In the following program, which names are exported?\n```go\npackage wizard\nimport \"fmt\"\n\nvar one string\nvar Two string\nvar greenTrees string\n\nfunc doMagic() {\n    fmt.Println(\"enchanted!\")\n}\n\nfunc Fireball() {\n    fmt.Println(\"fireball!!!\")\n}\n```\n\n1. doMagic and Fireball\n2. Fireball and Two *CORRECT*\n3. Fireball, greenTrees and Two\n4. Fireball, greenTrees, one and Two\n\n> **1:** doMagic starts with a lowercase letter; so, it's not exported.\n>\n> **2:** That's right. Fireball and Two, they both start with a capital letter.\n>\n> **3:** greenTrees starts with a lowercase letter; so, it's not exported.\n>\n> **4:** one and greenTrees do not start with capital letters; so, they're not exported.\n"
  },
  {
    "path": "06-variables/01-basic-data-types/exercises/01-print-the-literals/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the literals\n//\n//  1. Print a few integer literals\n//\n//  2. Print a few float literals\n//\n//  3. Print true and false bool constants\n//\n//  4. Print your name using a string literal\n//\n//  5. Print a non-english sentence using a string literal\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// Use fmt.Println()\n}\n"
  },
  {
    "path": "06-variables/01-basic-data-types/exercises/01-print-the-literals/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(42, 8500, 344433, -2323)\n\tfmt.Println(3.14, 6.28, -42.)\n\tfmt.Println(true, false)\n\tfmt.Println(\"Hi! I'm Inanc!\")\n\tfmt.Println(\"Merhaba, adım İnanç!\")\n}\n"
  },
  {
    "path": "06-variables/01-basic-data-types/exercises/02-print-hexes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// THIS EXERCISE IS OPTIONAL\n\n// ---------------------------------------------------------\n// EXERCISE: Print hexes\n//\n//  1. Print 0 to 9 in hexadecimal\n//\n//  2. Print 10 to 15 in hexadecimal\n//\n//  3. Print 17 in hexadecimal\n//\n//  4. Print 25 in hexadecimal\n//\n//  5. Print 50 in hexadecimal\n//\n//  6. Print 100 in hexadecimal\n//\n// EXPECTED OUTPUT\n//  0 1 2 3 4 5 6 7 8 9\n//  10 11 12 13 14 15\n//  17\n//  25\n//  50\n//  100\n//\n// NOTES\n//  https://stackoverflow.com/questions/910309/how-to-turn-hexadecimal-into-decimal-using-brain\n//\n// https://simple.wikipedia.org/wiki/Hexadecimal_numeral_system\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// EXAMPLES:\n\n\t// I'm going to print 10 in hexadecimal\n\tfmt.Println(0xa)\n\n\t// I'm going to print 16 in hexadecimal\n\t// 0x10\n\t//   ^^-----  1 * 0 = 0\n\t//   |\n\t//   +------ 16 * 1 = 16\n\t//                  = 16\n\tfmt.Println(0x10)\n\n\t// I'm going to print 150 in hexadecimal\n\t// 0x96\n\t//   ^^-----  1 * 6 = 6\n\t//   |\n\t//   +------ 16 * 9 = 144\n\t//                  = 150\n\tfmt.Println(0x96)\n\n\t// COMMENT-OUT ALL THE CODE ABOVE, THEN,\n\t// ADD YOUR OWN SOLUTIONS BELOW\n}\n"
  },
  {
    "path": "06-variables/01-basic-data-types/exercises/02-print-hexes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9)\n\tfmt.Println(0xa, 0xb, 0xc, 0xd, 0xe, 0xf)\n\tfmt.Println(0x11) // 17\n\tfmt.Println(0x19) // 25\n\tfmt.Println(0x32) // 50\n\tfmt.Println(0x64) // 100\n}\n"
  },
  {
    "path": "06-variables/01-basic-data-types/exercises/README.md",
    "content": "1. **[Print the literals](https://github.com/inancgumus/learngo/tree/master/06-variables/01-basic-data-types/exercises/01-print-the-literals)**\n\n    Print a few values using the literals\n\n2. **[Print hexes](https://github.com/inancgumus/learngo/tree/master/06-variables/01-basic-data-types/exercises/02-print-hexes)** (optional exercise)\n\n    Print numbers in hexadecimal\n"
  },
  {
    "path": "06-variables/01-basic-data-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// integer literal\n\tfmt.Println(\n\t\t-200, -100, 0, 50, 100, 100,\n\t)\n\n\t// float literal\n\tfmt.Println(\n\t\t-50.5, -20.5, -0., 1., 100.56, // ...\n\t)\n\n\t// bool constants\n\tfmt.Println(\n\t\ttrue, false,\n\t)\n\n\t// string literal - utf-8\n\tfmt.Println(\n\t\t\"\", // empty - prints just a space\n\t\t\"hi\",\n\n\t\t// unicode\n\t\t\"nasılsın?\",   // \"how are you\" in turkish\n\t\t\"hi there 星!\", // \"hi there star!\"\n\t)\n}\n"
  },
  {
    "path": "06-variables/01-basic-data-types/questions/README.md",
    "content": "## Which one below is an integer literal?\n* -42 *CORRECT*\n    * This is an integer literal\n* \"Hello\"\n    * This is a string literal\n* false\n    * This is a bool constant\n* 3.14\n    * This is a float literal\n\n## Which one below is a float literal?\n* -42\n* \"Hello\"\n* false\n* 3.14 *CORRECT*\n\n## Which one below is a float literal?\n* 6,28\n* ,28\n* .28 *CORRECT*\n* 628\n\n## Which one below is a string literal?\n* -42\n* \"Hello\" *CORRECT*\n* false\n* 3.14\n\n## Which one below is a bool constant?\n* -42\n* \"Hello\"\n* false *CORRECT*\n* 3.14\n"
  },
  {
    "path": "06-variables/02-declarations/01-declaration-syntax/01-syntax/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar speed int\n\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/01-declaration-syntax/02-naming-rules/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// VARIABLE NAMING RULES\n\nfunc main() {\n\t// CORRECT DECLARATIONS\n\tvar speed int\n\tvar SpeeD int\n\n\t// underscore is allowed but not recommended\n\tvar _speed int\n\n\t// Unicode letters are allowed\n\tvar 速度 int\n\n\t// keep the compiler happy\n\t_, _, _, _ = speed, SpeeD, _speed, 速度\n}\n"
  },
  {
    "path": "06-variables/02-declarations/01-declaration-syntax/03-order-of-declaration/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// fmt.Println(speed)\n\t// var speed int\n}\n"
  },
  {
    "path": "06-variables/02-declarations/02-example-declarations/01-int/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar nFiles int\n\tvar counter int\n\tvar nCPU int\n\n\tfmt.Println(\n\t\tnFiles,\n\t\tcounter,\n\t\tnCPU,\n\t)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/02-example-declarations/02-float64/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar heat float64\n\tvar ratio float64\n\tvar degree float64\n\n\tfmt.Println(\n\t\theat,\n\t\tratio,\n\t\tdegree,\n\t)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/02-example-declarations/03-bool/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar off bool\n\tvar valid bool\n\tvar closed bool\n\n\tfmt.Println(\n\t\toff,\n\t\tvalid,\n\t\tclosed,\n\t)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/02-example-declarations/04-string/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar msg string\n\tvar name string\n\tvar text string\n\n\tfmt.Println(\n\t\tmsg,\n\t\tname,\n\t\ttext,\n\t)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/03-zero-values/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// EXERCISE: Let's run this to see the zero-values yourself\n\nfunc main() {\n\tvar speed int    // numeric type\n\tvar heat float64 // numeric type\n\tvar off bool\n\tvar brand string\n\n\tfmt.Println(speed)\n\tfmt.Println(heat)\n\tfmt.Println(off)\n\n\t// I've used printf to print an empty string\n\t// EXERCISE: Use Println to see what happens\n\tfmt.Printf(\"%q\\n\", brand)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/04-unused-variables-and-blank-identifier/01-unused-variable/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// there's no warning for package-level vars\nvar packageLevelVar string\n\nfunc main() {\n\t// unused variable error\n\t// var speed int\n\n\t// if you use it, the error will be gone\n\t// fmt.Println(speed)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/04-unused-variables-and-blank-identifier/02-blank-identifier/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar speed int\n\n\t// let's assign the variable to the blank-identifier\n\t// so that Go compiler won't get grumpy\n\t_ = speed\n}\n"
  },
  {
    "path": "06-variables/02-declarations/05-multiple-declarations/01-multiple/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tspeed int\n\t\theat  float64\n\n\t\toff   bool\n\t\tbrand string\n\t)\n\n\tfmt.Println(speed)\n\tfmt.Println(heat)\n\tfmt.Println(off)\n\tfmt.Printf(\"%q\\n\", brand)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/05-multiple-declarations/02-parallel/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// this is equal to:\n\t//\n\t//   var (\n\t//     speed int\n\t//     velocity int\n\t//   )\n\t//\n\t// or:\n\t//\n\t//   var speed int\n\t//   var velocity int\n\t//\n\tvar speed, velocity int\n\n\tfmt.Println(speed, velocity)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/06-examples/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// names are case-sensitive:\n\t// MyAge, myAge, and MYAGE are different variables\n\n\t// USE-CASE:\n\t// When to use a parallel declaration?\n\t//\n\t// NOT GOOD:\n\t// var myAge int\n\t// var yourAge int\n\t//\n\t// SO-SO:\n\t// var (\n\t// \tmyAge int\n\t// \tyourAge int\n\t// )\n\t//\n\t// BETTER:\n\tvar myAge, yourAge int\n\tfmt.Println(myAge, yourAge)\n\n\tvar temperature float64\n\tfmt.Println(temperature)\n\n\tvar success bool\n\tfmt.Println(success)\n\n\tvar language string\n\tfmt.Println(language)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/01-int/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Declare int\n//\n//  1. Declare and print a variable with an int type\n//\n//  2. The declared variable's name should be: height\n//\n// EXPECTED OUTPUT\n//  0\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? ?\n\t// ?\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/01-int/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar height int\n\n\tfmt.Println(height)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/02-bool/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Declare bool\n//\n//  1. Declare and print a bool variable\n//\n//  2. The variable's name should be: isOn\n//\n// EXPECTED OUTPUT\n//  false\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? ?\n\t// ?\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/02-bool/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar isOn bool\n\tfmt.Println(isOn)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/03-float64/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Declare float64\n//\n//  1. Declare and print a variable with a float64 type\n//\n//  2. The declared variable's name should be: brightness\n//\n// EXPECTED OUTPUT\n//  0\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? ?\n\t// ?\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/03-float64/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar brightness float64\n\n\tfmt.Println(brightness)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/04-string/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Declare string\n//\n//  1. Declare a string variable\n//\n//  2. Print that variable\n//\n// EXPECTED OUTPUT\n//  \"\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// USE THE BELOW CODE\n\t// You'll learn about Printf later\n\n\t// var ?\n\t// fmt.Printf(\"s (%T): %q\\n\", s, s)\n\n\t// %T prints the type of the value\n\t// %q prints an empty string\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/04-string/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar s string\n\tfmt.Printf(\"s (%T): %q\\n\", s, s)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/05-undeclarables/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Undeclarables\n//\n//  1. Declare the variables below:\n//      3speed\n//      !speed\n//      spe?ed\n//      var\n//      func\n//      package\n//\n//  2. Observe the error messages\n//\n// NOTE\n//  The types of the variables are not important.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? int\n\t// var ? int\n\t// var ? int\n\t// var ? int\n\t// var ? int\n\t// var ? int\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/05-undeclarables/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// var 3speed int\n\t// var !speed int\n\t// var spe?ed int\n\t// var var int\n\t// var func int\n\t// var package int\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/06-with-bits/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Declare with bits\n//\n//  1. Declare a few variables using the following types\n//    int\n//    int8\n//    int16\n//    int32\n//    int64\n//    float32\n//    float64\n//    complex64\n//    complex128\n//    bool\n//    string\n//    rune\n//    byte\n//\n// 2. Observe their output\n//\n// 3. After you've done, check out the solution\n//    and read the comments there\n//\n// EXPECTED OUTPUT\n//  0 0 0 0 0 0 0 (0+0i) (0+0i) false 0 0\n//  \"\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var i int\n\t// var i8 int8\n\n\t// CONTINUE FROM HERE....\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/06-with-bits/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// integer types\n\tvar i int\n\tvar i8 int8\n\tvar i16 int16\n\tvar i32 int32\n\tvar i64 int64\n\n\t// float types\n\tvar f32 float32\n\tvar f64 float64\n\n\t// complex types\n\tvar c64 complex64\n\tvar c128 complex128\n\n\t// bool type\n\tvar b bool\n\n\t// string types\n\tvar s string\n\tvar r rune  // also a numeric type\n\tvar by byte // also a numeric type\n\n\tfmt.Println(\n\t\ti, i8, i16, i32, i64,\n\t\tf32, f64,\n\t\tc64, c128,\n\t\tb, r, by,\n\t)\n\n\t// You could do it with Println as well\n\tfmt.Printf(\"%q\\n\", s)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/07-multiple/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Multiple\n//\n//  1. Declare two variables using\n//     multiple variable declaration statement\n//\n//  2. The first variable's name should be active\n//  3. The second variable's name should be delta\n//\n//  4. Print them all\n//\n// HINT\n//  You should declare a bool and an int variable\n//\n// EXPECTED OUTPUT\n//  false 0\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var (\n\t//   ?\n\t// )\n\t// fmt.Println(active, delta)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/07-multiple/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tactive bool\n\t\tdelta  int\n\t)\n\tfmt.Println(active, delta)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/08-multiple-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Multiple #2\n//\n//  1. Declare and initialize two string variables\n//     using multiple variable declaration\n//\n//  2. Use the type once while declaring the variables\n//\n//  3. The first variable's name should be firstName\n//  4. The second variable's name should be lastName\n//\n//  5. Print them all\n//\n// EXPECTED OUTPUT\n//  \"\" \"\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATION HERE\n\t//\n\n\t// REPLACE THE QUESTION-MARKS BELOW\n\t// WITH THE NAME OF YOUR VARIABLES\n\n\t// fmt.Printf(\"%q %q\\n\", ?, ?)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/08-multiple-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar firstName, lastName string = \"\", \"\"\n\tfmt.Printf(\"%q %q\\n\", firstName, lastName)\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/09-unused/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Unused\n//\n//  1. Declare a variable\n//\n//  2. Variable's name should be: isLiquid\n//\n//  3. Discard it using a blank-identifier\n//\n// NOTE\n//  Do not print the variable\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/09-unused/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar isLiquid bool\n\t_ = isLiquid\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/10-package-variable/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Package Variable\n//\n//  1. Declare a variable in the package-scope\n//\n//  2. Observe whether something happens when you don't\n//     use it\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/10-package-variable/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nvar isLiquid bool\n\nfunc main() {\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/11-wrong-doer/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Wrong doer\n//\n//  1. Print a variable\n//\n//  2. Then declare it\n//  (This means: Try to print it before its declaration)\n//\n//  3. Observe the error\n// ---------------------------------------------------------\n\nfunc main() {\n\t// First print it:\n\t// fmt.Println(?)\n\n\t// Then declare it:\n\t// var ? ?\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/11-wrong-doer/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW TO SEE THE ERROR\n\n\t// fmt.Println(age)\n\t// var age int\n}\n"
  },
  {
    "path": "06-variables/02-declarations/exercises/README.md",
    "content": "# Declare and Print Variables\n\nWarm up. Declare a few variables and get some experience. Get used to the variable declaration syntax.\n\n1. **[Declare int](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/01-int)**\n\n2. **[Declare bool](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/02-bool)**\n\n3. **[Declare float64](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/03-float64)**\n\n4. **[Declare string](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/04-string)**\n\n5. **[Declare undeclarables](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/05-undeclarables)**\n\n6. **[Declare with bits](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/06-with-bits)**\n\n7. **[Declare multiple](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/07-multiple)**\n\n8. **[Declare multiple 2](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/08-multiple-2)**\n\n9. **[Declare an unused variable](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/09-unused)**\n\n10. **[Declare a package variable](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/10-package-variable)**\n\n11. **[Use before declare](https://github.com/inancgumus/learngo/tree/master/06-variables/02-declarations/exercises/11-wrong-doer)**"
  },
  {
    "path": "06-variables/02-declarations/questions/01-what/README.md",
    "content": "# QUESTIONS: What's a variable?\n\n## Where does a variable live?\n* Hard Disk\n* Computer Memory - *CORRECT*\n* CPU\n\n## What do you use a variable's name for?\n* To be able to access it later - *CORRECT*\n* It's just a label\n* I don't need to use it\n\n## How to change the value of a variable?\n* By using its name - *CORRECT*\n* By using its value\n* By asking to Go\n \n## After its declaration can you change the variable's type?\n* Yes : Go is dynamically-typed\n* No  : Go is statically-typed - *CORRECT*\n* Both: Go supports both of them\n\n"
  },
  {
    "path": "06-variables/02-declarations/questions/02-declaration/README.md",
    "content": "## Which statement do you need to use for declaring variables?\n* name int\n* vars string name\n* var name integer\n* var width int *CORRECT*\n\n## Which sentence below is correct?\n* You can use a variable before declaring it\n* You have to declare a variable before using it *CORRECT*\n\n## What kind of language is Go?\n* Weakly-Typed\n* Dynamically-Typed\n* Strongly-Typed *CORRECT*\n* Freely-Typed\n\n## Which variable name below is correct?\n* int\n* four *CORRECT*\n* 2computers\n* one?there"
  },
  {
    "path": "06-variables/02-declarations/questions/03-unused-variables/README.md",
    "content": "## What happens when you don't use a declared variable in the block scope?\n* Nothing, it will work fine\n* It will get removed automatically\n* The program won't compile *CORRECT*\n\n## What happens when you don't use a declared variable in the package scope?\n* Nothing, it will work fine *CORRECT*\n* It will get removed automatically\n* The program won't compile\n\n## How can you prevent unused variable error?\n* You can change the variable's name\n* You can use a blank-identifier to discard it *CORRECT*\n* You can change the variable's type"
  },
  {
    "path": "06-variables/02-declarations/questions/04-zero-values/README.md",
    "content": "## Which type's zero value is 0?\n- bool\n- pointer\n- string\n- all numeric types *CORRECT*\n\n## Which type's zero value is false?\n- bool *CORRECT*\n- pointer\n- string\n- all numeric types\n\n## Which type's zero value is \"\"?\n- bool\n- pointer\n- string *CORRECT*\n- all numeric types\n\n## Which type's zero value is nil?\n- bool\n- pointer *CORRECT*\n- string\n- all numeric types\n"
  },
  {
    "path": "06-variables/03-short-declaration/01-initialization-and-short-declaration/01-initialization/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// = is the assignment operator\n\t// when used within a variable declaration, it\n\t// initializes the variable to the given value\n\n\t// here, Go initializes the safe variable to true\n\n\t// OPTION #1 (option #2 is better)\n\t// var safe bool = true\n\n\t// OPTION #2\n\tvar safe = true\n\n\tfmt.Println(safe)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/01-initialization-and-short-declaration/02-short-declaration/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// OPTION #1 (option #2 is better)\n\t// var safe bool = true\n\n\t// OPTION #2 (OK)\n\t// var safe = true\n\n\t// OPTION #3 - SHORT DECLARATION (BEST)\n\t//\n\t// You don't even need to type the `var` keyword\n\t//\n\t// Short declaration equals to:\n\t//   var safe bool = true\n\t//   var safe = true\n\t//\n\t// Go gets (infers) the type from the initializer value\n\t//\n\t// true's default type is bool\n\t// so, the type of the safe variable becomes a bool\n\tsafe := true\n\n\tfmt.Println(safe)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/01-initialization-and-short-declaration/03-coding-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// var name string = \"Carl\"\n\t// var name = \"Carl\"\n\tname := \"Carl\"\n\n\t// var isScientist bool = true\n\t// var isScientist = true\n\tisScientist := true\n\n\t// var age int = 62\n\t// var age = 62\n\tage := 62\n\n\t// var degree float64 = 5.\n\t// var degree = 5.\n\tdegree := 5.\n\n\tfmt.Println(name, isScientist, age, degree)\n\n\t// type inference also works for variables\n\t//\n\t// Go gets the type of the variable and assigns it\n\t//   to the newly declared variable\n\t//\n\t// The type of the name2 variable is `string` now\n\tname2 := name\n\tfmt.Println(name2)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/02-package-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// You can't use declaration statements without a keyword\n// Short declaration doesn't have a keyword (`var`)\n// So, it can't be used at the package scope\n//\n// SYNTAX ERROR:\n// \"non-declaration statement outside function body\"\n\n// safe := true\n\n// However, you can use the normal declaration at the\n// package scope. Since it has a keyword: `var`\nvar safe = true\n\nfunc main() {\n\tfmt.Println(safe)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/03-multiple-short-declaration/01-declaration/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// the number of variables and values should be equal\n\n\t// -> `true` is being assigned to `safe`\n\t// -> `50` is being assigned to `speed`\n\n\tsafe, speed := true, 50\n\n\tfmt.Println(safe, speed)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/03-multiple-short-declaration/02-coding-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tname, lastname := \"Nikola\", \"Tesla\"\n\tfmt.Println(name, lastname)\n\n\tbirth, death := 1856, 1943\n\tfmt.Println(birth, death)\n\n\ton, off := true, false\n\tfmt.Println(on, off)\n\n\t// there's no limit\n\t// however, more declarations that you declare\n\t// more unreadable it becomes...\n\tdegree, ratio, heat := 10.55, 30.5, 20.\n\tfmt.Println(degree, ratio, heat)\n\n\t// you can short declare variables with different types\n\tnFiles, valid, msg := 10, true, \"hello\"\n\n\tfmt.Println(nFiles, valid, msg)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/03-multiple-short-declaration/03-redeclaration/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// `safe`'s value is `false`\n\tvar safe bool\n\n\t// `safe`'s value is now `true`\n\n\t// `speed` is declared and initialized to `50`\n\n\t// redeclaration only works when\n\t//\n\t// at least one of the variables\n\t// should be a new variable\n\n\tsafe, speed := true, 50\n\n\tfmt.Println(safe, speed)\n\n\t// EXERCISE\n\t//\n\t// Declare the speed variable before\n\t// the short declaration \"again\"\n\t//\n\t// Observe what happens\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/03-multiple-short-declaration/03-redeclaration/02-coding-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// EXAMPLE #1\n\n\tname := \"Nikola\"\n\tfmt.Println(name)\n\n\t// name already exists in this block\n\t// name := \"Marie\"\n\n\t// just assigns new values to name\n\t// and declares the new variable age with a value of 66\n\tname, age := \"Marie\", 66\n\tfmt.Println(name, age)\n\n\t// EXAMPLE #2\n\n\t// name = \"Albert\"\n\t// birth := 1879\n\n\t// redeclaration below equals to the statements just above\n\t//\n\t// `name` is an existing variable\n\t//   Go just assigns \"Albert\" to the name variable\n\t//\n\t// `birth` is a new variable\n\t//   Go declares it and assigns it a value of `1879`\n\tname, birth := \"Albert\", 1879\n\n\tfmt.Println(name, birth)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/04-short-vs-normal/01-declaration/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// normal declaration use cases\n\n// -----------------------------------------------------\n// when you need a package scoped variable\n// -----------------------------------------------------\n\n// version := 0 // YOU CAN'T\nvar version int\n\nfunc main() {\n\n\t// -----------------------------------------------------\n\t// if you don't know the initial value\n\t// -----------------------------------------------------\n\n\t// DON'T DO THIS:\n\t// score := 0\n\n\t// DO THIS:\n\t// var score int\n\n\t// -----------------------------------------------------\n\t// group variables for readability\n\t// -----------------------------------------------------\n\n\t// var (\n\t// \tvideo    string\n\n\t// \tduration int\n\t// \tcurrent  int\n\t// )\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/04-short-vs-normal/02-short-declaration/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// short declaration use cases\n\nfunc main() {\n\n\t// -----------------------------------------------------\n\t// if you know the initial value\n\t// -----------------------------------------------------\n\n\t// DON'T DO THIS:\n\t// var width, height = 100, 50\n\n\t// DO THIS (concise):\n\t// width, height := 100, 50\n\n\t// -----------------------------------------------------\n\t// redeclaration\n\t// -----------------------------------------------------\n\n\t// DON'T DO THIS:\n\t// width = 50\n\t// color := red\n\n\t// DO THIS (concise):\n\t// width, color := 50, \"red\"\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/01-short-declare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Short Declare\n//\n//  Declare and then print four variables using\n//  the short declaration statement.\n//\n// EXPECTED OUTPUT\n//  i: 314 f: 3.14 s: Hello b: true\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATIONS HERE\n\t//\n\n\t// THEN UNCOMMENT THE CODE BELOW\n\n\t// fmt.Println(\n\t// \t\"i:\", i,\n\t// \t\"f:\", f,\n\t// \t\"s:\", s,\n\t// \t\"b:\", b,\n\t// )\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/01-short-declare/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ti := 314\n\tf := 3.14\n\ts := \"Hello\"\n\tb := true\n\n\tfmt.Println(\n\t\t\"i:\", i,\n\t\t\"f:\", f,\n\t\t\"s:\", s,\n\t\t\"b:\", b,\n\t)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/02-multiple-short-declare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Multiple Short Declare\n//\n//  Declare two variables using multiple short declaration\n//\n// EXPECTED OUTPUT\n//  14 true\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATIONS HERE\n\t//\n\n\t// THEN UNCOMMENT THE CODE BELOW\n\n\t// fmt.Println(a, b)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/02-multiple-short-declare/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ta, b := 14, true\n\n\tfmt.Println(a, b)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/03-multiple-short-declare-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Multiple Short Declare #2\n//\n//  1. Declare two variables using multiple short declaration\n//\n//  2. `a` variable's value should be 42\n//  3. `c` variable's value should be \"good\"\n//\n// EXPECTED OUTPUT\n//  42 good\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATIONS HERE\n\t//\n\n\t// THEN UNCOMMENT THE CODE BELOW\n\n\t// fmt.Println(a, c)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/03-multiple-short-declare-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ta, c := 42, \"good\"\n\n\tfmt.Println(a, c)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/04-short-with-expression/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Short With Expression\n//\n// \t1. Short declare a variable named `sum`\n//\n//  2. Initialize it with an expression by adding 27 and 3.5\n//\n// EXPECTED OUTPUT\n//  30.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATION HERE\n\t//\n\n\t// THEN UNCOMMENT THE CODE BELOW\n\t// fmt.Println(sum)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/04-short-with-expression/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tsum := 27 + 3.5\n\n\tfmt.Println(sum)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/05-short-discard/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Short Discard\n//\n// \t1. Short declare two bool variables\n//     (use multiple short declaration syntax)\n//\n//  2. Initialize both variables to true\n//\n//  3. Change your declaration and\n//     discard the 2nd variable's value\n//     using the blank-identifier\n//\n//  4. Print only the 1st variable\n//\n// EXPECTED OUTPUT\n//  true\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATIONS HERE\n\t//\n\n\t// THEN UNCOMMENT THE CODE BELOW\n\n\t// fmt.Println(on)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/05-short-discard/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// You can discard values in a short declaration\n\n\ton, _ := true, true\n\n\tfmt.Println(on)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/06-redeclare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Redeclare\n//\n// \t1. Short declare two int variables: age and yourAge\n//     (use multiple short declaration syntax)\n//\n//  2. Short declare a new float variable: ratio\n//     And, change the 'age' variable to 42\n//\n//     (! You should use redeclaration)\n//\n//  4. Print all the variables\n//\n// EXPECTED OUTPUT\n//  42, 20, 3.14\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATIONS HERE\n\t//\n\n\t// THEN UNCOMMENT THE CODE BELOW\n\n\t// fmt.Println(age, yourAge, ratio)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/06-redeclare/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tage, yourAge := 10, 20\n\tage, ratio := 42, 3.14\n\n\tfmt.Println(age, yourAge, ratio)\n}\n"
  },
  {
    "path": "06-variables/03-short-declaration/exercises/README.md",
    "content": "# Short Declare\n\nTime to declare a few variables using the short declaration syntax. You'll also use the redeclaration and discarding.\n\n1. **[Short Declare](https://github.com/inancgumus/learngo/tree/master/06-variables/03-short-declaration/exercises/01-short-declare)**\n\n2. **[Multiple Short Declare](https://github.com/inancgumus/learngo/tree/master/06-variables/03-short-declaration/exercises/02-multiple-short-declare)**\n\n3. **[Multiple Short Declare #2](https://github.com/inancgumus/learngo/tree/master/06-variables/03-short-declaration/exercises/03-multiple-short-declare-2)**\n\n4. **[Short With Expression](https://github.com/inancgumus/learngo/tree/master/06-variables/03-short-declaration/exercises/04-short-with-expression)**\n\n5. **[Short Discard](https://github.com/inancgumus/learngo/tree/master/06-variables/03-short-declaration/exercises/05-short-discard)**\n\n6. **[Redeclare](https://github.com/inancgumus/learngo/tree/master/06-variables/03-short-declaration/exercises/06-redeclare)**"
  },
  {
    "path": "06-variables/03-short-declaration/questions/README.md",
    "content": "## Which is a correct declaration?\n* var int safe := 3\n* var safe bool := 3\n* safe := true *CORRECT*\n\n## Which is a correct declaration?\n* var short := true\n* int num := 1\n* speed := 50 *CORRECT*\n* num int := 2\n\n## Which is a correct declaration?\n* x, y, z := 10, 20\n* x = 10,\n* y, x, p := 5, \"hi\", 1.5 *CORRECT*\n* y, x = \"hello\", 10\n\n## Which declaration is equal to the following declaration?\n```go\nvar s string = \"hi\"\n```\n\n* var s int = \"hi\"\n* s := \"hi\" *CORRECT*\n* s, p := 2, 3\n\n## Which declaration is equal to the following declaration?\n```go\nvar n = 10\n```\n\n* n := 10.0\n* m, n := 1, 0\n* var n int = 10 *CORRECT*\n\n## What's the type of the `s` variable?\n```go\ns := \"hmm...\"\n```\n\n* bool\n* string *CORRECT*\n* int\n* float64\n\n## What's the type of the `b` variable?\n```go\nb := true\n```\n\n* bool *CORRECT*\n* string\n* int\n* float64\n\n## What's the type of the `i` variable?\n```go\ni := 42\n```\n\n* bool\n* string\n* int *CORRECT*\n* float64\n\n## What's the type of the `f` variable?\n```go\nf := 6.28\n```\n\n* bool\n* string\n* int\n* float64 *CORRECT*\n\n## What's the value of the `x` variable?\n\n```go\ny, x := false, 20\n```\n\n* 10\n* 20 *CORRECT*\n* false\n\n## What's the value of the `x` variable?\n\n```go\ny, x := false, 20\nx, z := 10, \"hi\"\n```\n\n* 10 *CORRECT*\n* 20\n* false\n\n## Which of the following declaration can be used in the package scope?\n\n* x := 10\n* y, x := 10, 5\n* var x, y = 5, 10 *CORRECT*\n"
  },
  {
    "path": "06-variables/04-assignment/01-assignment/01-assignment/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar speed int\n\tfmt.Println(speed)\n\n\tspeed = 100\n\tfmt.Println(speed)\n\n\tspeed = speed - 25\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/01-assignment/02-strongly-typed/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Go is a strongly typed programming language.\n\n// Even a float and an integer are different types.\n// Or: int32 and int are different types.\n\n// EXERCISE: Try uncommenting the lines\n//           And observe the errors\n\nfunc main() {\n\tvar speed int\n\t// speed = \"100\"\n\n\tvar running bool\n\t// running = 1\n\n\tvar force float64\n\t// speed = force\n\n\t// Go automatically converts the typeless\n\t//   integer literal to float64 automatically\n\tforce = 1\n\n\t// keep the compiler happy\n\t_, _, _ = speed, running, force\n}\n"
  },
  {
    "path": "06-variables/04-assignment/01-assignment/03-examples/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tname   string\n\t\tage    int\n\t\tfamous bool\n\t)\n\n\t// Example #1\n\tname = \"Newton\"\n\tage = 84\n\tfamous = true\n\n\tfmt.Println(name, age, famous)\n\n\t// Example #2\n\tname = \"Somebody\"\n\tage = 20\n\tfamous = false\n\n\tfmt.Println(name, age, famous)\n\n\t// Example #3\n\t// EXERCISE: Why this doesn't work? Think about it.\n\n\t// name = 20\n\t// name = age\n\n\t// save the previous value of the variable\n\t// to a new variable\n\tvar prevName string\n\tprevName = name\n\n\t// overwrite the value of the original variable\n\t// by assigning to it\n\tname = \"Einstein\"\n\n\tfmt.Println(\"previous name:\", prevName)\n\tfmt.Println(\"current name :\", name)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/01-overview/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar counter int\n\n\tfmt.Println(\"counter's name : counter\")\n\tfmt.Println(\"counter's value:\", counter)\n\tfmt.Printf(\"counter's type : %T\\n\", counter)\n\n\tcounter = 10 // OK\n\t// counter = \"ten\" // NOT OK\n\n\tfmt.Println(\"counter's value:\", counter)\n\n\tcounter++\n\tfmt.Println(\"counter's value:\", counter)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/05-multiple-assignment/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tvar (\n\t\tspeed int\n\t\tnow   time.Time\n\t)\n\n\tspeed, now = 100, time.Now()\n\n\tfmt.Println(speed, now)\n\n\t// EXERCISE:\n\t//   Try this alternative (formatted time).\n\n\t// fmt.Println(speed, now.Format(time.Kitchen))\n}\n"
  },
  {
    "path": "06-variables/04-assignment/06-swapping/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tspeed     = 100\n\t\tprevSpeed = 50\n\t)\n\n\tspeed, prevSpeed = prevSpeed, speed\n\n\tfmt.Println(speed, prevSpeed)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/07-path-project/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\tvar dir, file string\n\n\tdir, file = path.Split(\"css/main.css\")\n\n\tfmt.Println(\"dir :\", dir)\n\tfmt.Println(\"file:\", file)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/08-path-project-discarding/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\tvar file string\n\n\t_, file = path.Split(\"css/main.css\")\n\n\tfmt.Println(\"file:\", file)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/09-path-project-shortdecl/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\t_, file := path.Split(\"css/main.css\")\n\n\t// or this:\n\t// dir, file := path.Split(\"css/main.css\")\n\n\tfmt.Println(\"file:\", file)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/01-make-it-blue/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Make It Blue\n//\n//  1. Change `color` variable's value to \"blue\"\n//\n//  2. Print it\n//\n// EXPECTED OUTPUT\n//  blue\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW:\n\n\t// color := \"green\"\n\n\t// ADD YOUR CODE BELOW:\n\n\t// ?\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/01-make-it-blue/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcolor := \"green\"\n\n\tcolor = \"blue\"\n\n\tfmt.Println(color)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/02-vars-to-vars/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Variables To Variables\n//\n//  1. Change the value of `color` variable to \"dark green\"\n//\n//  2. Do not assign \"dark green\" to `color` directly\n//\n//     Instead, use the `color` variable again\n//     while assigning to `color`\n//\n//  3. Print it\n//\n// RESTRICTIONS\n//  WRONG ANSWER, DO NOT DO THIS:\n//  `color = \"dark green\"`\n//\n// HINT\n//  + operator can concatenate string values\n//\n//  Example:\n//\n//  \"h\" + \"e\" + \"y\" returns \"hey\"\n//\n// EXPECTED OUTPUT\n//  dark green\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW:\n\n\t// color := \"green\"\n\n\t// ADD YOUR CODE BELOW\n\n\t// ?\n\n\t// UNCOMMENT THE CODE BELOW TO PRINT THE VARIABLE\n\n\t// fmt.Println(color)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/02-vars-to-vars/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcolor := \"green\"\n\n\t// `\"dark \" + color` is an expression\n\n\tcolor = \"dark \" + color\n\n\tfmt.Println(color)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/03-assign-with-expressions/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Assign With Expressions\n//\n//  1. Multiply 3.14 with 2 and assign it to `n` variable\n//\n//  2. Print the `n` variable\n//\n// HINT\n//  Example: 3 * 2 = 6\n//  * is the product operator (it multiplies numbers)\n//\n// EXPECTED OUTPUT\n//  6.28\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DON'T TOUCH THIS\n\n\t// Declares a new float64 variable\n\t// 0. means 0.0\n\tn := 0.\n\n\t// ADD YOUR CODE BELOW\n\n\t// ?\n\n\tfmt.Println(n)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/03-assign-with-expressions/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tn := 0.\n\n\tn = 3.14 * 2\n\n\tfmt.Println(n)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/04-find-the-rectangle-perimeter/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Find the Rectangle's Perimeter\n//\n//  1. Find the perimeter of a rectangle\n//     Its width is  5\n//     Its height is 6\n//\n//  2. Assign the result to the `perimeter` variable\n//\n//  3. Print the `perimeter` variable\n//\n// HINT\n//  Formula = 2 times the width and height\n//\n// EXPECTED OUTPUT\n//  22\n//\n// BONUS\n//  Find more formulas here and calculate them in new programs\n//  https://www.mathsisfun.com/area.html\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW:\n\n\t// var (\n\t// \tperimeter        int\n\t// \twidth, height = 5, 6\n\t// )\n\n\t// USE THE VARIABLES ABOVE WHEN CALCULATING YOUR RESULT\n\n\t// ADD YOUR CODE BELOW\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/04-find-the-rectangle-perimeter/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tperimeter     int\n\t\twidth, height = 5, 6\n\t)\n\n\t// first calculates: (width + height)\n\t// then            :  multiplies it with 2\n\n\t// just like in math\n\n\tperimeter = 2 * (width + height)\n\n\tfmt.Println(perimeter)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/05-multi-assign/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Multi Assign\n//\n//  1. Assign \"go\" to `lang` variable\n//     and assign 2 to `version` variable\n//     using a multiple assignment statement\n//\n//  2. Print the variables\n//\n// EXPECTED OUTPUT\n//  go version 2\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DO NOT TOUCH THIS\n\tvar (\n\t\tlang    string\n\t\tversion int\n\t)\n\n\t// ADD YOUR CODE BELOW\n\n\t// DO NOT TOUCH THIS\n\tfmt.Println(lang, \"version\", version)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/05-multi-assign/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tlang    string\n\t\tversion int\n\t)\n\n\tlang, version = \"go\", 2\n\n\tfmt.Println(lang, \"version\", version)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/06-multi-assign-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Multi Assign #2\n//\n//  1. Assign the correct values to the variables\n//     to match to the EXPECTED OUTPUT below\n//\n//  2. Print the variables\n//\n// HINT\n//  Use multiple Println calls to print each sentence.\n//\n// EXPECTED OUTPUT\n//  Air is good on Mars\n//  It's true\n//  It is 19.5 degrees\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW:\n\n\t// var (\n\t// \tplanet string\n\t// \tisTrue bool\n\t// \ttemp   float64\n\t// )\n\n\t// ADD YOUR CODE BELOW\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/06-multi-assign-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tplanet string\n\t\tisTrue bool\n\t\ttemp   float64\n\t)\n\n\tplanet, isTrue, temp = \"Mars\", true, 19.5\n\n\tfmt.Println(\"Air is good on\", planet)\n\tfmt.Println(\"It's\", isTrue)\n\tfmt.Println(\"It is\", temp, \"degrees\")\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/07-multi-short-func/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Multi Short Func\n//\n// \t1. Declare two variables using multiple short declaration syntax\n//\n//  2. Initialize the variables using `multi` function below\n//\n//  3. Discard the 1st variable's value in the declaration\n//\n//  4. Print only the 2nd variable\n//\n// NOTE\n//  You should use `multi` function\n//  while initializing the variables\n//\n// EXPECTED OUTPUT\n//  4\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ADD YOUR DECLARATIONS HERE\n\t//\n\n\t// THEN UNCOMMENT THE CODE BELOW\n\n\t// fmt.Println(b)\n}\n\n// multi is a function that returns multiple int values\nfunc multi() (int, int) {\n\treturn 5, 4\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/07-multi-short-func/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t_, b := multi()\n\n\tfmt.Println(b)\n}\n\nfunc multi() (int, int) {\n\treturn 5, 4\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/08-swapper/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Swapper\n//\n//  1. Change `color` to \"orange\"\n//     and `color2` to \"green\" at the same time\n//\n//     (use multiple-assignment)\n//\n//  2. Print the variables\n//\n// EXPECTED OUTPUT\n//  orange green\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW:\n\n\t// color, color2 := \"red\", \"blue\"\n\n\t// ?\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/08-swapper/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcolor, color2 := \"red\", \"blue\"\n\n\tcolor, color2 = \"orange\", \"green\"\n\n\tfmt.Println(color, color2)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/09-swapper-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Swapper #2\n//\n//  1. Swap the values of `red` and `blue` variables\n//\n//  2. Print them\n//\n// EXPECTED OUTPUT\n//  blue red\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW:\n\n\t// red, blue := \"red\", \"blue\"\n\t// ?\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/09-swapper-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tred, blue := \"red\", \"blue\"\n\n\tred, blue = blue, red\n\n\tfmt.Println(red, blue)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/10-discard-the-file/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Discard The File\n//\n//  1. Print only the directory using `path.Split`\n//\n//  2. Discard the file part\n//\n// RESTRICTION\n//  Use short declaration\n//\n// EXPECTED OUTPUT\n//  secret/\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE CODE BELOW:\n\n\t// ? ?= path.Split(\"secret/file.txt\")\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/10-discard-the-file/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\tdir, _ := path.Split(\"secret/file.txt\")\n\n\tfmt.Println(dir)\n}\n"
  },
  {
    "path": "06-variables/04-assignment/exercises/README.md",
    "content": "# Assignments\n\nAssignment means \"copying\" values. Everything is getting copied in Go. You'll learn more about this afterward.\n\nNow, get your feet wet and try some assignment exercises.\n\n1. **[Make It Blue](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/01-make-it-blue)**\n\n2. **[Variables To Variables](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/02-vars-to-vars)**\n\n3. **[Assign With Expressions](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/03-assign-with-expressions)**\n\n4. **[Find the Rectangle's Perimeter](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/04-find-the-rectangle-perimeter)**\n\n5. **[Multi Assign](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/05-multi-assign)**\n\n6. **[Multi Assign #2](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/06-multi-assign-2)**\n\n7. **[Multi Short Func](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/07-multi-short-func)**\n\n8. **[Swapper](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/08-swapper)**\n\n9. **[Swapper #2](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/09-swapper-2)**\n\n10. **[Discard The File](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/10-discard-the-file)**\n"
  },
  {
    "path": "06-variables/04-assignment/questions/README.md",
    "content": "## What happens when you assign a variable to another variable?\n* The variables become the same variable\n* Assignee variable gets deleted\n* Variable's value is changed to the assigned variable's value *CORRECT*\n\n## Which one is a correct assignment statement?\n```go\nopened := true\n```\n* `closed := true`\n* `opened = false` *CORRECT*\n* `var x = 2`\n\n## Which one is a correct assignment statement?\n* `a, b = 3; 5`\n* `c, d = true, false` *CORRECT*\n* `a, b, c = 5, 3`\n\n## Which one is a correct assignment?\n```go\nvar (\n  n = 3\n  m int\n)\n```\n\n* `m = \"4\"`\n* `n = 10` *CORRECT*\n* `n = true`\n* `m = false`\n\n## Which one is a correct assignment?\n```go\nvar (\n  n = 3\n  m int\n  f float64\n)\n\n// one of the assignments below will be here\n\nfmt.Println(n, m, f)\n```\n\n* `n, m = 4, f`\n* `n = false`\n* `n, m, f = m + n, n + 5, 0.5` *CORRECT*\n* `n, m = 3.82, \"hi\"`\n\n## Which one is a correct assignment statement?\n```go\nvar (\n  a int\n  c bool\n)\n```\n* `a = _`\n* `c, _ = _, false` \n* `_, _ = a, c` *CORRECT*\n\n## Which one is a correct assignment?\n**REMEMBER:** `path.Split` returns two `string` values\n\n```go\n  var c, f string\n```\n* `_ = path.Split(\"assets/profile.png\")`\n* `_, _, c = path.Split(\"assets/profile.png\")`\n* `f = path.Split(\"assets/profile.png\")`\n* `_, f = path.Split(\"assets/profile.png\")` *CORRECT*\n"
  },
  {
    "path": "06-variables/05-type-conversion/01-destructive/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tspeed := 100 // int\n\tforce := 2.5 // float64\n\n\t// ERROR: invalid op\n\t// speed = speed * force\n\n\t// conversion can be a destructive operation\n\t// `force` loses its fractional part...\n\n\tspeed = speed * int(force)\n\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/02-correct/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// order of conversion matters...\n\nfunc main() {\n\tspeed := 100\n\tforce := 2.5\n\n\tfmt.Printf(\"speed     : %T\\n\", speed)\n\tfmt.Printf(\"conversion: %T\\n\", float64(speed))\n\tfmt.Printf(\"expression: %T\\n\", float64(speed)*force)\n\n\t// TYPE MISMATCH:\n\t//   speed is int\n\t//   expression is float64\n\t// speed = float64(speed) * force\n\n\t// CORRECT: int * int\n\tspeed = int(float64(speed) * force)\n\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/03-numeric-conversion/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar apple int\n\tvar orange int32\n\n\t// ERROR:\n\t// cannot assign orange to apple (different types)\n\t// apple = orange\n\n\t// you need to convert orange to apple\n\n\t// orange is convertable to int because,\n\t//   int and int32 are both numeric types\n\n\tapple = int(orange)\n\n\t// you can't convert a numeric type to a bool:\n\t// isDelicious := bool(orange)\n\n\t// but you can convert an int to a string\n\t// this only works with int types\n\torange = 65 // 65 is A\n\tcolor := string(orange)\n\tfmt.Println(color)\n\n\t// this doesn't work. 65.0 is a float.\n\t// fmt.Println(string(65.0))\n\n\t// this works: there are two byte values\n\t// byte is also an int\n\tfmt.Println(string([]byte{104, 105}))\n\n\t_ = apple\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/01-convert-and-fix/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Convert and Fix\n//\n//  Fix the code by using the conversion expression.\n//\n// EXPECTED OUTPUT\n//  15.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// a, b := 10, 5.5\n\t// fmt.Println(a + b)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/01-convert-and-fix/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ta, b := 10, 5.5\n\tfmt.Println(float64(a) + b)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/02-convert-and-fix-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Convert and Fix #2\n//\n//  Fix the code by using the conversion expression.\n//\n// EXPECTED OUTPUT\n//  10.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// a, b := 10, 5.5\n\t// a = b\n\t// fmt.Println(a + b)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/02-convert-and-fix-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ta, b := 10, 5.5\n\ta = int(b)\n\tfmt.Println(float64(a) + b)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/03-convert-and-fix-3/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Convert and Fix #3\n//\n//  Fix the code.\n//\n// EXPECTED OUTPUT\n//  5.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// fmt.Println(int(5.5))\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/03-convert-and-fix-3/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(5.5)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/04-convert-and-fix-4/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Convert and Fix #4\n//\n//  Fix the code.\n//\n// EXPECTED OUTPUT\n//  9.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// age := 2\n\t// fmt.Println(int(7.5) + int(age))\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/04-convert-and-fix-4/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tage := 2\n\tfmt.Println(7.5 + float64(age))\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/05-convert-and-fix-5/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Convert and Fix #5\n//\n//  Fix the code.\n//\n// HINTS\n//   maximum of int8  can be 127\n//   maximum of int16 can be 32767\n//\n// EXPECTED OUTPUT\n//  1127\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DO NOT TOUCH THESE VARIABLES\n\tmin := int8(127)\n\tmax := int16(1000)\n\n\t// FIX THE CODE HERE\n\tfmt.Println(int8(max) + min)\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/05-convert-and-fix-5/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tmin := int8(127)\n\tmax := int16(1000)\n\n\tfmt.Println(max + int16(min))\n\n\t// EXPLANATION\n\t//\n\t// `int8(max)` destroys the information of max\n\t// It reduces it to 127\n\t// Which is the maximum value of int8\n\t//\n\t// Correct conversion is int16(min)\n\t// Because, int16 > int8\n\t// When you do so, min doesn't lose information\n\t//\n\t// You will learn more about this in\n\t// the \"Go Type System\" section.\n}\n"
  },
  {
    "path": "06-variables/05-type-conversion/exercises/README.md",
    "content": "# Type Conversion\n\nHere are 5 exercises for you. You must find the errors and then fix them using the correct type conversions.\n\n1. **[Convert and Fix #1](https://github.com/inancgumus/learngo/tree/master/06-variables/05-type-conversion/exercises/01-convert-and-fix)**\n\n2. **[Convert and Fix #2](https://github.com/inancgumus/learngo/tree/master/06-variables/05-type-conversion/exercises/02-convert-and-fix-2)**\n\n3. **[Convert and Fix #3](https://github.com/inancgumus/learngo/tree/master/06-variables/05-type-conversion/exercises/03-convert-and-fix-3)**\n\n4. **[Convert and Fix #4](https://github.com/inancgumus/learngo/tree/master/06-variables/05-type-conversion/exercises/04-convert-and-fix-4)**\n\n5. **[Convert and Fix #5](https://github.com/inancgumus/learngo/tree/master/06-variables/05-type-conversion/exercises/05-convert-and-fix-5)**\n"
  },
  {
    "path": "06-variables/05-type-conversion/questions/questions.md",
    "content": "## Which one is a correct type conversion expression?\n* convert(40)\n* var(\"hi\")\n* int(4.) *CORRECT*\n* int[4]\n\n## What does this code print?\n```go\nage := 6.5\nfmt.Print(int(age))\n```\n* 6.5\n* 65\n* 6 *CORRECT*\n* .5\n\n> When you convert a float to integer\n> It loses its fractional part\n\n## What does this code print?\n```go\nfmt.Print(int(6.5))\n```\n* 6.5\n* 65\n* 6\n* Compile-Time Error *CORRECT*\n\n> Go can detect conversion errors at the compile-time\n\n## What does this code print?\n```go\narea := 10.5\nfmt.Print(area/2)\n```\n* 5.25 *CORRECT*\n* 5 \n* 0\n* Error\n\n## What does this code print?\n```go\narea := 10.5\ndiv := 2\nfmt.Print(area/div)\n```\n* 5.25\n* 5\n* ERROR *CORRECT*\n\n> You can't divide different type of values.\n> You need to convert: `area / float64(div)`\n\n## Which code below can fix the following code?\n```go\narea := 10.5\ndiv := 2\nfmt.Print(area/div)\n```\n* `fmt.Print(int(area)/div)`      // 5\n* `fmt.Print(area/int(div))`      // type mismatch\n* `fmt.Print(int(area)/int(div))` // 5\n* `fmt.Print(area/float64(div))`  *CORRECT*"
  },
  {
    "path": "06-variables/06-project-greeter/01-demonstration/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// NOTE: RUN THIS WITH 3 ARGUMENTS AT LEAST\n//       OR, THERE WILL BE AN ERROR\n\nfunc main() {\n\tfmt.Printf(\"%#v\\n\", os.Args)\n\n\t// Gets an item from the os.Args string slice:\n\t//     os.Args[INDEX]\n\t// INDEX can be 0 or greater\n\tfmt.Println(\"Path:\", os.Args[0])\n\tfmt.Println(\"1st argument:\", os.Args[1])\n\tfmt.Println(\"2nd argument:\", os.Args[2])\n\tfmt.Println(\"3rd argument:\", os.Args[3])\n\n\t// `len` function can find how many items\n\t// inside a slice value\n\tfmt.Println(\"Items inside os.Args:\", len(os.Args))\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/02-version1/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// Since, you didn't learn about the control flow statements yet\n// I didn't include an error detection here.\n//\n// So, if you don't pass a name,\n// this program will fail.\n// This is intentional.\n\nfunc main() {\n\tvar name string\n\n\t// assign a new value to the string variable below\n\tname = os.Args[1]\n\tfmt.Println(\"Hello great\", name, \"!\")\n\n\t// changes the name, declares the age with 85\n\tname, age := \"gandalf\", 85\n\n\tfmt.Println(\"My name is\", name)\n\tfmt.Println(\"My age is\", age)\n\tfmt.Println(\"BTW, you shall pass!\")\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/03-version2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// Since, you didn't learn about the control flow statements yet\n// I didn't include an error detection here.\n//\n// So, if you don't pass a name,\n// this program will fail.\n// This is intentional.\n\nfunc main() {\n\t// assign a new value to the string variable below\n\tname := os.Args[1]\n\tfmt.Println(\"Hello great\", name, \"!\")\n\n\t// changes the name, declares the age with 85\n\tname, age := \"gandalf\", 85\n\n\tfmt.Println(\"My name is\", name)\n\tfmt.Println(\"My age is\", age)\n\tfmt.Println(\"BTW, you shall pass!\")\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/01-count-arguments/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Count the Arguments\n//\n//  Print the count of the command-line arguments\n//\n// INPUT\n//  bilbo balbo bungo\n//\n// EXPECTED OUTPUT\n//  There are 3 names.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT & FIX THIS CODE\n\t// count := ?\n\n\t// UNCOMMENT IT & THEN DO NOT TOUCH THIS CODE\n\t// fmt.Printf(\"There are %d names.\\n\", count)\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/01-count-arguments/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tcount := len(os.Args) - 1\n\n\tfmt.Printf(\"There are %d names.\\n\", count)\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/02-print-the-path/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the Path\n//\n//  Print the path of the running program by getting it\n//  from `os.Args` variable.\n//\n// HINT\n//  Use `go build` to build your program.\n//  Then run it using the compiled executable program file.\n//\n// EXPECTED OUTPUT SHOULD INCLUDE THIS\n//  myprogram\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/02-print-the-path/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// STEPS:\n//\n// Compile it by typing:\n//   go build -o myprogram\n//\n// Then run it by typing:\n//   ./myprogram\n//\n// If you're on Windows, then type:\n//   myprogram\n\nfunc main() {\n\tfmt.Println(os.Args[0])\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/03-print-your-name/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print Your Name\n//\n//  Get it from the first command-line argument\n//\n// INPUT\n//  Call the program using your name\n//\n// EXPECTED OUTPUT\n//  It should print your name\n//\n// EXAMPLE\n//  go run main.go inanc\n//\n//    inanc\n//\n// BONUS: Make the output like this:\n//\n//  go run main.go inanc\n//    Hi inanc\n//    How are you?\n// ---------------------------------------------------------\n\nfunc main() {\n\t// get your name from the command-line\n\t// and print it\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/03-print-your-name/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tfmt.Println(os.Args[1])\n\n\t// BONUS SOLUTION:\n\tfmt.Println(\"Hello\", os.Args[1])\n\tfmt.Println(\"How are you?\")\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/04-greet-more-people/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Greet More People\n//\n// RESTRICTIONS\n//  1. Be sure to match the expected output below\n//  2. Store the length of the arguments in a variable\n//  3. Store all the arguments in variables as well\n//\n// INPUT\n//  bilbo balbo bungo\n//\n// EXPECTED OUTPUT\n//  There are 3 people!\n//  Hello great bilbo !\n//  Hello great balbo !\n//  Hello great bungo !\n//  Nice to meet you all.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// TYPE YOUR CODE HERE\n\n\t// BONUS #1:\n\t// Observe the error if you pass less then 3 arguments.\n\t// Search on the web how to solve that.\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/04-greet-more-people/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tvar (\n\t\tl  = len(os.Args) - 1\n\t\tn1 = os.Args[1]\n\t\tn2 = os.Args[2]\n\t\tn3 = os.Args[3]\n\t)\n\n\tfmt.Println(\"There are\", l, \"people !\")\n\tfmt.Println(\"Hello great\", n1, \"!\")\n\tfmt.Println(\"Hello great\", n2, \"!\")\n\tfmt.Println(\"Hello great\", n3, \"!\")\n\tfmt.Println(\"Nice to meet you all.\")\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/05-greet-5-people/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Greet 5 People\n//\n//  Greet 5 people this time.\n//\n//  Please do not copy paste from the previous exercise!\n//\n// RESTRICTION\n//  This time do not use variables.\n//\n// INPUT\n//  bilbo balbo bungo gandalf legolas\n//\n// EXPECTED OUTPUT\n//  There are 5 people!\n//  Hello great bilbo !\n//  Hello great balbo !\n//  Hello great bungo !\n//  Hello great gandalf !\n//  Hello great legolas !\n//  Nice to meet you all.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// TYPE YOUR CODE HERE\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/05-greet-5-people/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tfmt.Println(\"There are\", len(os.Args)-1, \"people !\")\n\tfmt.Println(\"Hello great\", os.Args[1], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[2], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[3], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[4], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[5], \"!\")\n\tfmt.Println(\"Nice to meet you all.\")\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/README.md",
    "content": "# Command Line Arguments\n\n1. **[Count the Arguments](https://github.com/inancgumus/learngo/tree/master/06-variables/06-project-greeter/exercises/01-count-arguments)**\n\n2. **[Print the Path](https://github.com/inancgumus/learngo/tree/master/06-variables/06-project-greeter/exercises/02-print-the-path)**\n\n3. **[Print Your Name](https://github.com/inancgumus/learngo/tree/master/06-variables/06-project-greeter/exercises/03-print-your-name)**\n\n4. **[Greet More People](https://github.com/inancgumus/learngo/tree/master/06-variables/06-project-greeter/exercises/04-greet-more-people)**\n\n5. **[Greet 5 People](https://github.com/inancgumus/learngo/tree/master/06-variables/06-project-greeter/exercises/05-greet-5-people)**\n"
  },
  {
    "path": "06-variables/06-project-greeter/exercises/solution-to-the-lecture-exercise/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// ---------------------------------------------------------\n// This is a solution to the exercise that I asked\n// in the lecture.\n// ---------------------------------------------------------\n\n// NOTE: You should run this program with 3 arguments\n//       at least. Or there will be an error.\n\nfunc main() {\n\t// assign a new value to the string variable below\n\tvar (\n\t\tname  = os.Args[1]\n\t\tname2 = os.Args[2]\n\t\tname3 = os.Args[3]\n\t)\n\n\tfmt.Println(\"Hello great\", name, \"!\")\n\tfmt.Println(\"And hellooo to you magnificient\", name2, \"!\")\n\tfmt.Println(\"Welcome\", name3, \"!\")\n\n\t// changes the name, declares the age with 131\n\tname, age := \"bilbo baggins\", 131 // unknown age!\n\n\tfmt.Println(\"My name is\", name)\n\tfmt.Println(\"My age is\", age)\n\tfmt.Println(\"And, I love adventures!\")\n}\n"
  },
  {
    "path": "06-variables/06-project-greeter/questions/questions.md",
    "content": "## What's does `os.Args` variable store in its first item?\n* The first argument that is passed to the program\n* The second argument that is passed to the program\n* Path to the running program *CORRECT*\n\n## What's the type of the `Args` variable?\n```go\nvar Args []string\n```\n* string\n* string array\n* a slice of strings *CORRECT*\n\n## What is the type of each value in the `Args` variable?\n```go\nvar Args []string\n```\n* string *CORRECT*\n* string array\n* a slice of strings\n\n## How to get the first item of the `Args` variable?\n```go\nvar Args []string\n```\n* Args.0\n* Args{1}\n* Args[0] *CORRECT*\n* Args(1)\n\n## How to get the second item of the `Args` variable?\n```go\nvar Args []string\n```\n* Args.2\n* Args[1] *CORRECT*\n* Args{1}\n* Args(2)\n\n## How to get the length of the `Args` variable?\n```go\nvar Args []string\n```\n* length(Args)\n* Args.len\n* len(Args) *CORRECT*\n* Args.Length\n\n## How to get the first \"argument\" from the command-line?\n* os.Args[0]\n* os.Args[1] *CORRECT*\n* os.Args[2]\n* os.Args[3]\n\n"
  },
  {
    "path": "07-printf/01-intro/01-println-vs-printf/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tops, ok, fail := 2350, 543, 433\n\n\tfmt.Println(\n\t\t\"total:\", ops, \"- success:\", ok, \"/\", fail,\n\t)\n\n\tfmt.Printf(\n\t\t\"total: %d - success: %d / %d\\n\",\n\t\tops, ok, fail,\n\t)\n}\n"
  },
  {
    "path": "07-printf/01-intro/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar brand string\n\n\t// prints the string in quoted-form like this \"\"\n\tfmt.Printf(\"%q\\n\", brand)\n\n\tbrand = \"Google\"\n\tfmt.Printf(\"%q\\n\", brand)\n}\n"
  },
  {
    "path": "07-printf/02-escape-sequences/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// without newline\n\tfmt.Println(\"hihi\")\n\n\t// with newline:\n\t//   \\n = escape sequence\n\t//   \\  = escape character\n\tfmt.Println(\"hi\\nhi\")\n\n\t// escape characters:\n\t//   \\\\ = \\\n\t//   \\\" = \"\n\tfmt.Println(\"hi\\\\n\\\"hi\\\"\")\n}\n"
  },
  {
    "path": "07-printf/03-printing-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// I'm using multiple declarations instead of singular\n\tvar (\n\t\tspeed int\n\t\theat  float64\n\t\toff   bool\n\t\tbrand string\n\t)\n\n\tfmt.Printf(\"%T\\n\", speed)\n\tfmt.Printf(\"%T\\n\", heat)\n\tfmt.Printf(\"%T\\n\", off)\n\tfmt.Printf(\"%T\\n\", brand)\n}\n"
  },
  {
    "path": "07-printf/04-coding/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tplanet   = \"venus\"\n\t\tdistance = 261\n\t\torbital  = 224.701\n\t\thasLife  = false\n\t)\n\n\t// swiss army knife %v verb\n\tfmt.Printf(\"Planet: %v\\n\", planet)\n\tfmt.Printf(\"Distance: %v millions kms\\n\", distance)\n\tfmt.Printf(\"Orbital Period: %v days\\n\", orbital)\n\tfmt.Printf(\"Does %v have life? %v\\n\", planet, hasLife)\n\n\t// argument indexing - indexes start from 1\n\tfmt.Printf(\n\t\t\"%v is %v away. Think! %[2]v kms! %[1]v OMG.\\n\",\n\t\tplanet, distance,\n\t)\n\n\t// why use other verbs than? because: type-safety\n\t// uncomment to see the warnings:\n\t//\n\t// fmt.Printf(\"Planet: %d\\n\", planet)\n\t// fmt.Printf(\"Distance: %s millions kms\\n\", distance)\n\t// fmt.Printf(\"Orbital Period: %t days\\n\", orbital)\n\t// fmt.Printf(\"Does %v has life? %f\\n\", planet, hasLife)\n\n\t// correct verbs:\n\t// fmt.Printf(\"Planet: %s\\n\", planet)\n\t// fmt.Printf(\"Distance: %d millions kms\\n\", distance)\n\t// fmt.Printf(\"Orbital Period: %f days\\n\", orbital)\n\t// fmt.Printf(\"Does %s has life? %t\\n\", planet, hasLife)\n\n\t// precision\n\tfmt.Printf(\"Orbital Period: %f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.0f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.1f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.2f days\\n\", orbital)\n}\n"
  },
  {
    "path": "07-printf/exercises/01-print-your-age/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print Your Age\n//\n//  Print your age using Printf\n//\n// EXPECTED OUTPUT\n//  I'm 30 years old.\n//\n// NOTE\n//  You should change 30 to your age, of course.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/01-print-your-age/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"I'm %d years old.\\n\", 30)\n}\n"
  },
  {
    "path": "07-printf/exercises/02-print-your-name-and-lastname/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print Your Name and LastName\n//\n//  Print your name and lastname using Printf\n//\n// EXPECTED OUTPUT\n//  My name is Inanc and my lastname is Gumus.\n//\n// BONUS\n//  Store the formatting specifier (first argument of Printf)\n//    in a variable.\n//  Then pass it to printf\n// ---------------------------------------------------------\n\nfunc main() {\n\t// BONUS: Use a variable for the format specifier\n\n\t// fmt.Printf(\"?\", ?, ?)\n}\n"
  },
  {
    "path": "07-printf/exercises/02-print-your-name-and-lastname/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"My name is %s and my lastname is %s.\\n\", \"Inanc\", \"Gumus\")\n\n\t// BONUS\n\tmsg := \"My name is %s and my lastname is %s.\\n\"\n\tfmt.Printf(msg, \"Inanc\", \"Gumus\")\n}\n"
  },
  {
    "path": "07-printf/exercises/03-false-claims/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: False Claims\n//\n//  Use printf to print the expected output using a variable.\n//\n// EXPECTED OUTPUT\n//  These are false claims.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// UNCOMMENT THE FOLLOWING CODE\n\t// AND DO NOT CHANGE IT AFTERWARDS\n\t// tf := false\n\n\t// TYPE YOUR CODE HERE\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/03-false-claims/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ttf := false\n\tfmt.Printf(\"These are %t claims.\\n\", tf)\n}\n"
  },
  {
    "path": "07-printf/exercises/04-print-the-temperature/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the Temperature\n//\n//  Print the current temperature in your area using Printf\n//\n// NOTE\n//  Do not use %v verb\n//  Output \"shouldn't\" be like 29.500000\n//\n// EXPECTED OUTPUT\n//  Temperature is 29.5 degrees.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/04-print-the-temperature/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Temperature is %.1f degrees.\\n\", 29.5)\n}\n"
  },
  {
    "path": "07-printf/exercises/05-double-quotes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Double Quotes\n//\n//  Print \"hello world\" with double-quotes using Printf\n//  (As you see here)\n//\n// NOTE\n//  Output \"shouldn't\" be just: hello world\n//\n// EXPECTED OUTPUT\n//  \"hello world\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/05-double-quotes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"%q\\n\", \"hello world\")\n}\n"
  },
  {
    "path": "07-printf/exercises/06-print-the-type/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the Type\n//\n//  Print the type and value of 3 using fmt.Printf\n//\n// EXPECTED OUTPUT\n//  Type of 3 is int\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/06-print-the-type/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %d is %[1]T\\n\", 3)\n}\n"
  },
  {
    "path": "07-printf/exercises/07-print-the-type-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the Type #2\n//\n//  Print the type and value of 3.14 using fmt.Printf\n//\n// EXPECTED OUTPUT\n//  Type of 3.14 is float64\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/07-print-the-type-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %.2f is %[1]T\\n\", 3.14)\n}\n"
  },
  {
    "path": "07-printf/exercises/08-print-the-type-3/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the Type #3\n//\n//  Print the type and value of \"hello\" using fmt.Printf\n//\n// EXPECTED OUTPUT\n// \tType of hello is string\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/08-print-the-type-3/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %s is %[1]T\\n\", \"hello\")\n}\n"
  },
  {
    "path": "07-printf/exercises/09-print-the-type-4/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the Type #4\n//  Print the type and value of true using fmt.Printf\n//\n// EXPECTED OUTPUT\n//  Type of true is bool\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "07-printf/exercises/09-print-the-type-4/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %t is %[1]T\\n\", true)\n}\n"
  },
  {
    "path": "07-printf/exercises/10-print-your-fullname/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print Your Fullname\n//\n//  1. Get your name and lastname from the command-line\n//  2. Print them using Printf\n//\n// EXAMPLE INPUT\n//  Inanc Gumus\n//\n// EXPECTED OUTPUT\n//  Your name is Inanc and your lastname is Gumus.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// BONUS: Use a variable for the format specifier\n}\n"
  },
  {
    "path": "07-printf/exercises/10-print-your-fullname/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\t// WARNING: This program will error\n\t//          if you don't pass your name and lastname\n\n\tname, lastname := os.Args[1], os.Args[2]\n\n\tmsg := \"Your name is %s and your lastname is %s.\\n\"\n\tfmt.Printf(msg, name, lastname)\n}\n"
  },
  {
    "path": "07-printf/exercises/README.md",
    "content": "# Printf\n\n1. **[Print Your Age](https://github.com/inancgumus/learngo/tree/07-printf/exercises/01-print-your-age)**\n\n2. **[Print Your Name and LastName](https://github.com/inancgumus/learngo/tree/07-printf/exercises/02-print-your-name-and-lastname)**\n\n3. **[False Claims](https://github.com/inancgumus/learngo/tree/07-printf/exercises/03-false-claims)**\n\n4. **[Print the Temperature](https://github.com/inancgumus/learngo/tree/07-printf/exercises/04-print-the-temperature)**\n\n5. **[Double Quotes](https://github.com/inancgumus/learngo/tree/07-printf/exercises/05-double-quotes)**\n\n6. **[Print the Type](https://github.com/inancgumus/learngo/tree/07-printf/exercises/06-print-the-type)**\n\n7. **[Print the Type #2](https://github.com/inancgumus/learngo/tree/07-printf/exercises/07-print-the-type-2)**\n\n8. **[Print the Type #3](https://github.com/inancgumus/learngo/tree/07-printf/exercises/08-print-the-type-3)**\n\n9. **[Print the Type #4](https://github.com/inancgumus/learngo/tree/07-printf/exercises/09-print-the-type-4)**\n\n10. **[Print Your Fullname](https://github.com/inancgumus/learngo/tree/07-printf/exercises/10-print-your-fullname)**\n"
  },
  {
    "path": "07-printf/questions/questions.md",
    "content": "## Which code is correct?\n* `fmt.Printf(\"Hi %s\")`\n* `fmt.Printf(\"Hi %s\", \"how\", \"are you\")`\n* `fmt.Printf(\"Hi %s\", \"hello\")` *CORRECT*\n* `fmt.Printf(\"Hi %s\", true)`\n\n## Which code is correct?\n* `fmt.Printf(\"Hi %s %s\", \"there\")`\n* `fmt.Printf(\"Hi %s %s\", \"5\", true)`\n* `fmt.Printf(\"Hi %s %s\", \"there\", \".\")` *CORRECT*\n* `fmt.Printf(\"Hi %s %s\", \"true\", false)`\n\n## Which verb is used for an int value?\n* %f\n* %d *CORRECT*\n* %s\n* %t\n\n## Which verb is used for a float value?\n* %f *CORRECT*\n* %d\n* %s\n* %t\n\n## Which verb is used for a string value?\n* %f\n* %d\n* %s *CORRECT*\n* %t\n\n## Which verb is used for a bool value?\n* %f\n* %d\n* %s\n* %t *CORRECT*\n\n## Which verb you can use for any type of value?\n* %f\n* %d\n* %v *CORRECT*\n* %t\n\n## What does `\"\\n\"` print?\n* \\n\n* Prints a newline *CORRECT*\n* Prints an empty string\n\n## What does `\"\\\\n\"` print?\n* \\n *CORRECT*\n* Prints a newline\n* Prints an empty string\n\n## What does \"c:\\\\secret\\\\directory\" print?\n* \"c:\\\\secret\\\\directory\"\n* c:\\\\secret\\\\directory\n* c:\\secret\\directory *CORRECT*\n\n## What does `\"\\\"heisenberg\\\"\"` print?\n* ERROR\n* heisenberg\n* \"heisenberg\" *CORRECT*\n* 'heisenberg'\n\n## What does `fmt.Printf(\"%T\", 3.14)` print?\n* ERROR\n* int\n* float64 *CORRECT*\n* string\n* bool\n\n## What does `fmt.Printf(\"%T\", true)` print?\n* ERROR\n* int\n* float64\n* string\n* bool *CORRECT*\n\n## What does `fmt.Printf(\"%T\", 42)` print?\n* ERROR\n* int *CORRECT*\n* float64\n* string\n* bool\n\n## What does `fmt.Printf(\"%T\", \"hi\")` print?\n* ERROR\n* int\n* float64\n* string *CORRECT*\n* bool\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/01-arithmetic-operators/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// when an integer and a float value used together\n\t// in an expression, the result always becomes\n\t// a float value\n\tfmt.Println(8 * -4.0) // -32.0 not -32\n\n\t// two integer values result in an integer value\n\tfmt.Println(-4 / 2)\n\n\t// remainder operator\n\t// it can only used with integers\n\tfmt.Println(5 % 2)\n\t// fmt.Println(5.0 % 2) // wrong\n\n\t// addition operators\n\tfmt.Println(1 + 2.5)\n\tfmt.Println(2 - 3)\n\n\t// negation operator\n\tfmt.Println(-(-2))\n\tfmt.Println(- -2) // this also works\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/01-arithmetic-operators/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tmyAge   = 30\n\t\tyourAge = 35\n\t\taverage float64\n\t)\n\n\taverage = float64(myAge+yourAge) / 2\n\n\tfmt.Println(average)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/01-arithmetic-operators/03-float-inaccuracy/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tratio := 1.0 / 10.0\n\n\t// after 10 operations\n\t// the inaccuracy is clear\n\t//\n\t// BTW, don't mind about this loop syntax for now\n\t// I'm going to explain it afterwards\n\tfor range [...]int{10: 0} {\n\t\tratio += 1.0 / 10.0\n\t}\n\n\tfmt.Printf(\"%.60f\", ratio)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/01-arithmetic-operators/03-float-inaccuracy/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Go compiler sees these numbers as integers,\n\t//   since, there are no fractional parts in\n\t//   integer values,\n\t// So, the result becomes 1 instead of 1.5\n\n\t// So, ratio variable here is an int variable,\n\t//   it's because, 3 divided by 2 results\n\t//   in an integer.\n\n\tratio := 3 / 2\n\n\tfmt.Printf(\"%d\", ratio)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/01-arithmetic-operators/03-float-inaccuracy/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// When you use a float value with an integer\n\t// in a calculation,\n\t// the result always becomes a float.\n\n\tratio := 3.0 / 2\n\n\t// OR:\n\t// ratio = 3 / 2.0\n\n\t// OR - if 3 is inside an int variable:\n\t// n := 3\n\t// ratio = float64(n) / 2\n\n\tfmt.Printf(\"%f\", ratio)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/02-arithmetic-operators-examples/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"sum :\", 3+2)   // sum - int\n\tfmt.Println(\"sum :\", 2+3.5) // sum - float64\n\tfmt.Println(\"dif :\", 3-1)   // difference - int\n\tfmt.Println(\"dif :\", 3-0.5) // difference - float64\n\tfmt.Println(\"prod:\", 4*5)   // product - int\n\tfmt.Println(\"prod:\", 5*2.5) // product - float64\n\tfmt.Println(\"quot:\", 8/2)   // quotient - int\n\tfmt.Println(\"quot:\", 8/1.5) // quotient - float64\n\n\t// remainder is only for integers\n\tfmt.Println(\"rem :\", 8%3)\n\t// fmt.Println(\"rem:\", 8.0%3) // error\n\n\t// you can do this\n\t// since the fractional part of a float is zero\n\tf := 8.0\n\tfmt.Println(\"rem :\", int(f)%3)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/02-arithmetic-operators-examples/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// what's the value of the ratio?\n\t// 3 / 2 = 1.5?\n\tvar ratio float64 = 3 / 2\n\tfmt.Println(ratio)\n\n\t// explain\n\t// above expression equals to this:\n\tratio = float64(int(3) / int(2))\n\tfmt.Println(ratio)\n\n\t// how to fix it?\n\t//\n\t// remember, when one of the values is a float value\n\t// the result becomes a float\n\tratio = float64(3) / 2\n\tfmt.Println(ratio)\n\n\t// or\n\tratio = 3.0 / 2\n\tfmt.Println(ratio)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/03-precedence/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\n\t\t2+2*4/2,\n\t\t2+((2*4)/2), // same as above\n\t)\n\n\tfmt.Println(\n\t\t1+4-2,\n\t\t(1+4)-2, // same as above\n\t)\n\n\tfmt.Println(\n\t\t(2+2)*4/2,\n\t\t(2+2)*(4/2), // same as above\n\t)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/03-precedence/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tn, m := 1, 5\n\n\tfmt.Println(2 + 1*m/n)\n\tfmt.Println(2 + ((1 * m) / n)) // same as above\n\n\t// let's change the precedence using parentheses\n\tfmt.Println(((2 + 1) * m) / n)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/03-precedence/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// // Precedence: Order of expressions\n\t// // Multiplication operators runs first: * and /\n\n\t// fmt.Println(\n\t// \t1 + 5 - 3*10/2,\n\t// )\n\n\t// // 3 * 10 = 30\n\t// // 30 / 2 = 15\n\t// // 1 + 5  = 6\n\t// // 6 - 15 = -9\n\n\t// // **** TIP ****\n\t// // Use parentheses to change the order of evaluation.\n\t// // First, (1+5-3), then (10/2) will be calculated.\n\n\t// fmt.Println(\n\t// \t(1 + 5 - 3) * (10 / 2),\n\t// )\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/03-precedence/04/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcelsius := 35.\n\n\t// Wrong formula  :  9*celsius + 160  / 5\n\t// Correct formula: (9*celsius + 160) / 5\n\tfahrenheit := (9*celsius + 160) / 5\n\n\tfmt.Printf(\"%g ºC is %g ºF\\n\", celsius, fahrenheit)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/04-incdec-statement/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar n int\n\n\t// ALTERNATIVES:\n\t// n = n + 1\n\t// n += 1\n\n\t// BETTER:\n\tn++\n\n\tfmt.Println(n)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/04-incdec-statement/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tn := 10\n\n\t// ALTERNATIVES:\n\t// n = n - 1\n\t// n -= 1\n\n\t// BETTER:\n\tn--\n\n\tfmt.Println(n)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/04-incdec-statement/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// incdec is a statement\n\nfunc main() {\n\tvar counter int\n\n\t// following \"statements\" are correct:\n\n\tcounter++ // 1\n\tcounter++ // 2\n\tcounter++ // 3\n\tcounter-- // 2\n\tfmt.Printf(\"There are %d line(s) in the file\\n\",\n\t\tcounter)\n\n\t// the following \"expressions\" are incorrect:\n\n\t// counter = 5+counter--\n\t// counter = ++counter + counter--\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/05-assignment-operations/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\twidth, height := 5., 12.\n\n\t// calculates the area of a rectangle\n\tarea := width * height\n\tfmt.Printf(\"%gx%g=%g\\n\", width, height, area)\n\n\tarea = area - 10 // decreases area by 10\n\tarea = area + 10 // increases area by 10\n\tarea = area * 2  // doubles the area\n\tarea = area / 2  // divides the area by 2\n\tfmt.Printf(\"area=%g\\n\", area)\n\n\t// // ASSIGNMENT OPERATIONS\n\tarea -= 10 // decreases area by 10\n\tarea += 10 // increases area by 10\n\tarea *= 2  // doubles the area\n\tarea /= 2  // divides the area by 2\n\tfmt.Printf(\"area=%g\\n\", area)\n\n\t// finds the remainder of area variable\n\t// since: area is float, this won't work:\n\t// area %= 7\n\n\t// this works\n\tarea = float64(int(area) % 7)\n\tfmt.Printf(\"area=%g\\n\", area)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/06-project-feet-to-meters/exercise-solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tc, _ := strconv.ParseFloat(os.Args[1], 64)\n\tf := c*1.8 + 32\n\n\t// Like this:\n\tfmt.Printf(\"%g ºC is %g ºF\\n\", c, f)\n\n\t// Or just like this (both are correct):\n\tfmt.Printf(\"%g ºF\\n\", f)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/06-project-feet-to-meters/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\targ := os.Args[1]\n\n\t// feet is a float64 now\n\tfeet, _ := strconv.ParseFloat(arg, 64)\n\n\tmeters := feet * 0.3048\n\n\tfmt.Printf(\"%f feet is %f meters.\\n\", feet, meters)\n\n\t// pretty print it:\n\n\t// fmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/01-do-some-calculations/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Do Some Calculations\n//\n//  1. Print the sum of 50 and 25\n//  2. Print the difference of 50 and 15.5\n//  3. Print the product of 50 and 0.5\n//  4. Print the quotient of 50 and 0.5\n//  5. Print the remainder of 25 and 3\n//  6. Print the negation of `5 + 2`\n//\n// EXPECTED OUTPUT\n//  75\n//  34.5\n//  25\n//  100\n//  1\n//  -7\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/01-do-some-calculations/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(50 + 25)\n\tfmt.Println(50 - 15.5)\n\tfmt.Println(50 * 0.5)\n\tfmt.Println(50 / 0.5)\n\tfmt.Println(25 % 3)\n\tfmt.Println(-(5 + 2))\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/02-fix-the-float/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Fix the Float\n//\n//  Fix the program to print 2.5 instead of 2\n//\n// EXPECTED OUTPUT\n//  2.5\n// ---------------------------------------------------------\n\nfunc main() {\n\tx := 5 / 2\n\tfmt.Println(x)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/02-fix-the-float/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Below solutions are correct:\n\tx := 5. / 2\n\t// x := 5 / 2.\n\t// x := float64(5) / 2\n\t// x := 5 / float64(2)\n\n\tfmt.Println(x)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/03-precedence/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Precedence\n//\n//  Change the expressions to produce the expected outputs\n//\n// RESTRICTION\n//  Use parentheses to change the precedence\n// ---------------------------------------------------------\n\nfunc main() {\n\t// This expression should print 20\n\tfmt.Println(10 + 5 - 5 - 10)\n\n\t// This expression should print -16\n\tfmt.Println(-10 + 0.5 - 1 + 5.5)\n\n\t// This expression should print -25\n\tfmt.Println(5 + 10*2 - 5)\n\n\t// This expression should print 0.5\n\tfmt.Println(0.5*2 - 1)\n\n\t// This expression should print 24\n\tfmt.Println(3 + 1/2*10 + 4)\n\n\t// This expression should print 15\n\tfmt.Println(10 / 2 * 10 % 7)\n\n\t// This expression should print 40\n\t// Note that you may need to use floats to solve this\n\tfmt.Println(100 / 5 / 2)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/03-precedence/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 10 + 5 - 5 - 10\n\tfmt.Println(10 + 5 - (5 - 10))\n\n\t// -10 + 0.5 - 1 + 5.5\n\tfmt.Println(-10 + 0.5 - (1 + 5.5))\n\n\t// 5 + 10*2 - 5\n\tfmt.Println(5 + 10*(2-5))\n\n\t// 0.5*2 - 1\n\tfmt.Println(0.5 * (2 - 1))\n\n\t// 3 + 1/2*10 + 4\n\tfmt.Println((3+1)/2*10 + 4)\n\n\t// 10 / 2 * 10 % 7\n\tfmt.Println(10 / 2 * (10 % 7))\n\n\t// 100 / 5 / 2\n\t// 5  / 2 = 2\n\t//  5 and 2 are integers, so, the fractional part drops\n\t// 5. / 2 = 2.5\n\t//  because 5. is a float, so the result becomes a float\n\tfmt.Println(100 / (5. / 2))\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/04-incdecs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Incdecs\n//\n//  1. Increase the `counter` 5 times\n//  2. Decrease the `factor` 2 times\n//  3. Print the product of counter and factor\n//\n// RESTRICTION\n//  Use only the incdec statements\n//\n// EXPECTED OUTPUT\n//  -75\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DO NOT TOUCH THIS\n\tcounter, factor := 45, 0.5\n\n\t// TYPE YOUR CODE BELOW\n\t// ...\n\n\t// LASTLY: REMOVE THE CODE BELOW\n\t_, _ = counter, factor\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/04-incdecs/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcounter, factor := 45, 0.5\n\n\tcounter++\n\tcounter++\n\tcounter++\n\tcounter++\n\tcounter++\n\n\tfactor--\n\tfactor--\n\n\tfmt.Println(float64(counter) * factor)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/05-manipulate-a-counter/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Manipulate a Counter\n//\n//  1. Write the simplest line of code to increase\n//     the counter variable by 1.\n//\n//  2. Write the simplest line of code to decrease\n//     the counter variable by 1.\n//\n//  3. Write the simplest line of code to increase\n//     the counter variable by 5.\n//\n//  4. Write the simplest line of code to multiply\n//     the counter variable by 10.\n//\n//  5. Write the simplest line of code to divide\n//     the counter variable by 5.\n//\n// EXPECTED OUTPUT\n//  10\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DO NOT CHANGE THE CODE BELOW\n\tvar counter int\n\n\t// TYPE YOUR CODE HERE\n\n\t// DO NOT CHANGE THE CODE BELOW\n\tfmt.Println(counter)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/05-manipulate-a-counter/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar counter int\n\n\tcounter++\n\tcounter--\n\n\tcounter += 5\n\tcounter *= 10\n\tcounter /= 5\n\n\tfmt.Println(counter)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/06-simplify-the-assignments/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Simplify the Assignments\n//\n//  Simplify the code (refactor)\n//\n// RESTRICTION\n//  Use only the incdec and assignment operations\n//\n// EXPECTED OUTPUT\n//  3\n// ---------------------------------------------------------\n\nfunc main() {\n\twidth, height := 10, 2\n\n\twidth = width + 1\n\twidth = width + height\n\twidth = width - 1\n\twidth = width - height\n\twidth = width * 20\n\twidth = width / 25\n\twidth = width % 5\n\n\tfmt.Println(width)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/06-simplify-the-assignments/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\twidth, height := 10, 2\n\n\twidth++\n\twidth += height\n\twidth--\n\twidth -= height\n\twidth *= 20\n\twidth /= 25\n\twidth %= 5\n\n\tfmt.Println(width)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/07-circle-area/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Circle Area\n//\n//  Calculate the area of a circle from the given radius\n//\n// CIRCLE AREA FORMULA\n//  area = πr²\n//  https://en.wikipedia.org/wiki/Area#Circles\n//\n// HINT\n//  For PI you can use `math.Pi`\n//\n// EXPECTED OUTPUT\n//  radius: 10 -> area: 314.1592653589793\n//\n// BONUS EXERCISE!\n//  1. Print the area as 314.16\n//  2. To do that you need to use the correct Printf verb :)\n//      Instead of `%g` verb below.\n//\n//    EXPECTED OUTPUT\n//     radius: 10 -> area: 314.16\n// ---------------------------------------------------------\n\nfunc main() {\n\tvar (\n\t\tradius = 10.\n\t\tarea   float64\n\t)\n\n\t// ADD YOUR CODE HERE\n\t// ...\n\n\t// DO NOT TOUCH THIS\n\tfmt.Printf(\"radius: %g -> area: %g\\n\", radius, area)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/07-circle-area/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n)\n\nfunc main() {\n\tvar (\n\t\tradius = 10.\n\t\tarea   float64\n\t)\n\n\tarea = math.Pi * radius * radius\n\n\tfmt.Printf(\"radius: %g -> area: %.2f\\n\",\n\t\tradius, area)\n\n\t// ALTERNATIVE:\n\t// math.Pow calculates the power of a float number\n\t// area = math.Pi * math.Pow(radius, 2)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/08-sphere-area/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Sphere Area\n//\n//  1. Get the radius from the command-line\n//  2. Convert it to a float64\n//  3. Calculate the surface area of a sphere\n//\n// SPHERE SURFACE AREA FORMULA\n//  area = 4πr²\n//  https://en.wikipedia.org/wiki/Sphere#Surface_area\n//\n// RESTRICTION\n//  Use `math.Pow` to calculate the area\n//  Read its documentation to see how it works.\n//  https://golang.org/pkg/math/#Pow\n//\n// EXPECTED OUTPUT\n//  go run main.go 10\n//    1256.64\n//\n//  go run main.go 54.2\n//    36915.47\n// ---------------------------------------------------------\n\nfunc main() {\n\tvar radius, area float64\n\n\t// ADD YOUR CODE HERE\n\t// ...\n\n\t// DO NOT TOUCH THIS\n\tfmt.Printf(\"radius: %g -> area: %.2f\\n\", radius, area)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/08-sphere-area/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tvar radius, area float64\n\n\tradius, _ = strconv.ParseFloat(os.Args[1], 64)\n\n\tarea = 4 * math.Pi * math.Pow(radius, 2)\n\n\tfmt.Printf(\"radius: %g -> area: %.2f\\n\",\n\t\tradius, area)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/09-sphere-volume/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Sphere Volume\n//\n//  1. Get the radius from the command-line\n//  2. Convert it to a float64\n//  3. Calculate the volume of a sphere\n//\n// SPHERE VOLUME FORMULA\n//  https://en.wikipedia.org/wiki/Sphere#Enclosed_volume\n//\n// RESTRICTION\n//  Use `math.Pow` to calculate the volume\n//\n// EXPECTED OUTPUT\n//  go run main.go 10\n//    4188.79\n//\n//  go run main.go .5\n//    0.52\n// ---------------------------------------------------------\n\nfunc main() {\n\tvar radius, vol float64\n\n\t// ADD YOUR CODE HERE\n\t// ...\n\n\t// DO NOT TOUCH THIS\n\tfmt.Printf(\"radius: %g -> volume: %.2f\\n\", radius, vol)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/09-sphere-volume/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tvar radius, vol float64\n\n\tradius, _ = strconv.ParseFloat(os.Args[1], 64)\n\n\tvol = (4 * math.Pi * math.Pow(radius, 3)) / 3\n\n\tfmt.Printf(\"radius: %g -> volume: %.2f\\n\", radius, vol)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/exercises/README.md",
    "content": "# Numbers, Precedence, and Assignment Operations\n\n1. **[Do Some Calculations](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/01-do-some-calculations)**\n\n2. **[Fix the Float](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/02-fix-the-float)**\n\n3. **[Precedence](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/03-precedence)**\n\n4. **[IncDecs](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/04-incdecs)**\n\n5. **[Manipulate a Counter](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/05-manipulate-a-counter)**\n\n6. **[Simplify the Assignments](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/06-simplify-the-assignments)**\n\n7. **[Circle Area](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/07-circle-area)**\n\n8. **[Sphere Area](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/08-sphere-area)**\n\n9. **[Sphere Volume](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/01-numbers/exercises/09-sphere-volume)**\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/questions/01-arithmetic-operators.md",
    "content": "## Which group of operators below is arithmetic operators?\n1. **, /, ^, !, ++, --\n2. *, /, %, +, - *CORRECT*\n3. &, |, +, -, /\n\n\n## Which value below you can use with a remainder operator?\n1. 3.54\n2. true\n3. 57 *CORRECT*\n4. \"Try Me!\"\n\n> **4:** Nice Try. But, that's not right. Sorry.\n>\n> **3:** That's right. The remainder operator only works on integer values.\n>\n\n\n## What's the result of this expression?\n```go\n8 % 3\n```\n1. 4\n2. 2 *CORRECT*\n3. 0\n4. 1 \n\n## What's the result of this expression?\n```go\n-(3 * -2)\n```\n1. -6\n2. -1\n3. 0\n4. 6 *CORRECT*\n\n\n## What's the result of this expression?\n```go\nvar degree float64 = 10 / 4\n```\n1. 2.5\n2. 2.49\n3. 2 *CORRECT*\n4. 0\n\n> **3:** That's right. An integer value cannot contain fractional parts.\n>\n\n\n## What's the result of this expression?\n```go\nvar degree float64 = 3. / 2\n```\n1. 1.5 *CORRECT*\n2. 1.49\n3. 1\n4. 0\n\n> **1:** That's right. `3.` makes the whole expression a float value.\n>\n\n\n## What's the type of the `x` variable?\n```go\nx := 5 * 2.\n```\n1. int\n2. float64 *CORRECT*\n3. bool\n4. string\n\n> **1:** Look closely to 2 there.\n>\n> **2:** Why? Because, `2.` there makes the expressions a float value. Cool.\n>\n> **3:** Oh, come on! Life is not always true and false.\n>\n> **4:** I can't see any double-quotes or back-quotes, can you?\n>\n\n\n## What's the type of the `x` variable?\n```go\nx := 5 * -(2)\n```\n1. int *CORRECT*\n2. float64\n3. bool\n4. string\n\n> **1:** Why? Because, there only integer numbers.\n>\n> **2:** I can't see any fractional parts there, can you?\n>\n> **3:** Oh, come on! Life is not always true and false.\n>\n> **4:** I can't see any double-quotes or back-quotes, can you?\n>\n\n\n## Which kind of values can result in inaccurate calculations?\n1. integers\n2. floats *CORRECT*\n3. bools\n4. strings\n"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/questions/02-precedence.md",
    "content": "## What's the result of the expression?\n```go\n5 - 2 * 5 + 7\n```\n1. 2 *CORRECT*\n2. 22\n3. -19\n4. 36\n5. -12\n\n\n## What's the result of the expression?\n```go\n5 - (2 * 5) + 7\n```\n1. 2 *CORRECT*\n2. 22\n3. -19\n4. 36\n5. -12\n\n> **1:** The expression can also be: 5 + (2 * 5) + 7\n\n## What's the result of the expression?\n```go\n5 - 2 * (5 + 7)\n```\n1. 2\n2. 22\n3. -19 *CORRECT*\n4. 36\n5. -12\n\n\n## What's the result of the expression?\n```go\n5. -(2 * 5 + 7)\n```\n1. 2\n2. 22\n3. -19\n4. -12\n5. -12.0 *CORRECT*\n\n> **4:** You're close but remember! The result of an expression with floats and integers is always a float.\n>\n>"
  },
  {
    "path": "08-numbers-and-strings/01-numbers/questions/03-assignment-operations.md",
    "content": "## Which expression increases `n` by 1?\n```go\nvar n float64\n```\n1. `n = +1`\n2. `n = n++`\n3. `n = n + 1` *CORRECT*\n4. `++n`\n\n> **1:** This just assigns 1 to n.\n>\n> **2:** IncDec statement can't be used as an operator.\n>\n> **4:** Go doesn't support prefix incdec notation.\n>\n\n\n## Which expression decreases `n` by 1?\n```go\nvar n int\n```\n1. `n = -1`\n2. `n = n--`\n3. `n = n - 1` *CORRECT*\n4. `--n`\n\n> **1:** This just assigns -1 to n.\n>\n> **2:** IncDec statement can't be used as an operator.\n>\n> **4:** Go doesn't support prefix incdec notation.\n>\n\n\n## Which code below equals to `n = n + 1`?\n1. `n++` *CORRECT*\n2. `n = n++`\n3. `++n`\n4. `n = n ++ 1`\n\n> **2:** IncDec statement can't be used as an operator.\n>\n> **3:** Go doesn't support prefix incdec notation.\n>\n> **4:** What's that? ++?\n>\n\n\n## Which code below equals to `n = n + 1`?\n1. `n = n++`\n2. `n += 1` *CORRECT*\n3. `++n`\n4. `n = n ++ 1`\n\n> **1:** IncDec statement can't be used as an operator.\n>\n> **3:** Go doesn't support prefix incdec notation.\n>\n> **4:** What's that? ++?\n>\n\n\n## Which code below equals to `n -= 1`?\n1. `n = n--`\n2. `n += 1--`\n3. `n--` *CORRECT*\n4. `--n`\n\n> **1:** IncDec statement can't be used as an operator.\n>\n> **2:** IncDec statement can't be used as an operator. And also, you can't use it with `1--`. The value should be addressable. You're going to learn what that means soon.\n>\n> **4:** Go doesn't support prefix incdec notation.\n>\n\n\n## Which code below divides the `length` by 10?\n1. `length = length // 10`\n2. `length /= 10` *CORRECT*\n3. `length //= 10`\n\n> **1:** What's that? `//`?\n>\n> **2:** That's right. This equals to: `length = length / 10`\n>\n> **3:** What's that? `//=`?\n>\n\n\n## Which code below equals to `x = x % 2`?\n1. `x = x / 2`\n2. `x =% 2`\n3. `x %= 2` *CORRECT*\n\n> **1:** This is a division. You need to use the remainder operator.\n>\n> **2:** Close... But, the `%` operator is on the wrong side of the assignment.\n>\n\n\n## Which function below converts a string value into a float value?\n1. `fmtconv.ToFloat`\n2. `conv.ParseFloat`\n3. `strconv.ParseFloat` *CORRECT*\n4. `strconv.ToFloat`\n\n\n## Which code is correct?\nIf you don't remember it, this its function signature:\n```go\nfunc ParseFloat(s string, bitSize int) (float64, error)\n```\n1. `strconv.ParseFloat(\"10\", 128)`\n2. `strconv.ParseFloat(\"10\", 64)` *CORRECT*\n3. `strconv.ParseFloat(\"10\", \"64\")`\n4. `strconv.ParseFloat(10, 64)`\n\n> **1:** There are no 128-bit floating point values in Go (Actually there are, but they only belong to the compile-time).\n>"
  },
  {
    "path": "08-numbers-and-strings/02-strings/01-raw-string-literal/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// The type of a string and a raw string literal\n\t// is the same. They both are strings.\n\t//\n\t// So, they both can be used as a string value.\n\tvar s string\n\ts = \"how are you?\"\n\ts = `how are you?`\n\tfmt.Println(s)\n\n\t// string literal\n\ts = \"<html>\\n\\t<body>\\\"Hello\\\"</body>\\n</html>\"\n\tfmt.Println(s)\n\n\t// raw string literal\n\ts = `\n<html>\n\t<body>\"Hello\"</body>\n</html>`\n\n\tfmt.Println(s)\n\n\t// windows path\n\tfmt.Println(\"c:\\\\my\\\\dir\\\\file\") // string literal\n\tfmt.Println(`c:\\my\\dir\\file`)    // raw string literal\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/02-concatenation/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tname, last := \"carl\", \"sagan\"\n\n\tfmt.Println(name + \" \" + last)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/02-concatenation/02-assignment-operation/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tname, last := \"carl\", \"sagan\"\n\n\t// assignment operation using string concat\n\tname += \" edward\"\n\n\t// equals to this:\n\t// name = name + \" edward\"\n\n\tfmt.Println(name + \" \" + last)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/02-concatenation/03-concat-non-strings/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tfmt.Println(\n\t\t\"hello\" + \", \" + \"how\" + \" \" + \"are\" + \" \" + \"today?\",\n\t)\n\n\t// you can combine raw string and string literals\n\tfmt.Println(\n\t\t`hello` + `, ` + `how` + ` ` + `are` + ` ` + \"today?\",\n\t)\n\n\t// ------------------------------------------\n\t// Converting non-string values into string\n\t// ------------------------------------------\n\n\teq := \"1 + 2 = \"\n\tsum := 1 + 2\n\n\t// invalid op\n\t// string concat op can only be used with strings\n\t// fmt.Println(eq + sum)\n\n\t// you need to convert it using strconv.Itoa\n\t// Itoa = Integer to ASCII\n\n\tfmt.Println(eq + strconv.Itoa(sum))\n\n\t//\n\n\t// invalid op\n\t// eq = true + \" \" + false\n\n\teq = strconv.FormatBool(true) +\n\t\t\" \" +\n\t\tstrconv.FormatBool(false)\n\n\tfmt.Println(eq)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/03-string-length/01-len/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tname := \"carl\"\n\n\t// strings are made up of bytes\n\t// len function counts the bytes in a string value\n\tfmt.Println(len(name))\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/03-string-length/02-unicode-len/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unicode/utf8\"\n)\n\nfunc main() {\n\t// strings are made up of bytes\n\n\t// len function counts the bytes in a string value.\n\t//\n\t// This string literal contains unicode characters.\n\t//\n\t// And, unicode characters can be 1-4 bytes.\n\t// So, \"İnanç\" is 7 bytes long, not 5.\n\t//\n\t// İ = 2 bytes\n\t// n = 1 byte\n\t// a = 1 byte\n\t// n = 1 byte\n\t// ç = 2 bytes\n\t// TOTAL = 7 bytes\n\tname := \"İnanç\"\n\tfmt.Printf(\"%q is %d bytes\\n\", name, len(name))\n\n\t// To get the actual characters (or runes) inside\n\t// a utf-8 encoded string value, you should do this:\n\tfmt.Printf(\"%q is %d characters\\n\",\n\t\tname, utf8.RuneCountInString(name))\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/04-project-banger/exercise-solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"os\"\n\t\"strings\"\n)\n\n// NOTE: You should always pass it at least one argument\n\nfunc main() {\n\tmsg := os.Args[1]\n\n\t// it's important to calculate things only once\n\t// so, do not call the repeat function twice\n\t// calling it once is enough\n\tmarks := strings.Repeat(\"!\", len(msg))\n\ts := marks + msg + marks\n\ts = strings.ToUpper(s)\n\n\t// you can also type this program more concisely\n\t// like this:\n\t//\n\t// msg := strings.ToUpper(os.Args[1])\n\t// marks := strings.Repeat(\"!\", len(msg))\n\t// fmt.Println(marks + msg + marks)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/04-project-banger/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\n// NOTE: You should always pass it at least one argument\n\nfunc main() {\n\tmsg := os.Args[1]\n\tl := len(msg)\n\n\ts := msg + strings.Repeat(\"!\", l)\n\ts = strings.ToUpper(s)\n\n\tfmt.Println(s)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/README.md",
    "content": "# Basic Strings\n\n1. **[Windows Path](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/01-windows-path)**\n\n2. **[Print JSON](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/02-print-json)**\n\n3. **[Raw Concat](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/03-raw-concat)**\n\n4. **[Count the Chars](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/04-count-the-chars)**\n\n5. **[Improved Banger](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/05-improved-banger)**\n\n6. **[ToLowercase](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/06-tolowercase)**\n\n7. **[Trim It](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/07-trim-it)**\n\n8. **[Right Trim It](https://github.com/inancgumus/learngo/tree/master/08-numbers-and-strings/02-strings/exercises/08-right-trim-it)**\n\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/01-windows-path/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Windows Path\n//\n//  1. Change the following program\n//  2. It should use a raw string literal instead\n//\n// HINT\n//  Run this program first to see its output.\n//  Then you can easily understand what it does.\n//\n// EXPECTED OUTPUT\n//  Your solution should output the same as this program.\n//  Only that it should use a raw string literal instead.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// HINTS:\n\t// \\\\ equals to backslash character\n\t// \\n equals to newline character\n\n\tpath := \"c:\\\\program files\\\\duper super\\\\fun.txt\\n\" +\n\t\t\"c:\\\\program files\\\\really\\\\funny.png\"\n\tfmt.Println(path)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/01-windows-path/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// this one uses a raw string literal\n\n\t// can you see how readable it is?\n\t// compared to the previous one?\n\n\tpath := `c:\\program files\\duper super\\fun.txt\nc:\\program files\\really\\funny.png`\n\n\tfmt.Println(path)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/02-print-json/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Print JSON\n//\n//  1. Change the following program\n//  2. It should use a raw string literal instead\n//\n// HINT\n//  Run this program first to see its output.\n//  Then you can easily understand what it does.\n//\n// EXPECTED OUTPUT\n//  Your solution should output the same as this program.\n//  Only that it should use a raw string literal instead.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// HINTS:\n\t// \\t equals to TAB character\n\t// \\n equals to newline character\n\t// \\\" equals to double-quotes character\n\n\tjson := \"\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\t\\\"Items\\\": [{\\n\" +\n\t\t\"\\t\\t\\\"Item\\\": {\\n\" +\n\t\t\"\\t\\t\\t\\\"name\\\": \\\"Teddy Bear\\\"\\n\" +\n\t\t\"\\t\\t}\\n\" +\n\t\t\"\\t}]\\n\" +\n\t\t\"}\\n\"\n\n\tfmt.Println(json)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/02-print-json/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// this one uses a raw string literal\n\n\t// can you see how readable it is?\n\t// compared to the previous one?\n\n\tjson := `\n{\n\t\"Items\": [{\n\t\t\"Item\": {\n\t\t\t\"name\": \"Teddy Bear\"\n\t\t}\n\t}]\n}`\n\n\tfmt.Println(json)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/03-raw-concat/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Raw Concat\n//\n//  1. Initialize the name variable\n//     by getting input from the command line\n//\n//  2. Use concatenation operator to concatenate it\n//     with the raw string literal below\n//\n// NOTE\n//  You should concatenate the name variable in the correct\n//  place.\n//\n// EXPECTED OUTPUT\n//  Let's say that you run the program like this:\n//   go run main.go inanç\n//\n//  Then it should output this:\n//   hi inanç!\n//   how are you?\n// ---------------------------------------------------------\n\nfunc main() {\n\t// uncomment the code below\n\t// name := \"and get the name from the command-line\"\n\n\t// replace and concatenate the `name` variable\n\t// after `hi ` below\n\n\tmsg := `hi CONCATENATE-NAME-VARIABLE-HERE!\nhow are you?`\n\n\tfmt.Println(msg)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/03-raw-concat/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tname := os.Args[1]\n\n\tmsg := `hi ` + name + `!\nhow are you?`\n\n\tfmt.Println(msg)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/04-count-the-chars/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Count the Chars\n//\n//  1. Change the following program to work with unicode\n//     characters.\n//\n// INPUT\n//  \"İNANÇ\"\n//\n// EXPECTED OUTPUT\n//  5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// Currently it returns 7\n\t// Because, it counts the bytes...\n\t// It should count the runes (codepoints) instead.\n\t//\n\t// When you run it with \"İNANÇ\", it should return 5 not 7.\n\n\tlength := len(os.Args[1])\n\tfmt.Println(length)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/04-count-the-chars/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"unicode/utf8\"\n)\n\nfunc main() {\n\tlength := utf8.RuneCountInString(os.Args[1])\n\tfmt.Println(length)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/05-improved-banger/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Improved Banger\n//\n//  Change the Banger program the work with Unicode\n//  characters.\n//\n// INPUT\n//  \"İNANÇ\"\n//\n// EXPECTED OUTPUT\n//  İNANÇ!!!!!\n// ---------------------------------------------------------\n\nfunc main() {\n\tmsg := os.Args[1]\n\n\ts := msg + strings.Repeat(\"!\", len(msg))\n\n\tfmt.Println(s)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/05-improved-banger/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\t\"unicode/utf8\"\n)\n\nfunc main() {\n\tmsg := os.Args[1]\n\tl := utf8.RuneCountInString(msg)\n\n\ts := msg + strings.Repeat(\"!\", l)\n\n\tfmt.Println(s)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/06-tolowercase/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: ToLowercase\n//\n//  1. Look at the documentation of strings package\n//  2. Find a function that changes the letters into lowercase\n//  3. Get a value from the command-line\n//  4. Print the given value in lowercase letters\n//\n// HINT\n//  Check out the strings package from Go online documentation.\n//  You will find the lowercase function there.\n//\n// INPUT\n//  \"SHEPARD\"\n//\n// EXPECTED OUTPUT\n//  shepard\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/06-tolowercase/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(strings.ToLower(os.Args[1]))\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/07-trim-it/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Trim It\n//\n//  1. Look at the documentation of strings package\n//  2. Find a function that trims the spaces from\n//     the given string\n//  3. Trim the text variable and print it\n//\n// EXPECTED OUTPUT\n//  The weather looks good.\n//  I should go and play.\n// ---------------------------------------------------------\n\nfunc main() {\n\tmsg := `\n\t\n\tThe weather looks good.\nI should go and play.\n\n\n\n\t`\n\n\tfmt.Println(msg)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/07-trim-it/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tmsg := `\n\t\n\tThe weather looks good.\nI should go and play.\n\n\n\n\t`\n\n\tfmt.Println(strings.TrimSpace(msg))\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/08-right-trim-it/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Right Trim It\n//\n//  1. Look at the documentation of strings package\n//  2. Find a function that trims the spaces from\n//     only the right-most part of the given string\n//  3. Trim it from the right part only\n//  4. Print the number of characters it contains.\n//\n// RESTRICTION\n//  Your program should work with unicode string values.\n//\n// EXPECTED OUTPUT\n//  5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// currently it prints 17\n\t// it should print 5\n\n\tname := \"inanç           \"\n\tfmt.Println(len(name))\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/exercises/08-right-trim-it/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"unicode/utf8\"\n)\n\nfunc main() {\n\tname := \"inanç           \"\n\n\tname = strings.TrimRight(name, \" \")\n\tl := utf8.RuneCountInString(name)\n\n\tfmt.Println(l)\n}\n"
  },
  {
    "path": "08-numbers-and-strings/02-strings/questions/questions.md",
    "content": "## What's the result of this expression?\n```go\n\"\\\"Hello\\\\\"\" + ` \\\"World\\\"`\n```\n\n1. \"Hello\" \"World\"\n2. \"Hello\" \\\"World\\\" *CORRECT*\n3. \"Hello\" `\"World\"`\n4. \"\\\"Hello\\\" `\\\"World\\\"`\"\n\n> **1:** Go doesn't interpret the escape sequences in raw string literals.\n>\n> **2:** That's right. Go interprets `\\\"` as `\"` but it doesn't do so for ` \\\"World\\\"`.\n>\n\n\n## What's the best way to represent the following text in the code?\n```xml\n<xml>\n  <items>\n    <item>\"Teddy Bear\"</item>\n  </items>\n</xml>\n```\n\n1. *CORRECT*\n```go\n`<xml>\n    <items>\n        <item>\"Teddy Bear\"</item>\n    </items>\n</xml>`\n```\n\n2. \n```go\n\"<xml>\n    <items>\n        <item>\"Teddy Bear\"</item>\n    </items>\n</xml>\"\n```\n\n3. \n```go\n\"<xml>\n    <items>\n        <item>\\\"Teddy Bear\\\"</item>\n    </items>\n</xml>\"\n```\n\n4. \n```go\n`<xml>\n    <items>\n        <item>\\\"Teddy Bear\\\"</item>\n    </items>\n</xml>`\n```\n\n> **2-3:** You can't write a string literal like that. It can't be multiple-lines.\n>\n> **4:** You don't need to use escape sequences inside raw string literals.\n>\n\n\n## What's the result of the following expression?\n```go\nlen(\"lovely\")\n```\n\n1. 7\n2. 8\n3. 6 *CORRECT*\n4. 0\n\n> **2:** Remember! \"a\" is 1 char. `a` is also 1 char.\n>\n\n\n## What's the result of the following expression?\n```go\nlen(\"very\") + len(`\\\"cool\\\"`)\n```\n\n1. 8\n2. 12 *CORRECT*\n3. 16\n4. 10\n\n> **1:** There are also double-quotes, count them as well.\n>\n> **2:** That's right. Go doesn't interpreted \\\" in raw string literals.\n>\n> **3:** Remember! \"very\" is 4 characters. `very` is also 4 characters.\n>\n> **4:** Remember! Go doesn't interpreted \\\" in raw string literals.\n>\n\n\n## What's the result of the following expression?\n```go\nlen(\"very\") + len(\"\\\"cool\\\"\")\n```\n\n1. 8\n2. 12\n3. 16\n4. 10 *CORRECT*\n\n> **1:** There are also double-quotes, count them as well.\n>\n> **2:** Remember! Go interprets escape sequences in string literals.\n>\n> **4:** That's right. Go does interpret \\\" in a string literal. So, \"\\\"\" means \", which is 1 character.\n>\n\n\n## What's the result of the following expression?\n```go\nlen(\"péripatéticien\")\n```\n\n**HINT:** é is 2 bytes long. And, the len function counts the bytes not the letters.\n\n**USELESS INFORMATION:** \"péripatéticien\" means \"wanderer\".\n\n1. 14\n2. 16 *CORRECT*\n3. 18\n4. 20\n\n> **1:** Remember! é is 2 bytes long.\n>\n> **2:** An english letter is 1 byte long. However, é is 2 bytes long. So, that makes up 16 bytes. Cool.\n>\n> **3:** You didn't count the double-quotes, did you?\n>\n\n\n## How can you find the correct length of the characters in this string literal?\n```go\n\"péripatéticien\"\n```\n\n1. `len(péripatéticien)`\n2. `len(\"péripatéticien\")`\n3. `utf8.RuneCountInString(\"péripatéticien\")` *CORRECT*\n4. `unicode/utf8.RuneCountInString(\"péripatéticien\")`\n\n> **1:** Where are the double-quotes?\n>\n> **2:** This only finds the bytes in a string value.\n>\n> **4:** You're close. But, the package's name is utf8 not unicode/utf8.\n>\n\n\n## What's the result of the following expression?\n```go\nutf8.RuneCountInString(\"péripatéticien\")\n```\n\n1. 16\n2. 14 *CORRECT*\n3. 18\n4. 20\n\n> **1:** This is its byte count. `RuneCountInString` counts the runes (codepoints) not the bytes.\n>\n> **2:** That's right. `RuneCountInString` returns the number of runes (codepoints) in a string value.\n>\n\n\n## Which package contains string manipulation functions?\n1. string\n2. unicode/utf8\n3. strings *CORRECT*\n4. unicode/strings\n\n\n## What's the result of this expression?\n```go\nstrings.Repeat(\"*x\", 3) + \"*\"\n```\n\n**HINT:** Repeat function repeats the given string.\n\n1. `*x*x*x`\n2. `x*x*x`\n3. `*x3`\n4. `*x*x*x*` *CORRECT*\n\n> **1:** You're close but you missed the concatenation at the end.\n>\n> **2:** Look closely.\n>\n> **3:** Wow! You should really watch the lectures again. Sorry.\n>\n> **4:** That's right. Repeat function repeats the given string. And, the concatenation operator combines the strings.\n>\n\n\n## What's the result of this expression?\n```go\nstrings.ToUpper(\"bye bye \") + \"see you!\"\n```\n\n1. `bye bye see you!`\n2. `BYE BYE SEE YOU!`\n3. `bye bye + see you!`\n4. `BYE BYE see you!` *CORRECT*\n\n> **1:** You missed the ToUpper?\n>\n> **2:** You're close but look closely. ToUpper only changes the first part of the string there.\n>\n> **3:** Not even close. Sorry.\n>\n> **4:** Perfect! Good catch! ToUpper only changes the first part of the string there.\n>"
  },
  {
    "path": "09-go-type-system/01-bits/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// %b verb prints bits\n\n\t// true false, on off, ...\n\t// 1 bit can encode 2 different state: 0 or 1\n\tfmt.Printf(\"%b\\n\", 0)\n\tfmt.Printf(\"%b\\n\", 1)\n\n\t// 2 bits can encode 4 different states\n\t// 0 0\n\t// 0 1\n\t// 1 0\n\t// 1 1\n\n\t// %02b prints 2 bits with leading zeros if any\n\n\tfmt.Printf(\"%02b = %d\\n\", 0, 0)\n\tfmt.Printf(\"%02b = %d\\n\", 1, 1)\n\tfmt.Printf(\"%02b = %d\\n\", 2, 2)\n\tfmt.Printf(\"%02b = %d\\n\", 3, 3)\n\n\t// run this and analyze:\n\t// how 1 moves from right to the left\n\n\t// %08b prints 8 bits with leading zeros if any\n\n\tfmt.Printf(\"%08b = %d\\n\", 1, 1)\n\tfmt.Printf(\"%08b = %d\\n\", 2, 2)\n\tfmt.Printf(\"%08b = %d\\n\", 4, 4)\n\tfmt.Printf(\"%08b = %d\\n\", 8, 8)\n\tfmt.Printf(\"%08b = %d\\n\", 16, 16)\n\tfmt.Printf(\"%08b = %d\\n\", 32, 32)\n\tfmt.Printf(\"%08b = %d\\n\", 64, 64)\n\tfmt.Printf(\"%08b = %d\\n\", 128, 128)\n\n\t// ------------------------------------------------\n\t// How to calculate bits?\n\t// ------------------------------------------------\n\n\t// note: ^ means power of.\n\t//       for example: 2^2 means 2 * 2     = 4\n\t//                or: 2^3 means 2 * 2 * 2 = 8\n\n\t// 0 0 0 0 0 0 1 0 is equal to 2 because:\n\t// ^ ^ ^ ^ ^ ^ ^ ^\n\t// | | | | | | | |\n\t// | | | | | | | +-> 2^0 * 0 = 0\n\t// | | | | | | +---> 2^1 * 1 = 2\n\t// | | | | | +-----> 2^2 * 0 = 0\n\t// | | | | +-------> 2^3 * 0 = 0\n\t// | | | +---------> 2^4 * 0 = 0\n\t// | | +-----------> 2^5 * 0 = 0\n\t// | +-------------> 2^6 * 0 = 0\n\t// +---------------> 2^7 * 0 = 0\n\t//                   ------------+\n\t//                             2\n\n\ti, _ := strconv.ParseInt(\"00000010\", 2, 64)\n\tfmt.Println(i)\n\n\t// 0 0 0 1 0 1 1 0 is equal to 22 because:\n\t// ^ ^ ^ ^ ^ ^ ^ ^\n\t// | | | | | | | |\n\t// | | | | | | | +-> 2^0 * 0 = 0\n\t// | | | | | | +---> 2^1 * 1 = 2\n\t// | | | | | +-----> 2^2 * 1 = 4\n\t// | | | | +-------> 2^3 * 0 = 0\n\t// | | | +---------> 2^4 * 1 = 16\n\t// | | +-----------> 2^5 * 0 = 0\n\t// | +-------------> 2^6 * 0 = 0\n\t// +---------------> 2^7 * 0 = 0\n\t//                   ------------+\n\t//                             22\n\n\ti, _ = strconv.ParseInt(\"00010110\", 2, 64)\n\tfmt.Println(i)\n}\n"
  },
  {
    "path": "09-go-type-system/02-bytes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// byte is an integer number with 8 bits (1 byte)\n\tvar b byte\n\n\t// all bits are empty or 0\n\t// this is the minimum number a byte can represent\n\tb = 0\n\tfmt.Printf(\"%08b = %d\\n\", b, b)\n\n\t// all bits are full or 1\n\t// this is the maximum number a byte can represent\n\tb = 255\n\tfmt.Printf(\"%08b = %d\\n\", b, b)\n}\n"
  },
  {
    "path": "09-go-type-system/03-predeclared-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"unsafe\"\n)\n\nfunc main() {\n\t// you can find the limits of numerics types\n\t// in the math package\n\tfmt.Println(\"int8   :\", math.MinInt8, math.MaxInt8)\n\tfmt.Println(\"int16  :\", math.MinInt16, math.MaxInt16)\n\tfmt.Println(\"int32  :\", math.MinInt32, math.MaxInt32)\n\tfmt.Println(\"int64  :\", math.MinInt64, math.MaxInt64)\n\n\t// unsigned type can only represent positive integers\n\tfmt.Println(\"uint8  :\", 0, math.MaxUint8)\n\tfmt.Println(\"uint16 :\", 0, math.MaxUint16)\n\tfmt.Println(\"uint32 :\", 0, math.MaxUint32)\n\tfmt.Println(\"uint64 :\", 0, uint64(math.MaxUint64))\n\t// You can't print MaxUint64 directly\n\t// Its size is way bigger for the runtime\n\t// It can only be used in constant expressions\n\n\t// e means zeros after the number (scientific notation)\n\t// 1e1, is 10 1e2, is 100, 12e1 is 120\n\tfmt.Println(\"float32:\", math.SmallestNonzeroFloat32,\n\t\tmath.MaxFloat32)\n\tfmt.Println(\"float64:\", math.SmallestNonzeroFloat64,\n\t\tmath.MaxFloat64)\n\n\t// memory costs\n\tfmt.Println(\"int    :\", unsafe.Sizeof(int(1)), \"bytes\")\n\tfmt.Println(\"int8   :\", unsafe.Sizeof(int8(1)), \"bytes\")\n\tfmt.Println(\"int16  :\", unsafe.Sizeof(int16(1)), \"bytes\")\n\tfmt.Println(\"int32  :\", unsafe.Sizeof(int32(1)), \"bytes\")\n\tfmt.Println(\"int64  :\", unsafe.Sizeof(int64(1)), \"bytes\")\n\n\tfmt.Println(\"uint   :\", unsafe.Sizeof(uint(1)), \"bytes\")\n\tfmt.Println(\"uint8  :\", unsafe.Sizeof(uint8(1)), \"bytes\")\n\tfmt.Println(\"uint16 :\", unsafe.Sizeof(uint16(1)), \"bytes\")\n\tfmt.Println(\"uint32 :\", unsafe.Sizeof(uint32(1)), \"bytes\")\n\tfmt.Println(\"uint64 :\", unsafe.Sizeof(uint64(1)), \"bytes\")\n\n\tfmt.Println(\"float32:\", unsafe.Sizeof(float32(1)), \"bytes\")\n\tfmt.Println(\"float64:\", unsafe.Sizeof(float64(1)), \"bytes\")\n\n\tfmt.Println(\"hello  :\", len(\"hello\")+8, \"bytes\")\n\tfmt.Println(\"hi     :\", len(\"hi\")+8, \"bytes\")\n}\n"
  },
  {
    "path": "09-go-type-system/04-overflow/01-problem/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\twidth  uint8 = 255\n\t\theight       = 255 // int\n\t)\n\n\twidth++\n\n\tif int(width) < height {\n\t\tfmt.Println(\"height is greater\")\n\t}\n\n\tfmt.Printf(\"width: %d height: %d\\n\", width, height)\n}\n"
  },
  {
    "path": "09-go-type-system/04-overflow/02-explain/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n)\n\nfunc main() {\n\t// go catches overflow at compile-time\n\t//\n\t// fmt.Println(int8(math.MaxInt8 + 1)) // overflows\n\n\t// but it cannot catch them in runtime\n\tvar n int8 = math.MaxInt8\n\n\t// wrap arounds to its negative maximum\n\tfmt.Println(\"max int8     :\", n)   // 127\n\tfmt.Println(\"max int8 + 1 :\", n+1) // -128\n\n\t// wrap arounds to its positive maximum\n\tn = math.MinInt8\n\tfmt.Println(\"min int8     :\", n)   // -128\n\tfmt.Println(\"min int8 - 1 :\", n-1) // 127\n\n\t// wrap arounds to its maximum\n\tvar un uint8\n\n\tfmt.Println(\"max uint8    :\", un)   // 0\n\tfmt.Println(\"max uint8 - 1:\", un-1) // 255\n\n\t// wrap around to its minimum\n\tun = math.MaxUint8\n\tfmt.Println(\"max uint8 + 1:\", un+1) // 0\n\n\t// floats goes to infinity when overflowed\n\tf := float32(math.MaxFloat32)\n\tfmt.Println(\"max float    :\", f*1.2)\n}\n"
  },
  {
    "path": "09-go-type-system/04-overflow/03-destructive/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// uint16 max value is 65535\n\tbig := uint16(65535)\n\n\t// uint8 destroys its value\n\t// to its own max value which is 255\n\t//\n\t// 65535 - 255 is lost.\n\tsmall := uint8(big)\n\n\t// fmt.Printf(\"%b %d\\n\", big, big)\n\t// fmt.Printf(\"%b %[1]d\\n\", big)\n\n\tfmt.Printf(\"%016b %[1]d\\n\", big)\n\tfmt.Printf(\"%016b %[1]d\\n\", small)\n}\n"
  },
  {
    "path": "09-go-type-system/05-defined-types/01-duration-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\th, _ := time.ParseDuration(\"4h30m\")\n\n\t// why would you want to create a new type?\n\n\t// 1- adding new methods to the type\n\tfmt.Println(h.Hours(), \"hours\")\n\n\t// 2- make it a distinct type for type-safety\n\t// you can't use the defined type\n\t//   with its underlying type directly.\n\t//\n\t// you need to convert one of them.\n\tvar m int64 = 2\n\th *= time.Duration(m)\n\tfmt.Println(h)\n\n\t// type of `h` and its underlying type are different\n\tfmt.Printf(\"Type of h: %T\\n\", h)\n\tfmt.Printf(\"Type of h's underlying type: %T\\n\", int64(h))\n}\n"
  },
  {
    "path": "09-go-type-system/05-defined-types/02-type-definition-create-your-own-type/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// type definitions usually declared at the package level\n//\n// EXERCISE: Move the declaration into main()'s scope\n//\ntype (\n\tgram  float64 // float64 is the underlying type of gram\n\tounce float64 // float64 is the underlying type of ounce\n)\n\n// above code is the same as the following:\n// type gram  float64\n// type ounce float64\n\nfunc main() {\n\t// type definitions are also allowed in blocks\n\n\t// underlying types are the same\n\tvar g gram = 1000 // gram  -> float64\n\tvar o ounce       // ounce -> float64\n\n\t// when the underlying types are the same\n\t// then they can be converted between:\n\t// gram, ounce or float64\n\n\t// afterwards, you'll see also that,\n\t// the important thing is the structure\n\t// of the type. not just its name.\n\t//\n\t// float64 has the real structure, representation,\n\t// and size.\n\t//\n\t// so, it gives the structure to the newly defined type.\n\n\t// TYPE ERROR: ounce and grams are different types\n\t// o = g * 0.035274\n\n\t// BUT: They're convertable to each other\n\to = ounce(g) * 0.035274\n\n\tfmt.Printf(\"%g grams is %.2f ounce\\n\", g, o)\n}\n"
  },
  {
    "path": "09-go-type-system/05-defined-types/03-underlying-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/inancgumus/learngo/09-go-type-system/05-defined-types/03-underlying-types/weights\"\n)\n\ntype (\n\t// Gram underlying type is int\n\tGram int\n\n\t// Kilogram underlying type is int\n\tKilogram Gram\n\n\t// Ton underlying type is int\n\tTon Kilogram\n)\n\nfunc main() {\n\tvar (\n\t\tsalt   Gram     = 100\n\t\tapples Kilogram = 5\n\t\ttruck  Ton      = 10\n\t)\n\n\t// types with different names cannot be used together\n\t// salt = apples\n\t// apples = truck\n\n\t// since their underlying type is int\n\t// they can be converted to any type\n\t//   with an underlying type of int\n\tsalt = Gram(apples)\n\tapples = Kilogram(truck)\n\ttruck = Ton(Kilogram(Gram(int(apples))))\n\n\tfmt.Printf(\"salt: %d, apples: %d, truck: %d\\n\",\n\t\tsalt, apples, truck)\n\n\t// -----------------------------------------------------\n\t// TYPES FROM DIFFERENT PACKAGES\n\t// -----------------------------------------------------\n\n\t// Gram and weights.Gram are different types\n\n\t// You cannot do this\n\t// salt = weights.Gram(100)\n\n\t// But, you can convert it back to Gram\n\t// Since, their underlying type is int\n\tsalt = Gram(weights.Gram(100))\n\n\tfmt.Printf(\"Type of weights.Gram: %T\\n\", weights.Gram(1))\n\tfmt.Printf(\"Type of main.Gram   : %T\\n\", Gram(1))\n\n\t// You can declare a new type\n\t// from a type of an external package\n\ttype myGram weights.Gram\n\n\tvar pepper myGram = 20\n\tpepper = myGram(salt)\n\n\tfmt.Printf(\"Type of pepper      : %T\\n\", pepper)\n}\n"
  },
  {
    "path": "09-go-type-system/05-defined-types/03-underlying-types/weights/weights.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage weights\n\ntype (\n\t// Gram underlying type is int64\n\tGram int\n\n\t// Kilogram underlying type is int64\n\tKilogram Gram\n\n\t// Ton underlying type is int64\n\tTon Kilogram\n)\n"
  },
  {
    "path": "09-go-type-system/06-aliased-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// aliased types are the same types\n\t// just with different names\n\t// for readability and refactoring\n\tvar (\n\t\t// type byte = int8\n\t\tbyteVal  byte\n\t\tuint8Val uint8\n\t\tintVal   int\n\t)\n\n\tuint8Val = byteVal // ok\n\n\tvar (\n\t\t// type rune = int32\n\t\truneVal  rune\n\t\tint32Val int32\n\t)\n\n\truneVal = int32Val // ok\n\n\truneVal = rune(int32Val)\n\truneVal = rune(runeVal)\n\n\t// keep the compiler happy\n\t_, _, _, _ = byteVal, uint8Val, intVal, runeVal\n}\n\n// For the curious - compiler internals:\n// https://github.com/golang/go/blob/4f1f503373cda7160392be94e3849b0c9b9ebbda/src/cmd/compile/internal/gc/universe.go#L409\n"
  },
  {
    "path": "09-go-type-system/exercises/01-optimal-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Optimal Types\n//\n//  1. Choose the optimal data types for the given situations.\n//  2. Print them all\n//  3. Try converting them to lesser data types.\n//     For example try converting int64 variable to int32.\n//     Then observe the result.\n//     Search the web why the result is so?\n//\n// NOTE\n//  This is just an exercise for teaching you different\n//  data types. Do not apply it to the real-life.\n//\n//  As I said in the lectures that, premature optimization\n//  is not a good thing.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DONT FORGET: There are also unsigned data types.\n\t//              (For positive numbers)\n\n\t// DO NOT USE: int data type\n\t// Use only the ones with the bitsizes\n\n\t// ---\n\n\t// an english letter (search web for: ascii control code)\n\n\t// a non-english letter (search web for: unicode codepoint)\n\n\t// a year in 4 digits like 2040\n\n\t// a month in 2 digits: 1 to 12\n\n\t// the speed of the light\n\n\t// angle of a circle\n\n\t// PI number: 3.141592653589793\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/01-optimal-types/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// an english letter (search web for: ascii control code)\n\tvar letter byte = 'A'\n\tfmt.Println(\"an english letter:\", letter)\n\n\t// a non-english letter (search web for: unicode codepoint)\n\tvar unicode rune\n\tunicode = 'Ç'\n\tfmt.Println(\"a non-english letter:\", unicode)\n\n\t// a year in 4 digits like 2040\n\tvar year uint16 = 2040\n\tfmt.Println(\"a year in 4 digits like 2040:\", year)\n\n\t// a month in 2 digits: 1 to 12\n\tvar month uint8 = 6\n\tfmt.Println(\"a month in 2 digits: 1 to 12:\", month)\n\n\t// the speed of the light\n\tvar lightSpeed uint32 = 670616629 // miles\n\tfmt.Println(\"the speed of the light:\", lightSpeed)\n\n\t// angle of a circle\n\tvar angle float32 = 35.8\n\tfmt.Println(\"angle of a circle:\", angle)\n\n\tvar pi float64\n\tpi = 3.141592653589793\n\tfmt.Println(\"PI number:\", pi)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/02-the-type-problem/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: The Type Problem\n//\n//  Solve the data type problem in the program.\n//\n// EXPECTED OUTPUT\n//  width: 265 height: 265\n//  are they equal? true\n// ---------------------------------------------------------\n\nfunc main() {\n\t// FIX THIS:\n\t// Change the following data types to the correct\n\t// data types where appropriate.\n\tvar (\n\t\twidth  uint8\n\t\theight uint16\n\t)\n\n\t// DONT TOUCH THIS:\n\twidth, height = 255, 265\n\twidth += 10\n\tfmt.Printf(\"width: %d height: %d\\n\", width, height)\n\n\t// UNCOMMENT THIS:\n\t// fmt.Println(\"are they equal?\", width == height)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/02-the-type-problem/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\twidth  uint16\n\t\theight uint16\n\t)\n\n\twidth, height = 255, 265\n\twidth += 10\n\n\tfmt.Printf(\"width: %d height: %d\\n\", width, height)\n\tfmt.Println(\"are they equal?\", width == height)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/03-parse-arg-numbers/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Parse Arg Numbers\n//\n//  Use strconv.ParseInt function to get int8, int16, and\n//  int32, and int64 values from command-line.\n//\n// HINT\n//  The third argument to ParseInt function represents\n//  the bitsize.\n//\n//  So, giving it 8 returns an int8 convertable value;\n//  whereas 16 returns an int16 convertable value.\n//\n//  Please explore the documentation of ParseInt function\n//  and learn how it works.\n//\n// EXPECTED OUTPUT\n//   When runned like this:\n//     go run main.go 50 25000 2000000 50000000000000000 00000100\n//\n//   It should return this:\n//     int8 value is : 50\n//     int16 value is: 25000\n//     int32 value is: 2000000\n//     int64 value is: 50000000000000000\n//     00000100 is: 4\n// ---------------------------------------------------------\n\nfunc main() {\n\t// --------------------------------------\n\t// EXAMPLE:\n\t// --------------------------------------\n\t// How to get an int8 from command-line:\n\t// First argument should be a value of -128 to 127 range\n\t//\n\t// Second argument: 10 means decimal number\n\t// Third argument : 8 means 8-bits (int8)\n\tval, _ := strconv.ParseInt(os.Args[1], 10, 8)\n\n\t// Now the val variable is int64 because ParseInt\n\t// returns an int64. But, since I passed 8 as its third\n\t// argument, it returns int8 convertable value.\n\t//\n\t// Try running the program with a value of -128 to 127\n\t// Running it beyond that range will result in\n\t// either -128 or 127.\n\tfmt.Println(\"int8 value is:\", int8(val))\n\n\t// --------------------------------------\n\t// NOW IT'S YOUR TURN!\n\t// --------------------------------------\n\n\t// 1. Get an int16 value using ParseInt and convert it and print it\n\n\t// 2. Get an int32 value using ParseInt and convert it and print it\n\n\t// 3. Get an int64 value using ParseInt and convert it and print it\n\n\t// 4. Get an int8 value using ParseInt and convert it and print it\n\t//    But this time, get the value in bits.\n\t//\n\t//    For example : 00000100\n\t//    Should print: 4\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/03-parse-arg-numbers/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// FOR EXAMPLE:\n\t//\n\t// Run this program with 5 arguments like this:\n\t//\n\t//                int8  int16  int32    int64       as bits\n\t// go run main.go 50    25000  2000000  5000000000  00000100\n\n\t// first argument is an int8\n\tval, _ := strconv.ParseInt(os.Args[1], 10, 8)\n\tfmt.Println(\"int8 value is :\", int8(val))\n\n\t// 2nd argument is an int16\n\tval, _ = strconv.ParseInt(os.Args[2], 10, 16)\n\tfmt.Println(\"int16 value is:\", int16(val))\n\n\t// 3rd argument is an int32\n\tval, _ = strconv.ParseInt(os.Args[3], 10, 32)\n\tfmt.Println(\"int32 value is:\", int32(val))\n\n\t// 4th argument is an int64\n\t// Remember ParseInt returns an int64\n\tval, _ = strconv.ParseInt(os.Args[4], 10, 64)\n\tfmt.Println(\"int64 value is:\", val)\n\n\t// 5th argument is a number in bits. And its int8.\n\t// ParseInt(.., 2, ...) -> 2 means binary base\n\tval, _ = strconv.ParseInt(os.Args[5], 2, 8)\n\tfmt.Printf(\"%s is: %d\\n\", os.Args[5], int8(val))\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/04-time-multiplier/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Time Multiplier\n//\n//  You should get an argument from the command-line and\n//  you need to multiply the time duration value `t` with\n//  the given argument.\n//\n//  1. Get an argument from the command-line\n//  2. Convert it to int64 and store it in a variable\n//  3. Multiply the `t` variable with that variable\n//  4. Print the result\n//\n// HINT\n//  You can use ParseInt to convert the command-line\n//    argument into an int64 value.\n//\n//  You can skip the error value using a blank-identifier.\n//\n// EXPECTED OUTPUT\n//\n//  When runned like this:\n//    go run main.go 2\n//\n//  It should print this:\n//    3h0m0s\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DONT TOUCH THIS\n\t// 1h30m means: 1 hour 30 minutes\n\tt, _ := time.ParseDuration(\"1h30m\")\n\n\t// TYPE YOUR CODE HERE\n\t// ....\n\n\t// DONT TOUCH THIS\n\tfmt.Println(t)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/04-time-multiplier/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nfunc main() {\n\tt, _ := time.ParseDuration(\"1h30m\")\n\n\t// 1. get the first command-line argument\n\t// 2. convert it to int64\n\tmultiplier, _ := strconv.ParseInt(os.Args[1], 10, 64)\n\n\t// 3. multiply the time duration with the given argument\n\t//\n\t//    converts the int64 value to time.Duration to be\n\t//    able to multiply it with the time.Duration value\n\tt *= time.Duration(multiplier)\n\n\t// 4. print it\n\tfmt.Println(t)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/05-refactor-feet-to-meter/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor Feet to Meter\n//\n//  Remember the feet to meters program?\n//  Now, it's time to refactor it.\n//  Define your own Feet and Meters types.\n//\n//  Follow the steps inside the code.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ----------------------------\n\t// 1. Define Feet and Meters types below\n\t//    Their underlying type can be float64\n\t// ...\n\n\t// ----------------------------\n\t// 2. UNCOMMENT THE CODE BELOW THEN DON'T TOUCH IT\n\t// var (\n\t// \tfeet   Feet\n\t// \tmeters Meters\n\t// )\n\n\t// ----------------------------\n\t// 3. Get feet value from the command-line\n\t// 4. Convert it to an float64 first using ParseFloat\n\t// 5. Then, convert it into a Feet type\n\t// ... TYPE YOUR CODE HERE\n\n\t// ----------------------------\n\t// 6. Uncomment the code below\n\t// 7. And, convert the expression to Meters type\n\n\t// meters = feet * 0.3048\n\n\t// ----------------------------\n\t// 8. UNCOMMENT THE CODE BELOW\n\t// fmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/05-refactor-feet-to-meter/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// WHY ADDING YOUR OWN TYPES IS IMPORTANT?\n\t//\n\t// 1. Type-Safety\n\t// 2. Increased Readability\n\t// 3. Adding Methods to your Types\n\ttype (\n\t\tFeet   float64\n\t\tMeters float64\n\t)\n\n\tvar (\n\t\tfeet   Feet\n\t\tmeters Meters\n\t)\n\n\targ := os.Args[1]\n\n\t// feet is a Feet value now\n\tval, _ := strconv.ParseFloat(arg, 64)\n\tfeet = Feet(val)\n\n\t// meters is a Meters value now\n\tmeters = Meters(feet * 0.3048)\n\n\tfmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/06-convert-the-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Convert the Types\n//\n//  Convert the variables to appropriate types.\n//\n// EXPECTED OUTPUT\n//  325.5 299.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DONT TOUCH THIS:\n\ttype (\n\t\tTemperature float64\n\t\tCelsius     Temperature\n\t\tFahrenheit  Temperature\n\t)\n\n\t// DONT TOUCH THIS:\n\tvar (\n\t\tcelsius       Celsius     = 15.5\n\t\tfahr          Fahrenheit  = 59.9\n\t\tcelsiusDegree Temperature = 10.5\n\t\tfahrDegree    Temperature = 2.5\n\t\tfactor                    = 2.\n\t)\n\n\t// ----------------------------------------\n\t// FIX THE CODE BELOW:\n\t// You should solve it only by using conversions.\n\t// Do not change the code in any other way.\n\n\t// celsius *= celsiusDegree * factor\n\t// fahr *= fahrDegree * factor\n\n\t// ----------------------------------------\n\t// DONT TOUCH THIS\n\tfmt.Println(celsius, fahr)\n\n\t// YOU MAY REMOVE THESE WHEN YOU'RE DONE\n\t_, _, _ = celsiusDegree, fahrDegree, factor\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/06-convert-the-types/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ttype (\n\t\tTemperature float64\n\t\tCelsius     Temperature\n\t\tFahrenheit  Temperature\n\t)\n\n\tvar (\n\t\tcelsius       Celsius     = 15.5\n\t\tfahr          Fahrenheit  = 59.9\n\t\tcelsiusDegree Temperature = 10.5\n\t\tfahrDegree    Temperature = 2.5\n\t\tfactor                    = 2.\n\t)\n\n\tcelsius *= Celsius(float64(celsiusDegree) * factor)\n\tfahr *= Fahrenheit(float64(fahrDegree) * factor)\n\n\tfmt.Println(celsius, fahr)\n}\n"
  },
  {
    "path": "09-go-type-system/exercises/README.md",
    "content": "# Types\n\n1. **[Find the Optimal Types](https://github.com/inancgumus/learngo/tree/master/09-go-type-system/exercises/01-optimal-types)**\n\n2. **[Fix the Type Problem](https://github.com/inancgumus/learngo/tree/master/09-go-type-system/exercises/02-the-type-problem)**\n\n3. **[Parse Arg Numbers](https://github.com/inancgumus/learngo/tree/master/09-go-type-system/exercises/03-parse-arg-numbers)**\n\n4. **[Time Multiplier](https://github.com/inancgumus/learngo/tree/master/09-go-type-system/exercises/04-time-multiplier)**\n\n5. **[Refactor Feet to Meter](https://github.com/inancgumus/learngo/tree/master/09-go-type-system/exercises/05-refactor-feet-to-meter)**\n\n6. **[Convert the Types](https://github.com/inancgumus/learngo/tree/master/09-go-type-system/exercises/06-convert-the-types)**"
  },
  {
    "path": "09-go-type-system/questions/01-questions-predeclared-types.md",
    "content": "## Which one is **not** a predeclared data type of Go?\n1. int\n2. float64\n3. uint64\n4. uint\n5. duration *CORRECT*\n6. int8\n7. rune\n8. byte\n9. float32\n10. complex128\n\n\n## What's a predeclared data type?\n1. A data type used only in the compiler\n2. A built-in data type that comes with Go that you can use it from anywhere without importing any package *CORRECT*\n3. The data type of a variable\n\n\n## By using only 8 bits, how many different numbers or states can you represent?\n1. 8\n2. 16\n3. 256 *CORRECT*\n4. 65536\n\n> **3:** 2^8 is 256, so you can represent 256 different states.\n>\n\n\n## How many bits 2 bytes contains?\n1. 2\n2. 8\n3. 16 *CORRECT*\n4. 32\n5. 64\n\n\n## What's the output of the following code?\n```go\nfmt.Printf(\"%08b = %d\", 2, 2)\n```\n1. 00000001 = 2\n2. 00000010 = 2 *CORRECT*\n3. 00000100 = 2\n4. 00001000 = 2\n\n> EXPLANATION = From right to left, each bit goes from 2^0 to 2^(n - 1).\n\n> **1:** EXPLANATION. Here: 1 is the first digit from the right. So, it is 2^(1 - 1) = 2^0 = 1.\n>\n> **2:** EXPLANATION. Here: 1 is the second digit from the right. So, it is 2^(2 - 1) = 2^1 = 2.\n>\n> **3:** EXPLANATION. Here: 1 is the third digit from the right. So, it is 2^(3 - 1) = 2^2 = 4.\n>\n> **4:** EXPLANATION. Here: 1 is the fourth digit from the right. So, it is 2^(4 - 1) = 2^3 = 8.\n>\n\n\n## How many bytes of memory does an int64 value use?\n1. 4\n2. 8 *CORRECT*\n3. 32\n4. 64\n\n> **2:** 1 byte is 8 bits and int64 is 64 bits. So, 64/8=8 bytes.\n>\n\n\n## How many bytes are needed to store a value of uint32 type?\n1. 4 *CORRECT*\n2. 8\n3. 32\n4. 64\n\n> **2:** 1 byte is 8 bits and uint32 is 32 bits. So, 32/8=4 bytes.\n>\n\n\n## What's the size of int data type?\n1. Depends: 32 bits or 64 bits. *CORRECT*\n2. 32 bits\n3. 64 bits\n\n> **1:** That's right. Go can change its size at the compile-time depending on which target machine you're compiling your program into.\n>\n\n\n## English letters can be represented by the numbers within the range of: 0-255. For example, 'A' can be 65. Or, 'B' can be 66. So, what's the best data type for storing an English letter?\n\n1. byte *CORRECT*\n2. rune\n3. int64\n4. float64\n\n> **1:** That's right. A byte can represent 0-255 different values. So, it's a great fit for representing English letters, and numbers.\n>\n> **2:** In practice, you can do it with a rune value. However, rune is 32-bits long and it can store almost every letter in existince. I'm asking for the optimal data type. Try again.\n>\n> **3:** That would be too large for only 255 different numbers.\n>\n> **4:** Float is not the best data type for numbers without fractional parts.\n>\n\n\n\n## What does the following code print?\n```go\nvar letter uint8 = 255\nfmt.Print(letter + 5)\n```\n1. 0\n2. 4 *CORRECT*\n3. 5\n4. 260\n\n> **2:** Unsigned integers wrap around after their maximum capacity. Uint8's max is 255, so, if 255 + 1 is 0, then 255 + 5 is 4.\n>\n> **3:** You're very close.\n>\n> **4:** Uint8's max capacity is 255. It can't be 260.\n>\n\n\n## What does the following code print?\n```go\nvar num int8 = -128\nfmt.Print(num - 3)\n```\n1. -131\n2. 125 *CORRECT*\n3. -125\n\n> **1:** int8's min capacity is -128. It can't be -131.\n>\n> **2:** Signed integers wrap around after their minimum capacity. int8's min is -128, so, if -128 - 1 is 127, then -128 - 3 is 125.\n>\n"
  },
  {
    "path": "09-go-type-system/questions/02-questions-defined-types.md",
    "content": "## Why you want to define new types?\n1. To declare new methods\n2. For type-safety\n3. For readability and conveying meaning\n4. All of the options above *CORRECT*\n\n> **1-3:** Yes, that's only one of the reasons.\n>\n\n\n## Let's suppose that you've declared the following defined type. Which property below the new type doesn't get from its underlying type?\n\n```go\n// For example, let's say that you've defined a new type\n// using time.Duration type like this:\ntype Millennium time.Duration\n```\n1. Methods *CORRECT*\n2. Representation\n3. Size\n4. Range of values\n\n> **1:** That's right. A defined type doesn't get its source type's methods.\n>\n> **2-4:** Actually the defined type gets it from its underlying type.\n>\n\n\n## How to define a new type using float32?\n1. `var radius float32`\n2. `radius = type float32`\n3. `type radius float32` *CORRECT*\n4. `type radius = float32`\n\n> **1-2:** This is not a correct syntax.\n>\n> **3:** `radius` is a new type, defined using `float32`.\n>\n> **4:** This declares `radius` as an alias to `float32`. So, they become the same types.\n>\n\n\n## How to fix the following code?\n```go\ntype Distance int\n\nvar (\n    village Distance = 50\n    city = 100\n)\n\nfmt.Print(village + city)\n```\n1. `int(village + city)`\n2. `village + int(city)`\n3. `village(int) + city`\n4. `village + Distance(city)` *CORRECT*\n\n> **1-3:** There's a type mismatch in this code. But, this won't fix it.\n>\n> **4:** That's right. Now, the `city`'s type is Distance in the expression.\n>\n\n\n## For the following program which types you might want to declare?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n\tcelsius := 35.\n\tfahrenheit := (9*celsius + 160) / 5\n\tfmt.Printf(\"%g ºC is %g ºF\\n\", celsius, fahrenheit)\n}\n```\n\n1. Celsius and Fahrenheit using int64\n2. Celsius and Fahrenheit using float64 *CORRECT*\n3. Temperature using int64\n4. Temperature using uint32\n\n> **1:** But a degree value has a floating part. So, using an integer may not the best way.\n>\n> **2:** float64 can represent a degree value.\n>\n> **3-4:** But a degree value has a floating part. So, using an integer may not the best way. Also, there are two different temperature units here: Celsius and Fahrenheit. Isn't it better to create two distinct types?\n>\n\n\n## What's the underlying type of the Millennium type?\n```go\ntype (\n    Duration int64\n    Century Duration\n    Millennium Century\n)\n```\n1. `int64` *CORRECT*\n2. `Duration`\n3. `Century`\n4. Another type\n\n> **1:** That's right. Go's type system is flat. So, the defined type's underlying type is a type with a real structure. int64 is not just a name, it has its own structure, it's a predeclared type.\n>\n> **2:** Duration is just a new type name. It doesn't have its own structure.\n>\n> **3:** Century is just a new type name. It doesn't have its own structure.\n>\n\n\n## Which types do not need to be converted between each other?\n**HINT:** Aliased types do not require type conversion.\n\n1. byte and uint8 *CORRECT*\n2. byte and rune\n3. rune and uint8\n4. byte and uint32\n\n> **1:** byte data type is an alias to uint8 data type. So, they don't need conversion between each other. They're the same types.\n>\n\n\n## Which types do not need to be converted between each other?\n**HINT:** Aliased types do not require type conversion.\n\n1. byte and uint32\n2. byte and rune\n3. rune and int32 *CORRECT*\n4. byte and int8\n\n> **3:** rune data type is an alias to int32 data type. So, they don't need conversion between each other. They're the same types.\n>"
  },
  {
    "path": "10-constants/01-declarations/01-syntax/01-magic-numbers/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// This program uses magic values\n\nfunc main() {\n\tcm := 100\n\tm := cm / 100 // 100 is a magic value\n\tfmt.Printf(\"%dcm is %dm\\n\", cm, m)\n\n\tcm = 200\n\tm = cm / 100 // 100 is a magic value\n\tfmt.Printf(\"%dcm is %dm\\n\", cm, m)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/01-syntax/02-constants/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// This program uses a named constant\n// instead of a magic value\n\nfunc main() {\n\tconst meters int = 100\n\n\tcm := 100\n\tm := cm / meters // using a named constant\n\tfmt.Printf(\"%dcm is %dm\\n\", cm, m)\n\n\tcm = 200\n\tm = cm / meters // using a named constant\n\tfmt.Printf(\"%dcm is %dm\\n\", cm, m)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/01-syntax/03-safety/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Go can't catch the same error at runtime\n\t// When you run this, there will be an error:\n\t//\n\t// panic: runtime error: integer divide by zero\n\tn, m := 1, 0\n\tfmt.Println(n / m)\n\n\t// Go will detect the division by zero error\n\t// at compile-time\n\t//\n\t// const n int = 1\n\t// const m int = 0\n\t// fmt.Println(n / m)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/01-syntax/04-rules/01-immutability/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tconst max int = 100\n\n\t// ERROR: cannot assign to max\n\t//        constants are immutable (cannot change)\n\t// max = 100\n}\n"
  },
  {
    "path": "10-constants/01-declarations/01-syntax/04-rules/02-runtime-func/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n)\n\nfunc main() {\n\t// math.Pow calculates the power of the given number\n\tfmt.Println(math.Pow10(2)) // 100\n\tfmt.Println(math.Pow10(3)) // 1000\n\tfmt.Println(math.Pow10(4)) // 10000\n\n\t// ERROR: math.Pow is not a constant\n\t//        constants cannot use runtime constructs\n\n\t// const max int = math.Pow10(2)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/01-syntax/04-rules/03-runtime-var/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tn := 2\n\n\t// ERROR: n is not a constant\n\t// const max int = n\n\n\t_ = n\n}\n"
  },
  {
    "path": "10-constants/01-declarations/01-syntax/04-rules/04-len/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// When argument to len is a constant, len can be used\n\t// while initializing a constant\n\t//\n\t// Here, \"Hello\" is a constant.\n\n\tconst max int = len(\"Hello\")\n\n\tfmt.Println(max)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/02-constant-types-and-expressions/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min int = 1\n\tconst pi float64 = 3.14\n\tconst version string = \"2.0.1\"\n\tconst debug bool = true\n\tconst A rune = 'A'\n\n\tfmt.Println(min, pi, version, debug, A)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/02-constant-types-and-expressions/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min = 1\n\tconst pi = 3.14\n\tconst version = \"2.0.1\"\n\tconst debug = true\n\tconst A = 'A'\n\n\tfmt.Println(min, pi, version, debug, A)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/02-constant-types-and-expressions/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min = 1 + 1\n\tconst pi = 3.14 * min\n\tconst version = \"2.0.1\" + \"-beta\"\n\tconst debug = !true\n\tconst A rune = 'A' + 1\n\n\tfmt.Println(min, pi, version, debug, A)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/03-multiple-declaration/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// below declaration is the same as this one:\n\n\t// const (\n\t// \tmin int = 1\n\t// \tmax int = 1000\n\t// )\n\n\tconst min, max int = 1, 1000\n\n\tfmt.Println(min, max)\n\n\t// print the types of min and max\n\tfmt.Printf(\"%T %T\\n\", min, max)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/03-multiple-declaration/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// constants repeat the previous type and expression\n\tconst (\n\t\tmin int = 1\n\t\tmax     // int = 1\n\t)\n\n\tfmt.Println(min, max)\n\n\t// print the types of min and max\n\tfmt.Printf(\"%T %T\\n\", min, max)\n}\n"
  },
  {
    "path": "10-constants/01-declarations/03-multiple-declaration/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// constants repeat the previous type and expression\n\tconst (\n\t\tmin int = 1 + 1\n\t\tmax     // int = 1 + 1\n\t)\n\n\tfmt.Println(min, max)\n\n\t// print the types of min and max\n\tfmt.Printf(\"%T %T\\n\", min, max)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/01-typeless-constants/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// min and pi are typeless constants\n\tconst min = 1 + 1\n\tconst pi = 3.14 * min\n\n\tfmt.Println(min, pi)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/02-typed-vs-typeless/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min int = 42\n\n\tvar i int\n\ti = min // OK\n\n\tfmt.Println(i)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/02-typed-vs-typeless/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min int = 42\n\n\tvar f float64\n\n\t// ERROR: Type Mismatch\n\t// f = min // NOT OK\n\n\tfmt.Println(f)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/02-typed-vs-typeless/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min = 42\n\n\tvar f float64\n\n\tf = min // OK when min is typeless\n\n\tfmt.Println(f)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/02-typed-vs-typeless/04/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min = 42\n\n\t// I've removed int from the below declaration\n\t// since, min's default type is int (you'll learn)\n\tvar i = min\n\n\tvar f float64 = min\n\tvar b byte = min\n\tvar j int32 = min\n\tvar r rune = min\n\n\t// behind the scenes:\n\t// below statement equals to:\n\t//\n\t// var b byte = min\n\tb = byte(min)\n\n\tfmt.Println(i, f, b, j, r)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/03-default-type/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min int32 = 1\n\n\tmax := 5 + min\n\t// above line equals to this:\n\t// max := int32(5) + min\n\n\tfmt.Printf(\"Type of max: %T\\n\", max)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/03-default-type/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst min = 1\n\n\tmax := 5 + min\n\t// above line equals to this:\n\t// max := int(5) + int(min)\n\n\tfmt.Printf(\"Type of max: %T\\n\", max)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/03-default-type/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ti := 42\n\tf := 3.14\n\tb := true\n\ts := \"Hello\"\n\tr := 'A'\n\n\tfmt.Printf(\"i is %T\\n\", i)\n\tfmt.Printf(\"f is %T\\n\", f)\n\tfmt.Printf(\"b is %T\\n\", b)\n\tfmt.Printf(\"s is %T\\n\", s)\n\n\t// int32 = rune (type alias)\n\tfmt.Printf(\"r is %T\\n\", r)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/03-default-type/04/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ti := 42 + 3.14 // OK: 42 and 3.14 are typeless\n\n\t// above line equals to this:\n\t// i := float64(42 + 3.14)\n\n\tfmt.Printf(\"i is %T\\n\", i)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/03-default-type/05/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// NOT OK\n\t// \"Hello\" string literal cannot be converted\n\t//   into a bool value\n\t// f := true + \"Hello\"\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/04-demo/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\ttype Duration int64\n\n\tconst (\n\t\tNanosecond  Duration = 1\n\t\tMicrosecond          = 1000 * Nanosecond\n\t\tMillisecond          = 1000 * Microsecond\n\t\tSecond               = 1000 * Millisecond\n\t\tMinute               = 60 * Second\n\t\tHour                 = 60 * Minute\n\t)\n\n\t// The types are main.Duration instead of just Duration\n\t// It's because, Duration type now belongs to main func\n\tfmt.Printf(\"Nanosecond is %T\\n\", Nanosecond)\n\tfmt.Printf(\"Microsecond is %T\\n\", Microsecond)\n\tfmt.Printf(\"Millisecond is %T\\n\", Millisecond)\n\tfmt.Printf(\"Second is %T\\n\", Second)\n\tfmt.Printf(\"Minute is %T\\n\", Minute)\n\tfmt.Printf(\"Hour is %T\\n\", Hour)\n\n\t// Print the types of time.Duration constants directly\n\t// This time, types will be time.Duration\n\t// It's because, they're inside the time package\n\tfmt.Printf(\"Nanosecond is %T\\n\", time.Nanosecond)\n\tfmt.Printf(\"Microsecond is %T\\n\", time.Microsecond)\n\tfmt.Printf(\"Millisecond is %T\\n\", time.Millisecond)\n\tfmt.Printf(\"Second is %T\\n\", time.Second)\n\tfmt.Printf(\"Minute is %T\\n\", time.Minute)\n\tfmt.Printf(\"Hour is %T\\n\", time.Hour)\n}\n"
  },
  {
    "path": "10-constants/02-typeless-constants/04-demo/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\t// #1\n\tt := time.Second * 10\n\n\tfmt.Println(t)\n\n\t// #2\n\ti := 10\n\n\t// NOT OK\n\t// time.Duration and int are different types\n\t// t = time.Second * i\n\n\t// OK: i is int, Duration is int64\n\t//     So, i is convertable to int64\n\tt = time.Second * time.Duration(i)\n\n\tfmt.Println(t)\n\n\t// #3\n\tconst c = 10\n\n\t// OK: Because, c is typeless\n\tt = time.Second * c\n\n\tfmt.Println(t)\n}\n"
  },
  {
    "path": "10-constants/03-refactor-feet-to-meters/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\n// EXERCISE\n//\n// This program uses magic numbers\n// Refactor it and use named constants instead\n\nfunc main() {\n\targ := os.Args[1]\n\n\tfeet, _ := strconv.ParseFloat(arg, 64)\n\n\tmeters := feet * 0.3048\n\tyards := feet * 0.3333\n\n\tfmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n\tfmt.Printf(\"%g feet is %g yards.\\n\", feet, yards)\n}\n"
  },
  {
    "path": "10-constants/03-refactor-feet-to-meters/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"os\"\n\t\"strconv\"\n)\n\n// This program contains a lot of comments\n// Non-commented version is in /without-comments/main.go\n\nfunc main() {\n\t// You cannot use this syntax.\n\t//\n\t// feetInMeters is declared\n\t//   when the declaration completes,\n\t//   (at the end of the whole declaration)\n\t//\n\t// And, it's not easy to read\n\t//\n\t// const feetInMeters, feetInYards float64 = 0.3048,\n\t//   feetInMeters / 0.9144\n\n\tconst (\n\t\tfeetInMeters = 0.3048\n\t\tfeetInYards  = feetInMeters / 0.9144\n\n\t\t// cannot call runtime funcs\n\t\t// feetInYards = math.Round(feetInYards)\n\t)\n\n\t// Immutable: You cannot assign new values\n\t// feetInYards = 0.333333\n\n\targ := os.Args[1]\n\n\tfeet, _ := strconv.ParseFloat(arg, 64)\n\n\tmeters := feet * feetInMeters\n\tyards := math.Round(feet * feetInYards)\n\n\tfmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n\tfmt.Printf(\"%g feet is %g yards.\\n\", feet, yards)\n}\n"
  },
  {
    "path": "10-constants/03-refactor-feet-to-meters/solution/without-comments/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"os\"\n\t\"strconv\"\n)\n\n// I copied the same program here but without comments.\n// So, you can easily read it.\n\nfunc main() {\n\tconst (\n\t\tfeetInMeters float64 = 0.3048\n\t\tfeetInYards          = feetInMeters / 0.9144\n\t)\n\n\targ := os.Args[1]\n\n\tfeet, _ := strconv.ParseFloat(arg, 64)\n\n\tmeters := feet * feetInMeters\n\tyards := math.Round(feet * feetInYards)\n\n\tfmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n\tfmt.Printf(\"%g feet is %g yards.\\n\", feet, yards)\n}\n"
  },
  {
    "path": "10-constants/04-iota/01-manually/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tmonday    = 0\n\t\ttuesday   = 1\n\t\twednesday = 2\n\t\tthursday  = 3\n\t\tfriday    = 4\n\t\tsaturday  = 5\n\t\tsunday    = 6\n\t)\n\n\tfmt.Println(monday, tuesday, wednesday, thursday, friday,\n\t\tsaturday, sunday)\n}\n"
  },
  {
    "path": "10-constants/04-iota/02-with-iota/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tmonday = iota\n\t\ttuesday\n\t\twednesday\n\t\tthursday\n\t\tfriday\n\t\tsaturday\n\t\tsunday\n\t)\n\n\tfmt.Println(monday, tuesday, wednesday, thursday, friday,\n\t\tsaturday, sunday)\n}\n"
  },
  {
    "path": "10-constants/04-iota/03-expressions/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tmonday = iota + 1\n\t\ttuesday\n\t\twednesday\n\t\tthursday\n\t\tfriday\n\t\tsaturday\n\t\tsunday\n\t)\n\n\tfmt.Println(monday, tuesday, wednesday, thursday, friday,\n\t\tsaturday, sunday)\n}\n"
  },
  {
    "path": "10-constants/04-iota/04-blank-identifier/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tEST = -5\n\t\tMST = -7\n\t\tPST = -8\n\t)\n\n\tfmt.Println(EST, MST, PST)\n}\n"
  },
  {
    "path": "10-constants/04-iota/04-blank-identifier/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tEST = -(5 + iota) // CORRECT: -5\n\t\tMST               // CORRECT: -6\n\t\tPST               // CORRECT: -7\n\t)\n\n\tfmt.Println(EST, MST, PST)\n}\n"
  },
  {
    "path": "10-constants/04-iota/04-blank-identifier/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tEST = -(5 + iota) // CORRECT: -5\n\t\t_\n\t\tMST // CORRECT: -7\n\t\tPST // CORRECT: -8\n\t)\n\n\tfmt.Println(EST, MST, PST)\n}\n"
  },
  {
    "path": "10-constants/exercises/01-minutes-in-weeks/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Minutes in Weeks\n//\n//  Calculate how many minutes in two weeks.\n//\n//  STEPS:\n//  1. Declare `minsPerDay` constant and initialize it\n//     to the number of minutes in a day\n//\n//  2. Declare `weekDays` constant and initialize it\n//     to 7.\n//\n//  3. Use printf to print the total number of minutes\n//     in two weeks.\n//\n// EXPECTED OUTPUT\n//  There are 20160 minutes in 2 weeks.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "10-constants/exercises/01-minutes-in-weeks/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tminsPerDay = 60 * 24\n\t\tweekDays   = 7\n\t)\n\n\tfmt.Printf(\"There are %d minutes in %d weeks.\\n\",\n\t\tminsPerDay*weekDays*2, 2)\n}\n"
  },
  {
    "path": "10-constants/exercises/02-remove-the-magic/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Remove the Magic\n//\n//  Get rid of the magic numbers in the following code.\n//\n// RESTRICTIONS\n//  1. You should declare 3 constants named:\n//       hoursInDay, daysInWeek, and hoursPerWeek\n//\n//  2. And, hoursPerWeek constant should be initialized\n//     using hoursInDay and daysInWeek constants.\n//\n// EXPECTED OUTPUT\n//  There are 840 hours in 5 weeks.\n// ---------------------------------------------------------\n\nfunc main() {\n\tfmt.Printf(\"There are %d hours in %d weeks.\\n\",\n\t\t24*7*5, 5)\n}\n"
  },
  {
    "path": "10-constants/exercises/02-remove-the-magic/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\thoursInDay   = 24\n\t\tdaysInWeek   = 7\n\t\thoursPerWeek = hoursInDay * daysInWeek\n\t)\n\n\tfmt.Printf(\"There are %d hours in %d weeks.\\n\",\n\t\thoursPerWeek*5, 5)\n}\n"
  },
  {
    "path": "10-constants/exercises/03-constant-length/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Constant Length\n//\n//  Calculate how many characters inside the `home`\n//  constant and print it.\n//\n// STEPS:\n//  1. Declare a constant named `home`\n//  2. Initialize it to \"Milky Way Galaxy\" string literal\n//\n//  3. Declare another constant named `length`\n//  4. Initialize it by using the built-in function `len`.\n//\n//  5. Print the message below using the constants that\n//     you've declared.\n//\n// RESTRICTION:\n//  Use Printf.\n//  Print the `home` constant using the quoted-string verb.\n//\n// EXPECTED OUTPUT\n//  There are 16 characters inside \"Milky Way Galaxy\"\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "10-constants/exercises/03-constant-length/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\thome   = \"Milky Way Galaxy\"\n\t\tlength = len(home)\n\t)\n\n\tfmt.Printf(\"There are %d characters inside %q\\n\",\n\t\tlength, home)\n}\n"
  },
  {
    "path": "10-constants/exercises/04-tau/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: TAU\n//\n//  Fix the following program and print the TAU number.\n//\n// HINT\n//  You can use %g verb for printing tau.\n//\n// EXPECTED OUTPUT\n//  tau = 6.283185307179586\n// ---------------------------------------------------------\n\nfunc main() {\n\t// What's the problem with this code?\n\t// Why it doesn't work?\n\n\t// const pi, tau = 3.14159265358979323846264, pi * 2\n}\n"
  },
  {
    "path": "10-constants/exercises/04-tau/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tpi  = 3.14159265358979323846264\n\t\ttau = pi * 2\n\t)\n\n\tfmt.Printf(\"tau = %g\\n\", tau)\n}\n"
  },
  {
    "path": "10-constants/exercises/05-area/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Area\n//\n//  Fix the following program.\n//\n// RESTRICTION\n//  You should not use any variables.\n//\n// EXPECTED OUTPUT\n//  area = 1250\n// ---------------------------------------------------------\n\nfunc main() {\n\t// const (\n\t// \twidth  int16 = 25\n\t// \theight int32 = width * 2\n\t// )\n\n\t// fmt.Printf(\"area = %d\\n\", width*height)\n}\n"
  },
  {
    "path": "10-constants/exercises/05-area/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Make them typeless\n\tconst (\n\t\twidth  = 25\n\t\theight = width * 2\n\t)\n\n\tfmt.Printf(\"area = %d\\n\", width*height)\n}\n"
  },
  {
    "path": "10-constants/exercises/06-no-conversions-allowed/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: No Conversions Allowed\n//\n//  1. Fix the program without doing any conversion.\n//  2. Explain why it doesn't work.\n//\n// EXPECTED OUTPUT\n//  10h0m0s later...\n// ---------------------------------------------------------\n\nfunc main() {\n\t// const later int = 10\n\n\t// hours, _ := time.ParseDuration(\"1h\")\n\n\t// fmt.Printf(\"%s later...\\n\", hours*later)\n}\n"
  },
  {
    "path": "10-constants/exercises/06-no-conversions-allowed/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\t// hours's type is time.Duration\n\t// but later's type was int\n\t// now, `later` is typeless\n\t//\n\t// time.Duration's underlying type is int64\n\t// and, `later` is numeric typeless value\n\t// so, they can be multiplied\n\tconst later = 10\n\n\thours, _ := time.ParseDuration(\"1h\")\n\n\tfmt.Printf(\"%s later...\\n\", hours*later)\n}\n"
  },
  {
    "path": "10-constants/exercises/07-iota-months/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Iota Months\n//\n//  1. Initialize the constants using iota.\n//  2. You should find the correct formula for iota.\n//\n// RESTRICTIONS\n//  1. Remove the initializer values from all constants.\n//  2. Then use iota once for initializing one of the\n//     constants.\n//\n// EXPECTED OUTPUT\n//  9 10 11\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\tNov = 11\n\t\tOct = 10\n\t\tSep = 9\n\t)\n\n\tfmt.Println(Sep, Oct, Nov)\n}\n"
  },
  {
    "path": "10-constants/exercises/07-iota-months/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tNov = 11 - iota // 11 - 0 = 11\n\t\tOct             // 11 - 1 = 10\n\t\tSep             // 11 - 2 = 9\n\t)\n\n\tfmt.Println(Sep, Oct, Nov)\n}\n"
  },
  {
    "path": "10-constants/exercises/08-iota-months-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Iota Months #2\n//\n//  1. Initialize multiple constants using iota.\n//  2. Please follow the instructions inside the code.\n//\n// EXPECTED OUTPUT\n//  1 2 3\n// ---------------------------------------------------------\n\nfunc main() {\n\t// HINT: This is a valid constant declaration\n\t//       Blank-Identifier can be used in place of a name\n\tconst _ = iota\n\t//    ^- this is just a name\n\n\t// Now, use iota and initialize the following constants\n\t// \"automatically\" to 1, 2, and 3 respectively.\n\tconst (\n\t\tJan = iota\n\t\tFeb\n\t\tMar\n\t)\n\n\t// This should print: 1 2 3\n\t// Not: 0 1 2\n\tfmt.Println(Jan, Feb, Mar)\n}\n"
  },
  {
    "path": "10-constants/exercises/08-iota-months-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\t_   = iota // 0\n\t\tJan        // 1\n\t\tFeb        // 2\n\t\tMar        // 3\n\t)\n\n\tfmt.Println(Jan, Feb, Mar)\n}\n"
  },
  {
    "path": "10-constants/exercises/09-iota-seasons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Iota Seasons\n//\n//  Use iota to initialize the season constants.\n//\n// HINT\n//  You can change the order of the constants.\n//\n// EXPECTED OUTPUT\n//  12 3 6 9\n// ---------------------------------------------------------\n\nfunc main() {\n\t// NOTE : You should remove all the initializers below\n\t//        first. Then use iota to fix it.\n\tconst (\n\t\tWinter = 12\n\t\tSpring = 3\n\t\tSummer = 6\n\t\tFall   = 9\n\t)\n\n\tfmt.Println(Winter, Spring, Summer, Fall)\n}\n"
  },
  {
    "path": "10-constants/exercises/09-iota-seasons/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst (\n\t\tSpring = (iota + 1) * 3\n\t\tSummer\n\t\tFall\n\t\tWinter\n\t)\n\n\tfmt.Println(Winter, Spring, Summer, Fall)\n}\n"
  },
  {
    "path": "10-constants/exercises/README.md",
    "content": "# Constants\n\n1. **[Minutes in Weeks](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/01-minutes-in-weeks)**\n\n2. **[Remove the Magic](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/02-remove-the-magic)**\n\n3. **[Constant Length](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/03-constant-length)**\n\n4. **[TAU](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/04-tau)**\n\n5. **[Area](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/05-area)**\n\n6. **[No Conversions Allowed](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/06-no-conversions-allowed)**\n\n7. **[Iota Months](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/07-iota-months)**\n\n8. **[Iota Months #2](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/08-iota-months-2)**\n\n9. **[Iota Seasons](https://github.com/inancgumus/learngo/tree/master/10-constants/exercises/09-iota-seasons)**\n\n"
  },
  {
    "path": "10-constants/questions/questions.md",
    "content": "## What's a magic value?\n1. A value which pops up from somewhere\n2. Merlin the Wizard's spell\n3. An unnamed constant value in the source code *CORRECT*\n4. A named constant\n\n\n## What's a named constant?\n1. A constant with a cool name\n2. A constant value declared with a name *CORRECT*\n3. A literal value converted to a name\n\n\n## How to declare a constant?\n1. `Const version int = 3`\n2. `const version int := 3`\n2. `const version int = 3` *CORRECT*\n\n> **1:** \"C\"onst should be just \"c\"onst.\n>\n\n\n## Which code below is correct?\n1. `s := \"pick me\"; const length = len(s)`\n2. `const message = \"pick me!\"; const length = len(message)` *CORRECT*\n3. `const length = utf8.RuneCountInString(\"pick me\")`\n\n> **1:** `s` not a constant.\n>\n> **2:** `len` function can be used as an initial value to a constant, when the argument to `len` is also a constant.\n>\n> **3:** You cannot call functions while initializing a constant.\n>\n\n\n## Which explanation below is correct for the following code?\n```go\nconst speed = 100\nporsche := speed * 3\n```\n1. speed is typeless and porsche's type is int *CORRECT*\n2. speed's type is int and porsche's type is also int\n3. speed and porsche are typeless\n\n> **2:** speed has no type.\n>\n> **3:** A variable cannot be typeless.\n>\n\n\n## How to fix the following code?\n```go\nconst spell string\nspell = \"Abracadabra\"\n```\n1. `const spell = \"Abracadabra\"` *CORRECT*\n2. `spell := \"Abracadabra\"`\n3. `var spell = \"Abracadabra\"`\n\n> **1:** A constant always have to be initialized to a value. And, sometimes the type declaration is not necessary.\n>\n> **2-3:** That's a variable not a constant.\n>\n\n\n## How to fix the following code?\n```go\nconst total int8 = 10\nx := 5\n\nfmt.Print(total * x)\n```\n\n```go\n// #1 - *CORRECT*\nconst total = 10\nx := 5\n\nfmt.Print(total * x)\n\n// #2\nconst total int64 = 10\nx := 5\n\nfmt.Print(total * x)\n\n// #3\nconst total int64 = 10\nx := 5\n\nfmt.Print(int64(total) * x)\n```\n\n> **1:** Now, the total constant is typeless, so it can be used with the x variable.\n>\n> **2:** There's still a type mismatch. x is int not int64.\n>\n> **3:** total is already int64. No need to convert it again.\n>\n\n\n## What are the values of the following constants?\n```go\nconst (\n    Yes = (iota * 5) + 2\n    No\n    Both\n)\n```\n1. Yes=0 No=1 Both=2\n2. Yes=2 No=3 Both=4\n3. Yes=7 No=12 Both=17\n4. Yes=2 No=7 Both=12 *CORRECT*\n\n> **3:** iota starts at 0, not 1.\n>"
  },
  {
    "path": "11-if/01-boolean-operators/01-comparison-operators/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tspeed := 100 // #1\n\t// speed := 10 // #2\n\n\tfast := speed >= 80\n\tslow := speed < 20\n\n\tfmt.Printf(\"fast's type is %T\\n\", fast)\n\n\tfmt.Printf(\"going fast? %t\\n\", fast)\n\tfmt.Printf(\"going slow? %t\\n\", slow)\n\n\tfmt.Printf(\"is it 100 mph? %t\\n\", speed == 100)\n\tfmt.Printf(\"is it not 100 mph? %t\\n\", speed != 100)\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/02-comparison-and-assignability/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar speed int\n\t// speed = \"100\" // NOT OK\n\n\tvar running bool\n\t// running = 50 // NOT OK\n\n\tvar force float64\n\t// speed = force // NOT OK\n\n\t_, _, _ = speed, running, force\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/02-comparison-and-assignability/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar speed int\n\tspeed = 50 // OK\n\n\tvar running bool\n\trunning = true // OK\n\n\tvar force float64\n\tspeed = int(force)\n\n\t_, _, _ = speed, running, force\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/02-comparison-and-assignability/03/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tspeed := 100 // #1\n\t// speed := 10 // #2\n\n\tfast := speed >= 80\n\tslow := speed < 20\n\n\tfmt.Printf(\"going fast? %t\\n\", fast)\n\tfmt.Printf(\"going slow? %t\\n\", slow)\n\n\tfmt.Printf(\"is it 100 mph? %t\\n\", speed == 100)\n\tfmt.Printf(\"is it not 100 mph? %t\\n\", speed != 100)\n\n\tfmt.Println(strings.Repeat(\"-\", 25))\n\n\t// -------------------------\n\t// #3\n\tspeedB := 150.5\n\tfaster := speedB > 100 // ok: untyped\n\n\tfmt.Println(\"is the other car going faster?\", faster)\n\n\t// ERROR: Type Mismatch\n\t// faster = speedB > speed\n\tfaster = speedB > float64(speed)\n\tfmt.Println(\"is the other car going faster?\", faster)\n\n\t// #4\n\t// ERROR:\n\t// only numeric values are comparable with\n\t// ordering operators: <, <=, >, >=\n\n\t// fmt.Println(true > faster)\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/03-logical-operators/01-and-operator/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// remove the comments and run\n\t// I've commented the lines it's because of the warnings\n\n\t// fmt.Println(\"true  && true  =\", true && true)\n\tfmt.Println(\"true  && false =\", true && false)\n\tfmt.Println(\"false && true  =\", false && true)\n\t// fmt.Println(\"false && false =\", false && false)\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/03-logical-operators/01-and-operator/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tspeed := 100\n\tfmt.Println(\"within limits?\",\n\t\tspeed >= 40 && speed <= 55,\n\t)\n\n\tspeed = 20\n\tfmt.Println(\"within limits?\",\n\t\tspeed >= 40 && speed <= 55,\n\t\t// ^- short-circuits in the first expression here\n\t\t//    because, it becomes false\n\t)\n\n\tspeed = 50\n\tfmt.Println(\"within limits?\",\n\t\tspeed >= 40 && speed <= 55,\n\t)\n\n\t// ERROR: invalid\n\t// both operands should be booleans\n\t// 1 && 2\n\tfmt.Println(1 == 1 && 2 == 2)\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/03-logical-operators/02-or-operator/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// remove the comments and run\n\t// I've commented the lines it's because of the warnings\n\n\t// fmt.Println(\"true  || true  =\", true || true)\n\tfmt.Println(\"true  || false =\", true || false)\n\tfmt.Println(\"false || true  =\", false || true)\n\t// fmt.Println(\"false || false =\", false || false)\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/03-logical-operators/02-or-operator/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcolor := \"red\"\n\n\tfmt.Println(\"reddish colors?\",\n\t\t// true || false => true (short-circuits)\n\t\tcolor == \"red\" || color == \"dark red\",\n\t)\n\n\tcolor = \"dark red\"\n\n\tfmt.Println(\"reddish colors?\",\n\t\t// false || true => true\n\t\tcolor == \"red\" || color == \"dark red\",\n\t)\n\n\tfmt.Println(\"greenish colors?\",\n\t\t// false || false => false\n\t\tcolor == \"green\" || color == \"light green\",\n\t)\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/03-logical-operators/03-not-operator/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\n\t\t\"hi\" == \"hi\" && 3 > 2,    //   true  && true  => true\n\t\t\"hi\" != \"hi\" || 3 > 2,    //   false || true  => true\n\t\t!(\"hi\" != \"hi\" || 3 > 2), // !(false || true) => false\n\t)\n}\n"
  },
  {
    "path": "11-if/01-boolean-operators/03-logical-operators/03-not-operator/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar on bool\n\n\ton = !on\n\tfmt.Println(on)\n\n\ton = !!on\n\tfmt.Println(on)\n}\n"
  },
  {
    "path": "11-if/02-if-statement/01-if-branch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tscore, valid := 5, true\n\n\tif score > 3 && valid {\n\t\tfmt.Println(\"good\")\n\t}\n}\n"
  },
  {
    "path": "11-if/02-if-statement/02-else-branch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tscore, valid := 3, true\n\n\tif score > 3 && valid {\n\t\tfmt.Println(\"good\")\n\t} else {\n\t\tfmt.Println(\"low\")\n\t}\n}\n"
  },
  {
    "path": "11-if/02-if-statement/03-else-if-branch/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tscore := 3\n\n\tif score > 3 {\n\t\tfmt.Println(\"good\")\n\t} else if score == 3 {\n\t\tfmt.Println(\"on the edge\")\n\t} else {\n\t\tfmt.Println(\"low\")\n\t}\n}\n"
  },
  {
    "path": "11-if/02-if-statement/03-else-if-branch/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tscore := 2\n\n\tif score > 3 {\n\t\tfmt.Println(\"good\")\n\t} else if score == 3 {\n\t\tfmt.Println(\"on the edge\")\n\t} else if score == 2 {\n\t\tfmt.Println(\"meh...\")\n\t} else {\n\t\tfmt.Println(\"low\")\n\t}\n}\n"
  },
  {
    "path": "11-if/02-if-statement/04-refactor-feet-to-meters/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst usage = `\nFeet to Meters\n--------------\nThis program converts feet into meters.\n\nUsage:\nfeet [feetsToConvert]`\n\nfunc main() {\n\tif len(os.Args) < 2 {\n\t\tfmt.Println(strings.TrimSpace(usage))\n\n\t\t// ALTERNATIVE:\n\t\t// fmt.Println(\"Please tell me a value in feet\")\n\n\t\treturn\n\t}\n\n\targ := os.Args[1]\n\n\tfeet, _ := strconv.ParseFloat(arg, 64)\n\n\tmeters := feet * 0.3048\n\n\tfmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n}\n"
  },
  {
    "path": "11-if/02-if-statement/05-challenge-userpass/01-1st-challenge/01-challenge/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// CHALLENGE #1\n//  Create a user/password protected program.\n//\n// EXAMPLE USER\n//  username: jack\n//  password: 1888\n//\n// EXPECTED OUTPUT\n//  go run main.go\n//    Usage: [username] [password]\n//\n//  go run main.go albert\n//    Usage: [username] [password]\n//\n//  go run main.go hacker 42\n//    Access denied for \"hacker\".\n//\n//  go run main.go jack 6475\n//    Invalid password for \"jack\".\n//\n//  go run main.go jack 1888\n//    Access granted to \"jack\".\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/02-if-statement/05-challenge-userpass/01-1st-challenge/02-solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 3 {\n\t\tfmt.Println(\"Usage: [username] [password]\")\n\t\treturn\n\t}\n\n\tu, p := args[1], args[2]\n\n\tif u != \"jack\" {\n\t\tfmt.Printf(\"Access denied for %q.\\n\", u)\n\t} else if p != \"1888\" {\n\t\tfmt.Printf(\"Invalid password for %q.\\n\", u)\n\t} else {\n\t\tfmt.Printf(\"Access granted to %q.\\n\", u)\n\t}\n}\n"
  },
  {
    "path": "11-if/02-if-statement/05-challenge-userpass/01-1st-challenge/03-solution-refactor/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nconst (\n\tusage    = \"Usage: [username] [password]\"\n\terrUser  = \"Access denied for %q.\\n\"\n\terrPwd   = \"Invalid password for %q.\\n\"\n\taccessOK = \"Access granted to %q.\\n\"\n\tuser     = \"jack\"\n\tpass     = \"1888\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 3 {\n\t\tfmt.Println(usage)\n\t\treturn\n\t}\n\n\tu, p := args[1], args[2]\n\n\tif u != user {\n\t\tfmt.Printf(errUser, u)\n\t} else if p != pass {\n\t\tfmt.Printf(errPwd, u)\n\t} else {\n\t\tfmt.Printf(accessOK, u)\n\t}\n}\n"
  },
  {
    "path": "11-if/02-if-statement/05-challenge-userpass/02-2nd-challenge/01-challenge/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// ---------------------------------------------------------\n// CHALLENGE #2\n//  Add one more user to the PassMe program below.\n//\n// EXAMPLE USERS\n//  username: jack\n//  password: 1888\n//\n//  username: inanc\n//  password: 1879\n//\n// EXPECTED OUTPUT\n//  go run main.go\n//    Usage: [username] [password]\n//\n//  go run main.go hacker 42\n//    Access denied for \"hacker\".\n//\n//  go run main.go jack 1888\n//    Access granted to \"jack\".\n//\n//  go run main.go inanc 1879\n//    Access granted to \"inanc\".\n//\n//  go run main.go jack 1879\n//    Invalid password for \"jack\".\n//\n//  go run main.go inanc 1888\n//    Invalid password for \"inanc\".\n// ---------------------------------------------------------\n\nconst (\n\tusage    = \"Usage: [username] [password]\"\n\terrUser  = \"Access denied for %q.\\n\"\n\terrPwd   = \"Invalid password for %q.\\n\"\n\taccessOK = \"Access granted to %q.\\n\"\n\tuser     = \"jack\"\n\tpass     = \"1888\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 3 {\n\t\tfmt.Println(usage)\n\t\treturn\n\t}\n\n\tu, p := args[1], args[2]\n\n\tif u != user {\n\t\tfmt.Printf(errUser, u)\n\t} else if p != pass {\n\t\tfmt.Printf(errPwd, u)\n\t} else {\n\t\tfmt.Printf(accessOK, u)\n\t}\n}\n"
  },
  {
    "path": "11-if/02-if-statement/05-challenge-userpass/02-2nd-challenge/02-solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nconst (\n\tusage       = \"Usage: [username] [password]\"\n\terrUser     = \"Access denied for %q.\\n\"\n\terrPwd      = \"Invalid password for %q.\\n\"\n\taccessOK    = \"Access granted to %q.\\n\"\n\tuser, user2 = \"jack\", \"inanc\"\n\tpass, pass2 = \"1888\", \"1879\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 3 {\n\t\tfmt.Println(usage)\n\t\treturn\n\t}\n\n\tu, p := args[1], args[2]\n\n\tif u != user && u != user2 {\n\t\tfmt.Printf(errUser, u)\n\t} else if u == user && p == pass {\n\t\tfmt.Printf(accessOK, u)\n\t} else if u == user2 && p == pass2 {\n\t\tfmt.Printf(accessOK, u)\n\t} else {\n\t\tfmt.Printf(errPwd, u)\n\t}\n}\n"
  },
  {
    "path": "11-if/03-error-handling/01-itoa/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// Itoa doesn't return any errors\n\t// So, you don't have to handle the errors for it\n\n\ts := strconv.Itoa(42)\n\n\tfmt.Println(s)\n}\n"
  },
  {
    "path": "11-if/03-error-handling/02-atoi/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// Atoi returns an error value\n\t// So, you should always check it\n\n\tn, err := strconv.Atoi(os.Args[1])\n\n\tfmt.Println(\"Converted number    :\", n)\n\tfmt.Println(\"Returned error value:\", err)\n}\n"
  },
  {
    "path": "11-if/03-error-handling/03-atoi-error-handling/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tage := os.Args[1]\n\n\t// Atoi returns an int and an error value\n\t// So, you need to handle the errors\n\n\tn, err := strconv.Atoi(age)\n\n\t// handle the error immediately and quit\n\t// don't do anything else here\n\n\tif err != nil {\n\t\tfmt.Println(\"ERROR:\", err)\n\n\t\t// quits/returns from the main function\n\t\t// so, the program ends\n\t\treturn\n\t}\n\n\t// DO NOT DO THIS:\n\t// else {\n\t//   happy path\n\t// }\n\n\t// DO THIS:\n\n\t// happy path (err is nil)\n\tfmt.Printf(\"SUCCESS: Converted %q to %d.\\n\", age, n)\n}\n"
  },
  {
    "path": "11-if/03-error-handling/04-challenge-feet-to-meters/01-challenge/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// ---------------------------------------------------------\n// CHALLENGE\n//  Add error handling to the feet to meters program.\n//\n// EXPECTED OUTPUT\n//  go run main.go hello\n//    error: 'hello' is not a number.\n//\n//  go run main.go what\n//    error: 'what' is not a number.\n//\n//  go run main.go 100\n//    100 feet is 30.48 meters.\n// ---------------------------------------------------------\n\nconst usage = `\nFeet to Meters\n--------------\nThis program converts feet into meters.\n\nUsage:\nfeet [feetsToConvert]`\n\nfunc main() {\n\tif len(os.Args) < 2 {\n\t\tfmt.Println(strings.TrimSpace(usage))\n\t\treturn\n\t}\n\n\targ := os.Args[1]\n\n\tfeet, _ := strconv.ParseFloat(arg, 64)\n\tmeters := feet * 0.3048\n\n\tfmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n}\n"
  },
  {
    "path": "11-if/03-error-handling/04-challenge-feet-to-meters/02-solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst usage = `\nFeet to Meters\n--------------\nThis program converts feet into meters.\n\nUsage:\nfeet [feetsToConvert]`\n\nfunc main() {\n\tif len(os.Args) < 2 {\n\t\tfmt.Println(strings.TrimSpace(usage))\n\t\treturn\n\t}\n\n\targ := os.Args[1]\n\n\tfeet, err := strconv.ParseFloat(arg, 64)\n\tif err != nil {\n\t\tfmt.Printf(\"error: '%s' is not a number.\\n\", arg)\n\t\treturn\n\t}\n\n\tmeters := feet * 0.3048\n\n\tfmt.Printf(\"%g feet is %g meters.\\n\", feet, meters)\n}\n"
  },
  {
    "path": "11-if/04-short-if/01-without-short-if/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tn, err := strconv.Atoi(\"42\")\n\n\tif err == nil {\n\t\tfmt.Println(\"There was no error, n is\", n)\n\t}\n}\n"
  },
  {
    "path": "11-if/04-short-if/02-with-short-if/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif n, err := strconv.Atoi(\"42\"); err == nil {\n\t\t// n and err are available here\n\t\tfmt.Println(\"There was no error, n is\", n)\n\t}\n\n\t// n and err are not available here\n\t// fmt.Println(n, err)\n}\n"
  },
  {
    "path": "11-if/04-short-if/03-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif a := os.Args; len(a) != 2 {\n\n\t\t// only a is available here\n\t\tfmt.Println(\"Give me a number.\")\n\n\t\t// no need to return on error\n\t\t// return\n\n\t} else if n, err := strconv.Atoi(a[1]); err != nil {\n\n\t\t// a, n and err are available here\n\t\tfmt.Printf(\"Cannot convert %q.\\n\", a[1])\n\n\t\t// no need to return on error\n\t\t// return\n\n\t} else {\n\t\t// all of the variables (names)\n\t\t// are available here\n\t\tfmt.Printf(\"%s * 2 is %d\\n\", a[1], n*2)\n\t}\n\n\t// a, n and err are not available here\n\t// they belong to the if statement\n\n\t// TRY:\n\t// fmt.Println(a, n, err)\n}\n"
  },
  {
    "path": "11-if/04-short-if/04-scope-shadowing/01-shadowing/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// UNCOMMENT THIS TO SEE IT IN ACTION:\n\t// var n int\n\n\tif a := os.Args; len(a) != 2 {\n\t\tfmt.Println(\"Give me a number.\")\n\t} else if n, err := strconv.Atoi(a[1]); err != nil {\n\t\t// else if here shadows the main func's n\n\t\t// variable and it declares it own\n\t\t// with the same name: n\n\n\t\tfmt.Printf(\"Cannot convert %q.\\n\", a[1])\n\t} else {\n\t\tfmt.Printf(\"%s * 2 is %d\\n\", a[1], n*2)\n\t}\n\n\t// n here belongs to the main func\n\t// not to the if statement above\n\n\t// UNCOMMENT ALSO LINES BELOW TO SEE IT IN ACTION:\n\t// fmt.Printf(\"n is %d. 👻 👻 👻 - you've been shadowed ;-)\\n\", n)\n}\n"
  },
  {
    "path": "11-if/04-short-if/04-scope-shadowing/02-shadowing-solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// n and err belongs to the main function now\n\t// not only to the if statement below\n\tvar (\n\t\tn   int\n\t\terr error\n\t)\n\n\tif a := os.Args; len(a) != 2 {\n\t\tfmt.Println(\"Give me a number.\")\n\t} else if n, err = strconv.Atoi(a[1]); err != nil {\n\t\t// here else if uses the main func's n and err\n\t\t// variables instead of its own\n\n\t\tfmt.Printf(\"Cannot convert %q.\\n\", a[1])\n\t} else {\n\t\t// assigns the result back into main func's\n\t\t// n variable\n\t\tn *= 2\n\n\t\tfmt.Printf(\"%s * 2 is %d\\n\", a[1], n)\n\t}\n\n\t// if statement has calculated the result using\n\t// the main func's n variable\n\t//\n\t// so, that's why it prints the correct result here\n\tfmt.Println(\"n is\", n)\n}\n"
  },
  {
    "path": "11-if/exercises/01-age-seasons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Age Seasons\n//\n//  Let's start simple. Print the expected outputs,\n//  depending on the age variable.\n//\n// EXPECTED OUTPUT\n//  If age is greater than 60, print:\n//    Getting older\n//  If age is greater than 30, print:\n//    Getting wiser\n//  If age is greater than 20, print:\n//    Adulthood\n//  If age is greater than 10, print:\n//    Young blood\n//  Otherwise, print:\n//    Booting up\n// ---------------------------------------------------------\n\nfunc main() {\n\t// Change this accordingly to produce the expected outputs\n\t// age := 10\n\n\t// Type your if statement here.\n}\n"
  },
  {
    "path": "11-if/exercises/01-age-seasons/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tage := 10\n\n\tif age > 60 {\n\t\tfmt.Println(\"Getting older\")\n\t} else if age > 30 {\n\t\tfmt.Println(\"Getting wiser\")\n\t} else if age > 20 {\n\t\tfmt.Println(\"Adulthood\")\n\t} else if age > 10 {\n\t\tfmt.Println(\"Young blood\")\n\t} else {\n\t\tfmt.Println(\"Booting up\")\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/02-simplify-it/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Simplify It\n//\n//  Can you simplify the if statement inside the code below?\n//\n//  When:\n//    isSphere == true and\n//    radius is equal or greater than 200\n//\n//    It will print \"It's a big sphere.\"\n//\n//    Otherwise, it will print \"I don't know.\"\n//\n// EXPECTED OUTPUT\n//  It's a big sphere.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DO NOT TOUCH THIS\n\tisSphere, radius := true, 200\n\n\tvar big bool\n\n\tif radius >= 50 {\n\t\tif radius >= 100 {\n\t\t\tif radius >= 200 {\n\t\t\t\tbig = true\n\t\t\t}\n\t\t}\n\t}\n\n\tif big != true {\n\t\tfmt.Println(\"I don't know.\")\n\t} else if !(isSphere == false) {\n\t\tfmt.Println(\"It's a big sphere.\")\n\t} else {\n\t\tfmt.Println(\"I don't know.\")\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/02-simplify-it/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tisSphere, radius := true, 200\n\n\tif isSphere && radius >= 200 {\n\t\tfmt.Println(\"It's a big sphere.\")\n\t} else {\n\t\tfmt.Println(\"I don't know.\")\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/03-arg-count/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Arg Count\n//\n//  1. Get arguments from command-line.\n//  2. Print the expected outputs below depending on the number\n//     of arguments.\n//\n// EXPECTED OUTPUT\n//  go run main.go\n//    Give me args\n//\n//  go run main.go hello\n//    There is one: \"hello\"\n//\n//  go run main.go hi there\n//    There are two: \"hi there\"\n//\n//  go run main.go I wanna be a gopher\n//    There are 5 arguments\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/exercises/03-arg-count/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tvar (\n\t\targs = os.Args\n\t\tl    = len(args) - 1\n\t)\n\n\tif l == 0 {\n\t\tfmt.Println(\"Give me args\")\n\t} else if l == 1 {\n\t\tfmt.Printf(\"There is one: %q\\n\", args[1])\n\t} else if l == 2 {\n\t\tfmt.Printf(\n\t\t\t`There are two: \"%s %s\"`+\"\\n\",\n\t\t\targs[1], args[2],\n\t\t)\n\t} else {\n\t\tfmt.Printf(\"There are %d arguments\\n\", l)\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/04-vowel-or-cons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Vowel or Consonant\n//\n//  Detect whether a letter is vowel or consonant.\n//\n// NOTE\n//  y or w is called a semi-vowel.\n//  Check out: https://www.merriam-webster.com/words-at-play/why-y-is-sometimes-a-vowel-usage\n//  Check out: https://www.dictionary.com/e/w-vowel/\n//\n// HINT\n//  + You can find the length of an argument using the len function.\n//\n//  + len(os.Args[1]) will give you the length of the 1st argument.\n//\n// BONUS\n//  Use strings.IndexAny function to detect the vowels.\n//  Search on Google for: golang pkg strings IndexAny\n//\n// Furthermore, you can also use strings.ContainsAny. Check out: https://golang.org/pkg/strings/#ContainsAny\n//\n// EXPECTED OUTPUT\n//  go run main.go\n//    Give me a letter\n//\n//  go run main.go hey\n//    Give me a letter\n//\n//  go run main.go a\n//    \"a\" is a vowel.\n//\n//  go run main.go y\n//    \"y\" is sometimes a vowel, sometimes not.\n//\n//  go run main.go w\n//    \"w\" is sometimes a vowel, sometimes not.\n//\n//  go run main.go x\n//    \"x\" is a consonant.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/exercises/04-vowel-or-cons/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 2 || len(args[1]) != 1 {\n\t\tfmt.Println(\"Give me a letter\")\n\t\treturn\n\t}\n\n\t// I didn't use a short-if here because, it's already\n\t// hard to read. Do not make it harder.\n\n\ts := args[1]\n\tif s == \"a\" || s == \"e\" || s == \"i\" || s == \"o\" || s == \"u\" {\n\t\tfmt.Printf(\"%q is a vowel.\\n\", s)\n\t} else if s == \"w\" || s == \"y\" {\n\t\tfmt.Printf(\"%q is sometimes a vowel, sometimes not.\\n\", s)\n\t} else {\n\t\tfmt.Printf(\"%q is a consonant.\\n\", s)\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/04-vowel-or-cons/solution2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 2 || len(args[1]) != 1 {\n\t\tfmt.Println(\"Give me a letter\")\n\t\treturn\n\t}\n\n\ts := args[1]\n\tif strings.IndexAny(s, \"aeiou\") != -1 {\n\t\tfmt.Printf(\"%q is a vowel.\\n\", s)\n\t} else if s == \"w\" || s == \"y\" {\n\t\tfmt.Printf(\"%q is sometimes a vowel, sometimes not.\\n\", s)\n\t} else {\n\t\tfmt.Printf(\"%q is a consonant.\\n\", s)\n\t}\n\n\t// Notice that:\n\t//\n\t// I didn't use IndexAny for the else if above.\n\t//\n\t// It's because, calling a function is a costly operation.\n\t// And, this way, the code is simpler.\n}\n"
  },
  {
    "path": "11-if/exercises/05-movie-ratings/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// STORY\n//\n//  Your boss wants you to create a program that will check\n//  whether a person can watch a particular movie or not.\n//\n//  Imagine that another program provides the age to your\n//  program. Depending on what you return, the other program\n//  will issue the tickets to the person automatically.\n//\n// EXERCISE: Movie Ratings\n//\n//  1. Get the age from the command-line.\n//\n//  2. Return one of the following messages if the age is:\n//     -> Above 17         : \"R-Rated\"\n//     -> Between 13 and 17: \"PG-13\"\n//     -> Below 13         : \"PG-Rated\"\n//\n// RESTRICTIONS:\n//  1. If age data is wrong or absent let the user know.\n//  2. Do not accept negative age.\n//\n// BONUS:\n//  1. BONUS: Use if statements only twice throughout your program.\n//  2. BONUS: Use an if statement only once.\n//\n// EXPECTED OUTPUT\n//  go run main.go 18\n//    R-Rated\n//\n//  go run main.go 17\n//    PG-13\n//\n//  go run main.go 12\n//    PG-Rated\n//\n//  go run main.go\n//    Requires age\n//\n//  go run main.go -5\n//    Wrong age: \"-5\"\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/exercises/05-movie-ratings/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Requires age\")\n\t\treturn\n\t}\n\n\tage, err := strconv.Atoi(os.Args[1])\n\n\tif err != nil || age < 0 {\n\t\tfmt.Printf(`Wrong age: %q`+\"\\n\", os.Args[1])\n\t\treturn\n\t} else if age > 17 {\n\t\tfmt.Println(\"R-Rated\")\n\t} else if age >= 13 && age <= 17 {\n\t\tfmt.Println(\"PG-13\")\n\t} else if age < 13 {\n\t\tfmt.Println(\"PG-Rated\")\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/05-movie-ratings/solution2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\n// 🛑 DON'T DO THIS:\n//     It's hard to read.\n//     It's just an exercise.\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Requires age\")\n\t\treturn\n\t} else if age, err := strconv.Atoi(os.Args[1]); err != nil || age < 0 {\n\t\tfmt.Printf(`Wrong age: %q`+\"\\n\", os.Args[1])\n\t\treturn\n\t} else if age > 17 {\n\t\tfmt.Println(\"R-Rated\")\n\t} else if age >= 13 && age <= 17 {\n\t\tfmt.Println(\"PG-13\")\n\t} else if age < 13 {\n\t\tfmt.Println(\"PG-Rated\")\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/06-odd-even/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Odd or Even\n//\n//  1. Get a number from the command-line.\n//\n//  2. Find whether the number is odd, even and divisible by 8.\n//\n// RESTRICTION\n//  Handle the error. If the number is not a valid number,\n//  or it's not provided, let the user know.\n//\n// EXPECTED OUTPUT\n//  go run main.go 16\n//    16 is an even number and it's divisible by 8\n//\n//  go run main.go 4\n//    4 is an even number\n//\n//  go run main.go 3\n//    3 is an odd number\n//\n//  go run main.go\n//    Pick a number\n//\n//  go run main.go ABC\n//    \"ABC\" is not a number\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/exercises/06-odd-even/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Pick a number\")\n\t\treturn\n\t}\n\n\tn, err := strconv.Atoi(os.Args[1])\n\tif err != nil {\n\t\tfmt.Printf(\"%q is not a number\\n\", os.Args[1])\n\t\treturn\n\t}\n\n\tif n%8 == 0 {\n\t\tfmt.Printf(\"%d is an even number and it's divisible by 8\\n\", n)\n\t} else if n%2 == 0 {\n\t\tfmt.Printf(\"%d is an even number\\n\", n)\n\t} else {\n\t\tfmt.Printf(\"%d is an odd number\\n\", n)\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/07-leap-year/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Leap Year\n//\n//  Find out whether a given year is a leap year or not.\n//\n// EXPECTED OUTPUT\n//  go run main.go\n//    Give me a year number\n//\n//  go run main.go eighties\n//    \"eighties\" is not a valid year.\n//\n//  go run main.go 2018\n//    2018 is not a leap year.\n//\n//  go run main.go 2100\n//    2100 is not a leap year.\n//\n//  go run main.go 2019\n//    2019 is not a leap year.\n//\n//  go run main.go 2020\n//    2020 is a leap year.\n//\n//  go run main.go 2024\n//    2024 is a leap year.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/exercises/07-leap-year/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Give me a year number\")\n\t\treturn\n\t}\n\n\tyear, err := strconv.Atoi(os.Args[1])\n\tif err != nil {\n\t\tfmt.Printf(\"%q is not a valid year.\\n\", os.Args[1])\n\t\treturn\n\t}\n\n\t// Notice that:\n\t// I've intentionally created this solution as verbose\n\t// as I can.\n\t//\n\t// See the next exercise.\n\n\tvar leap bool\n\tif year%400 == 0 {\n\t\tleap = true\n\t} else if year%100 == 0 {\n\t\tleap = false\n\t} else if year%4 == 0 {\n\t\tleap = true\n\t}\n\n\tif leap {\n\t\tfmt.Printf(\"%d is a leap year.\\n\", year)\n\t} else {\n\t\tfmt.Printf(\"%d is not a leap year.\\n\", year)\n\t}\n}\n"
  },
  {
    "path": "11-if/exercises/08-simplify-leap-year/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Simplify the Leap Year\n//\n//  1. Look at the solution of \"the previous exercise\".\n//\n//  2. And simplify the code (especially the if statements!).\n//\n// EXPECTED OUTPUT\n//  It's the same as the previous exercise.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/exercises/08-simplify-leap-year/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Give me a year number\")\n\t\treturn\n\t}\n\n\tyear, err := strconv.Atoi(os.Args[1])\n\tif err != nil {\n\t\tfmt.Printf(\"%q is not a valid year.\\n\", os.Args[1])\n\t\treturn\n\t}\n\n\tif year%4 == 0 && (year%100 != 0 || year%400 == 0) {\n\t\tfmt.Printf(\"%d is a leap year.\\n\", year)\n\t} else {\n\t\tfmt.Printf(\"%d is not a leap year.\\n\", year)\n\t}\n}\n\n// Review the original source code here:\n// https://github.com/golang/go/blob/ad644d2e86bab85787879d41c2d2aebbd7c57db8/src/time/time.go#L1289\n"
  },
  {
    "path": "11-if/exercises/09-days-in-month/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Days in a Month\n//\n//  Print the number of days in a given month.\n//\n// RESTRICTIONS\n//  1. On a leap year, february should print 29. Otherwise, 28.\n//\n//     Set your computer clock to 2020 to see whether it works.\n//\n//  2. It should work case-insensitive. See below.\n//\n//     Search on Google: golang pkg strings ToLower\n//\n//  3. Get the current year using the time.Now()\n//\n//     Search on Google: golang pkg time now year\n//\n//\n// EXPECTED OUTPUT\n//\n//  -----------------------------------------\n//  Your solution should not accept invalid months\n//  -----------------------------------------\n//  go run main.go\n//    Give me a month name\n//\n//  go run main.go sheep\n//    \"sheep\" is not a month.\n//\n//  -----------------------------------------\n//  Your solution should handle the leap years\n//  -----------------------------------------\n//  go run main.go january\n//    \"january\" has 31 days.\n//\n//  go run main.go february\n//    \"february\" has 28 days.\n//\n//  go run main.go march\n//    \"march\" has 31 days.\n//\n//  go run main.go april\n//    \"april\" has 30 days.\n//\n//  go run main.go may\n//    \"may\" has 31 days.\n//\n//  go run main.go june\n//    \"june\" has 30 days.\n//\n//  go run main.go july\n//    \"july\" has 31 days.\n//\n//  go run main.go august\n//    \"august\" has 31 days.\n//\n//  go run main.go september\n//    \"september\" has 30 days.\n//\n//  go run main.go october\n//    \"october\" has 31 days.\n//\n//  go run main.go november\n//    \"november\" has 30 days.\n//\n//  go run main.go december\n//    \"december\" has 31 days.\n//\n//  -----------------------------------------\n//  Your solution should be case insensitive\n//  -----------------------------------------\n//  go run main.go DECEMBER\n//    \"DECEMBER\" has 31 days.\n//\n//  go run main.go dEcEmBeR\n//    \"dEcEmBeR\" has 31 days.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "11-if/exercises/09-days-in-month/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\t\"time\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Give me a month name\")\n\t\treturn\n\t}\n\n\t// get the current year and find out whether it's a leap year\n\tyear := time.Now().Year()\n\tleap := year%4 == 0 && (year%100 != 0 || year%400 == 0)\n\n\t// setting it to 28, saves me typing it below again\n\tdays := 28\n\n\tmonth := os.Args[1]\n\n\t// case insensitive\n\tif m := strings.ToLower(month); m == \"april\" ||\n\t\tm == \"june\" ||\n\t\tm == \"september\" ||\n\t\tm == \"november\" {\n\t\tdays = 30\n\t} else if m == \"january\" ||\n\t\tm == \"march\" ||\n\t\tm == \"may\" ||\n\t\tm == \"july\" ||\n\t\tm == \"august\" ||\n\t\tm == \"october\" ||\n\t\tm == \"december\" {\n\t\tdays = 31\n\t} else if m == \"february\" {\n\t\t// try a \"logical and operator\" above.\n\t\t// like: `else if m == \"february\" && leap`\n\t\tif leap {\n\t\t\tdays = 29\n\t\t}\n\t} else {\n\t\tfmt.Printf(\"%q is not a month.\\n\", month)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%q has %d days.\\n\", month, days)\n}\n"
  },
  {
    "path": "11-if/exercises/README.md",
    "content": "# If Statement\n\n1. **[Age Seasons](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/01-age-seasons)**\n\n2. **[Simplify It](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/02-simplify-it)**\n\n3. **[Arg Count](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/03-arg-count)**\n\n4. **[Vowel or Consonant](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/04-vowel-or-cons)**\n\n## Error Handling\n\n5. **[Movie Ratings](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/05-movie-ratings)**\n\n6. **[Odd or Even](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/06-odd-even)**\n\n7. **[Leap Year](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/07-leap-year)**\n\n8. **[Simplify the Leap Year](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/08-simplify-leap-year)**\n\n9. **[Days in a Month](https://github.com/inancgumus/learngo/tree/master/11-if/exercises/09-days-in-month)**\n\n"
  },
  {
    "path": "11-if/questions/1-comparison-operators.md",
    "content": "## Which one below is not one of the equality operators of Go?\n1. `==`\n2. `!=`\n3. `>` *CORRECT*\n\n> **3:** That's the greater operator. It checks whether an ordered value is greater than the other or not.\n\n\n## Which one below is not one of the ordering operators of Go?\n1. `>`\n2. `<=`\n3. `==` *CORRECT*\n4. `<`\n\n> **3:** That's the equal operator. In an expression, it checks whether a value (operand) is equal to another value (operand).\n\n\n## Which one of these types is returned by the comparison operators?\n1. int\n2. byte\n3. bool *CORRECT*\n4. float64\n\n> **3:** That's right. All the comparison operators return an untyped bool value (true or false).\n\n\n## Which one of these below cannot be used as an operand to ordering operators (`>`, `<`, `>=`, `<=`)?\n1. int value\n2. byte value\n3. string value\n4. bool value *CORRECT*\n5. all of them\n\n> **1-2:** This is an ordered value, it can be used.\n> \n> **3:** String is an ordered value because it's a series of numbers. So, it can be used as an operand.\n> \n> **4:** That's right. A bool value is not an ordered value, so it cannot be used with ordering operators.\n\n\n## Which one of these cannot be used as an operand to equality operators (`==`, `!=`)?\n1. int value\n2. byte value\n3. string value\n4. bool value\n5. They all can be used *CORRECT*\n\n> **5:** That's right. Every **comparable value** can be used as an operand to equality operators.\n\n\n## What does this code print?\n```go\nfmt.Println(\"go\" != \"go!\")\nfmt.Println(\"go\" == \"go!\")\n```\n\n1. true true\n2. true false *CORRECT*\n3. false true\n4. false false\n5. error\n\n> **3-4:** Watch out for the exclamation mark at the end of the second string value.\n\n\n## What does this code print?\n```go\nfmt.Println(1 == true)\n```\n\n1. true\n2. 1\n3. false\n4. 2\n5. error *CORRECT*\n\n> **5:** That's right. A numeric constant cannot be compared to a bool value.\n\n\n## What does this code print?\n```go\nfmt.Println(2.9 > 2.9)\nfmt.Println(2.9 <= 2.9)\n```\n\n1. true true\n2. true false\n3. false true *CORRECT*\n4. false false\n5. error\n\n\n## What does this code print?\n```go\nfmt.Println(false >= true)\nfmt.Println(true <= false)\n```\n\n1. true true\n2. true false\n3. false true\n4. false false\n5. error *CORRECT*\n\n> **5:** That's right. Bool values are not ordered values, so they cannot be compared using the comparison operators.\n\n\n## How to fix this program without losing precision?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    weight, factor := 500, 1.5\n    weight *= factor\n\n    fmt.Println(weight)\n}\n```\n\n1. It cannot be fixed\n2. `weight *= float64(factor)`\n3. `weight *= int(factor)`\n4. `weight = float64(weight) * factor`\n5. `weight = int(float64(weight) * factor)` *CORRECT*\n\n> **1:** It can be fixed.\n> \n> **2:** Type mismatch: weight is int.\n>\n> **3:** Lost precision: factor will be 1.\n> \n> **4:** Type mismatch: weight is int (cannot assign back).\n>\n> **5:** That's right. The result would be 750."
  },
  {
    "path": "11-if/questions/2-logical-operators.md",
    "content": "## Which one below is not one of the logical operators of Go?\n1. `||`\n2. `!=` *CORRECT*\n3. `!`\n4. `&&`\n\n> **2:** That's the \"not equal\" operator. It's a comparison operator, not a logical operator.\n\n\n## Which one of these types is returned by a logical operator?\n1. int\n2. byte\n3. bool *CORRECT*\n4. float64\n\n> **3:** That's right. All the logical operators return an untyped bool value (true or false).\n\n\n## Which one of these can be used as an operand to a logical operator?\n1. int\n2. byte\n3. bool *CORRECT*\n4. float64\n\n> **3:** That's right. All the logical operators expect a bool value (or a bool expression that yields a bool value).\n\n\n## Which expression below equals to the sentence below?\n\"age is equal or above 15 and hair color is yellow\"\n\n1. `age > 15 || hairColor == \"yellow\"`\n2. `age < 15 || hairColor != \"yellow\"`\n3. `age >= 15 && hairColor == \"yellow\"` *CORRECT*\n4. `age > 15 && hairColor == \"yellow\"`\n\n\n## What does this program print?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    var (\n        on  = true\n        off = !on\n    )\n\n    fmt.Println(!on && !off)\n    fmt.Println(!on || !off)\n}\n```\n\n1. true true\n2. true false\n3. false true *CORRECT*\n4. false false\n5. error\n\n> **3:** `!on` is false. `!off` is true. So, `!on && !off` is false. And, `!on || !off` is true.\n\n\n## What does this program print?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    on := 1\n    fmt.Println(on == true)\n}\n```\n\n1. true\n2. false\n3. error *CORRECT*\n\n> **3:** `on` is int, while `true` is a bool. So, there's a type mismatch error here. Go is not like other C based languages where `1` equals to `true`.\n\n\n## What does this code print?\n```go\n// Note: \"a\" comes before \"b\"\na := \"a\" > \"b\"\nb := \"b\" <= \"c\"\nfmt.Println(a || b)\n```\n\n1. \"a\"\n2. \"b\"\n3. true *CORRECT*\n4. false\n5. error\n\n> **1-2:** Logical operators return a bool value only.\n\n> **3:** Order is like so: \"a\", \"b\", \"c\". So, `\"a\" > \"b\"` is false. `\"b\" <= \"c\"` is true. So, `a || b` is true.\n\n> **5:** There isn't an error. Strings are actually numbers, so, they're ordered and can be compared using the ordering operators.\n\n\n## What does the following program print?\n```go\n// Let's say that there are two functions like this:\n//\n//   isOn() which returns true and prints \"on \".\n//   isOff() which returns false and prints \"off \".\n//\n// Remember: Logical operators short-circuit.\n\npackage main\nimport \"fmt\"\n\nfunc main() {\n    _ = isOff() && isOn()\n    _ = isOn() || isOff()\n}\n\n// Don't mind about these functions.\n// Just focus on the problem.\n// They are here just for you to understand what's going on better.\nfunc isOn() bool {\n    fmt.Print(\"on \")\n    return true\n}\n\nfunc isOff() bool {\n    fmt.Print(\"off \")\n    return false\n}\n```\n\n1. \"on off on off \"\n2. \"off on \" *CORRECT*\n3. \"off on on off \"\n4. \"on off \"\n\n> **1, 3:** Remember: Logical operators short-circuit.\n\n> **2:** That's right.\n> \n> In: `isOff() && isOn()`, `isOff()` returns false, so, logical AND operator short-circuits and doesn't call `isOn()`; so it prints: `\"off \"`.\n> \n> Then, in: `isOn() || isOff()`, `isOn()` returns true, so, logical OR operator short circuits and doesn't call `isOff()`; so it prints `\"on \"`.\n\n> **4:** Think again.\n\nExample program is [here](https://play.golang.org/p/6z3afaOf7yT)."
  },
  {
    "path": "11-if/questions/3-if.md",
    "content": "## What does \"control flow\" mean?\n1. Changing the top-to-bottom execution of a program\n2. Changing the left-to-right execution of a program\n3. Deciding which statements are executed *CORRECT*\n\n> **1, 2:** You can't change that.\n> \n> **3:** That's right. Control flow allows us to decide which parts of a program is to be run depending on condition values such as true or false.\n\n\n## How can you simplify the condition expression of this if statement?\n```go\nif (mood == \"perfect\") {\n    // this code is not important\n}\n```\n\n1. `if {mood == \"perfect\"}`\n2. `if [mood == \"perfect\"]`\n3. `if mood = \"perfect\"`\n4. `if mood == \"perfect\"` *CORRECT*\n\n> **1, 2:** That's a syntax error. Try again.\n> \n> **3:** `=` is the assignment operator. It cannot be used as a condition.\n> \n> **4:** That's right. In Go, you don't need to use the parentheses.\n\n\n## The following code doesn't work. How you can fix it?\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    // this program prints \"cool\"\n    // when the mood is \"happy\"\n\n    mood := \"happy\"\n\n    if \"happy\" {\n        fmt.Println(\"cool\")\n    }\n}\n```\n1. Just wrap the \"happy\" inside parentheses.\n2. You need to compare mood with \"happy\". Like this: `if mood == \"happy\" { ... }` *CORRECT*\n3. Just directly use `mood` instead of `happy`. Like this: `if mood { ... }`\n4. This should work! This is a tricky question.\n\n> **1:** That won't change anything. Go adds the parentheses automatically behind the scenes for every if statement.\n>\n> **2:** Yep. In Go, condition expressions always yield a bool value. Using a comparison operator will yield a bool value. So, it will work.\n>\n> **4:** No, it's not :)\n\n\n## How can you simplify the following code? You only need to change the condition expression, but how?\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    happy := true\n\n    if happy == true {\n        fmt.Println(\"cool!\")\n    }\n}\n```\n1. `happy != false`\n2. `!happy == false`\n3. `happy` *CORRECT*\n4. `!happy == true`\n\n> **1, 2:** Right! But you can do it better.\n>\n> **3:** Perfect! You don't need to compare the value to `true`. `happy` is already true, so it'll print \"cool!\".\n>\n> **4:** That won't print anything. `!happy` yields false.\n\n\n## How can you simplify the following code? You only need to change the condition expression, but how?\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    happy := false\n\n    if happy == !true {\n        fmt.Println(\"why not?\")\n    }\n}\n```\n1. Easy! Like this: `happy != true`\n2. `!happy` *CORRECT*\n3. `happy == false`\n4. `!happy == false`\n\n> **1, 3:** Right! But you can do it better.\n>\n> **2:** Perfect! You don't need to compare the value to `false` or to `!true` (which is false). `!happy` already returns true, because it's false at the beginning.\n>\n> **4:** That won't print anything. `happy` will be true.\n\n\n## This code contains an error. How to fix it?\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    happy := false\n\n    if happy {\n        fmt.Println(\"cool!\")\n    } else if !happy {\n        fmt.Println(\"why not?\")\n    } else {\n        fmt.Println(\"why not?\")\n    } else {\n        fmt.Println(\"why not?\")\n    }\n}\n```\n1. Remove one of the else branches. *CORRECT*\n2. Move the else if as the last branch.\n3. It repeats \"why not?\" several times.\n4. Remove the `else if` branch.\n\n> **1:** Right. There can be only one else branch.\n> \n> **2:** If there's an else branch, you can't move else if branch as the last branch.\n>\n> **3, 4:** So? :) That's not the cause of the problem.\n>\n\n\n## What's the problem with the following code?\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    happy := true\n    energic := happy\n\n    if happy {\n        fmt.Println(\"cool!\")\n    } else if !happy {\n        fmt.Println(\"why not?\")\n    } else if energic {\n        fmt.Println(\"working out?\")\n    }\n}\n```\n1. It declares the energic variable unnecessarily.\n2. You can't use more than one else if branch.\n3. It will never run the last else if branch. *CORRECT*\n4. There's no else branch.\n\n> **2:** Well, actually you can.\n> \n> **3:** Right. `happy` can only be either true or false. That means, it will always execute the first two branches, but it will never execute the else if branch.\n> \n> **4:** It doesn't have to be. Else branch is optional.\n\n\n## How can you simplify the following code?\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    happy := false\n\n    if happy {\n        fmt.Println(\"cool!\")\n    } else if happy != true {\n        fmt.Println(\"why not?\")\n    } else {\n        fmt.Println(\"why not?\")\n    }\n}\n```\n1. Change `else if`'s condition to: `!happy`.\n2. Move the else branch before else if.\n3. Remove the else branch.\n4. Remove the else if branch. *CORRECT*\n\n> **1, 3:** Close! But, you can do it even better.\n>\n> **2:** You can't: `else` branch should be the last branch.\n>\n> **4:** Cool. That's not necessary because `else` branch already handless \"unhappy\" situation. It's simpler because it doesn't have a condition."
  },
  {
    "path": "11-if/questions/4-error-handling.md",
    "content": "## Why error handling is needed?\n1. I don't know.\n2. To control the execution flow.\n3. To make a program malware safe.\n4. Because, things can go wrong. *CORRECT*\n\n> **1:** Then, please watch the lecture again! :)\n>\n> **2:** Actually yes, but that's not the main reason. \n> \n> **3:** Come on!\n\n\n## What's a nil value?\n1. The dark matter that rules the universe.\n2. It's a zero value for pointers or pointer-based types. It means the value is uninitialized. *CORRECT*\n3. It's equal to empty string: `\"\" == nil` is true.\n\n\n## What's an error value?\n1. It stores the error details *CORRECT*\n2. A global variable which stores the error status.\n3. A global constant which stores the error status.\n\n> **2, 3:** There aren't any global variables in Go. There are only package level variables. And, since the error value is just a value, so it can be stored in any variable.\n> \n\n\n## How Go handles error handling?\n1. Using a throw/catch statement\n2. Using a simple if statement with nil comparison *CORRECT*\n3. Using a mechanism called tagging\n\n> **1:** There isn't a throw/catch statement in Go; unlike Java, C#, and so on... Go is explicit.\n\n\n## When you should handle the errors?\n1. After the main func ends.\n2. Before calling a function.\n3. Immediately, after calling a function which returns an error value. *CORRECT*\n\n\n## For which one of the following functions that you might want to handle the errors?\n```go\nfunc Read() error\nfunc Write() error\nfunc String() string\nfunc Reset()\n```\n1. Read and Write *CORRECT*\n2. String and Reset\n3. Read, Write and Reset\n4. For neither of them\n5. For all of them\n\n> **1:** They return error values. So, you might want to handle the errors after you call them.\n> \n> **2:** They don't return error values. So, you don't have to handle any errors.\n> \n> **3:** Partially true. Try again.\n\n\n## Let's say a function returns a nil error value. So, what does that mean?\n1. The function call failed.\n2. The function call is successful. *CORRECT*\n3. The function call is in an indeterministic state. We can't know.\n\n\n## Let's say a function returns a non-nil error value. So, what does that mean?\n1. The function call failed. *CORRECT*\n2. The function call is successful.\n3. The function call is in an indeterministic state. We can't know.\n\n> **1:** Yep. Later on you'll learn that, this is not always true. Sometimes a function can return a non-nil error value, and the returned value may indicate something rather than an error. Search on Google: golang io EOF error if you're curious.\n\n\n## Does the following program correctly handles the error?\n\n**NOTE:** This is what the `ParseDuration` function looks like:\n\n```go\nfunc ParseDuration(s string) (Duration, error)\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\td, err := time.ParseDuration(\"1h10s\")\n\tif err != nil {\n\t\tfmt.Println(d)\n\t}\n}\n```\n1. Yes. It prints the parsed duration if it's successful.\n2. No. It doesn't check for the errors.\n3. No. It prints the duration even when there's an error. *CORRECT*\n\n> **1:** Yes, it handles the error; however it does so incorrectly. Something is missing here. Look closely.\n> \n> **2:** Actually, it does.\n> \n> **3:** That's right. It shouldn't use the returned value when there's an error.\n\n\n## Does the following program correctly handles the error?\n\n**NOTE:** This is what the `ParseDuration` function looks like:\n\n```go\nfunc ParseDuration(s string) (Duration, error)\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\td, err := time.ParseDuration(\"1h10s\")\n\tif err != nil {\n        fmt.Println(\"Parsing error:\", err)\n        return\n    }\n    fmt.Println(d)\n}\n```\n1. Yes. It prints the parsed duration if it's successful. *CORRECT*\n2. No. It doesn't check for the errors.\n3. No. It prints the duration even when there's an error.\n\n> **1:** That's right. When there's an error, it prints a message and it quits from the program.\n> \n> **2:** Actually, it does.\n> \n> **3:** No, it does not. It only prints it when there isn't an error.\n"
  },
  {
    "path": "11-if/questions/5-short-if.md",
    "content": "## How to fix this program?\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tif err != nil; d, err := time.ParseDuration(\"1h10s\") {\n\t\tfmt.Println(d)\n\t}\n}\n```\n1. Swap the simple statement with the `err != nil` check. *CORRECT*\n2. Remove the error handling.\n3. Remove the semicolon.\n4. Change the short declaration to an assignment.\n\n> **1:** Yes. In a short if statement, the simple statement (the short declaration there) should be the first part of it. Then, after the semicolon separator, there should be a condition expression.\n> \n> **2:** You don't want that. That's not the issue here.\n\n\n## What does this program print?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n\tdone := false\n\tif done := true; done {\n\t\tfmt.Println(done)\n\t}\n\tfmt.Println(done)\n}\n```\n1. true and true\n2. false and false\n3. true and false *CORRECT*\n4. false and true\n\n> **3:** Yes. It shadows the main()'s done variable, and inside the if statement, it prints \"true\". Then, after the if statement ends, it prints the main()'s done variable which is \"false\".\n\n\n## There's a shadowing issue in this program. The program should print: 10, now it prints: 0.\n\n**How can you fix this it?**\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"strconv\"\n)\n\nfunc main() {\n  var n int\n\n  if n, err := strconv.Atoi(\"10\"); err != nil {\n    fmt.Printf(\"error: %s (n: %d)\", err, n)\n    return\n  }\n\n  fmt.Println(n)\n}\n```\n\n_See the code also in here: https://play.golang.org/p/fDrmcXWGnQB_\n\n1. Remove the first declaration (main()'s n variable).\n2. Remove the declaration in the short-if (if's n).\n3. Declare an error variable outside of the main.\n4. Declare an error variable along with main's n variable, then change the short-if declaration to an assignment. *CORRECT*\n\n> **1:** That will break the program. Because, the last line prints it.\n> \n> **2:** The program uses it to set the n.\n> \n> **3:** There will be \"unused variable\" error.\n> **4:** Yes, that will solve the shadowing issue. Short-if will reuse the same 'n' variable (main()'s n). So, the converted number 'n' will be printed as: 10. See the solution here: https://play.golang.org/p/6jc-nZJNHYb\n\n"
  },
  {
    "path": "12-switch/01-one-case/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcity := \"Paris\"\n\n\tswitch city {\n\tcase \"Paris\":\n\t\tfmt.Println(\"France\")\n\t}\n\n\t// SIMILAR TO IF\n\t// ------------------------------------\n\n\t// switch statement is converted to an if statement\n\t// automatically behind the scenes\n\t//\n\t// above switch statement is similar to this if\n\n\t// if city == \"Paris\" {\n\t// \tfmt.Println(\"France\")\n\t// }\n}\n"
  },
  {
    "path": "12-switch/02-multiple-cases/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tcity := os.Args[1]\n\n\tswitch city {\n\tcase \"Paris\":\n\t\tfmt.Println(\"France\")\n\t\t// break // unnecessary in Go\n\n\t\t// vip := true\n\t\t// fmt.Println(\"VIP trip?\", vip)\n\n\tcase \"Tokyo\":\n\t\tfmt.Println(\"Japan\")\n\t\t// fmt.Println(\"VIP trip?\", vip)\n\t}\n\n\t// if city == \"Paris\" {\n\t// \tfmt.Println(\"France\")\n\t// } else if city == \"Tokyo\" {\n\t// \tfmt.Println(\"Japan\")\n\t// }\n}\n"
  },
  {
    "path": "12-switch/03-default-clause/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tcity := os.Args[1]\n\n\tswitch city {\n\tcase \"Paris\":\n\t\tfmt.Println(\"France\")\n\tcase \"Tokyo\":\n\t\tfmt.Println(\"Japan\")\n\tdefault:\n\t\tfmt.Println(\"Where?\")\n\t\t// there can be only one default in a switch\n\t\t// default:\n\t\t// \tfmt.Println(\"Where?\")\n\t}\n\n\t// if city == \"Paris\" {\n\t// \tfmt.Println(\"France\")\n\t// } else if city == \"Tokyo\" {\n\t// \tfmt.Println(\"Japan\")\n\t// } else {\n\t// \tfmt.Println(\"Where?\")\n\t// }\n}\n"
  },
  {
    "path": "12-switch/04-multiple-conditions/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tcity := os.Args[1]\n\n\tswitch city {\n\tcase \"Paris\", \"Lyon\":\n\t\tfmt.Println(\"France\")\n\tcase \"Tokyo\":\n\t\tfmt.Println(\"Japan\")\n\t}\n\n\t// if city == \"Paris\" || city == \"Lyon\" {\n\t// \tfmt.Println(\"France\")\n\t// } else if city == \"Tokyo\" {\n\t// \tfmt.Println(\"Japan\")\n\t// }\n}\n"
  },
  {
    "path": "12-switch/05-bool-expressions/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ti := 10\n\n\tswitch {\n\tcase i > 0:\n\t\tfmt.Println(\"positive\")\n\tcase i < 0:\n\t\tfmt.Println(\"negative\")\n\tdefault:\n\t\tfmt.Println(\"zero\")\n\t}\n}\n"
  },
  {
    "path": "12-switch/06-fallthrough/01-without/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ti := 142\n\n\tswitch {\n\tcase i > 100:\n\t\tfmt.Print(\"big positive number\")\n\tcase i > 0:\n\t\tfmt.Print(\"positive number\")\n\tdefault:\n\t\tfmt.Print(\"number\")\n\t}\n\n\tfmt.Println()\n}\n"
  },
  {
    "path": "12-switch/06-fallthrough/02-with/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ti := 142\n\n\tswitch {\n\tcase i > 100:\n\t\tfmt.Print(\"big \")\n\t\tfallthrough\n\tcase i > 0:\n\t\tfmt.Print(\"positive \")\n\t\tfallthrough\n\tdefault:\n\t\tfmt.Print(\"number\")\n\t}\n\n\tfmt.Println()\n}\n"
  },
  {
    "path": "12-switch/07-short-switch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// i := 10\n\n\t// true is in a comment now\n\t// you can delete that part if you want\n\t// it's by default true anyway.\n\tswitch i := 10; /* true */ {\n\tcase i > 0:\n\t\tfmt.Println(\"positive\")\n\tcase i < 0:\n\t\tfmt.Println(\"negative\")\n\tdefault:\n\t\tfmt.Println(\"zero\")\n\t}\n}\n"
  },
  {
    "path": "12-switch/08-parts-of-the-day/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\t// time.Now() gets the current time\n\t// and in turn, .Hour() gets the current hour from it\n\n\t// h := time.Now().Hour()\n\t// fmt.Println(\"Current hour is\", h)\n\n\tswitch h := time.Now().Hour(); {\n\tcase h >= 18: // 18 to 23\n\t\tfmt.Println(\"good evening\")\n\tcase h >= 12: // 12 to 18\n\t\tfmt.Println(\"good afternoon\")\n\tcase h >= 6: // 6 to 12\n\t\tfmt.Println(\"good morning\")\n\tdefault: // 0 to 5\n\t\tfmt.Println(\"good night\")\n\t}\n\n\t// h is not available here\n\t// it's bound to switch statement's block\n\t// fmt.Println(h)\n}\n"
  },
  {
    "path": "12-switch/09-when-to-use/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Gimme a month name.\")\n\t\treturn\n\t}\n\n\t// m := os.Args[1]\n\n\t// if m == \"Dec\" || m == \"Jan\" || m == \"Feb\" {\n\t// \tfmt.Println(\"Winter\")\n\t// } else if m == \"Mar\" || m == \"Apr\" || m == \"May\" {\n\t// \tfmt.Println(\"Spring\")\n\t// } else if m == \"Jun\" || m == \"Jul\" || m == \"Aug\" {\n\t// \tfmt.Println(\"Summer\")\n\t// } else if m == \"Sep\" || m == \"Oct\" || m == \"Nov\" {\n\t// \tfmt.Println(\"Fall\")\n\t// } else {\n\t// \tfmt.Println(\"ERROR: not a month.\")\n\t// }\n\n\tswitch m := os.Args[1]; m {\n\tcase \"Dec\", \"Jan\", \"Feb\":\n\t\tfmt.Println(\"Winter\")\n\tcase \"Mar\", \"Apr\", \"May\":\n\t\tfmt.Println(\"Spring\")\n\tcase \"Jun\", \"Jul\", \"Aug\":\n\t\tfmt.Println(\"Summer\")\n\tcase \"Sep\", \"Oct\", \"Nov\":\n\t\tfmt.Println(\"Fall\")\n\tdefault:\n\t\tfmt.Printf(\"%q is not a month.\\n\", m)\n\t}\n}\n"
  },
  {
    "path": "12-switch/exercises/01-richter-scale/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// STORY\n//  You're curious about the richter scales. When reporters\n//  say: \"There's been a 5.5 magnitude earthquake\",\n//\n//  You want to know what that means.\n//\n//  So, you've decided to write a program to do that for you.\n//\n// EXERCISE: Richter Scale\n//\n//  1. Get the earthquake magnitude from the command-line.\n//  2. Display its corresponding description.\n//\n// ---------------------------------------------------------\n// MAGNITUDE                    DESCRIPTION\n// ---------------------------------------------------------\n// Less than 2.0                micro\n// 2.0 and less than 3.0        very minor\n// 3.0 and less than 4.0        minor\n// 4.0 and less than 5.0        light\n// 5.0 and less than 6.0        moderate\n// 6.0 and less than 7.0        strong\n// 7.0 and less than 8.0        major\n// 8.0 and less than 10.0       great\n// 10.0 or more                 massive\n//\n// EXPECTED OUTPUT\n//  go run main.go\n//    Give me the magnitude of the earthquake.\n//\n//  go run main.go ABC\n//    I couldn't get that, sorry.\n//\n//  go run main.go 0.5\n//    0.50 is micro\n//\n//  go run main.go 2.5\n//    2.50 is very minor\n//\n//  go run main.go 3\n//    3.00 is minor\n//\n//  go run main.go 4.5\n//    4.50 is light\n//\n//  go run main.go 5\n//    5.00 is moderate\n//\n//  go run main.go 6\n//    6.00 is strong\n//\n//  go run main.go 7\n//    7.00 is major\n//\n//  go run main.go 8\n//    8.00 is great\n//\n//  go run main.go 11\n//    11.00 is massive\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "12-switch/exercises/01-richter-scale/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\targs := os.Args\n\tif len(args) != 2 {\n\t\tfmt.Println(\"Give me the magnitude of the earthquake.\")\n\t\treturn\n\t}\n\n\trichter, err := strconv.ParseFloat(args[1], 64)\n\tif err != nil {\n\t\tfmt.Println(\"I couldn't get that, sorry.\")\n\t\treturn\n\t}\n\n\tvar desc string\n\n\tswitch r := richter; {\n\tcase r < 2:\n\t\tdesc = \"micro\"\n\tcase r >= 2 && r < 3:\n\t\tdesc = \"very minor\"\n\tcase r >= 3 && r < 4:\n\t\tdesc = \"minor\"\n\tcase r >= 4 && r < 5:\n\t\tdesc = \"light\"\n\tcase r >= 5 && r < 6:\n\t\tdesc = \"moderate\"\n\tcase r >= 6 && r < 7:\n\t\tdesc = \"strong\"\n\tcase r >= 7 && r < 8:\n\t\tdesc = \"major\"\n\tcase r >= 8 && r < 10:\n\t\tdesc = \"great\"\n\tdefault:\n\t\tdesc = \"massive\"\n\t}\n\n\tfmt.Printf(\"%.2f is %s\\n\", richter, desc)\n}\n"
  },
  {
    "path": "12-switch/exercises/02-richter-scale-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Richter Scale #2\n//\n//  Repeat the previous exercise.\n//\n//  But, this time, get the description and print the\n//  corresponding richter scale.\n//\n//  See the expected outputs.\n//\n// ---------------------------------------------------------\n// MAGNITUDE                    DESCRIPTION\n// ---------------------------------------------------------\n// Less than 2.0                micro\n// 2.0 to less than 3.0         very minor\n// 3.0 to less than 4.0         minor\n// 4.0 to less than 5.0         light\n// 5.0 to less than 6.0         moderate\n// 6.0 to less than 7.0         strong\n// 7.0 to less than 8.0         major\n// 8.0 to less than 10.0        great\n// 10.0 or more                 massive\n//\n// EXPECTED OUTPUT\n//  go run main.go\n//   Tell me the magnitude of the earthquake in human terms.\n//\n//  go run main.go alien\n//   alien's richter scale is unknown\n//\n//  go run main.go micro\n//   micro's richter scale is less than 2.0\n//\n//  go run main.go \"very minor\"\n//   very minor's richter scale is 2 - 2.9\n//\n//  go run main.go minor\n//   minor's richter scale is 3 - 3.9\n//\n//  go run main.go light\n//   light's richter scale is 4 - 4.9\n//\n//  go run main.go moderate\n//   moderate's richter scale is 5 - 5.9\n//\n//  go run main.go strong\n//   strong's richter scale is 6 - 6.9\n//\n//  go run main.go major\n//   major's richter scale is 7 - 7.9\n//\n//  go run main.go great\n//   great's richter scale is 8 - 9.9\n//\n//  go run main.go massive\n//   massive's richter scale is 10+\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "12-switch/exercises/02-richter-scale-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args\n\tif len(args) != 2 {\n\t\tfmt.Println(\"Tell me the magnitude of the earthquake in human terms.\")\n\t\treturn\n\t}\n\n\tvar richter string\n\n\tdesc := args[1]\n\n\tswitch desc {\n\tcase \"micro\":\n\t\trichter = \"less than 2.0\"\n\tcase \"very minor\":\n\t\trichter = \"2 - 2.9\"\n\tcase \"minor\":\n\t\trichter = \"3 - 3.9\"\n\tcase \"light\":\n\t\trichter = \"4 - 4.9\"\n\tcase \"moderate\":\n\t\trichter = \"5 - 5.9\"\n\tcase \"strong\":\n\t\trichter = \"6 - 6.9\"\n\tcase \"major\":\n\t\trichter = \"7 - 7.9\"\n\tcase \"great\":\n\t\trichter = \"8 - 9.9\"\n\tcase \"massive\":\n\t\trichter = \"10+\"\n\tdefault:\n\t\trichter = \"unknown\"\n\t}\n\n\tfmt.Printf(\n\t\t\"%s's richter scale is %s\\n\",\n\t\tdesc, richter,\n\t)\n}\n"
  },
  {
    "path": "12-switch/exercises/03-convert/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Convert\n//\n//  Convert the if statement to a switch statement.\n// ---------------------------------------------------------\n\nconst (\n\tusage       = \"Usage: [username] [password]\"\n\terrUser     = \"Access denied for %q.\\n\"\n\terrPwd      = \"Invalid password for %q.\\n\"\n\taccessOK    = \"Access granted to %q.\\n\"\n\tuser, user2 = \"jack\", \"inanc\"\n\tpass, pass2 = \"1888\", \"1879\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 3 {\n\t\tfmt.Println(usage)\n\t\treturn\n\t}\n\n\tu, p := args[1], args[2]\n\n\t//\n\t// REFACTOR THIS TO A SWITCH\n\t//\n\tif u != user && u != user2 {\n\t\tfmt.Printf(errUser, u)\n\t} else if u == user && p == pass {\n\t\tfmt.Printf(accessOK, u)\n\t} else if u == user2 && p == pass2 {\n\t\tfmt.Printf(accessOK, u)\n\t} else {\n\t\tfmt.Printf(errPwd, u)\n\t}\n}\n"
  },
  {
    "path": "12-switch/exercises/03-convert/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nconst (\n\tusage       = \"Usage: [username] [password]\"\n\terrUser     = \"Access denied for %q.\\n\"\n\terrPwd      = \"Invalid password for %q.\\n\"\n\taccessOK    = \"Access granted to %q.\\n\"\n\tuser, user2 = \"jack\", \"inanc\"\n\tpass, pass2 = \"1888\", \"1879\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 3 {\n\t\tfmt.Println(usage)\n\t\treturn\n\t}\n\n\tu, p := args[1], args[2]\n\n\t// More readable, right? 👍\n\tswitch {\n\tcase u != user && u != user2:\n\t\tfmt.Printf(errUser, u)\n\tcase u == user && p == pass:\n\t\t// notice this one (no more duplication)\n\t\tfallthrough\n\tcase u == user2 && p == pass2:\n\t\tfmt.Printf(accessOK, u)\n\tdefault:\n\t\tfmt.Printf(errPwd, u)\n\t}\n}\n"
  },
  {
    "path": "12-switch/exercises/04-string-manipulator/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// STORY\n//  You want to write a program that will manipulate a\n//  given string to uppercase, lowercase, and title case.\n//\n// EXERCISE: String Manipulator\n//\n//  1. Get the operation as the first argument.\n//\n//  2. Get the string to be manipulated as the 2nd argument.\n//\n// HINT\n//  You can find the manipulation functions in the strings\n//  package Go documentation (ToLower, ToUpper, Title).\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//    [command] [string]\n//\n//    Available commands: lower, upper and title\n//\n//  go run main.go lower 'OMG!'\n//    omg!\n//\n//  go run main.go upper 'omg!'\n//    OMG!\n//\n//  go run main.go title \"mr. charles darwin\"\n//    Mr. Charles Darwin\n//\n//  go run main.go genius \"mr. charles darwin\"\n//    Unknown command: \"genius\"\n// ---------------------------------------------------------\n\nfunc main() {\n\n}\n"
  },
  {
    "path": "12-switch/exercises/04-string-manipulator/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst usage = `[command] [string]\n\nAvailable commands: lower, upper and title`\n\nfunc main() {\n\targs := os.Args\n\tif len(args) != 3 {\n\t\tfmt.Println(usage)\n\t\treturn\n\t}\n\n\tcmd, str := args[1], args[2]\n\tswitch cmd {\n\tcase \"lower\":\n\t\tfmt.Println(strings.ToLower(str))\n\tcase \"upper\":\n\t\tfmt.Println(strings.ToUpper(str))\n\tcase \"title\":\n\t\tfmt.Println(strings.Title(str))\n\tdefault:\n\t\tfmt.Printf(\"Unknown command: %q\\n\", cmd)\n\t}\n}\n"
  },
  {
    "path": "12-switch/exercises/05-days-in-month/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\t\"time\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Days in a Month\n//\n//  Refactor the previous exercise from the if statement\n//  section.\n//\n//  \"Print the number of days in a given month.\"\n//\n//  Use a switch statement instead of if statements.\n// ---------------------------------------------------------\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Give me a month name\")\n\t\treturn\n\t}\n\n\tyear := time.Now().Year()\n\tleap := year%4 == 0 && (year%100 != 0 || year%400 == 0)\n\n\tdays, month := 28, os.Args[1]\n\n\tif m := strings.ToLower(month); m == \"april\" ||\n\t\tm == \"june\" ||\n\t\tm == \"september\" ||\n\t\tm == \"november\" {\n\t\tdays = 30\n\t} else if m == \"january\" ||\n\t\tm == \"march\" ||\n\t\tm == \"may\" ||\n\t\tm == \"july\" ||\n\t\tm == \"august\" ||\n\t\tm == \"october\" ||\n\t\tm == \"december\" {\n\t\tdays = 31\n\t} else if m == \"february\" {\n\t\tif leap {\n\t\t\tdays = 29\n\t\t}\n\t} else {\n\t\tfmt.Printf(\"%q is not a month.\\n\", month)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%q has %d days.\\n\", month, days)\n}\n"
  },
  {
    "path": "12-switch/exercises/05-days-in-month/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\t\"time\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Give me a month name\")\n\t\treturn\n\t}\n\n\tyear := time.Now().Year()\n\tleap := year%4 == 0 && (year%100 != 0 || year%400 == 0)\n\n\tdays, month := 28, os.Args[1]\n\n\tswitch strings.ToLower(month) {\n\tcase \"april\", \"june\", \"september\", \"november\":\n\t\tdays = 30\n\tcase \"january\", \"march\", \"may\", \"july\",\n\t\t\"august\", \"october\", \"december\":\n\t\tdays = 31\n\tcase \"february\":\n\t\tif leap {\n\t\t\tdays = 29\n\t\t}\n\tdefault:\n\t\tfmt.Printf(\"%q is not a month.\\n\", month)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%q has %d days.\\n\", month, days)\n}\n"
  },
  {
    "path": "12-switch/exercises/README.md",
    "content": "# Switch Statement\n\n1. **[Richter Scale](https://github.com/inancgumus/learngo/tree/master/12-switch/exercises/01-richter-scale)**\n\n2. **[Richter Scale #2](https://github.com/inancgumus/learngo/tree/master/12-switch/exercises/02-richter-scale-2)**\n\n3. **[Convert](https://github.com/inancgumus/learngo/tree/master/12-switch/exercises/03-convert)**\n\n4. **[String Manipulator](https://github.com/inancgumus/learngo/tree/master/12-switch/exercises/04-string-manipulator)**\n\n5. **[Days in a Month](https://github.com/inancgumus/learngo/tree/master/12-switch/exercises/05-days-in-month)**\n"
  },
  {
    "path": "12-switch/questions/questions.md",
    "content": "## What's the difference between if and switch statements?\n1. If statements control the execution flow but switch statements do not\n2. If statements are much more readable alternatives to switch statements\n3. Switch statements are much more readable alternatives to if statements *CORRECT*\n\n> **1:** They both control the execution flow.\n> \n> **2:** Sometimes true, but, for complex if statements, switch statement can make them much more readable.\n\n\n## What type of values can you use as a switch condition?\n```go\nswitch condition {\n    // ....\n}\n```\n1. int\n2. bool\n3. string\n4. Any type of values *CORRECT*\n\n> **4:** Unlike most other C based languages, in Go, a switch statement is actually a syntactic-sugar for a if statement. This means that, Go converts a switch statement into an if statement behind the scenes. So, any type of values can be used as a condition.\n\n\n## What type of values can you use as the case conditions for the following switch statement?\n```go\nswitch false {\ncase condition:\n    // ...\n}\n```\n1. int\n2. bool *CORRECT*\n3. string\n4. Any type of values\n\n> **2:** Yes, you can only use bool values because in the example, the switch's condition is a bool.\n\n\n## What type of values can you use as the case conditions for the following switch statement?\n```go\nswitch \"go\" {\ncase condition:\n    // ...\n}\n```\n1. int\n2. bool\n3. string *CORRECT*\n4. Any type of values\n\n> **3:** Yes, you can only use string values because in the example, the switch's condition is a string.\n\n\n## What's the problem in the following code?\n```go\nswitch 5 {\ncase 5:\ncase 6:\ncase 5:\n}\n```\n1. Case clauses don't have any statements\n2. The same constants are used multiple times in case conditions *CORRECT*\n3. Switch condition cannot be an untyped int\n\n> **2:** That's right. 5 is used by multiple case clauses as case conditions. It should be used only once.\n\n\n## When the following code runs, which case will be executed?\n```go\nweather := \"hot\"\nswitch weather {\ncase \"very cold\", \"cold\":\n    // ...\ncase \"very hot\", \"hot\":\n    // ...\ndefault:\n    // ...\n}\n```\n1. None of them\n2. The first case clause\n3. The second case clause *CORRECT*\n4. The default clause\n\n> **3:** That's right. When switch's condition is either \"hot\" or \"very hot\", the 2nd case will be executed.\n\n\n## When the following code runs, which clause will be executed?\n```go\nswitch weather := \"too hot\"; weather {\ndefault:\n    // ...\ncase \"very cold\", \"cold\":\n    // ...\ncase \"very hot\", \"hot\":\n    // ...\n}\n```\n1. None of them\n2. The first case clause\n3. The second case clause\n4. The default clause *CORRECT*\n\n> **4:** That's right. The switch's condition doesn't match to any of the case conditions, so the default clause will be executed as a last resort. And the default clause can be in any place inside a switch statement.\n\n\n## When the following code runs, which case will be executed?\n```go\nswitch weather := \"too hot\"; weather {\ncase \"very cold\", \"cold\":\n    // ...\ncase \"very hot\", \"hot\":\n    // ...\n}\n```\n1. None of them *CORRECT*\n2. The first case clause\n3. The second case clause\n4. The default clause\n\n> **1:** That's right. The switch's condition doesn't match to any of the case conditions, and there isn't a default clause. So, none of the clauses will be executed.\n\n\n## What does the following program print?\n```go\nrichter := 2.5\n\nswitch r := richter; {\ncase r < 2:\n    fallthrough\ncase r >= 2 && r < 3:\n    fallthrough\ncase r >= 5 && r < 6:\n    fmt.Println(\"Not important\")\ncase r >= 6 && r < 7:\n    fallthrough\ncase r >= 7:\n    fmt.Println(\"Destructive\")\n}\n```\n1. Nothing\n2. \"Not important\" *CORRECT*\n3. \"Destructive\"\n\n> **2:** That's right! When fallthrough is used, the following clause will be executed without checking its condition.\n\n\n## What's the problem in the following code?\n```go\nrichter := 14.5\n\nswitch r := richter; {\ncase r >= 5 && r < 6:\n    fallthrough\n    fmt.Println(\"Moderate\")\ndefault:\n    fmt.Println(\"Unknown\")\ncase r >= 7:\n    fmt.Println(\"Destructive\")\n}\n```\n1. default clause should be the last clause\n2. default clause should have a fallthrough statement\n3. The first case should use the fallthrough statement as its last statement *CORRECT*\n\n> **3:** That's right! In a case block, fallthrough can only be used as the last statement.\n\n\n## What does the following program print?\n```go\nn := 8\n\nswitch {\ncase n > 5, n < 1:\n    fmt.Println(\"n is big\")\ncase n == 8:\n    fmt.Println(\"n is 8\")\n}\n```\n1. Nothing\n2. \"n is 8\"\n3. \"n is big\" *CORRECT*\n\n> **3:** That's right! Switch runs top-to-bottom and case conditions run left-to-right. Here, 1st case's 1st condition expression (which is n > 5) will yield true, so the 1st case will be executed.\n"
  },
  {
    "path": "13-loops/01-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar sum int\n\n\t// sum += 1\n\t// sum += 2\n\t// sum += 3\n\t// sum += 4\n\t// sum += 5\n\n\tfor i := 1; i <= 1000; i++ {\n\t\tsum += i\n\t}\n\n\tfmt.Println(sum)\n}\n"
  },
  {
    "path": "13-loops/02-break/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar (\n\t\tsum int\n\t\ti   = 1\n\t)\n\n\tfor {\n\t\tif i > 5 {\n\t\t\tbreak\n\t\t}\n\n\t\tsum += i\n\n\t\tfmt.Println(i, \"-->\", sum)\n\n\t\ti++\n\t}\n\n\tfmt.Println(sum)\n}\n"
  },
  {
    "path": "13-loops/03-continue/01-a-before/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar (\n\t\tsum int\n\t\ti   = 1\n\t)\n\n\tfor {\n\t\tif i > 10 {\n\t\t\tbreak\n\t\t}\n\n\t\tif i%2 != 0 {\n\t\t\t// this continue creates an endless loop\n\t\t\t// since the code never increases the i\n\t\t\tcontinue\n\t\t}\n\n\t\tsum += i\n\n\t\tfmt.Println(i, \"-->\", sum)\n\n\t\ti++\n\t}\n\n\tfmt.Println(sum)\n}\n"
  },
  {
    "path": "13-loops/03-continue/01-b-after/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar (\n\t\tsum int\n\t\ti   = 1\n\t)\n\n\tfor {\n\t\tif i > 10 {\n\t\t\tbreak\n\t\t}\n\n\t\tif i%2 != 0 {\n\t\t\t// just by putting this here we solve the problem\n\t\t\ti++\n\t\t\tcontinue\n\t\t}\n\n\t\tsum += i\n\n\t\tfmt.Println(i, \"-->\", sum)\n\n\t\ti++\n\t}\n\n\tfmt.Println(sum)\n}\n"
  },
  {
    "path": "13-loops/04-nested-loops-multiplication-table/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// EXERCISE: Get the `max` from the user\n//           And create the table according to that.\n\nconst max = 5\n\nfunc main() {\n\t// print the header\n\tfmt.Printf(\"%5s\", \"X\")\n\tfor i := 0; i <= max; i++ {\n\t\tfmt.Printf(\"%5d\", i)\n\t}\n\tfmt.Println()\n\n\tfor i := 0; i <= max; i++ {\n\t\t// print the vertical header\n\t\tfmt.Printf(\"%5d\", i)\n\n\t\t// print the cells\n\t\tfor j := 0; j <= max; j++ {\n\t\t\tfmt.Printf(\"%5d\", i*j)\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "13-loops/05-for-range/01-loop-over-slices/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\t// i := 1\n\t// fmt.Printf(\"%q\\n\", os.Args[1])\n\t// fmt.Printf(\"%q\\n\", os.Args[i])\n\n\t// i++\n\t// fmt.Printf(\"%q\\n\", os.Args[2])\n\t// fmt.Printf(\"%q\\n\", os.Args[i])\n\n\t// i++\n\t// fmt.Printf(\"%q\\n\", os.Args[3])\n\t// fmt.Printf(\"%q\\n\", os.Args[i])\n\n\t// --------------------------------\n\t// #1st way:\n\t// --------------------------------\n\n\t// for i := 1; i < len(os.Args); i++ {\n\t// \tfmt.Printf(\"%q\\n\", os.Args[i])\n\t// }\n\n\t// --------------------------------\n\t// #2nd way:\n\t// --------------------------------\n\n\t// for i, v := range os.Args {\n\t// \tif i == 0 {\n\t// \t\tcontinue\n\t// \t}\n\t// \tfmt.Printf(\"%q\\n\", v)\n\t// }\n\n\t// --------------------------------\n\t// #3rd way (best):\n\t// --------------------------------\n\n\tfor _, v := range os.Args[1:] {\n\t\tfmt.Printf(\"%q\\n\", v)\n\t}\n}\n"
  },
  {
    "path": "13-loops/05-for-range/02-loop-over-words/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// this will split the following string by spaces\n\t// and then it will put it inside words variable\n\t// as a slice of strings\n\twords := strings.Fields(\n\t\t\"lazy cat jumps again and again and again\",\n\t)\n\t//    1    2    3    4    5     6    7    8\n\n\t// --------------------------------\n\t// #1st way:\n\t// --------------------------------\n\t// for j := 0; j < len(words); j++ {\n\t// \tfmt.Printf(\"#%-2d: %q\\n\", j+1, words[j])\n\t// }\n\n\t// --------------------------------\n\t// #2nd way (best):\n\t// --------------------------------\n\tfor i, v := range words {\n\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, v)\n\t}\n\n\t// --------------------------------\n\t// #3rd way (reuse mechanism):\n\t// --------------------------------\n\t// var (\n\t// \ti int\n\t// \tv string\n\t// )\n\n\t// for i, v = range words {\n\t// \tfmt.Printf(\"#%-2d: %q\\n\", i+1, v)\n\t// }\n\n\t// fmt.Printf(\"Last value of i and v %d %q\\n\", i, v)\n}\n"
  },
  {
    "path": "13-loops/06-project-lucky-number-game/01-randomization/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"time\"\n)\n\nfunc main() {\n\t// rand.Seed(10)\n\t// rand.Seed(100)\n\n\t// t := time.Now()\n\t// rand.Seed(t.UnixNano())\n\n\t// ^-- same:\n\n\trand.Seed(time.Now().UnixNano())\n\n\tguess := 10\n\n\tfor n := 0; n != guess; {\n\t\tn = rand.Intn(guess + 1)\n\t\tfmt.Printf(\"%d \", n)\n\t}\n\tfmt.Println()\n}\n"
  },
  {
    "path": "13-loops/06-project-lucky-number-game/02-game/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) != 1 {\n\t\t// fmt.Println(\"Pick a number.\")\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tguess, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess < 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\n\tfor turn := 0; turn < maxTurns; turn++ {\n\t\tn := rand.Intn(guess + 1)\n\n\t\tif n == guess {\n\t\t\tfmt.Println(\"🎉  YOU WIN!\")\n\t\t\treturn\n\t\t}\n\t}\n\n\tfmt.Println(\"☠️  YOU LOST... Try again?\")\n}\n"
  },
  {
    "path": "13-loops/07-project-word-finder/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst corpus = \"lazy cat jumps again and again and again\"\n\nfunc main() {\n\twords := strings.Fields(corpus)\n\tquery := os.Args[1:]\n\n\t// after the inner loop breaks\n\t// this parent loop will look for the next queried word\n\tfor _, q := range query {\n\n\t\t// \"break\" will terminate this loop\n\t\tfor i, w := range words {\n\t\t\tif q == w {\n\t\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\n\t\t\t\t// find the first word then break\n\t\t\t\t// the nested loop\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t}\n}\n"
  },
  {
    "path": "13-loops/08-word-finder-labeled-break/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst corpus = \"lazy cat jumps again and again and again\"\n\nfunc main() {\n\twords := strings.Fields(corpus)\n\tquery := os.Args[1:]\n\n\t// labels and other names do not share the same scope\n\t// var queries string\n\t// _ = queries\n\n\t// this label labels the parent loop below\n\t// label's scope is the whole function body\n\t// not only it's block\nqueries:\n\tfor _, q := range query {\n\t\tfor i, w := range words {\n\t\t\tif q == w {\n\t\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\n\t\t\t\t// find the first word then quit\n\t\t\t\tbreak queries\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "13-loops/09-word-finder-labeled-continue/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst corpus = \"lazy cat jumps again and again and again\"\n\nfunc main() {\n\twords := strings.Fields(corpus)\n\tquery := os.Args[1:]\n\nqueries:\n\tfor _, q := range query {\n\t\tfor i, w := range words {\n\t\t\tif q == w {\n\t\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\n\t\t\t\t// skip duplicate words\n\t\t\t\tcontinue queries\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "13-loops/10-word-finder-labeled-switch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst corpus = \"lazy cat jumps again and again and again\"\n\nfunc main() {\n\twords := strings.Fields(corpus)\n\tquery := os.Args[1:]\n\n\t// labels and other names do not share the same scope\n\t// this will work even though `queries` label exists\n\t//\n\t// var queries string\n\t// _ = queries\n\n\t// this label labels the parent loop below.\n\t// label's scope is the whole func main()\nqueries:\n\tfor _, q := range query {\n\n\tsearch:\n\t\tfor i, w := range words {\n\t\t\tswitch q {\n\t\t\tcase \"and\", \"or\", \"the\":\n\t\t\t\tbreak search\n\t\t\t}\n\n\t\t\tif q == w {\n\t\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\n\t\t\t\t// find the first word then quit\n\t\t\t\tcontinue queries\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "13-loops/11-goto/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// cannot step over any variable declarations\n\t// ERROR: \"i\" variable is declared after the jump\n\t//\n\t// goto loop\n\n\tvar i int\n\nloop:\n\tif i < 3 {\n\t\tfmt.Println(\"looping\")\n\t\ti++\n\t\tgoto loop\n\t}\n\tfmt.Println(\"done\")\n}\n"
  },
  {
    "path": "13-loops/exercises/01-basics.md",
    "content": "# Loops\n\n1. **[Sum the Numbers](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/01-sum-the-numbers)**\n\n2. **[Sum the Numbers: Verbose Edition](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/02-sum-the-numbers-verbose)**\n\n3. **[Sum up to N](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/03-sum-up-to-n)**\n\n4. **[Only Evens](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/04-only-evens)**\n\n5. **[Break Up](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/05-break-up)**\n\n6. **[Infinite Kill](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/06-infinite-kill)**"
  },
  {
    "path": "13-loops/exercises/01-sum-the-numbers/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Sum the Numbers\n//\n//  1. By using a loop, sum the numbers between 1 and 10.\n//  2. Print the sum.\n//\n// EXPECTED OUTPUT\n//  Sum: 55\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/01-sum-the-numbers/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar sum int\n\tfor i := 1; i <= 10; i++ {\n\t\tsum += i\n\t}\n\tfmt.Println(\"Sum:\", sum)\n}\n"
  },
  {
    "path": "13-loops/exercises/02-multiplication-table.md",
    "content": "# Multiplication Table\n\n1. **[Dynamic Table](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/07-multiplication-table-exercises/01-dynamic-table)**\n\n2. **[Math Table](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/07-multiplication-table-exercises/02-math-tables)**"
  },
  {
    "path": "13-loops/exercises/02-sum-the-numbers-verbose/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Sum the Numbers: Verbose Edition\n//\n//  By using a loop, sum the numbers between 1 and 10.\n//\n// HINT\n//  1. For printing it as in the expected output, use Print\n//     and Printf functions. They don't print a newline\n//     automatically (unlike a Println).\n//\n//  2. Also, you need to use an if statement to prevent\n//     printing the last plus sign.\n//\n// EXPECTED OUTPUT\n//    1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/02-sum-the-numbers-verbose/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tconst min, max = 1, 10\n\n\tvar sum int\n\tfor i := min; i <= max; i++ {\n\t\tsum += i\n\n\t\tfmt.Print(i)\n\t\tif i < max {\n\t\t\tfmt.Print(\" + \")\n\t\t}\n\t}\n\tfmt.Printf(\" = %d\\n\", sum)\n}\n"
  },
  {
    "path": "13-loops/exercises/03-lucky-number.md",
    "content": "# Lucky Number\n\n1. **[First Turn Winner](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/08-lucky-number-exercises/01-first-turn-winner)**\n\n2. **[Random Messages](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/08-lucky-number-exercises/02-random-messages)**\n\n3. **[Double Guesses](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/08-lucky-number-exercises/03-double-guesses)**\n\n4. **[Verbose Mode](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/08-lucky-number-exercises/04-verbose-mode)**\n\n5. **[Enough Picks](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/08-lucky-number-exercises/05-enough-picks)**\n\n6. **[Dynamic Difficulty](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/08-lucky-number-exercises/06-dynamic-difficulty)**"
  },
  {
    "path": "13-loops/exercises/03-sum-up-to-n/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Sum up to N\n//\n//  1. Get two numbers from the command-line: min and max\n//  2. Convert them to integers (using Atoi)\n//  3. By using a loop, sum the numbers between min and max\n//\n// RESTRICTIONS\n//  1. Be sure to handle the errors. So, if a user doesn't\n//     pass enough arguments or she passes non-numerics,\n//     then warn the user and exit from the program.\n//\n//  2. Also, check that, min < max.\n//\n// HINT\n//  For converting the numbers, you can use `strconv.Atoi`.\n//\n// EXPECTED OUTPUT\n//  Let's suppose that the user runs it like this:\n//\n//    go run main.go 1 10\n//\n//  Then it should print:\n//\n//    1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/03-sum-up-to-n/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif len(os.Args) != 3 {\n\t\tfmt.Println(\"gimme two numbers\")\n\t\treturn\n\t}\n\n\tmin, err1 := strconv.Atoi(os.Args[1])\n\tmax, err2 := strconv.Atoi(os.Args[2])\n\tif err1 != nil || err2 != nil || min >= max {\n\t\tfmt.Println(\"wrong numbers\")\n\t\treturn\n\t}\n\n\tvar sum int\n\tfor i := min; i <= max; i++ {\n\t\tsum += i\n\n\t\tfmt.Print(i)\n\t\tif i < max {\n\t\t\tfmt.Print(\" + \")\n\t\t}\n\t}\n\tfmt.Printf(\" = %d\\n\", sum)\n}\n"
  },
  {
    "path": "13-loops/exercises/04-only-evens/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Only Evens\n//\n//  1. Extend the \"Sum up to N\" exercise\n//  2. Sum only the even numbers\n//\n// RESTRICTIONS\n//  Skip odd numbers using the `continue` statement\n//\n// EXPECTED OUTPUT\n//  Let's suppose that the user runs it like this:\n//\n//    go run main.go 1 10\n//\n//  Then it should print:\n//\n//    2 + 4 + 6 + 8 + 10 = 30\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/04-only-evens/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif len(os.Args) < 3 {\n\t\tfmt.Println(\"gimme two numbers\")\n\t\treturn\n\t}\n\n\tmin, err1 := strconv.Atoi(os.Args[1])\n\tmax, err2 := strconv.Atoi(os.Args[2])\n\tif err1 != nil || err2 != nil || min >= max {\n\t\tfmt.Println(\"wrong numbers\")\n\t\treturn\n\t}\n\n\tvar sum int\n\tfor i := min; i <= max; i++ {\n\t\tif i%2 != 0 {\n\t\t\tcontinue\n\t\t}\n\t\tsum += i\n\n\t\tfmt.Print(i)\n\t\tif i < max-1 {\n\t\t\tfmt.Print(\" + \")\n\t\t}\n\t}\n\tfmt.Printf(\" = %d\\n\", sum)\n}\n"
  },
  {
    "path": "13-loops/exercises/04-word-finder.md",
    "content": "# Word Finder\n\n1. **[Case Insensitive Search](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/09-word-finder-exercises/01-case-insensitive)**\n\n2. **[Path Searcher](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/09-word-finder-exercises/02-path-searcher)**"
  },
  {
    "path": "13-loops/exercises/05-break-up/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Break Up\n//\n//  1. Extend the \"Only Evens\" exercise\n//  2. This time, use an infinite loop.\n//  3. Break the loop when it reaches to the `max`.\n//\n// RESTRICTIONS\n//  You should use the `break` statement once.\n//\n// HINT\n//  Do not forget incrementing the `i` before the `continue`\n//  statement and at the end of the loop.\n//\n// EXPECTED OUTPUT\n//    go run main.go 1 10\n//    2 + 4 + 6 + 8 + 10 = 30\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/05-break-up/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tif len(os.Args) < 3 {\n\t\tfmt.Println(\"gimme two numbers\")\n\t\treturn\n\t}\n\n\tmin, err1 := strconv.Atoi(os.Args[1])\n\tmax, err2 := strconv.Atoi(os.Args[2])\n\tif err1 != nil || err2 != nil || min >= max {\n\t\tfmt.Println(\"wrong numbers\")\n\t\treturn\n\t}\n\n\tvar (\n\t\ti   = min\n\t\tsum int\n\t)\n\n\tfor {\n\t\tif i > max {\n\t\t\tbreak\n\t\t} else if i%2 != 0 {\n\t\t\ti++\n\t\t\tcontinue\n\t\t}\n\n\t\tfmt.Print(i)\n\t\tif i < max-1 {\n\t\t\tfmt.Print(\" + \")\n\t\t}\n\n\t\tsum += i\n\t\ti++\n\t}\n\tfmt.Printf(\" = %d\\n\", sum)\n}\n"
  },
  {
    "path": "13-loops/exercises/05-crunch-the-primes.md",
    "content": "# Crunch the Primes\n\n1. **[Crunch the primes](https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/10-crunch-the-primes)**\n"
  },
  {
    "path": "13-loops/exercises/06-infinite-kill/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Infinite Kill\n//\n//  1. Create an infinite loop\n//  2. On each step of the loop print a random character.\n//  3. And, sleep for 250 milliseconds.\n//  4. Run the program and wait a couple of seconds\n//     then kill it using CTRL+C keys\n//\n// RESTRICTIONS\n//  1. Print one of those characters randomly: \\ / | -\n//  2. Before printing a character print also this\n//     escape sequence: \\r\n//\n//     Like this: \"\\r/\", or this: \"\\r|\", and so on...\n//\n//  3. NOTE : If you're using Go Playground, use \"\\f\" instead of \"\\r\"\n//\n// HINTS\n//  1. Use `time.Sleep` to sleep.\n//  2. You should pass a `time.Duration` value to it.\n//  3. Check out the Go online documentation for the\n//     `Millisecond` constant.\n//  4. When printing, do not use a newline! Or a Println!\n//     Use Print or Printf instead.\n//\n// NOTE\n//  If this exercise is hard for you now, wait until the\n//  lucky number lecture. Even then so, then just skip it.\n//\n//  You can return back to it afterwards.\n//\n// EXPECTED OUTPUT\n//  - The program should display the following messages in any order.\n//  - And, the first character (\\, -, /, or |) should be randomly\n//    displayed.\n//  - \\r or \\f sequence will clear the line.\n//\n//  \\ Please Wait. Processing....\n//  - Please Wait. Processing....\n//  / Please Wait. Processing....\n//  | Please Wait. Processing....\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/06-infinite-kill/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"time\"\n)\n\nfunc main() {\n\tfor {\n\t\tvar c string\n\n\t\tswitch rand.Intn(4) {\n\t\tcase 0:\n\t\t\tc = \"\\\\\"\n\t\tcase 1:\n\t\t\tc = \"/\"\n\t\tcase 2:\n\t\t\tc = \"|\"\n\t\tcase 3:\n\t\t\tc = \"-\"\n\t\t}\n\t\tfmt.Printf(\"\\r%s Please Wait. Processing....\", c)\n\t\ttime.Sleep(time.Millisecond * 250)\n\t}\n}\n"
  },
  {
    "path": "13-loops/exercises/07-multiplication-table-exercises/01-dynamic-table/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Dynamic Table\n//\n//  Get the size of the table from the command-line\n//    Passing 5 should create a 5x5 table\n//    Passing 10 for a 10x10 table\n//\n// RESTRICTION\n//  Solve this exercise without looking at the original\n//  multiplication table exercise.\n//\n// HINT\n//  There was a max constant in the original program.\n//  That determines the size of the table.\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//    Give me the size of the table\n//\n//  go run main.go -5\n//    Wrong size\n//\n//  go run main.go ABC\n//    Wrong size\n//\n//  go run main.go 1\n//    X    0    1\n//    0    0    0\n//    1    0    1\n//\n//  go run main.go 2\n//    X    0    1    2\n//    0    0    0    0\n//    1    0    1    2\n//    2    0    2    4\n//\n//  go run main.go 3\n//    X    0    1    2    3\n//    0    0    0    0    0\n//    1    0    1    2    3\n//    2    0    2    4    6\n//    3    0    3    6    9\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/07-multiplication-table-exercises/01-dynamic-table/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\targs := os.Args\n\n\tif len(args) != 2 {\n\t\tfmt.Println(\"Give me the size of the table\")\n\t\treturn\n\t}\n\n\tsize, err := strconv.Atoi(args[1])\n\tif err != nil || size <= 0 {\n\t\tfmt.Println(\"Wrong size\")\n\t\treturn\n\t}\n\n\t// print the header\n\tfmt.Printf(\"%5s\", \"X\")\n\tfor i := 0; i <= size; i++ {\n\t\tfmt.Printf(\"%5d\", i)\n\t}\n\tfmt.Println()\n\n\tfor i := 0; i <= size; i++ {\n\t\t// print the vertical header\n\t\tfmt.Printf(\"%5d\", i)\n\n\t\t// print the cells\n\t\tfor j := 0; j <= size; j++ {\n\t\t\tfmt.Printf(\"%5d\", i*j)\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "13-loops/exercises/07-multiplication-table-exercises/02-math-tables/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Math Tables\n//\n//  Create division, addition and subtraction tables\n//\n//  1. Get the math operation and\n//     the size of the table from the user\n//\n//  2. Print the table accordingly\n//\n//  3. Correctly handle the division by zero error\n//\n//\n// BONUS #1\n//\n//  Use strings.IndexAny function to detect\n//    the valid operations.\n//\n//  Search on Google for: golang pkg strings IndexAny\n//\n// BONUS #2\n//\n//  Add remainder operation as well (remainder table using %).\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//    Usage: [op=*/+-] [size]\n//\n//  go run main.go \"*\"\n//    Size is missing\n//    Usage: [op=*/+-] [size]\n//\n//  go run main.go \"%\" 4\n//    Invalid operator.\n//    Valid ops one of: */+-\n//\n//  go run main.go \"*\" 4\n//    *    0    1    2    3    4\n//    0    0    0    0    0    0\n//    1    0    1    2    3    4\n//    2    0    2    4    6    8\n//    3    0    3    6    9   12\n//    4    0    4    8   12   16\n//\n//  go run main.go \"/\" 4\n//    /    0    1    2    3    4\n//    0    0    0    0    0    0\n//    1    0    1    0    0    0\n//    2    0    2    1    0    0\n//    3    0    3    1    1    0\n//    4    0    4    2    1    1\n//\n//  go run main.go \"+\" 4\n//    +    0    1    2    3    4\n//    0    0    1    2    3    4\n//    1    1    2    3    4    5\n//    2    2    3    4    5    6\n//    3    3    4    5    6    7\n//    4    4    5    6    7    8\n//\n//  go run main.go \"-\" 4\n//    -    0    1    2    3    4\n//    0    0   -1   -2   -3   -4\n//    1    1    0   -1   -2   -3\n//    2    2    1    0   -1   -2\n//    3    3    2    1    0   -1\n//    4    4    3    2    1    0\n//\n// BONUS:\n//\n//  go run main.go \"%\" 4\n//    %    0    1    2    3    4\n//    0    0    0    0    0    0\n//    1    0    0    1    1    1\n//    2    0    0    0    2    2\n//    3    0    0    1    0    3\n//    4    0    0    0    1    0\n//\n// NOTES:\n//\n//   When running the program in Windows Git Bash, you might need\n//   to escape the characters like this.\n//\n//   This happens because those characters have special meaning.\n//\n//   Division:\n//     go run main.go // 4\n//\n//   Multiplication and others:\n//   (this is also necessary for non-Windows bashes):\n//\n//     go run main.go \"*\" 4\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/07-multiplication-table-exercises/02-math-tables/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst (\n\tvalidOps = \"%*/+-\"\n\n\tusageMsg       = \"Usage: [op=\" + validOps + \"] [size]\"\n\tsizeMissingMsg = \"Size is missing\"\n\tinvalidOpMsg   = `Invalid operator.\nValid ops one of: ` + validOps\n\n\tinvalidOp = -1\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\n\tswitch l := len(args); {\n\tcase l == 1:\n\t\tfmt.Println(sizeMissingMsg)\n\t\tfallthrough\n\tcase l < 1:\n\t\tfmt.Println(usageMsg)\n\t\treturn\n\t}\n\n\top := args[0]\n\tif strings.IndexAny(op, validOps) == invalidOp {\n\t\tfmt.Println(invalidOpMsg)\n\t\treturn\n\t}\n\n\tsize, err := strconv.Atoi(args[1])\n\tif err != nil || size <= 0 {\n\t\tfmt.Println(\"Wrong size\")\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%5s\", op)\n\tfor i := 0; i <= size; i++ {\n\t\tfmt.Printf(\"%5d\", i)\n\t}\n\tfmt.Println()\n\n\tfor i := 0; i <= size; i++ {\n\t\tfmt.Printf(\"%5d\", i)\n\n\t\tfor j := 0; j <= size; j++ {\n\t\t\tvar res int\n\n\t\t\tswitch op {\n\t\t\tcase \"*\":\n\t\t\t\tres = i * j\n\t\t\tcase \"%\":\n\t\t\t\tif j != 0 {\n\t\t\t\t\tres = i % j\n\t\t\t\t}\n\t\t\tcase \"/\":\n\t\t\t\tif j != 0 {\n\t\t\t\t\tres = i / j\n\t\t\t\t}\n\t\t\tcase \"+\":\n\t\t\t\tres = i + j\n\t\t\tcase \"-\":\n\t\t\t\tres = i - j\n\t\t\t}\n\n\t\t\tfmt.Printf(\"%5d\", res)\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/01-first-turn-winner/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: First Turn Winner\n//\n//  If the player wins on the first turn, then display\n//  a special bonus message.\n//\n// RESTRICTION\n//  The first picked random number by the computer should\n//  match the player's guess.\n//\n// EXAMPLE SCENARIO\n//  1. The player guesses 6\n//  2. The computer picks a random number and it happens\n//     to be 6\n//  3. Terminate the game and print the bonus message\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/01-first-turn-winner/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) != 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tguess, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess <= 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\n\tfor turn := 1; turn <= maxTurns; turn++ {\n\t\tn := rand.Intn(guess) + 1\n\n\t\tif n == guess {\n\t\t\tif turn == 1 {\n\t\t\t\tfmt.Println(\"🥇 FIRST TIME WINNER!!!\")\n\t\t\t} else {\n\t\t\t\tfmt.Println(\"🎉  YOU WON!\")\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n\n\tfmt.Println(\"☠️  YOU LOST... Try again?\")\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/01-first-turn-winner/solution-better/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) != 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tguess, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess <= 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\n\tfor turn := 1; turn <= maxTurns; turn++ {\n\t\tn := rand.Intn(guess) + 1\n\n\t\t// Better, why?\n\t\t//\n\t\t// Instead of nesting the if statement into\n\t\t//   another if statement; it simply continues.\n\t\t//\n\t\t// TLDR: Avoid nested statements.\n\t\tif n != guess {\n\t\t\tcontinue\n\t\t}\n\n\t\tif turn == 1 {\n\t\t\tfmt.Println(\"🥇 FIRST TIME WINNER!!!\")\n\t\t} else {\n\t\t\tfmt.Println(\"🎉  YOU WON!\")\n\t\t}\n\t\treturn\n\t}\n\n\tfmt.Println(\"☠️  YOU LOST... Try again?\")\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/02-random-messages/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Random Messages\n//\n//  Display a few different won and lost messages \"randomly\".\n//\n// HINTS\n//  1. You can use a switch statement to do that.\n//  2. Set its condition to the random number generator.\n//  3. I would use a short switch.\n//\n// EXAMPLES\n//  The Player wins: then randomly print one of these:\n//\n//  go run main.go 5\n//    YOU WON\n//  go run main.go 5\n//    YOU'RE AWESOME\n//\n//  The Player loses: then randomly print one of these:\n//\n//  go run main.go 5\n//    LOSER!\n//  go run main.go 5\n//    YOU LOST. TRY AGAIN?\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/02-random-messages/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) != 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tguess, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess <= 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\n\tfor turn := 0; turn < maxTurns; turn++ {\n\t\tn := rand.Intn(guess) + 1\n\n\t\tif n == guess {\n\t\t\tswitch rand.Intn(3) {\n\t\t\tcase 0:\n\t\t\t\tfmt.Println(\"🎉  YOU WIN!\")\n\t\t\tcase 1:\n\t\t\t\tfmt.Println(\"🎉  YOU'RE AWESOME!\")\n\t\t\tcase 2:\n\t\t\t\tfmt.Println(\"🎉  PERFECT!\")\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n\n\tmsg := \"%s Try again?\\n\"\n\n\tswitch rand.Intn(2) {\n\tcase 0:\n\t\tfmt.Printf(msg, \"☠️  YOU LOST...\")\n\tcase 1:\n\t\tfmt.Printf(msg, \"☠️  JUST A BAD LUCK...\")\n\t}\n\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/03-double-guesses/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Double Guesses\n//\n//  Let the player guess two numbers instead of one.\n//\n// HINT:\n//  Generate random numbers using the greatest number\n//  among the guessed numbers.\n//\n// EXAMPLES\n//  go run main.go 5 6\n//  Player wins if the random number is either 5 or 6.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/03-double-guesses/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) < 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tguess, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tvar guess2 int\n\tif len(args) == 2 {\n\t\tguess2, err = strconv.Atoi(args[1])\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Not a number.\")\n\t\t\treturn\n\t\t}\n\t}\n\n\tif guess <= 0 || guess2 <= 0 {\n\t\tfmt.Println(\"Please pick positive numbers.\")\n\t\treturn\n\t}\n\n\tmin := guess\n\tif guess < guess2 {\n\t\tmin = guess2\n\t}\n\n\tfor turn := 0; turn < maxTurns; turn++ {\n\t\tn := rand.Intn(min) + 1\n\n\t\tif n == guess || n == guess2 {\n\t\t\tfmt.Println(\"🎉  YOU WIN!\")\n\t\t\treturn\n\t\t}\n\t}\n\n\tfmt.Println(\"☠️  YOU LOST... Try again?\")\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/04-verbose-mode/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Verbose Mode\n//\n//  When the player runs the game like this:\n//\n//    go run main.go -v 4\n//\n//  Display each generated random number:\n\n//    1 3 4 🎉  YOU WIN!\n//\n//  In this example, computer picks 1, 3, and 4. And the\n//  player wins.\n//\n// HINT\n//  You need to get and interpret the command-line arguments.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/04-verbose-mode/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n\n(Provide -v flag to see the picked numbers.)\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) < 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tvar verbose bool\n\n\tif args[0] == \"-v\" {\n\t\tverbose = true\n\t}\n\n\tguess, err := strconv.Atoi(args[len(args)-1])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess <= 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\n\tfor turn := 1; turn <= maxTurns; turn++ {\n\t\tn := rand.Intn(guess) + 1\n\n\t\tif verbose {\n\t\t\tfmt.Printf(\"%d \", n)\n\t\t}\n\n\t\tif n == guess {\n\t\t\tif turn == 1 {\n\t\t\t\tfmt.Println(\"🥇 FIRST TIME WINNER!!!\")\n\t\t\t} else {\n\t\t\t\tfmt.Println(\"🎉  YOU WON!\")\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n\n\tfmt.Println(\"☠️  YOU LOST... Try again?\")\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/05-enough-picks/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Enough Picks\n//\n//  If the player's guess number is below 10;\n//  then make sure that the computer generates a random\n//  number between 0 and 10.\n//\n//  However, if the guess number is above 10; then the\n//  computer should generate the numbers\n//  between 0 and the guess number.\n//\n// WHY?\n//  This way the game will be harder.\n//\n//  Because, in the current version of the game, if\n//  the player's guess number is for example 3; then the\n//  computer picks a random number between 0 and 3.\n//\n//  So, currently a player can easily win the game.\n//\n// EXAMPLE\n//  Suppose that the player runs the game like this:\n//    go run main.go 9\n//\n//  Or like this:\n//    go run main.go 2\n//\n//    Then the computer should pick a random number\n//    between 0-10.\n//\n//  Or, if the player runs it like this:\n//    go run main.go 15\n//\n//    Then the computer should pick a random number\n//    between 0-15.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/05-enough-picks/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) < 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tguess, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess <= 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\n\tmin := 10\n\tif guess > min {\n\t\tmin = guess\n\t}\n\n\tfor turn := 0; turn < maxTurns; turn++ {\n\t\tn := rand.Intn(min) + 1\n\n\t\tif n == guess {\n\t\t\tfmt.Println(\"🎉  YOU WIN!\")\n\t\t\treturn\n\t\t}\n\t}\n\n\tfmt.Println(\"☠️  YOU LOST... Try again?\")\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/06-dynamic-difficulty/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Dynamic Difficulty\n//\n//  Current game picks only 5 numbers (5 turns).\n//\n//  Make sure that the game adjust its own difficulty\n//  depending on the guess number.\n//\n// RESTRICTION\n//  Do not make the game too easy. Only adjust the\n//  difficulty if the guess is above 10.\n//\n// EXPECTED OUTPUT\n//  Suppose that the player runs the game like this:\n//    go run main.go 5\n//\n//    Then the computer should pick 5 random numbers.\n//\n//  Or, if the player runs it like this:\n//    go run main.go 25\n//\n//    Then the computer may pick 11 random numbers\n//    instead.\n//\n//  Or, if the player runs it like this:\n//    go run main.go 100\n//\n//    Then the computer may pick 30 random numbers\n//    instead.\n//\n//  As you can see, greater guess number causes the\n//  game to increase the game turns, which in turn\n//  adjust the game's difficulty dynamically.\n//\n//  Because, greater guess number makes it harder to win.\n//  But, this way, game's difficulty will be dynamic.\n//  It will adjust its own difficulty depending on the\n//  guess number.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/08-lucky-number-exercises/06-dynamic-difficulty/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\n\tif len(args) != 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tguess, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess <= 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\t\n\tvar balancer int\n\tif guess > 10 {\n\t\tbalancer = guess / 4\n\t}\n\n\tfor turn := maxTurns + balancer; turn > 0; turn-- {\n\t\tn := rand.Intn(guess) + 1\n\n\t\tif n == guess {\n\t\t\tfmt.Println(\"🎉  YOU WIN!\")\n\t\t\treturn\n\t\t}\n\t}\n\n\tfmt.Println(\"☠️  YOU LOST... Try again?\")\n}\n"
  },
  {
    "path": "13-loops/exercises/09-word-finder-exercises/01-case-insensitive/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Case Insensitive Search\n//\n//  Allow for case-insensitive searching\n//\n// EXAMPLE\n//  Let's say that the user runs the program like this:\n//    go run main.go LAZY\n//\n//  Or like this: go run main.go lAzY\n//  Or like this: go run main.go lazy\n//\n//  For all cases above, the program should find\n//  the \"lazy\" keyword.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/09-word-finder-exercises/01-case-insensitive/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst corpus = \"lazy cat jumps again and again and again\"\n\nfunc main() {\n\twords := strings.Fields(corpus)\n\tquery := os.Args[1:]\n\nqueries:\n\tfor _, q := range query {\n\t\t// case insensitive search\n\t\tq = strings.ToLower(q)\n\n\tsearch:\n\t\tfor i, w := range words {\n\t\t\tswitch q {\n\t\t\tcase \"and\", \"or\", \"the\":\n\t\t\t\tbreak search\n\t\t\t}\n\n\t\t\tif q == w {\n\t\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\t\t\t\tcontinue queries\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "13-loops/exercises/09-word-finder-exercises/02-path-searcher/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Path Searcher\n//\n//  Your program should search inside the path environment\n//  variable.\n//\n//  Remove the corpus constant then get the corpus from the\n//  environment variable \"Path\" or \"PATH\".\n//\n// HINTS\n//  1. Search the web to find out what is an environment\n//     variable and how to use it (if you don't know\n//     what it is already).\n//\n//  2. Look up for the necessary functions for getting\n//     an environment variable. It's in the \"os\" package.\n//\n//     Search for it on the Go online documentation.\n//\n//  3. Look up for the necessary function for splitting\n//     the path variable into directory names.\n//\n//     It's in the \"path/filepath\" package.\n//\n// EXAMPLE\n//  For example, on my Mac, my PATH environment variable\n//  looks like this:\n//\n//    \"/usr/local/bin:/sbin:/Users/inanc/go/bin\"\n//\n//  So, if the user runs the program like this:\n//\n//    go run main.go /sbin\n//\n//  It should print this:\n//\n//    #2 : \"/sbin\"\n// ---------------------------------------------------------\n\n// ---------------------------------------------------------\n// BONUS EXERCISE\n//  Make your program cross platform. So, it can search\n//  the path environment variable when you run it on\n//  a Windows or on a Mac (OS X) or on a Linux.\n//\n// BONUS EXERCISE #2\n//  Also find the directories for the directories that\n//  contains the searched query.\n//\n//  And let it match in a case-insensitive manner. See the examples.\n//\n//  EXAMPLE:\n//    Let's say:\n//      PATH=\"/usr/local/bin:/sbin:/Users/inanc/go/bin\"\n//\n//  So, if the user runs the program like this:\n//    go run main.go bin\n//\n//  It should print this:\n//    #1 : \"/usr/local/bin\"\n//    #2 : \"/sbin\"\n//    #3 : \"/Users/inanc/go/bin\"\n//\n//  Or like this (case insensitive):\n//    go run main.go Us\n//\n//  Output:\n//    #1 : \"/usr/local/bin\"\n//    #2 : \"/Users/inanc/go/bin\"\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/09-word-finder-exercises/02-path-searcher/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// Get and split the PATH environment variable\n\n\t// SplitList function automatically finds the\n\t// separator for the path env variable\n\twords := filepath.SplitList(os.Getenv(\"PATH\"))\n\n\t// Alternative way, but above one is better:\n\t// words := strings.Split(\n\t// \tos.Getenv(\"PATH\"),\n\t// \tstring(os.PathListSeparator))\n\n\tquery := os.Args[1:]\n\n\tfor _, q := range query {\n\t\tfor i, w := range words {\n\t\t\tq, w = strings.ToLower(q), strings.ToLower(w)\n\n\t\t\tif strings.Contains(w, q) {\n\t\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "13-loops/exercises/10-crunch-the-primes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Crunch the primes\n//\n//  1. Get numbers from the command-line.\n//  2. `for range` over them.\n//  4. Convert each one to an int.\n//  5. If one of the numbers isn't an int, just skip it.\n//  6. Print the ones that are only the prime numbers.\n//\n// RESTRICTION\n//  The user can run the program with any number of\n//  arguments.\n//\n// HINT\n//  Find whether a number is prime using this algorithm:\n//  https://stackoverflow.com/a/1801446/115363\n//\n// EXPECTED OUTPUT\n//  go run main.go 2 4 6 7 a 9 c 11 x 12 13\n//    2 7 11 13\n//\n//  go run main.go 1 2 3 5 7 A B C\n//    2 3 5 7\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "13-loops/exercises/10-crunch-the-primes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// remember [1:] skips the first argument\n\nmain:\n\tfor _, arg := range os.Args[1:] {\n\t\tn, err := strconv.Atoi(arg)\n\t\tif err != nil {\n\t\t\t// skip non-numerics\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch {\n\t\t// prime\n\t\tcase n == 2 || n == 3:\n\t\t\tfmt.Print(n, \" \")\n\t\t\tcontinue\n\n\t\t// not a prime\n\t\tcase n <= 1 || n%2 == 0 || n%3 == 0:\n\t\t\tcontinue\n\t\t}\n\n\t\tfor i, w := 5, 2; i*i <= n; {\n\t\t\t// not a prime\n\t\t\tif n%i == 0 {\n\t\t\t\tcontinue main\n\t\t\t}\n\n\t\t\ti += w\n\t\t\tw = 6 - w\n\t\t}\n\n\t\t// all checks ok: it's a prime\n\t\tfmt.Print(n, \" \")\n\t}\n\n\tfmt.Println()\n}\n"
  },
  {
    "path": "13-loops/exercises/README.md",
    "content": "There are 17 exercises in this section.\n\nYou can find them inside the subdirectories."
  },
  {
    "path": "13-loops/questions/01-loops.md",
    "content": "## Which one of these is a valid loop statement in Go?\n1. while\n2. forever\n3. until\n4. for *CORRECT*\n\n> **4:** Correct. There is only one loop statement in Go.\n\n\n## What does this code print?\n```go\nfor i := 3; i > 0; i-- {\n    fmt.Println(i)\n}\n```\n1. 3 2 1 *CORRECT*\n2. 1 2 3\n3. 0 1 2\n4. 2 1 0\n\n\n## What does this code print?\n```go\nfor i := 3; i > 0; {\n    i--\n    fmt.Println(i)\n}\n```\n1. 3 2 1\n2. 1 2 3\n3. 0 1 2\n4. 2 1 0 *CORRECT*\n\n\n## What does this code print?\n```go\nfor i := 3; ; {\n    if i <= 0 {\n        break\n    }\n\n    i--\n    fmt.Println(i)\n}\n```\n1. 3 2 1\n2. 1 2 3\n3. 0 1 2\n4. 2 1 0 *CORRECT*\n\n\n## What does this code print?\n```go\nfor i := 2; i <= 9; i++ {\n    if i % 3 != 0 {\n        continue\n    }\n\n    fmt.Println(i)\n}\n```\n1. 3 6 9 *CORRECT*\n2. 9 6 3\n3. 2 3 6 9\n4. 2 3 4 5 6 7 8 9\n\n\n## How can you simplify this code?\n```go\nfor ; true ; {\n    // ...\n}\n```\n1. ```go\n   for true {\n   }\n   ```\n2. ```go\n   for true; {\n   }\n   ```\n3. ```go\n   for {\n   }\n   ```\n   *CORRECT*\n4. ```go\n   for ; true {\n   }\n   ```\n\n\n## What does this code print?\nLet's say that you run the program like this:\n```bash\ngo run main.go go is awesome\n```\n\n```go\nfor i, v := range os.Args[1:] {\n    fmt.Println(i+1, v)\n}\n```\n1. ```\n   1 go\n   2 is\n   3 awesome\n   ```\n   *CORRECT*\n2. ```\n   go\n   is\n   awesome\n   ```\n3. ```\n   0 go\n   1 is\n   2 awesome\n   ```\n4. ```\n   1\n   2\n   3\n   ```\n\n\n## What does this code print?\nLet's say that you run the program like this:\n```bash\ngo run main.go go is awesome\n```\n\n```go\nfor i := range os.Args[1:] {\n    fmt.Println(i+1)\n}\n```\n1. ```\n   1 go\n   2 is\n   3 awesome\n   ```\n2. ```\n   go\n   is\n   awesome\n   ```\n3. ```\n   0 go\n   1 is\n   2 awesome\n   ```\n4. ```\n   1\n   2\n   3\n   ```\n   *CORRECT*\n\n\n## What does this code print?\nLet's say that you run the program like this:\n```bash\ngo run main.go go is awesome\n```\n\n```go\nfor _, v := range os.Args[1:] {\n    fmt.Println(v)\n}\n```\n1. ```\n   1 go\n   2 is\n   3 awesome\n   ```\n2. ```\n   go\n   is\n   awesome\n   ```\n   *CORRECT*\n3. ```\n   0 go\n   1 is\n   2 awesome\n   ```\n4. ```\n   1\n   2\n   3\n   ```\n\n\n## What does this code print?\nLet's say that you run the program like this:\n```bash\ngo run main.go go is awesome\n```\n\n```go\nvar i int\n\nfor range os.Args {\n    i++\n}\n\nfmt.Println(i)\n```\n1. go is awesome\n2. 1 2 3\n3. 2\n4. 4 *CORRECT*\n\n> **4:** As you can see, you can also use a for range statement for counting things.\n"
  },
  {
    "path": "13-loops/questions/02-randomization.md",
    "content": "## What's pseudorandom number generation?\n1. Numbers appear to be randomly generated but in reality they are not *CORRECT*\n2. Generating random numbers according to the physical laws\n3. Generating pseudo even and odd numbers\n\n> **1:** Computers are deterministic machines. They can't generate truly random numbers (unlike actual physical processes).\n\n\n## What's a seed number?\n1. Exchanging of random numbers between two computers\n2. It's used to getting a random number between 0 and the seed number\n3. It's used initialize a pseduorandom number generator *CORRECT*\n\n\n## Which package is used to generate pseudorandom numbers in Go?\n1. pseudorand\n2. rand *CORRECT*\n3. random\n4. randomizer\n\n\n## What does [0, 5) mean?\n1. A range of numbers between 0 and 5 (excluding 5) *CORRECT*\n2. A range of numbers between 0 and 5 (including 5)\n3. Just 0 and 5\n4. Just 0 and 4\n\n> **1:** Right. The square-brace means: \"inclusion\". The parenthesis means: \"exclusion\". So, [0, 5] means: 0, 1, 2, 3, 4. It's called the \"mathematical interval notation\".\n\n\n## Why this function call would not work?\n```go\nrand.Intn(0)\n```\n1. First you should seed it\n2. It expects two arguments\n3. Intn works within a range of [0, 0). So, it doesn't make sense to include 0 and not include 0 at the same time. *CORRECT*\n\n> **1:** That's not the cause of this error. You don't always have to seed it.\n> **2:** No, it does not.\n\n\n## What does this program print?\nNote that, each seed number below returns pseudorandom numbers as these:\n\n```\nSeed: 0\n  3 3 6 8 4 1 9 3 6 6\n\nSeed: 1\n  1 1 9 3 2 4 7 6 6 6\n\nSeed: 2\n  10 1 2 2 0 6 4 1 0 5\n```\n\nHere's the program:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n)\n\nfunc main() {\n\tfor i := 0; i < 3; i++ {\n\t\trand.Seed(int64(i))\n\t\tfmt.Print(rand.Intn(11), \" \")\n\t\tfmt.Print(rand.Intn(11), \" \")\n\t}\n}\n```\n1. 3 1 10 3 1 1\n2. 3 6 1 6 10 5\n3. 1 10 1 1 3 3\n4.  3 3 1 1 10 1 *CORRECT*\n\n> **4:** The numbers are determined depending on the seed number. So, this loop, seeds the pseudorandom generator with 0, 1, and 2 respectively.\n> \n> And, after each seed, it calls Intn twice to generate two random numbers.\n> \n> So, if you look at the result, 3 3 is the first two numbers of Seed: 0. 1 1 for Seed: 1. And, 10 1 for Seed: 2.\n\n\n## What you should do if you want the pseudorandom generator to produce random numbers each time you run your program?\n1. You need to seed it like this: rand.Seed(rand.Random)\n2. You need to seed it like this: rand.Seed(time.Now().UnixNano()) *CORRECT*\n3. You need to seed it like this: rand.Seed(time.Now())"
  },
  {
    "path": "13-loops/questions/03-labeled-statements.md",
    "content": "## Which scope a label belongs to?\n1. To the scope of the statement that it is in\n2. To the body of the function that it is in *CORRECT*\n3. To the package scope that it is in\n\n> **1:** Labels do not belong to statement scopes unlike other names like variable or constant names.\n> \n> **2:** They can be used throughout the function, even before their declaration inside the function. This also what makes goto statement jump to any label within a function.\n\n\n## There two for loop statements below and a label called \"words\". Which statement does the \"words label\" label?\"\n```go\nfor range words {\nwords:\n    for range letters {\n        // ...\n    }\n}\n```\n1. The first loop\n2. The second, nested loop *CORRECT*\n3. All the loops\n\n> **2:** A label can only label one statement at a time.\n\n\n## Will this loop terminate after the break?\n**BTW:** _\"terminate\" is the same thing with \"quit\". Remember, statements can also terminate. This means that the statement will end. It doesn't mean that the program will end._\n\n```go\npackage main\n\nfunc main() {\nmain:\n\tfor {\n\t\tswitch \"A\" {\n        case \"A\":\n            break // <- here!\n        case \"B\":\n            continue main\n        }\n\t}\n}\n```\n1. No, the break will only terminate the switch but the loop will continue *CORRECT*\n2. Yes, the break will terminate the loop\n3. Yes, the break will terminate the switch\n\n> **1:** Yep. This is an unlabeled break. So, it breaks the closest statement, which in here, it's that switch statement. And, since it only breaks the switch, the loop will keep continue.\n> \n> **3:** Yep. However, why would that kill the loop as well?\n\n\n## Will this loop ever terminate?\n```go\npackage main\n\nfunc main() {\n\tflag := \"A\"\n\nmain:\n\tfor {\n\t\tswitch flag {\n\t\tcase \"A\":\n\t\t\tflag = \"B\"\n\t\t\tbreak\n\t\tcase \"B\":\n\t\t\tbreak main\n\t\t}\n\t}\n}\n\n```\n1. No, this loop will loop to infinity\n2. Yes, the first break will terminate the loop\n3. Yes, the second break will terminate the loop *CORRECT*\n\n> **2:** No it does not but it helps.\n> \n> **3:** Yep. Do you know why? Because, at first, first case will match, and it will set the flag to \"B\". So, in the next loop step, the 2nd case will be hit, then, it will break from the loop, because the loop is labeled with the main label.\n\n\n## What the first break below does?\n\nNote that, in this program, there's an infinite loop.\n\n```go\npackage main\n\nfunc main() {\n\tfor {\n\tswitcher:\n\t\tswitch 1 {\n\t\tcase 1:\n\t\t\tswitch 2 {\n\t\t\tcase 2:\n\t\t\t\tbreak switcher\n\t\t\t}\n\t\t}\n\t\tbreak\n\t}\n}\n```\n1. It breaks from the 2nd switch causing the program will loop indefinitely\n2. It breaks from the 2nd switch and then the 2nd break will terminate the loop\n3. It breaks from the 1st switch and then the 2nd break will terminate the loop *CORRECT*\n\n> **1:** There's another break after the switch, so the loop will end immediately.\n>\n> **2:** It doesn't break the 2nd switch. The label labels the 1st switch.\n\n\n## What's wrong with this program?\n\n```go\npackage main\n\nfunc main() {\n\tfor {\n\tswitcher:\n\t\tswitch {\n\t\tcase true:\n\t\t\tswitch {\n\t\t\tcase false:\n\t\t\t\tcontinue switcher\n\t\t\t}\n\t\t}\n\t}\n}\n```\n1. continue statement can only continue a loop *CORRECT*\n2. continue statement cannot be used within a switch statement\n3. It will loop to infinity\n\n> **1:** Yes! Here, the switcher label labels the first switch statement. So, it's a switch label. And, then it tries to jump to that label using a continue. However, a continue statement can only be used to jump to a loop label.\n>\n> **2:** Yes, it can be used in a switch statement to continue for the next loop step. But, that's not the problem with this program.\n>\n> **3:** Yes, but that's not the real problem.\n\n\n## Which one of these programs will terminate?\n\nI mean: When you run it, which one will quit. Some of the codes here will indefinitely run.\n\n1. ```go\n    func main() {\n        start: goto exit\n        exit : fmt.Println(\"exiting\")\n        goto start\n    }\n   ```\n2. ```go\n    func main() {\n        exit: fmt.Println(\"exiting\")\n        goto exit\n    }\n   ```\n\n3. ```go\n    func main() {\n        goto exit\n        start : goto getout\n        exit  : goto start\n        getout: fmt.Println(\"exiting\")\n    }\n   ```\n   *CORRECT*\n\n> **1:** In the start label: \"goto exit\" sends the execution to the exit label. In the exit label: \"goto start\" sends the execution back to the start label. So, it's an infinite loop. The program will never terminate.\n>\n> **2:** In the exit label: \"goto exit\" sends the execution back to the exit label. So, it's an infinite loop. The program will never terminate.\n>\n> **3:** \"goto exit\" sends the execution to the exit label. In the exit label: \"goto start\" sends the execution to the start label. In the start label: \"goto getout\" sends the execution to the getout label. And, since the getout label is the last statement of the main function, the program will terminate there."
  },
  {
    "path": "14-arrays/01-whats-an-array/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tmyAge  byte\n\t\therAge byte\n\n\t\t// this declares an array with two byte elements\n\t\t// its length      : 2\n\t\t// its element type: byte\n\t\tages [2]byte\n\n\t\t// this declares an array with five string elements\n\t\t// its length      : 5\n\t\t// its element type: string\n\t\ttags [5]string\n\n\t\t// this array doesn't occupy any memory space (its length is zero)\n\t\t// its length      : 0\n\t\t// its element type: byte\n\t\tzero [0]byte\n\n\t\t// this array uses a constant expression\n\t\t// its length      : 3\n\t\t// its element type: byte\n\t\tagesExp [2 + 1]byte\n\n\t\t// uncomment the code below and observe the error\n\t\t//\n\t\t// wrongDeclaration [-1]byte\n\t)\n\n\tfmt.Printf(\"myAge             : %d\\n\", myAge)\n\tfmt.Printf(\"herAge            : %d\\n\", herAge)\n\n\t// Since arrays we've declared here don't have any elements,\n\t// Go automatically sets all their elements to their zero values\n\t// depending on their element type.\n\n\t// #v verb prints the array's length, element type and its elements\n\tfmt.Printf(\"ages              : %#v\\n\", ages)\n\tfmt.Printf(\"tags              : %#v\\n\", tags)\n\tfmt.Printf(\"zero              : %#v\\n\", zero)\n\tfmt.Printf(\"agesExp           : %#v\\n\", agesExp)\n\n\t// note:\n\t// ages and agesExp get printed 0x0 because they're byte arrays.\n\t// bytes are represented with hex values. 0x0 means 0.\n\n\t// =========================================================================\n\t// GETTING AND SETTING ARRAY ELEMENTS\n\t// =========================================================================\n\n\t// Note:\n\t//\n\t// Since, I've already declared the ages variable above,\n\t//   and, to show you the example below, I needed to create a new block.\n\t//\n\t// ages variable below is in a new block below. So, it's a new variable.\n\t//\n\t// I did so because I need to change the element type of the ages array\n\t//   to int (or, subtracting from a byte results in wraparound).\n\t{\n\t\tvar ages [2]int\n\n\t\tfmt.Println()\n\t\tfmt.Printf(\"ages              : %#v\\n\", ages)\n\t\tfmt.Printf(\"ages's type       : %T\\n\", ages)\n\n\t\tfmt.Println(\"len(ages)         :\", len(ages))\n\t\tfmt.Println(\"ages[0]           :\", ages[0])\n\t\tfmt.Println(\"ages[1]           :\", ages[1])\n\t\tfmt.Println(\"ages[len(ages)-1] :\", ages[len(ages)-1])\n\n\t\t// WRONG:\n\t\t// fmt.Println(\"ages[-1]          :\", ages[-1])\n\t\t// fmt.Println(\"ages[2]           :\", ages[2])\n\t\t// fmt.Println(\"ages[len(ages)]   :\", ages[len(ages)])\n\n\t\tages[0] = 6\n\t\tages[1] -= 3\n\n\t\t// WRONG:\n\t\t// ages[0] = \"Can I?\"\n\n\t\tfmt.Println(\"ages[0]           :\", ages[0])\n\t\tfmt.Println(\"ages[1]           :\", ages[1])\n\n\t\tages[0] *= ages[1]\n\t\tfmt.Println(\"ages[0]           :\", ages[0])\n\t\tfmt.Println(\"ages[1]           :\", ages[1])\n\t}\n}\n"
  },
  {
    "path": "14-arrays/02-examples-1-hipsters-love-bookstore/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// STORY:\n// Hipster's Love store publishes limited books\n// twice a year.\n//\n// The number of books they publish is fixed at 4.\n\n// So, let's create a 4 elements string array for the books.\n\nconst (\n\twinter = 1\n\tsummer = 3\n\tyearly = winter + summer\n)\n\nfunc main() {\n\t// var books [4]string\n\t// var books [1 + 3]string\n\tvar books [yearly]string\n\n\tbooks[0] = \"Kafka's Revenge\"\n\tbooks[1] = \"Stay Golden\"\n\tbooks[2] = \"Everythingship\"\n\tbooks[3] += books[0] + \" 2nd Edition\"\n\n\t// --------------------\n\t// INDEXING\n\t// --------------------\n\n\t// Go compiler can catch indexing errors when constant is used\n\t// books[4] = \"Neverland\"\n\n\t// Go compiler cannot catch indexing errors when non-constant is used\n\t// i := 4\n\t// books[i] = \"Neverland\"\n\n\t// --------------------\n\t// PRINTING ARRAYS\n\t// --------------------\n\n\t// print the type\n\tfmt.Printf(\"books  : %T\\n\", books)\n\n\t// print the elements\n\tfmt.Println(\"books  :\", books)\n\n\t// print the elements in quoted string\n\tfmt.Printf(\"books  : %q\\n\", books)\n\n\t// print the elements along with their types\n\tfmt.Printf(\"books  : %#v\\n\", books)\n}\n"
  },
  {
    "path": "14-arrays/03-examples-2-hipsters-love-bookstore/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// STORY:\n// Hipster's Love store publishes limited books\n// twice a year.\n//\n// The number of books they publish is fixed at 4.\n\n// So, let's create a 4 elements string array for the books.\n\nconst (\n\twinter = 1\n\tsummer = 3\n\tyearly = winter + summer\n)\n\nfunc main() {\n\tvar books [yearly]string\n\n\tbooks[0] = \"Kafka's Revenge\"\n\tbooks[1] = \"Stay Golden\"\n\tbooks[2] = \"Everythingship\"\n\tbooks[3] += books[0] + \" 2nd Edition\"\n\tfmt.Printf(\"books  : %#v\\n\", books)\n\n\t// ------------------------------------\n\t// SEASONAL BOOKS\n\t// ------------------------------------\n\n\tvar (\n\t\twBooks [winter]string\n\t\tsBooks [summer]string\n\t)\n\n\t// assign the first book as the wBook's first book\n\twBooks[0] = books[0]\n\n\t// assign all the books starting from the 2nd book\n\t// to sBooks array\n\n\t// sBooks[0] = books[1]\n\t// sBooks[1] = books[2]\n\t// sBooks[2] = books[3]\n\n\t// for i := 0; i < len(sBooks); i++ {\n\t// \tsBooks[i] = books[i+1]\n\t// }\n\n\tfor i := range sBooks {\n\t\tsBooks[i] = books[i+1]\n\t\t// changes to sBooks[i] will not be visible here.\n\t\t// sBooks here is a copy of the original array.\n\t}\n\t// changes to sBooks are visible here\n\n\t// sBooks is a copy of the original sBooks array.\n\t//\n\t// v is also a copy of the original array element.\n\t//\n\t// if you want to update the original element, use it as in the loop above.\n\t//\n\t// for _, v := range sBooks {\n\t// \tv += \"won't effect\"\n\t// }\n\n\tfmt.Printf(\"\\nwinter : %#v\\n\", wBooks)\n\tfmt.Printf(\"\\nsummer : %#v\\n\", sBooks)\n\n\t// ------------------------------------\n\t// Let's print the published books\n\t// ------------------------------------\n\n\t// equal to: [4]bool\n\tvar published [len(books)]bool\n\n\tpublished[0] = true\n\tpublished[len(books)-1] = true\n\n\tfmt.Println(\"\\nPublished Books:\")\n\tfor i, ok := range published {\n\t\tif ok {\n\t\t\tfmt.Printf(\"+ %s\\n\", books[i])\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "14-arrays/04-array-literal/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// STORY:\n// Hipster's Love store publishes limited books\n// twice a year.\n//\n// The number of books they publish is fixed at 4.\n\n// So, let's create a 4 elements string array for the books.\n\nfunc main() {\n\t// Use this only when you don't know about the elements beforehand\n\t{\n\t\tvar books [4]string\n\n\t\tbooks[0] = \"Kafka's Revenge\"\n\t\tbooks[1] = \"Stay Golden\"\n\t\tbooks[2] = \"Everythingship\"\n\t\tbooks[3] += \"Kafka's Revenge 2nd Edition\"\n\n\t\t_ = books\n\t}\n\n\t// This is not necessary, use the short declaration syntax below\n\t{\n\t\tvar books = [4]string{\n\t\t\t\"Kafka's Revenge\",\n\t\t\t\"Stay Golden\",\n\t\t\t\"Everythingship\",\n\t\t\t\"Kafka's Revenge 2nd Edition\",\n\t\t}\n\n\t\t_ = books\n\t}\n\n\t// Use this if you know about the elements\n\t{\n\t\tbooks := [4]string{\n\t\t\t\"Kafka's Revenge\",\n\t\t\t\"Stay Golden\",\n\t\t\t\"Everythingship\",\n\t\t\t\"Kafka's Revenge 2nd Edition\",\n\t\t}\n\n\t\t_ = books\n\t}\n\n\t{\n\t\t// Use this if you know about the elements\n\t\tbooks := [4]string{\n\t\t\t\"Kafka's Revenge\",\n\t\t\t\"Stay Golden\",\n\t\t}\n\n\t\t// Uninitialized elements will be set to their zero values\n\t\tfmt.Printf(\"books  : %#v\\n\", books)\n\t}\n\n\t// You can also use the ellipsis syntax\n\t// ... equals to 4\n\t{\n\t\tbooks := [...]string{\n\t\t\t\"Kafka's Revenge\",\n\t\t\t\"Stay Golden\",\n\t\t\t\"Everythingship\",\n\t\t\t\"Kafka's Revenge 2nd Edition\",\n\t\t}\n\n\t\t_ = books\n\t}\n}\n"
  },
  {
    "path": "14-arrays/05-examples-3-hipsters-love-bookstore/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// STORY:\n// Hipster's Love store publishes limited books\n// twice a year.\n//\n// The number of books they publish is fixed at 4.\n\n// So, let's create a 4 elements string array for the books.\n\nconst (\n\twinter = 1\n\tsummer = 3\n\tyearly = winter + summer\n)\n\nfunc main() {\n\tbooks := [...]string{\n\t\t\"Kafka's Revenge\",\n\t\t\"Stay Golden\",\n\t\t\"Everythingship\",\n\t\t\"Kafka's Revenge 2nd Edition\",\n\t}\n\tfmt.Printf(\"books  : %#v\\n\", books)\n}\n"
  },
  {
    "path": "14-arrays/06-challenge-moodly/challenge/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Moodly\n//\n//   1. Get username from command-line\n//\n//   2. Display the usage if the username is missing\n//\n//   3. Create an array\n//     1. Add three positive mood messages\n//     2. Add three negative mood messages\n//\n//   4. Randomly select and print one of the mood messages\n//\n// EXPECTED OUTPUT\n//\n//   go run main.go\n//     [your name]\n//\n//   go run main.go Socrates\n//     Socrates feels good 👍\n//\n//   go run main.go Socrates\n//     Socrates feels bad 👎\n//\n//   go run main.go Socrates\n//     Socrates feels sad 😞\n//\n//   go run main.go Socrates\n//     Socrates feels happy 😀\n//\n//   go run main.go Socrates\n//     Socrates feels awesome 😎\n//\n//   go run main.go Socrates\n//     Socrates feels terrible 😩\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/06-challenge-moodly/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"time\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"[your name]\")\n\t\treturn\n\t}\n\n\tname := args[0]\n\n\tmoods := [...]string{\n\t\t\"happy 😀\", \"good 👍\", \"awesome 😎\",\n\t\t\"sad 😞\", \"bad 👎\", \"terrible 😩\",\n\t}\n\n\trand.Seed(time.Now().UnixNano())\n\tn := rand.Intn(len(moods))\n\n\tfmt.Printf(\"%s feels %s\\n\", name, moods[n])\n}\n\n// inspired from:\n// https://github.com/moby/moby/blob/1fd7e4c28d3a4a21c3540f03a045f96a4190b527/pkg/namesgenerator/names-generator.go\n"
  },
  {
    "path": "14-arrays/07-compare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// STORY:\n// You want to compare two bookcases,\n// whether they're equal or not.\n\nfunc main() {\n\t// When comparing two arrays, their types should be identical\n\n\t// Comment out one of the following pair of variables and observe the results.\n\n\tvar (\n\t\t// equal (types + elements are identical)::\n\t\tblue = [3]int{6, 9, 3}\n\t\tred  = [3]int{6, 9, 3}\n\n\t\t// equal (types + elements are identical):\n\t\t// blue = [...]int{6, 9, 3}\n\t\t// red  = [3]int{6, 9, 3}\n\n\t\t// not equal (element ordering are different):\n\t\t// blue = [3]int{6, 9, 3}\n\t\t// red  = [3]int{3, 9, 6}\n\n\t\t// not equal (the last elements are not equal):\n\t\t// blue = [3]int{6, 9}\n\t\t// red  = [3]int{6, 9, 3}\n\n\t\t// not comparable (type mismatch: length):\n\t\t// blue = [3]int{6, 9, 3}\n\t\t// red  = [5]int{6, 9, 3}\n\n\t\t// not comparable (type mismatch: element type):\n\t\t// blue = [3]int64{6, 9, 3}\n\t\t// red  = [3]int{6, 9, 3}\n\t)\n\tfmt.Printf(\"blue bookcase : %v\\n\", blue)\n\tfmt.Printf(\"red bookcase  : %v\\n\", red)\n\n\tfmt.Println(\"Are they equal?\", blue == red)\n}\n"
  },
  {
    "path": "14-arrays/08-assignment/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tblue := [3]int{6, 9, 3}\n\tred := blue\n\n\tblue[0] = 10\n\n\tfmt.Printf(\"blue: %#v\\n\", blue)\n\tfmt.Printf(\"red : %#v\\n\", red)\n\n\t// UNASSIGNABLE:\n\t// blue := [3]int{6, 9, 3}\n\t// red := [2]int{3, 5}\n\t// red = blue\n}\n"
  },
  {
    "path": "14-arrays/08-assignment/02-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tprev := [3]string{\"Kafka's Revenge\", \"Stay Golden\", \"Everythingship\"}\n\n\t// You can't do this:\n\t// books = prev\n\n\tvar books [4]string\n\n\tfor i, b := range prev {\n\t\tbooks[i] += b + \" 2nd Ed.\"\n\t}\n\n\tbooks[3] = \"Awesomeness\"\n\n\tfmt.Printf(\"last year:\\n%#v\\n\", prev)\n\tfmt.Printf(\"\\nthis year:\\n%#v\\n\", books)\n}\n"
  },
  {
    "path": "14-arrays/09-multi-dimensional/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// ------------------------------------\n\t// #1 - THE BEST WAY\n\t// ------------------------------------\n\n\tstudents := [...][3]float64{\n\t\t{5, 6, 1},\n\t\t{9, 8, 4},\n\t}\n\n\tvar sum float64\n\n\tfor _, grades := range students {\n\t\tfor _, grade := range grades {\n\t\t\tsum += grade\n\t\t}\n\t}\n\n\tconst N = float64(len(students) * len(students[0]))\n\tfmt.Printf(\"Avg Grade: %g\\n\", sum/N)\n\n\t// ------------------------------------\n\t// #2 - SO SO WAY\n\t// ------------------------------------\n\n\t// // You don't need to define the types for the inner arrays\n\t// students := [2][3]float64{\n\t// \t[3]float64{5, 6, 1},\n\t// \t[3]float64{9, 8, 4},\n\t// }\n\n\t// var sum float64\n\n\t// sum += students[0][0] + students[0][1] + students[0][2]\n\t// sum += students[1][0] + students[1][1] + students[1][2]\n\n\t// const N = float64(len(students) * len(students[0]))\n\t// fmt.Printf(\"Avg Grade: %g\\n\", sum/N)\n\n\t// ------------------------------------\n\t// #3 - MANUAL WAY\n\t// ------------------------------------\n\n\t// student1 := [3]float64{5, 6, 1}\n\t// student2 := [3]float64{9, 8, 4}\n\n\t// var sum float64\n\t// sum += student1[0] + student1[1] + student1[2]\n\t// sum += student2[0] + student2[1] + student2[2]\n\n\t// const N = float64(len(student1) * 2)\n\t// fmt.Printf(\"Avg Grade: %g\\n\", sum/N)\n}\n"
  },
  {
    "path": "14-arrays/10-challenge-moodly-2/challenge/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"time\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Moodly #2\n//\n//   This challenge is based on the previous Moodly challenge.\n//\n//   1. Display the usage if the username or the mood is missing\n//\n//   2. Change the moods array to a multi-dimensional array.\n//\n//      So, create two inner arrays:\n//        1. One for positive moods\n//        2. Another one for negative moods\n//\n//   4. Randomly select and print one of the mood messages depending\n//      on the given mood command-line argument.\n//\n// EXPECTED OUTPUT\n//\n//   go run main.go\n//     [your name] [positive|negative]\n//\n//   go run main.go Socrates\n//     [your name] [positive|negative]\n//\n//   go run main.go Socrates positive\n//     Socrates feels good 👍\n//\n//   go run main.go Socrates positive\n//     Socrates feels happy 😀\n//\n//   go run main.go Socrates positive\n//     Socrates feels awesome 😎\n//\n//   go run main.go Socrates negative\n//     Socrates feels bad 👎\n//\n//   go run main.go Socrates negative\n//     Socrates feels sad 😞\n//\n//   go run main.go Socrates negative\n//     Socrates feels terrible 😩\n// ---------------------------------------------------------\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"[your name]\")\n\t\treturn\n\t}\n\n\tname := args[0]\n\n\tmoods := [...]string{\n\t\t\"happy 😀\", \"good 👍\", \"awesome 😎\",\n\t\t\"sad 😞\", \"bad 👎\", \"terrible 😩\",\n\t}\n\n\trand.Seed(time.Now().UnixNano())\n\tn := rand.Intn(len(moods))\n\n\tfmt.Printf(\"%s feels %s\\n\", name, moods[n])\n}\n"
  },
  {
    "path": "14-arrays/10-challenge-moodly-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"time\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 2 {\n\t\tfmt.Println(\"[your name] [positive|negative]\")\n\t\treturn\n\t}\n\n\tname, mood := args[0], args[1]\n\n\tmoods := [...][3]string{\n\t\t{\"happy 😀\", \"good 👍\", \"awesome 😎\"},\n\t\t{\"sad 😞\", \"bad 👎\", \"terrible 😩\"},\n\t}\n\n\trand.Seed(time.Now().UnixNano())\n\tn := rand.Intn(len(moods[0]))\n\n\tvar mi int\n\tif mood != \"positive\" {\n\t\tmi = 1\n\t}\n\tfmt.Printf(\"%s feels %s\\n\", name, moods[mi][n])\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/01-unkeyed/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\trates := [3]float64{\n\t\t0.5,\n\t\t2.5,\n\t\t1.5,\n\t}\n\n\tfmt.Println(rates)\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/02-keyed/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\trates := [3]float64{\n\t\t0: 0.5, // index: 0\n\t\t1: 2.5, // index: 1\n\t\t2: 1.5, // index: 2\n\t}\n\n\tfmt.Println(rates)\n\n\t// above array literal equals to this:\n\t//\n\t// rates := [3]float64{\n\t// \t0.5,\n\t// \t2.5,\n\t// \t1.5,\n\t// }\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/03-keyed-order/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\trates := [3]float64{\n\t\t1: 2.5, // index: 1\n\t\t0: 0.5, // index: 0\n\t\t2: 1.5, // index: 2\n\t}\n\n\tfmt.Println(rates)\n\n\t// above array literal equals to this:\n\t//\n\t// rates := [3]float64{\n\t// \t0.5,\n\t// \t2.5,\n\t// \t1.5,\n\t// }\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/04-keyed-auto-initialize/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\trates := [3]float64{\n\t\t// index 0 empty\n\t\t// index 1 empty\n\t\t2: 1.5, // index: 2\n\t}\n\n\tfmt.Println(rates)\n\n\t// above array literal equals to this:\n\t//\n\t// rates := [3]float64{\n\t// \t0.,\n\t// \t0.,\n\t// \t1.5,\n\t// }\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/05-keyed-auto-initialize-ellipsis/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// below ellipsis (...) calculates the length of the\n\t// array automatically\n\trates := [...]float64{\n\t\t// index 0 empty\n\t\t// index 1 empty\n\t\t// index 2 empty\n\t\t// index 3 empty\n\t\t// index 4 empty\n\t\t5: 1.5, // index: 5\n\t}\n\n\tfmt.Println(rates)\n\n\t// above array literal equals to this:\n\t//\n\t// rates := [6]float64{\n\t// \t0.,\n\t// \t0.,\n\t// \t0.,\n\t// \t0.,\n\t// \t0.,\n\t// \t1.5,\n\t// }\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/06-keyed-and-unkeyed/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\trates := [...]float64{\n\t\t// index 1 to 4 empty\n\n\t\t5:   1.5, // index: 5\n\t\t2.5, //      index: 6\n\t\t0:   0.5, // index: 0\n\t}\n\n\tfmt.Println(rates)\n\n\t// above array literal equals to this:\n\t//\n\t// rates := [7]float64{\n\t// \t0.5,\n\t// \t0.,\n\t// \t0.,\n\t// \t0.,\n\t// \t0.,\n\t// \t1.5,\n\t//  2.5,\n\t// }\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/07-xratio-example/01-without-keys/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\trates := [...]float64{\n\t\t25.5,  // ethereum\n\t\t120.5, // wanchain\n\t}\n\n\t// uses magic values - not good\n\tfmt.Printf(\"1 BTC is %g ETH\\n\", rates[0])\n\tfmt.Printf(\"1 BTC is %g WAN\\n\", rates[1])\n}\n"
  },
  {
    "path": "14-arrays/11-keyed-elements/07-xratio-example/02-with-keys/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// REFACTORED VERSION\n// It uses well-defined names instead of magic numbers.\n// Thanks to the keyed elements and constants.\n\nfunc main() {\n\tconst (\n\t\tETH = 9 - iota\n\t\tWAN\n\t\tICX\n\t\t// you can add more cryptocurrencies here\n\t\t// watch out the -1 index though!\n\t)\n\n\trates := [...]float64{\n\t\tETH: 25.5,\n\t\tWAN: 120.5,\n\t\tICX: 20,\n\t\t// you can add more cryptocurrencies here\n\t}\n\n\t// uses well-defined names (ETH, WAN, ...) - good\n\tfmt.Printf(\"1 BTC is %g ETH\\n\", rates[ETH])\n\tfmt.Printf(\"1 BTC is %g WAN\\n\", rates[WAN])\n\tfmt.Printf(\"1 BTC is %g ICX\\n\", rates[ICX])\n\n\tfmt.Printf(\"%#v\\n\", rates)\n}\n"
  },
  {
    "path": "14-arrays/12-compare-unnamed/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// STORY:\n// You want to compare two bookcases,\n// whether they're equal or not.\n\nfunc main() {\n\ttype (\n\t\t// integer int\n\n\t\tbookcase [5]int\n\t\tcabinet  [5]int\n\t\t//          ^- try changing this to: integer\n\t\t//             but first: uncomment the integer type above\n\t)\n\n\tblue := bookcase{6, 9, 3, 2, 1}\n\tred := cabinet{6, 9, 3, 2, 1}\n\n\tfmt.Print(\"Are they equal? \")\n\n\tif cabinet(blue) == red {\n\t\tfmt.Println(\"✅\")\n\t} else {\n\t\tfmt.Println(\"❌\")\n\t}\n\n\tfmt.Printf(\"blue: %#v\\n\", blue)\n\tfmt.Printf(\"red : %#v\\n\", bookcase(red))\n\n\t// ------------------------------------------------\n\t// The underlying type of an unnamed type is itself.\n\t//\n\t//   [5]integer's underlying type: [5]integer\n\t//   [5]int's underlying type    : [5]int\n\t//\n\t//   > [5]integer and [5]int are different types.\n\t//   > Their memory layout is not important.\n\t//   > Their types are not the same.\n\n\t// _ = [5]integer{} == [5]int{}\n\n\t// ------------------------------------------------\n\t// An unnamed and a named type can be compared,\n\t// if they've identical underlying types.\n\t//\n\t//   [5]integer's underlying type: [5]integer\n\t//   cabinet's underlying type   : [5]integer\n\t//\n\t// Note: Assuming the cabinet's type definition is like so:\n\t//       type cabinet [5]integer\n\n\t// _ = [5]integer{} == cabinet{}\n}\n"
  },
  {
    "path": "14-arrays/exercises/01-declare-empty/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Declare empty arrays\n//\n//  1. Declare and print the following arrays with their types:\n//\n//    1. The names of your three best friends (names array)\n//\n//    2. The distances to five different locations (distances array)\n//\n//    3. A data buffer with five bytes of capacity (data array)\n//\n//    4. Currency exchange ratios only for a single currency (ratios array)\n//\n//    5. Up/Down status of four different web servers (alives array)\n//\n//    6. A byte array that doesn't occupy memory space (zero array)\n//\n//  2. Print only the types of the same arrays.\n//\n//  3. Print only the elements of the same arrays.\n//\n// HINT\n//   When printing the elements of an array, you can use the usual Printf verbs.\n//\n//   For example:\n//     When printing a string array, you can use \"%q\" verb as usual.\n//\n// EXPECTED OUTPUT\n//  names    : [3]string{\"\", \"\", \"\"}\n//  distances: [5]int{0, 0, 0, 0, 0}\n//  data     : [5]uint8{0x0, 0x0, 0x0, 0x0, 0x0}\n//  ratios   : [1]float64{0}\n//  alives   : [4]bool{false, false, false, false}\n//  zero     : [0]uint8{}\n//\n//  names    : [3]string\n//  distances: [5]int\n//  data     : [5]uint8\n//  ratios   : [1]float64\n//  alives   : [4]bool\n//  zero     : [0]uint8\n//\n//  names    : [\"\" \"\" \"\"]\n//  distances: [0 0 0 0 0]\n//  data     : [0 0 0 0 0]\n//  ratios   : [0.00]\n//  alives   : [false false false false]\n//  zero     : []\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/01-declare-empty/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tnames     [3]string  // The names of your three best friends\n\t\tdistances [5]int     // The distances to five different locations\n\t\tdata      [5]byte    // A data buffer with five bytes of capacity\n\t\tratios    [1]float64 // Currency exchange ratios only for a single currency\n\t\talives    [4]bool    // Up/Down status of four different web servers\n\t\tzero      [0]byte    // A byte array that doesn't occupy memory space\n\t)\n\n\t// 1. Declare and print the arrays with their types.\n\tfmt.Printf(\"names    : %#v\\n\", names)\n\tfmt.Printf(\"distances: %#v\\n\", distances)\n\tfmt.Printf(\"data     : %#v\\n\", data)\n\tfmt.Printf(\"ratios   : %#v\\n\", ratios)\n\tfmt.Printf(\"alives   : %#v\\n\", alives)\n\tfmt.Printf(\"zero     : %#v\\n\", zero)\n\n\t//  2. Print only the types of the same arrays.\n\tfmt.Println()\n\tfmt.Printf(\"names    : %T\\n\", names)\n\tfmt.Printf(\"distances: %T\\n\", distances)\n\tfmt.Printf(\"data     : %T\\n\", data)\n\tfmt.Printf(\"ratios   : %T\\n\", ratios)\n\tfmt.Printf(\"alives   : %T\\n\", alives)\n\tfmt.Printf(\"zero     : %T\\n\", zero)\n\n\t// 3. Print only the elements of the same arrays.\n\tfmt.Println()\n\tfmt.Printf(\"names    : %q\\n\", names)\n\tfmt.Printf(\"distances: %d\\n\", distances)\n\tfmt.Printf(\"data     : %d\\n\", data)\n\tfmt.Printf(\"ratios   : %.2f\\n\", ratios)\n\tfmt.Printf(\"alives   : %t\\n\", alives)\n\tfmt.Printf(\"zero     : %d\\n\", zero)\n}\n"
  },
  {
    "path": "14-arrays/exercises/02-get-set-arrays/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Get and Set Array Elements\n//\n//  1. Use the 01-declare-empty exercise\n//  2. Remove everything but the array declarations\n//\n//  3. Assign your best friends' names to the names array\n//\n//  4. Assign distances to the closest cities to you to the distance array\n//\n//  5. Assign arbitrary bytes to the data array\n//\n//  6. Assign a value to the ratios array\n//\n//  7. Assign true/false values to the alives arrays\n//\n//  8. Try to assign to the zero array and observe the error\n//\n//  9. Now use ordinary loop statements for each array and print them\n//      (do not use for range)\n//\n//  10. Now use for range loop statements for each array and print them\n//\n//  11. Try assigning different types of values to the arrays, break things,\n//     and observe the errors\n//\n//  12. Remove some of the array assignments and observe the loop outputs\n//      (zero values)\n//\n//\n// EXPECTED OUTPUT\n//\n//  Note: The output can change depending on the values that you've assigned to them, of course.\n//        You're free to assign any values.\n//\n//   names\n//   ====================\n//   names[0]: \"Einstein\"\n//   names[1]: \"Tesla\"\n//   names[2]: \"Shepard\"\n//\n//   distances\n//   ====================\n//   distances[0]: 50\n//   distances[1]: 40\n//   distances[2]: 75\n//   distances[3]: 30\n//   distances[4]: 125\n//\n//   data\n//   ====================\n//   data[0]: 72\n//   data[1]: 69\n//   data[2]: 76\n//   data[3]: 76\n//   data[4]: 79\n//\n//   ratios\n//   ====================\n//   ratios[0]: 3.14\n//\n//   alives\n//   ====================\n//   alives[0]: true\n//   alives[1]: false\n//   alives[2]: true\n//   alives[3]: false\n//\n//   zero\n//   ====================\n\n//\n//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//   FOR RANGES\n//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//\n//   names\n//   ====================\n//   names[0]: \"Einstein\"\n//   names[1]: \"Tesla\"\n//   names[2]: \"Shepard\"\n//\n//   distances\n//   ====================\n//   distances[0]: 50\n//   distances[1]: 40\n//   distances[2]: 75\n//   distances[3]: 30\n//   distances[4]: 125\n//\n//   data\n//   ====================\n//   data[0]: 72\n//   data[1]: 69\n//   data[2]: 76\n//   data[3]: 76\n//   data[4]: 79\n//\n//   ratios\n//   ====================\n//   ratios[0]: 3.14\n//\n//   alives\n//   ====================\n//   alives[0]: true\n//   alives[1]: false\n//   alives[2]: true\n//   alives[3]: false\n//\n//   zero\n//   ====================\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/02-get-set-arrays/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tvar (\n\t\tnames     [3]string  // The names of your three best friends\n\t\tdistances [5]int     // The distances to five different locations\n\t\tdata      [5]byte    // A data buffer with five bytes of capacity\n\t\tratios    [1]float64 // Currency exchange ratios only for a single currency\n\t\talives    [4]bool    // Up/Down status of four different web servers\n\t\tzero      [0]byte    // A byte array that doesn't occupy memory space\n\t)\n\n\tnames[0] = \"Einstein\"\n\tnames[1] = \"Tesla\"\n\tnames[2] = \"Shepard\"\n\n\tdistances[0] = 50\n\tdistances[1] = 40\n\tdistances[2] = 75\n\tdistances[3] = 30\n\tdistances[4] = 125\n\n\tdata[0] = 'H'\n\tdata[1] = 'E'\n\tdata[2] = 'L'\n\tdata[3] = 'L'\n\tdata[4] = 'O'\n\n\tratios[0] = 3.14145\n\n\talives[0] = true\n\talives[1] = false\n\talives[2] = true\n\talives[3] = false\n\n\t// zero[0] = \"BOMB!\"\n\t_ = zero\n\n\t// =========================================================================\n\n\tseparator := \"\\n\" + strings.Repeat(\"=\", 20) + \"\\n\"\n\n\tfmt.Print(\"names\", separator)\n\tfor i := 0; i < len(names); i++ {\n\t\tfmt.Printf(\"names[%d]: %q\\n\", i, names[i])\n\t}\n\n\tfmt.Print(\"\\ndistances\", separator)\n\tfor i := 0; i < len(distances); i++ {\n\t\tfmt.Printf(\"distances[%d]: %d\\n\", i, distances[i])\n\t}\n\n\tfmt.Print(\"\\ndata\", separator)\n\tfor i := 0; i < len(data); i++ {\n\t\t// try the %c verb\n\t\tfmt.Printf(\"data[%d]: %d\\n\", i, data[i])\n\t}\n\n\tfmt.Print(\"\\nratios\", separator)\n\tfor i := 0; i < len(ratios); i++ {\n\t\tfmt.Printf(\"ratios[%d]: %.2f\\n\", i, ratios[i])\n\t}\n\n\tfmt.Print(\"\\nalives\", separator)\n\tfor i := 0; i < len(alives); i++ {\n\t\tfmt.Printf(\"alives[%d]: %t\\n\", i, alives[i])\n\t}\n\n\t// no loop for zero elements\n\tfmt.Print(\"\\nzero\", separator)\n\tfor i := 0; i < len(zero); i++ {\n\t\tfmt.Printf(\"zero[%d]: %d\\n\", i, zero[i])\n\t}\n\n\t// =========================================================================\n\n\t// you know how this works :) don't be freaked out!\n\tfmt.Printf(`\n\n%s\nFOR RANGES\n%[1]s\n\n`, strings.Repeat(\"~\", 30))\n\n\tfmt.Print(\"names\", separator)\n\tfor i, v := range names {\n\t\tfmt.Printf(\"names[%d]: %q\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\ndistances\", separator)\n\tfor i, v := range distances {\n\t\tfmt.Printf(\"distances[%d]: %d\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\ndata\", separator)\n\tfor i, v := range data {\n\t\t// try the %c verb\n\t\tfmt.Printf(\"data[%d]: %d\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\nratios\", separator)\n\tfor i, v := range ratios {\n\t\tfmt.Printf(\"ratios[%d]: %.2f\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\nalives\", separator)\n\tfor i, v := range alives {\n\t\tfmt.Printf(\"alives[%d]: %t\\n\", i, v)\n\t}\n\n\t// no loop for zero elements\n\tfmt.Print(\"\\nzero\", separator)\n\tfor i, v := range zero {\n\t\tfmt.Printf(\"zero[%d]: %d\\n\", i, v)\n\t}\n}\n"
  },
  {
    "path": "14-arrays/exercises/03-array-literal/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor to Array Literals\n//\n//  1. Use the 02-get-set-arrays exercise\n//\n//  2. Refactor the array assignments to array literals\n//\n//    1. You would need to change the array declarations to array literals\n//\n//    2. Then, you would need to move the right-hand side of the assignments,\n//       into the array literals.\n//\n// EXPECTED OUTPUT\n//   The output should be the same as the 02-get-set-arrays exercise.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/03-array-literal/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// The names of your three best friends\n\tnames := [3]string{\n\t\t\"Einstein\",\n\t\t\"Tesla\",\n\t\t\"Shepard\",\n\t}\n\n\t// The distances to five different locations\n\tdistances := [5]int{50, 40, 75, 30, 125}\n\n\t// A data buffer with five bytes of capacity\n\tdata := [5]byte{'H', 'E', 'L', 'L', 'O'}\n\n\t// Currency exchange ratios only for a single currency\n\tratios := [1]float64{3.14145}\n\n\t// Up/Down status of four different web servers\n\talives := [4]bool{true, false, true, false}\n\n\t// A byte array that doesn't occupy memory space\n\t//\n\t// Don't do this:\n\t//   zero := [0]byte{}\n\t//\n\t// Do this (when you don't assign elements):\n\tvar zero [0]byte\n\n\t// =========================================================================\n\n\tseparator := \"\\n\" + strings.Repeat(\"=\", 20) + \"\\n\"\n\n\tfmt.Print(\"names\", separator)\n\tfor i := 0; i < len(names); i++ {\n\t\tfmt.Printf(\"names[%d]: %q\\n\", i, names[i])\n\t}\n\n\tfmt.Print(\"\\ndistances\", separator)\n\tfor i := 0; i < len(distances); i++ {\n\t\tfmt.Printf(\"distances[%d]: %d\\n\", i, distances[i])\n\t}\n\n\tfmt.Print(\"\\ndata\", separator)\n\tfor i := 0; i < len(data); i++ {\n\t\t// try the %c verb\n\t\tfmt.Printf(\"data[%d]: %d\\n\", i, data[i])\n\t}\n\n\tfmt.Print(\"\\nratios\", separator)\n\tfor i := 0; i < len(ratios); i++ {\n\t\tfmt.Printf(\"ratios[%d]: %.2f\\n\", i, ratios[i])\n\t}\n\n\tfmt.Print(\"\\nalives\", separator)\n\tfor i := 0; i < len(alives); i++ {\n\t\tfmt.Printf(\"alives[%d]: %t\\n\", i, alives[i])\n\t}\n\n\t// no loop for zero elements\n\tfmt.Print(\"\\nzero\", separator)\n\tfor i := 0; i < len(zero); i++ {\n\t\tfmt.Printf(\"zero[%d]: %d\\n\", i, zero[i])\n\t}\n\n\t// =========================================================================\n\n\t// you know how this works :) don't be freaked out!\n\tfmt.Printf(`\n\n%s\nFOR RANGES\n%[1]s\n\n`, strings.Repeat(\"~\", 30))\n\n\tfmt.Print(\"names\", separator)\n\tfor i, v := range names {\n\t\tfmt.Printf(\"names[%d]: %q\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\ndistances\", separator)\n\tfor i, v := range distances {\n\t\tfmt.Printf(\"distances[%d]: %d\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\ndata\", separator)\n\tfor i, v := range data {\n\t\t// try the %c verb\n\t\tfmt.Printf(\"data[%d]: %d\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\nratios\", separator)\n\tfor i, v := range ratios {\n\t\tfmt.Printf(\"ratios[%d]: %.2f\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\nalives\", separator)\n\tfor i, v := range alives {\n\t\tfmt.Printf(\"alives[%d]: %t\\n\", i, v)\n\t}\n\n\t// no loop for zero elements\n\tfmt.Print(\"\\nzero\", separator)\n\tfor i, v := range zero {\n\t\tfmt.Printf(\"zero[%d]: %d\\n\", i, v)\n\t}\n}\n"
  },
  {
    "path": "14-arrays/exercises/04-ellipsis/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor to Ellipsis\n//\n//  1. Use the 03-array-literal exercise\n//\n//  2. Refactor the length of the array literals to ellipsis\n//\n//    This means: Use the ellipsis instead of defining the array's length\n//                manually.\n//\n// EXPECTED OUTPUT\n//   The output should be the same as the 03-array-literal exercise.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/04-ellipsis/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// The names of your three best friends\n\tnames := [...]string{\n\t\t\"Einstein\",\n\t\t\"Tesla\",\n\t\t\"Shepard\",\n\t}\n\n\t// The distances to five different locations\n\tdistances := [...]int{50, 40, 75, 30, 125}\n\n\t// A data buffer with five bytes of capacity\n\tdata := [...]byte{'H', 'E', 'L', 'L', 'O'}\n\n\t// Currency exchange ratios only for a single currency\n\tratios := [...]float64{3.14145}\n\n\t// Up/Down status of four different web servers\n\talives := [...]bool{true, false, true, false}\n\n\t// A byte array that doesn't occupy memory space\n\t// Obviously, do not use ellipsis on this one\n\tvar zero []byte\n\n\t// =========================================================================\n\n\tseparator := \"\\n\" + strings.Repeat(\"=\", 20) + \"\\n\"\n\n\tfmt.Print(\"names\", separator)\n\tfor i := 0; i < len(names); i++ {\n\t\tfmt.Printf(\"names[%d]: %q\\n\", i, names[i])\n\t}\n\n\tfmt.Print(\"\\ndistances\", separator)\n\tfor i := 0; i < len(distances); i++ {\n\t\tfmt.Printf(\"distances[%d]: %d\\n\", i, distances[i])\n\t}\n\n\tfmt.Print(\"\\ndata\", separator)\n\tfor i := 0; i < len(data); i++ {\n\t\t// try the %c verb\n\t\tfmt.Printf(\"data[%d]: %d\\n\", i, data[i])\n\t}\n\n\tfmt.Print(\"\\nratios\", separator)\n\tfor i := 0; i < len(ratios); i++ {\n\t\tfmt.Printf(\"ratios[%d]: %.2f\\n\", i, ratios[i])\n\t}\n\n\tfmt.Print(\"\\nalives\", separator)\n\tfor i := 0; i < len(alives); i++ {\n\t\tfmt.Printf(\"alives[%d]: %t\\n\", i, alives[i])\n\t}\n\n\t// no loop for zero elements\n\tfmt.Print(\"\\nzero\", separator)\n\tfor i := 0; i < len(zero); i++ {\n\t\tfmt.Printf(\"zero[%d]: %d\\n\", i, zero[i])\n\t}\n\n\t// =========================================================================\n\n\t// you know how this works :) don't be freaked out!\n\tfmt.Printf(`\n\n%s\nFOR RANGES\n%[1]s\n\n`, strings.Repeat(\"~\", 30))\n\n\tfmt.Print(\"names\", separator)\n\tfor i, v := range names {\n\t\tfmt.Printf(\"names[%d]: %q\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\ndistances\", separator)\n\tfor i, v := range distances {\n\t\tfmt.Printf(\"distances[%d]: %d\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\ndata\", separator)\n\tfor i, v := range data {\n\t\t// try the %c verb\n\t\tfmt.Printf(\"data[%d]: %d\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\nratios\", separator)\n\tfor i, v := range ratios {\n\t\tfmt.Printf(\"ratios[%d]: %.2f\\n\", i, v)\n\t}\n\n\tfmt.Print(\"\\nalives\", separator)\n\tfor i, v := range alives {\n\t\tfmt.Printf(\"alives[%d]: %t\\n\", i, v)\n\t}\n\n\t// no loop for zero elements\n\tfmt.Print(\"\\nzero\", separator)\n\tfor i, v := range zero {\n\t\tfmt.Printf(\"zero[%d]: %d\\n\", i, v)\n\t}\n}\n"
  },
  {
    "path": "14-arrays/exercises/05-fix/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Fix\n//\n//  1. Uncomment the code\n//\n//  2. And fix the problems\n//\n//  3. BONUS: Simplify the code\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var names [3]string = [3]string{\n\t// \t\"Einstein\" \"Shepard\"\n\t// \t\"Tesla\"\n\t// }\n\n\t// var books [5]string = [5]string{\n\t// \t\"Kafka's Revenge\",\n\t// \t\"Stay Golden\",\n\t// \t\"\",\n\t// \t\"\",\n\t// \t\"\"\n\t// }\n\n\t// fmt.Printf(\"%q\\n\", names)\n\t// fmt.Printf(\"%q\\n\", books)\n}\n"
  },
  {
    "path": "14-arrays/exercises/05-fix/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tnames := [...]string{\"Einstein\", \"Shepard\", \"Tesla\"}\n\tbooks := [5]string{\"Kafka's Revenge\", \"Stay Golden\"}\n\n\tfmt.Printf(\"%q\\n\", names)\n\tfmt.Printf(\"%q\\n\", books)\n}\n"
  },
  {
    "path": "14-arrays/exercises/06-compare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Compare the Arrays\n//\n//  1. Uncomment the code\n//\n//  2. Fix the problems so that arrays become comparable\n//\n// EXPECTED OUTPUT\n//  true\n//  true\n//  false\n// ---------------------------------------------------------\n\nfunc main() {\n\t// week := [...]string{\"Monday\", \"Tuesday\"}\n\t// wend := [4]string{\"Saturday\", \"Sunday\"}\n\n\t// fmt.Println(week != wend)\n\n\t// evens := [...]int{2, 4, 6, 8, 10}\n\t// evens2 := [...]int32{2, 4, 6, 8, 10}\n\n\t// fmt.Println(evens == evens2)\n\n\t// Use     : uint8 for one of the arrays instead of byte here.\n\t// Remember: Aliased types are the same types.\n\timage := [5]byte{'h', 'i'}\n\tvar data [5]byte\n\n\tfmt.Println(data == image)\n}\n"
  },
  {
    "path": "14-arrays/exercises/06-compare/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tweek := [...]string{\"Monday\", \"Tuesday\"}\n\twend := [...]string{\"Saturday\", \"Sunday\"}\n\n\tfmt.Println(week != wend)\n\n\tevens := [...]int{2, 4, 6, 8, 10}\n\tevens2 := [...]int{2, 4, 6, 8, 10}\n\n\tfmt.Println(evens == evens2)\n\n\t// Use     : uint8 for one of the arrays instead of byte here.\n\t// Remember: Aliased types are the same types.\n\timage := [5]uint8{'h', 'i'}\n\tvar data [5]byte\n\n\tfmt.Println(data == image)\n}\n"
  },
  {
    "path": "14-arrays/exercises/07-assign/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Assign the Arrays\n//\n//  1. Create an array named books\n//\n//  2. Add book titles to the array\n//\n//  3. Create two more copies of the array named: upper and lower\n//\n//  4. Change the book titles to uppercase in the upper array only\n//\n//  5. Change the book titles to lowercase in the lower array only\n//\n//  6. Print all the arrays\n//\n//  7. Observe that the arrays are not connected when they're copied.\n//\n// NOTE\n//  Check out the strings package, it has functions to convert letters to\n//  upper and lower cases.\n//\n// BONUS\n//  Invent your own arrays with different types other than string,\n//  and do some manipulations on them.\n//\n// EXPECTED OUTPUT\n//   Note: Don't worry about the book titles here, you can use any title.\n//\n//   books: [\"Kafka's Revenge\" \"Stay Golden\" \"Everythingship\"]\n//   upper: [\"KAFKA'S REVENGE\" \"STAY GOLDEN\" \"EVERYTHINGSHIP\"]\n//   lower: [\"kafka's revenge\" \"stay golden\" \"everythingship\"]\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/07-assign/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tbooks := [...]string{\"Kafka's Revenge\", \"Stay Golden\", \"Everythingship\"}\n\n\tupper, lower := books, books\n\n\tfor i := range books {\n\t\tupper[i] = strings.ToUpper(upper[i])\n\t\tlower[i] = strings.ToLower(lower[i])\n\t}\n\n\tfmt.Printf(\"books: %q\\n\", books)\n\tfmt.Printf(\"upper: %q\\n\", upper)\n\tfmt.Printf(\"lower: %q\\n\", lower)\n}\n"
  },
  {
    "path": "14-arrays/exercises/08-wizard-printer/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Wizard Printer\n//\n//   In this exercise, your goal is to display a few famous scientists\n//   in a pretty table.\n//\n//   1. Create a multi-dimensional array\n//   2. In each inner array, store the scientist's name, lastname and his/her\n//      nickname\n//   3. Print their information in a pretty table using a loop.\n//\n// EXPECTED OUTPUT\n//   First Name      Last Name       Nickname\n//   ==================================================\n//   Albert          Einstein        time\n//   Isaac           Newton          apple\n//   Stephen         Hawking         blackhole\n//   Marie           Curie           radium\n//   Charles         Darwin          fittest\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/08-wizard-printer/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tnames := [...][3]string{\n\t\t{\"First Name\", \"Last Name\", \"Nickname\"},\n\t\t{\"Albert\", \"Einstein\", \"emc2\"},\n\t\t{\"Isaac\", \"Newton\", \"apple\"},\n\t\t{\"Stephen\", \"Hawking\", \"blackhole\"},\n\t\t{\"Marie\", \"Curie\", \"radium\"},\n\t\t{\"Charles\", \"Darwin\", \"fittest\"},\n\t}\n\n\tfor i := range names {\n\t\tn := names[i]\n\t\tfmt.Printf(\"%-15s %-15s %-15s\\n\", n[0], n[1], n[2])\n\n\t\tif i == 0 {\n\t\t\tfmt.Println(strings.Repeat(\"=\", 50))\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "14-arrays/exercises/09-currency-converter/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Currency Converter\n//\n//   In this exercise, you're going to display currency exchange ratios\n//   against USD.\n//\n//   1. Declare a few constants with iota. They're going to be the keys\n//      of the array.\n//\n//   2. Create an array that contains the conversion ratios.\n//\n//      You should use keyed elements and the contants you've declared before.\n//\n//   3. Get the USD amount to be converted from the command line.\n//\n//   4. Handle the error cases for missing or invalid input.\n//\n//   5. Print the exchange ratios.\n//\n// EXPECTED OUTPUT\n//   go run main.go\n//     Please provide the amount to be converted.\n//\n//   go run main.go invalid\n//     Invalid amount. It should be a number.\n//\n//   go run main.go 10.5\n//     10.50 USD is 9.24 EUR\n//     10.50 USD is 8.19 GBP\n//     10.50 USD is 1186.71 JPY\n//\n//   go run main.go 1\n//     1.00 USD is 0.88 EUR\n//     1.00 USD is 0.78 GBP\n//     1.00 USD is 113.02 JPY\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/09-currency-converter/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tconst (\n\t\tEUR = iota\n\t\tGBP\n\t\tJPY\n\t)\n\n\trates := [...]float64{\n\t\tEUR: 0.88,\n\t\tGBP: 0.78,\n\t\tJPY: 113.02,\n\t}\n\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"Please provide the amount to be converted.\")\n\t\treturn\n\t}\n\n\tamount, err := strconv.ParseFloat(args[0], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Invalid amount. It should be a number.\")\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%.2f USD is %.2f EUR\\n\", amount, rates[EUR]*amount)\n\tfmt.Printf(\"%.2f USD is %.2f GBP\\n\", amount, rates[GBP]*amount)\n\tfmt.Printf(\"%.2f USD is %.2f JPY\\n\", amount, rates[JPY]*amount)\n}\n"
  },
  {
    "path": "14-arrays/exercises/10-hipsters-love-search/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Hipster's Love Bookstore Search Engine\n//\n//  Your goal is to allow people to search for books.\n//\n//  1. Create an array with the following book titles:\n//      Kafka's Revenge\n//      Stay Golden\n//      Everythingship\n//      Kafka's Revenge 2nd Edition\n//\n//  2. Get the search query from the command-line argument\n//\n//  3. Search for the books in the books array\n//\n//  4. When the program finds the book, print it.\n//  5. Otherwise, print that the book doesn't exist.\n//\n//  6. Handle the errors.\n//\n// RESTRICTION:\n//   + The search should be case insensitive.\n//\n// EXPECTED OUTPUT\n//   go run main.go\n//     Tell me a book title\n//\n//   go run main.go STAY\n//     Search Results:\n//     + Stay Golden\n//\n//   go run main.go sTaY\n//     Search Results:\n//     + Stay Golden\n//\n//   go run main.go \"Kafka's Revenge\"\n//     Search Results:\n//     + Kafka's Revenge\n//     + Kafka's Revenge 2nd Edition\n//\n//   go run main.go void\n//     Search Results:\n//     We don't have the book: \"void\"\n//\n// HINTS:\n//   + To find out whether a string contains another string value, you can use the strings.Contains function.\n//   + To convert a string value to lowercase, you can use the strings.ToLower function.\n//   + Check out the strings package for more information.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/10-hipsters-love-search/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\tbooks := [4]string{\n\t\t\"Kafka's Revenge\",\n\t\t\"Stay Golden\",\n\t\t\"Everythingship\",\n\t\t\"Kafka's Revenge 2nd Edition\",\n\t}\n\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"Tell me a book title\")\n\t\treturn\n\t}\n\tquery := strings.ToLower(args[0])\n\n\tfmt.Println(\"Search Results:\")\n\n\tvar found bool\n\tfor _, v := range books {\n\t\tif strings.Contains(strings.ToLower(v), query) {\n\t\t\tfmt.Println(\"+\", v)\n\t\t\tfound = true\n\t\t}\n\t}\n\n\tif !found {\n\t\tfmt.Printf(\"We don't have the book: %q\\n\", query)\n\t}\n}\n"
  },
  {
    "path": "14-arrays/exercises/11-average/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Find the Average\n//\n//  Your goal is to fill an array with numbers and find the average.\n//\n//  1. Get the numbers from the command-line.\n//\n//  2. Create an array and assign the given numbers to that array.\n//\n//  3. Print the given numbers and their average.\n//\n// RESTRICTION\n//   + Maximum 5 numbers can be provided\n//   + If one of the arguments are not a valid number, skip it\n//\n// EXPECTED OUTPUT\n//   go run main.go\n//     Please tell me numbers (maximum 5 numbers).\n//\n//   go run main.go 1 2 3 4 5 6\n//     Please tell me numbers (maximum 5 numbers).\n//\n//   go run main.go 1 2 3 4 5\n//     Your numbers: [1 2 3 4 5]\n//     Average: 3\n//\n//   go run main.go 1 a 2 b 3\n//     Your numbers: [1 0 2 0 3]\n//     Average: 2\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/11-average/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif l := len(args); l == 0 || l > 5 {\n\t\tfmt.Println(\"Please tell me numbers (maximum 5 numbers).\")\n\t\treturn\n\t}\n\n\tvar (\n\t\tsum   float64\n\t\tnums  [5]float64\n\t\ttotal float64\n\t)\n\n\tfor i, v := range args {\n\t\tn, err := strconv.ParseFloat(v, 64)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\ttotal++\n\t\tnums[i] = n\n\t\tsum += n\n\t}\n\n\tfmt.Println(\"Your numbers:\", nums)\n\tfmt.Println(\"Average:\", sum/total)\n}\n"
  },
  {
    "path": "14-arrays/exercises/12-sorter/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Number Sorter\n//\n//  Your goal is to sort the given numbers from the command-line.\n//\n//  1. Get the numbers from the command-line.\n//\n//  2. Create an array and assign the given numbers to that array.\n//\n//  3. Sort the given numbers and print them.\n//\n// RESTRICTION\n//   + Maximum 5 numbers can be provided\n//   + If one of the arguments is not a valid number, skip it\n//\n// HINTS\n//  + You can use the bubble-sort algorithm to sort the numbers.\n//    Please watch this: https://youtu.be/nmhjrI-aW5o?t=7\n//\n//  + When swapping the elements, do not check for the last element.\n//\n//    Or, you will receive this error:\n//    \"panic: runtime error: index out of range\"\n//\n// EXPECTED OUTPUT\n//   go run main.go\n//     Please give me up to 5 numbers.\n//\n//   go run main.go 6 5 4 3 2 1\n//     Sorry. Go arrays are fixed. So, for now, I'm only supporting sorting 5 numbers...\n//\n//   go run main.go 5 4 3 2 1\n//     [1 2 3 4 5]\n//\n//   go run main.go 5 4 a c 1\n//     [0 0 1 4 5]\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/12-sorter/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\n\tswitch l := len(args); {\n\tcase l == 0:\n\t\tfmt.Println(\"Please give me up to 5 numbers.\")\n\t\treturn\n\tcase l > 5:\n\t\tfmt.Println(\"Sorry. Go arrays are fixed.\",\n\t\t\t\"So, for now, I'm only supporting sorting 5 numbers...\")\n\t\treturn\n\t}\n\n\tvar nums [5]float64\n\n\t// fill the array with the numbers\n\tfor i, v := range args {\n\t\tn, err := strconv.ParseFloat(v, 64)\n\t\tif err != nil {\n\t\t\t// skip if it's not a valid number\n\t\t\tcontinue\n\t\t}\n\n\t\tnums[i] = n\n\t}\n\n\t/*\n\t\tcheck whether it's the last element or not:\n\t\t  i < len(nums)-1\n\n\t\tcheck whether the next number is greater than the current one, if so, swap it:\n\t\t  v > nums[i+1]\n\t*/\n\tfor range nums {\n\t\tfor i, v := range nums {\n\t\t\tif i < len(nums)-1 && v > nums[i+1] {\n\t\t\t\tnums[i], nums[i+1] = nums[i+1], nums[i]\n\t\t\t}\n\t\t}\n\t}\n\n\tfmt.Println(nums)\n}\n"
  },
  {
    "path": "14-arrays/exercises/13-word-finder/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Word Finder\n//\n//   Your goal is to search for the words inside the corpus.\n//\n//   Note: This exercise is similar to the previous word finder program:\n//   https://github.com/inancgumus/learngo/tree/master/13-loops/10-word-finder-labeled-switch\n//\n//   1. Get the search query from the command-line (it can be multiple words)\n//\n//   2. Filter these words, do not search for them:\n//      and, or, was, the, since, very\n//\n//      To do this, use an array for the filtered words.\n//\n//   3. Print the words found.\n//\n// RESTRICTION\n//   + The search and the filtering should be case insensitive\n//\n// HINT\n//   + strings.Fields function converts a given string to a slice.\n//\n//     You can find its example in the word finder program that I've mentioned\n//     above.\n//\n// EXPECTED OUTPUT\n//   go run main.go\n//     Please give me a word to search.\n//\n//   go run main.go and was\n//\n//   go run main.go AND WAS\n//\n//   go run main.go cat beginning\n//     #2 : \"cat\"\n//     #11: \"beginning\"\n//\n//   go run main.go Cat Beginning\n//     #2 : \"cat\"\n//     #11: \"beginning\"\n// ---------------------------------------------------------\n\nconst corpus = \"lazy cat jumps again and again and again since the beginning this was very important\"\n\nfunc main() {\n}\n"
  },
  {
    "path": "14-arrays/exercises/13-word-finder/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst corpus = \"lazy cat jumps again and again and again since the beginning this was very important\"\n\nfunc main() {\n\tquery := os.Args[1:]\n\tif len(query) == 0 {\n\t\tfmt.Println(\"Please give me a word to search.\")\n\t\treturn\n\t}\n\n\tfilter := [...]string{\n\t\t\"and\", \"or\", \"was\", \"the\", \"since\", \"very\",\n\t}\n\n\twords := strings.Fields(corpus)\n\nqueries:\n\tfor _, q := range query {\n\t\tq = strings.ToLower(q)\n\n\t\tfor _, v := range filter {\n\t\t\tif q == v {\n\t\t\t\tcontinue queries\n\t\t\t}\n\t\t}\n\n\t\tfor i, w := range words {\n\t\t\tif q == w {\n\t\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "14-arrays/exercises/README.md",
    "content": "# Array Exercises\n\n## Exercises Level I - Basics\n\n1. **[Declare Empty Arrays](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/01-declare-empty)**\n\n2. **[Get and Set Array Elements](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/02-get-set-arrays)**\n\n3. **[Refactor to Array Literals](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/03-array-literal)**\n\n4. **[Refactor to Ellipsis](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/04-ellipsis)**\n\n5. **[Fix](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/05-fix)**\n\n6. **[Compare the Arrays](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/06-compare)**\n\n7. **[Assign the Arrays](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/07-assign)**\n\n---\n\n## Exercises Level II\n\n1. **[Wizard Printer](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/08-wizard-printer)**\n\n2. **[Currency Converter](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/09-currency-converter)**\n\n3. **[Hipster's Bookstore Search Engine](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/10-hipsters-love-search)**\n\n4. **[Find the Average](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/11-average)**\n\n5. **[Number Sorter](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/12-sorter)**\n   \n6. **[Word Finder](https://github.com/inancgumus/learngo/tree/master/14-arrays/exercises/13-word-finder)**\n"
  },
  {
    "path": "14-arrays/questions/1-array-basics.md",
    "content": "# Array Basics Quiz\n\n## What's an array?\n1. Accelerated charged particle array gun from Star Wars\n2. Collection of values with dynamic length and type\n3. Collection of values with fixed length and type *CORRECT*\n\n\n## Where is the 2nd variable below stored in memory?\n```go\n// Let's say that the first variable below is stored in this memory location: 20th\nvar (\n    first  int32 = 100\n    second int32 = 150\n)\n```\n1. 21\n2. 22\n3. 24\n4. It can be stored anywhere *CORRECT*\n\n> **4:** That's right. It can be anywhere. Because, unlike arrays, there isn't any guarantee that variables will be stored in contiguous memory locations.\n\n\n## Where is the 3rd element of the nums array stored in memory?\n\n```go\n// Let's say: nums array is stored in this memory location: 500th\nvar nums [5]int64\n```\n1. 3\n2. 2\n3. 502\n4. 503\n5. 516 *CORRECT*\n\n> **2:** Nope, that's the index of an element.\n>\n> **3, 4:** 500+index? You're getting closer.\n>\n> **5:** Perfect. Array elements are stored in contiguous memory locations. Here, the array's location is 500, and each element is 8 bytes (int64). So, 1st element is stored in: 500th, 2nd element: 508th, 3rd element: 516th, and so on. Formula for math lovers: 516 = 500 + 8 * (3 - 1). General formula: Starting position + The size of each element * (Element's index position - 1).\n\n\n## How many values this variable stores?\n**HINT:** _I'm asking about the variable not about the array inside the variable._\n```go\nvar gophers [10]string\n```\n1. 0\n2. 1 *CORRECT*\n3. 2\n4. 10\n\n> **2:** That's right! A variable can only store one value. Here, it stores a single array value. However, through the variable, you can also access to individual string values inside the array value.\n>\n> **4:** That's the length of the array. It's not the number of values that the gophers variable stores.\n\n\n## What's the length of this array?\n```go\nvar gophers [5]int\n```\n1. 5 *CORRECT*\n2. 1\n3. 2\n\n> **1:** That's right! It stores 5 int values.\n>\n\n## What's the length of this array?\n```go\nconst length = 5 * 2\nvar gophers [length - 1]int\n```\n1. 10\n2. 9 *CORRECT*\n3. 1\n\n> **2:** That's right! 5 * 2 - 1 is 9. You can use constant expressions while declaring the length of an array.\n\n\n## What's the element type of this array?\n```go\nvar luminosity [100]float32\n```\n1. [100]float32\n2. luminosity\n3. float32 *CORRECT*\n\n\n## What's the type of this array?\n```go\nvar luminosity [100]float32\n```\n1. [100]float32 *CORRECT*\n2. luminosity\n3. float32\n\n> **1:** That's right. Array's type is consisting of its length and its element type together.\n>\n\n\n## What does this program print?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n\tvar names [3]string\n\n\tnames[len(names)-1] = \"!\"\n\tnames[1] = \"think\" + names[2]\n\tnames[0] = \"Don't\"\n\tnames[0] += \" \"\n\n\tfmt.Println(names[0] + names[1] + names[2])\n}\n```\n1. !think!Don't\n2. Don't think!! *CORRECT*\n3. This program is incorrect\n\n> **2:** \"Don't think!! Just do!\". Explanation is here: https://play.golang.org/p/y_Tqwn_XRlg\n>\n\n\n## What does this program print?\n_It's OK if you can't solve this question. This is a hard question. You may try it on Go Playground here: https://play.golang.org/p/o0o0UM7Ktyy_\n```go\npackage main\nimport \"fmt\"\n\n// This program sets the next element of the array,\n// then it quits just before the last element.\nfunc main() {\n\tvar sum [5]int\n\n\tfor i, v := range sum {\n\t    if i == len(sum) - 1 {\n\t        break\n\t    }\n\n\t    sum[i+1] = 10\n\t    fmt.Print(v, \" \")\n\t}\n}\n```\n1. 0 0 0 0 *CORRECT*\n2. 10 10 10 10\n3. 0 10 10 10\n\n> **1:** That's right! the for range clause copies the sum array. So, changing the elements of the sum array while inside of the loop won't effect the original sum array. However, if you try to print it right after the loop, you'll see that it has changed. Try printing it like so on Go Playground.\n>\n> **2:** That's not right. Because, the for range clause copies the sum array.\n>\n\n"
  },
  {
    "path": "14-arrays/questions/2-arrays.md",
    "content": "# Arrays Quiz\n\n## What's the length of this array literal?\n```go\ngadgets := [...]string{\"Mighty Mouse\", \"Amazing Keyboard\", \"Shiny Monitor\"}\n```\n1. 0\n2. 1\n3. 2\n4. 3 *CORRECT*\n\n> **4:** Yes! There are 3 elements in the element list. So, Go sets the length of the array to 3.\n>\n\n\n## What's the type and length of this array literal?\n```go\ngadgets := [...]string{}\n```\n1. [0]string and 0 *CORRECT*\n2. [0]string{} and 0\n3. [1]string and 1 \n4. [1]string{} and 1 \n\n> **1:** Yes! There are no elements in the element list. So, Go sets the length of the array to 0.\n>\n\n## What does this program print?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n\tgadgets := [3]string{\"Confused Drone\"}\n\tfmt.Printf(\"%q\\n\", gadgets)\n}\n```\n1. [3]string{\"Confused Drone\", \"\", \"\"}\n2. [1]string{\"Confused Drone\"}\n3. [\"Confused Drone\" \"\" \"\"] *CORRECT*\n4. [\"Confused Drone\"]\n\n> **1:** %q verb doesn't print the type of an array.\n>\n> **2, 4:** Array's length cannot change depending on the elements.\n>\n> **3:** Yes! Go sets the uninitialized elements to their zero values.\n>\n\n\n## Are these arrays comparable?\n```go\ngadgets := [3]string{\"Confused Drone\"}\ngears   := [...]string{\"Confused Drone\"}\n\nfmt.Println(gadgets == gears)\n```\n1. Yes, because they have identical types and elements\n2. No, because their types are different *CORRECT*\n3. No, because their elements are different\n\n> **2:** Yes! gadget's type is [3]string whereas gears's type is [1]string.\n>\n\n\n## What does this program print?\n```go\ngadgets := [3]string{\"Confused Drone\", \"Broken Phone\"}\ngears   := gadgets\n\ngears[2] = \"Shiny Mouse\"\n\nfmt.Printf(\"%q\\n\", gadgets)\n```\n1. [\"Confused Drone\" \"Broken Phone\" \"Shiny Mouse\"]\n2. [\"Confused Drone\" \"Broken Phone\" \"\"] *CORRECT*\n3. [\"\" \"\" \"Shiny Mouse\"]\n4. [\"\" \"\" \"\"]\n\n> **2:** Yes! When you assign an array, Go creates a copy of the original array. So, gadgets and gears arrays are not connected. Changing one of them won't effect the other one.\n>\n\n\n## What's the type of the digits array?\n```go\ndigits := [...][5]string{\n\t{\n\t\t\"## \",\n\t\t\" # \",\n\t\t\" # \",\n\t\t\" # \",\n\t\t\"###\",\n\t},\n\t[5]string{\n\t\t\"###\",\n\t\t\"  #\",\n\t\t\"###\",\n\t\t\"  #\",\n\t\t\"###\",\n\t},\n}\n```\n1. [...][5]string\n2. [2][2]string\n3. [2][5]string *CORRECT*\n4. [5][5]string\n\n> **3:** Awesome! There are two inner arrays, so the outer array's length becomes 2. Also note that, `[5]string` in front of the second element is unnecessary.\n>\n\n\n## What does this program print?\n```go\nrates := [...]float64{\n    5: 1.5,\n    2.5,\n    0: 0.5,\n}\n\nfmt.Printf(\"%#v\\n\", rates)\n```\n1. [7]float64{0.5, 0, 0, 0, 0, 1.5, 2.5} *CORRECT*\n2. [7]float64{1.5, 2.5, 0.5, 0, 0, 0, 0}\n3. [3]float64{1.5, 2.5, 0.5}\n4. [3]float64{0.5, 2.5, 1.5}\n\n> **1:** That's right! For the explanation check out the example in the course repository here: https://github.com/inancgumus/learngo/tree/master/14-arrays/11-keyed-elements/06-keyed-and-unkeyed\n>\n\n\n\n## Are these arrays equal?\n```go\ntype three [3]int\n\nnums  := [3]int{1, 2, 3}\nnums2 := three{1, 2, 3}\n\nfmt.Println(nums == nums2)\n```\n**Note:** _To solve this question you need to watch the comparison and unnamed types lectures._\n1. Yes, because they have identical underlying types and elements *CORRECT*\n2. No, because their types are different\n3. No, because their length is different\n\n> **1:** Yes! They both have the same underlying types: [3]int\n>\n\n\n## Are these array variables equal?\n```go\ntype (\n    threeA [3]int\n    threeB [3]int\n)\n\nnums  := threeA{1, 2, 3}\nnums2 := threeA(threeB{1, 2, 3})\n\nfmt.Println(nums == nums2)\n```\n**Note:** _To solve this question you need to the watch comparison and unnamed types lectures._\n1. Yes, because they have identical underlying types and elements *CORRECT*\n2. No, because their types are different\n3. No, because their length is different\n\n> **1:** Yes! Actually, arrays have different types, so normally they're not comparable. However, when you convert `threeB{1, 2, 3}` array to `threeA` type, they become comparable.\n>"
  },
  {
    "path": "14-arrays/questions/README.md",
    "content": "# Array Quizzes\n\n* [Array Basics](1-array-basics.md)\n* [Arrays](2-arrays.md)"
  },
  {
    "path": "15-project-retro-led-clock/01-printing-the-digits/README.md",
    "content": "# GOAL 1: Printing the Digits\n\n## Challenge Steps\n\n1. Define a new placeholder type\n\n2. Create the digits from \"zero\" to \"nine\"\n\n      You can use these characters for the clock:\n\n      ```\n      Digit character       : █\n      Separator character   : ░\n      ```\n\n1. Put them into the \"digits\" array\n\n2. Print the digits side-by-side\n\n     1. Loop for all the lines in a digit\n\n     2. Print each digit line by line\n\n     3. Don't forget printing a space after each digit\n\n     4. Don't forget printing a newline after each line\n\n     EXAMPLE: Let's say you want to print 10.\n\n```\n      ██   ███ <--- Print a new line after printing a single line from\n       █   █ █     all the digits.\n       █   █ █\n       █   █ █\n      ███  ███\n         ^^\n         ||\n         ++----> Add space between the digits\n```\n\n## Solution\n\nYou can find the solution in the solution folder.\n"
  },
  {
    "path": "15-project-retro-led-clock/01-printing-the-digits/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/01-printing-the-digits/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// for keeping things easy to read and type-safe\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\t// This array's type is \"like\": [10][5]string\n\t//\n\t// However:\n\t// + \"placeholder\" is not equal to [5]string in type-wise.\n\t// + Because: \"placeholder\" is a defined type, which is different\n\t//   from [5]string type.\n\t// + [5]string is an unnamed type.\n\t// + placeholder is a named type.\n\t// + The underlying type of [5]string and placeholder is the same:\n\t//     [5]string\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\t// Explanation: digits[0]\n\t// + Each element of clock has the same length.\n\t// + So: Getting the length of only one element is OK.\n\t// + This could be: \"zero\" or \"one\" and so on... Instead of: digits[0]\n\t//\n\t// The range clause below is ~equal to the following code:\n\t// line := 0; line < 5; line++\n\tfor line := range digits[0] {\n\t\t// Print a line for each placeholder in digits\n\t\tfor digit := range digits {\n\t\t\tfmt.Print(digits[digit][line], \"  \")\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/02-printing-the-clock/README.md",
    "content": "# GOAL 2: Printing the Clock\n\n## Notes\n\n* Note main.go file contains the solution of the previous step.\n* \"solution\" folder contains the solution for this step.\n\n## Challenge Steps\n\n1. Get the current time\n\n2. Get the current hour, minute and second from the current time\n\n3. Create the clock array by getting the digits from the digits array\n\n4. Print the clock by using the clock array\n\n5. Create a separator array (it's also a placeholder type)\n\n6. Add the separators into the correct positions of the clock array"
  },
  {
    "path": "15-project-retro-led-clock/02-printing-the-clock/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\tfor line := range digits[0] {\n\t\tfor digit := range digits {\n\t\t\tfmt.Print(digits[digit][line], \"  \")\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/02-printing-the-clock/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tcolon := placeholder{\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t}\n\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\tnow := time.Now()\n\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\tfmt.Printf(\"hour: %d, min: %d, sec: %d\\n\", hour, min, sec)\n\n\t// [8][5]string\n\tclock := [...]placeholder{\n\t\t// extract the digits: 17 becomes, 1 and 7 respectively\n\t\tdigits[hour/10], digits[hour%10],\n\t\tcolon,\n\t\tdigits[min/10], digits[min%10],\n\t\tcolon,\n\t\tdigits[sec/10], digits[sec%10],\n\t}\n\n\tfor line := range clock[0] {\n\t\tfor digit := range clock {\n\t\t\tfmt.Print(clock[digit][line], \"  \")\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/03-animating-the-clock/README.md",
    "content": "# GOAL 3: Animate the Clock\n\n## Notes\n\n* Note main.go file contains the solution of the previous step.\n* \"solution\" folder contains the solution for this step.\n\n## Challenge Steps\n\n1. Create an infinite loop to update the clock\n\n2. Update the clock every second\n\n   [time.Sleep(time.Second)](https://golang.org/pkg/time/#Sleep) will stop the world for 1 second\n\n3. Clear the screen before the infinite loop\n\n   1. Get my library for clearing the screen:\n\n        `go get -u github.com/inancgumus/screen`\n\n   2. Then, import it and call it in your code like this:\n\n        `screen.Clear()`\n\n   3. If you're using Go Playground instead, do this:\n\n        `fmt.Println(\"\\f\")`\n\n 4. Move the cursor to the top-left corner of the screen, before each step\n    of the infinite loop\n\n    * Call this in your code like this:\n\n        `screen.MoveTopLeft()`\n\n    * If you're using Go Playground instead, do this again:\n\n        `fmt.Println(\"\\f\")`\n\n---\n\n## SIDE NOTE FOR THE CURIOUS\n\nIf you're curious about how my screen clearing package works, read on.\n\n**On bash**, it uses special commands, if you open the code, you can see that.\n\n* `\\033` is a special control code:\n* `[2J` clears the screen and the cursor\n* `[H`  moves the cursor to 0, 0 screen position\n* [See for more information](https://bluesock.org/~willkg/dev/ansi.html).\n\n**On Windows**, I'm directly calling the Windows API functions. This is way advanced at this stage of the course, however, I'll probably explain it afterward.\n\nSo, my package automatically adjusts itself depending on where it is compiled. On Windows, it uses the special Windows API calls; On other operating systems, it uses the bash special commands that I've explained above.\n"
  },
  {
    "path": "15-project-retro-led-clock/03-animating-the-clock/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tcolon := placeholder{\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t}\n\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\tnow := time.Now()\n\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\tfmt.Printf(\"hour: %d, min: %d, sec: %d\\n\", hour, min, sec)\n\n\t// [8][5]string\n\tclock := [...]placeholder{\n\t\t// extract the digits: 17 becomes, 1 and 7 respectively\n\t\tdigits[hour/10], digits[hour%10],\n\t\tcolon,\n\t\tdigits[min/10], digits[min%10],\n\t\tcolon,\n\t\tdigits[sec/10], digits[sec%10],\n\t}\n\n\tfor line := range clock[0] {\n\t\tfor digit := range clock {\n\t\t\tfmt.Print(clock[digit][line], \"  \")\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/03-animating-the-clock/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tcolon := placeholder{\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t}\n\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\t// For Go Playground, do not use this.\n\tscreen.Clear()\n\n\t// Go Playground will not run an infinite loop.\n\t// So, instead, you may loop for 1000 times:\n\t// for i := 0; i < 1000; i++ {\n\tfor {\n\t\t// For Go Playground, use this instead:\n\t\t// fmt.Print(\"\\f\")\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor digit := range clock {\n\t\t\t\tfmt.Print(clock[digit][line], \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\t// pause for 1 second\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/04-blinking-the-separators/README.md",
    "content": "# GOAL 4: Blinking the Separators\n\n## Notes\n\n* Note main.go file contains the solution of the previous step.\n* \"solution\" folder contains the solution for this step.\n\n## Challenge Steps\n\nSeparators should be visible once in every two seconds.\n\n### Example:\n\n* 1st second: They're invisible\n* 2nd second: visible\n* 3rd second: invisible\n* 4th second: visible\n\n### HINT\n\nThere are two ways to do this:\n\n1. Manipulating the clock array directly (by adding/removing the separators)\n\n2. Or: Deciding what placeholders to print when printing the clock"
  },
  {
    "path": "15-project-retro-led-clock/04-blinking-the-separators/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tcolon := placeholder{\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t}\n\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor digit := range clock {\n\t\t\t\tfmt.Print(clock[digit][line], \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/04-blinking-the-separators/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tcolon := placeholder{\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t}\n\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor index, digit := range clock {\n\t\t\t\t// colon blink\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/05-full-annotated-solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\t// for keeping things easy to read and type-safe\n\ttype placeholder [5]string\n\n\t// put the digits (placeholders) into variables\n\t// using the placeholder array type above\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tcolon := placeholder{\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t}\n\n\t// This array's type is \"like\": [10][5]string\n\t//\n\t// However:\n\t// + \"placeholder\" is not equal to [5]string in type-wise.\n\t// + Because: \"placeholder\" is a defined type, which is different\n\t//   from [5]string type.\n\t// + [5]string is an unnamed type.\n\t// + placeholder is a named type.\n\t// + The underlying type of [5]string and placeholder is the same:\n\t//     [5]string\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\t// For Go Playground, do not use this.\n\tscreen.Clear()\n\n\t// Go Playground will not run an infinite loop.\n\t// Loop for example 1000 times instead, like this:\n\t//   for i := 0; i < 1000; i++ { ... }\n\tfor {\n\t\t// For Go Playground, use this instead:\n\t\t// fmt.Print(\"\\f\")\n\t\tscreen.MoveTopLeft()\n\n\t\t// get the current hour, minute and second\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\t// extract the digits: 17 becomes, 1 and 7 respectively\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\t// Explanation: clock[0]\n\t\t// + Each element of clock has the same length.\n\t\t// + So: Getting the length of only one element is OK.\n\t\t// + This could be: \"zero\" or \"one\" and so on... Instead of: digits[0]\n\t\t//\n\t\t// The range clause below is ~equal to the following code:\n\t\t//   line := 0; line < len(clock[0]); line++\n\t\tfor line := range clock[0] {\n\t\t\t// Print a line for each placeholder in clock\n\t\t\tfor index, digit := range clock {\n\t\t\t\t// Colon blink on every two seconds.\n\t\t\t\t// + On each sec divisible by two, prints an empty line\n\t\t\t\t// + Otherwise: prints the current pixel\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\t// Print the next line and,\n\t\t\t\t// give it enough space for the next placeholder\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\n\t\t\t// After each line of a placeholder, print a newline\n\t\t\tfmt.Println()\n\t\t}\n\n\t\t// pause for 1 second\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/README.md",
    "content": "## NOTES\n- I've explained the challenges and the solutions step by step\n- So, if you get stuck, you can check out the next step without having to look at the entire final solution\n- You can find the explanations and solutions by clicking on the header links below \n\n## GET SOCIAL\n- Click the link below to tweet your solution when you complete: http://bit.ly/GOTWEET-CLOCK\n- Discuss your solution with other gophers here: http://bit.ly/LEARNGOSLACK\n\n---\n\n## GOALS:\n\n### 👉 [STEP #1 — Print the Digits](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/01-printing-the-digits/)\n- [ ] Define a new placeholder type\n- [ ] Create the digit arrays from 0 to 9\n- [ ] Put them into the \"digits\" array\n- [ ] Print them side-by-side\n\n### 👉 [STEP #2 — Print the Clock](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/02-printing-the-clock/)\n- [ ] Get the current time\n- [ ] Create the clock array\n- [ ] Print the clock\n- [ ] Add the separators\n\n### 👉 [STEP #3 — Animate the Clock](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/03-animating-the-clock/)\n- [ ] Create an infinite loop to update the clock\n- [ ] Update the clock every second\n- [ ] Clear the screen before the infinite loop\n- [ ] Move the cursor to the top-left corner of the screen before each\n      step of the infinite loop\n\n### 👉 [BONUS: STEP #4 — Blink the Clock](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/04-blinking-the-separators/)\n- [ ] Blink the separators\n\n### 👉 [FULL ANNOTATED SOLUTION](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/05-full-annotated-solution/main.go)"
  },
  {
    "path": "15-project-retro-led-clock/exercises/01-refactor/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor\n//\n//  Goal is refactoring the clock project by moving some of its parts to\n//  a new file in the same package.\n//\n//  1. Create a new file: placeholders.go\n//  2. Move the placeholder type to placeholder.go\n//  3. Move all the placeholders (zero to nine and the colon) to placeholder.go\n//  4. Move the digits array to placeholders.go\n//\n// HINT\n//  + placeholders.go file should belong to main package as well\n//\n//    To remember how to do so: Rewatch the \"PART I — Packages, Scopes and Importing\"\n//    section.\n//\n//  + Short declaration won't work in the package scope.\n//    Remember why by watching: \"Short Declaration: Package Scope\" lecture\n//\n//  + If you receive the following error and you don't know what to do watch:\n//    \"Packages - Learn how to run multiple files\" lecture.\n//\n//    # command-line-arguments\n//    undefined: placeholder\n//    undefined: colon\n//\n// EXPECTED OUTPUT\n//  The same output before the refactoring.\n// ---------------------------------------------------------\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\ttype placeholder [5]string\n\n\tzero := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tone := placeholder{\n\t\t\"██ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"███\",\n\t}\n\n\ttwo := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t}\n\n\tthree := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tfour := placeholder{\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\tfive := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tsix := placeholder{\n\t\t\"███\",\n\t\t\"█  \",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tseven := placeholder{\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t\t\"  █\",\n\t}\n\n\teight := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t}\n\n\tnine := placeholder{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"  █\",\n\t\t\"███\",\n\t}\n\n\tcolon := placeholder{\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t\t\" ░ \",\n\t\t\"   \",\n\t}\n\n\tdigits := [...]placeholder{\n\t\tzero, one, two, three, four, five, six, seven, eight, nine,\n\t}\n\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor index, digit := range clock {\n\t\t\t\t// colon blink\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/01-refactor/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor index, digit := range clock {\n\t\t\t\t// colon blink\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/01-refactor/solution/placeholders.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype placeholder [5]string\n\nvar zero = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar one = placeholder{\n\t\"██ \",\n\t\" █ \",\n\t\" █ \",\n\t\" █ \",\n\t\"███\",\n}\n\nvar two = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n}\n\nvar three = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar four = placeholder{\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar five = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar six = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar seven = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar eight = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar nine = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar colon = placeholder{\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n}\n\nvar digits = [...]placeholder{\n\tzero, one, two, three, four, five, six, seven, eight, nine,\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/02-alarm/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Set an Alarm\n//\n//  Goal is printing \" ALARM! \" every 10 seconds.\n//\n// EXPECTED OUTPUT\n//\n//     ██   ███       ███  ██        ███  ███\n//      █     █   ░     █   █    ░     █  █ █\n//      █   ███       ███   █        ███  ███\n//      █   █     ░     █   █    ░     █    █\n//     ███  ███       ███  ███       ███  ███\n//\n//          ███  █    ███  ██   █ █   █\n//          █ █  █    █ █  █ █  ███   █\n//          ███  █    ███  ██   █ █   █\n//          █ █  █    █ █  █ █  █ █\n//          █ █  ███  █ █  █ █  █ █   █\n//\n//     ██   ███       ███  ██        █ █  ██\n//      █     █   ░     █   █    ░   █ █   █\n//      █   ███       ███   █        ███   █\n//      █   █     ░     █   █    ░     █   █\n//     ███  ███       ███  ███         █  ███\n//\n// HINTS\n//\n//  <<< BEWARE THE SPOILER! >>>\n//\n//  I recommend you to first solve the exercise yourself before reading the\n//  following hint.\n//\n//\n//  + You can create a new array named alarm with the same length of the\n//    clocks array, so you can copy the alarm array to the clocks array\n//    every 10 seconds.\n//\n// ---------------------------------------------------------\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor index, digit := range clock {\n\t\t\t\t// colon blink\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/02-alarm/placeholders.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype placeholder [5]string\n\nvar zero = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar one = placeholder{\n\t\"██ \",\n\t\" █ \",\n\t\" █ \",\n\t\" █ \",\n\t\"███\",\n}\n\nvar two = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n}\n\nvar three = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar four = placeholder{\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar five = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar six = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar seven = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar eight = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar nine = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar colon = placeholder{\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n}\n\nvar digits = [...]placeholder{\n\tzero, one, two, three, four, five, six, seven, eight, nine,\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/02-alarm/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\talarmed := sec%10 == 0\n\n\t\tfor line := range clock[0] {\n\t\t\tif alarmed {\n\t\t\t\tclock = alarm\n\t\t\t}\n\n\t\t\tfor index, digit := range clock {\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/02-alarm/solution/placeholders.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype placeholder [5]string\n\nvar zero = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar one = placeholder{\n\t\"██ \",\n\t\" █ \",\n\t\" █ \",\n\t\" █ \",\n\t\"███\",\n}\n\nvar two = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n}\n\nvar three = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar four = placeholder{\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar five = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar six = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar seven = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar eight = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar nine = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar colon = placeholder{\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n}\n\nvar alarm = [...]placeholder{\n\t{\n\t\t\"   \",\n\t\t\"   \",\n\t\t\"   \",\n\t\t\"   \",\n\t\t\"   \",\n\t},\n\t{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t},\n\t{\n\t\t\"█  \",\n\t\t\"█  \",\n\t\t\"█  \",\n\t\t\"█  \",\n\t\t\"███\",\n\t},\n\t{\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t},\n\t{\n\t\t\"██ \",\n\t\t\"█ █\",\n\t\t\"██ \",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t},\n\t{\n\t\t\"█ █\",\n\t\t\"███\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t\t\"█ █\",\n\t},\n\t{\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\" █ \",\n\t\t\"   \",\n\t\t\" █ \",\n\t},\n\t{\n\t\t\"   \",\n\t\t\"   \",\n\t\t\"   \",\n\t\t\"   \",\n\t\t\"   \",\n\t},\n}\n\nvar digits = [...]placeholder{\n\tzero, one, two, three, four, five, six, seven, eight, nine,\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/03-split-second/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Add Split Seconds\n//\n//  Your goal is adding the split second to the clock. A split second is\n//  1/10th of a second.\n//\n//  1. Find the current split second\n//  2. Add dot character to the clock (as in the expected output)\n//  3. Add the split second digit to the clock\n//  4. Blink the dot every two seconds (just like the separators)\n//  5. Update the clock every 1/10th of a second, instead of every second.\n//     (Update the clock every 100 millliseconds)\n//\n// HINTS\n//   + You can find the split second using Nanosecond method of the Time type.\n//     https://golang.org/pkg/time/#Time.Nanosecond\n//\n//   + A split second is the first digit of the Nanosecond.\n//\n//   + Remember: time.Second is an integer constant, so it can be divided\n//               with a number.\n//\n//     https://golang.org/pkg/time/#Time.Second\n//\n// EXPECTED OUTPUT\n//     Note that, clock is updated every split second instead of a second.\n//\n//     Separators are displayed (second is an odd number):\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █       █ █\n//      █    █        ███   █         █     █       █ █\n//      █    █    ░     █   █    ░    █     █       █ █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     ██   ██        ███  ██        ██   ███       ██\n//      █    █    ░   █     █    ░    █     █        █\n//      █    █        ███   █         █     █        █\n//      █    █    ░     █   █    ░    █     █        █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █         █\n//      █    █        ███   █         █     █       ███\n//      █    █    ░     █   █    ░    █     █       █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █         █\n//      █    █        ███   █         █     █       ███\n//      █    █    ░     █   █    ░    █     █         █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     ██   ██        ███  ██        ██   ███       █ █\n//      █    █    ░   █     █    ░    █     █       █ █\n//      █    █        ███   █         █     █       ███\n//      █    █    ░     █   █    ░    █     █         █\n//     ███  ███       ███  ███       ███    █   ░     █\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █       █\n//      █    █        ███   █         █     █       ███\n//      █    █    ░     █   █    ░    █     █         █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █       █\n//      █    █        ███   █         █     █       ███\n//      █    █    ░     █   █    ░    █     █       █ █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █         █\n//      █    █        ███   █         █     █         █\n//      █    █    ░     █   █    ░    █     █         █\n//     ███  ███       ███  ███       ███    █   ░     █\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █       █ █\n//      █    █        ███   █         █     █       ███\n//      █    █    ░     █   █    ░    █     █       █ █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █    ░   █     █    ░    █     █       █ █\n//      █    █        ███   █         █     █       ███\n//      █    █    ░     █   █    ░    █     █         █\n//     ███  ███       ███  ███       ███    █   ░   ███\n//\n//     Separators are not displayed (second is an even number):\n//\n//     ██   ██        ███  ██        ██   ███       ███\n//      █    █        █     █         █   █ █       █ █\n//      █    █        ███   █         █   ███       █ █\n//      █    █          █   █         █   █ █       █ █\n//     ███  ███       ███  ███       ███  ███       ███\n//\n// ---------------------------------------------------------\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor index, digit := range clock {\n\t\t\t\t// colon blink\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/03-split-second/placeholders.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype placeholder [5]string\n\nvar zero = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar one = placeholder{\n\t\"██ \",\n\t\" █ \",\n\t\" █ \",\n\t\" █ \",\n\t\"███\",\n}\n\nvar two = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n}\n\nvar three = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar four = placeholder{\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar five = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar six = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar seven = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar eight = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar nine = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar colon = placeholder{\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n}\n\nvar digits = [...]placeholder{\n\tzero, one, two, three, four, five, six, seven, eight, nine,\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/03-split-second/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\t\tssec := now.Nanosecond() / 1e8\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t\tdot,\n\t\t\tdigits[ssec],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor index, digit := range clock {\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif (digit == colon || digit == dot) && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\tconst splitSecond = time.Second / 10\n\t\ttime.Sleep(splitSecond)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/03-split-second/solution/placeholders.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype placeholder [5]string\n\nvar zero = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar one = placeholder{\n\t\"██ \",\n\t\" █ \",\n\t\" █ \",\n\t\" █ \",\n\t\"███\",\n}\n\nvar two = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n}\n\nvar three = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar four = placeholder{\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar five = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar six = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar seven = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar eight = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar nine = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar colon = placeholder{\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n}\n\nvar dot = placeholder{\n\t\"   \",\n\t\"   \",\n\t\"   \",\n\t\"   \",\n\t\" ░ \",\n}\n\nvar digits = [...]placeholder{\n\tzero, one, two, three, four, five, six, seven, eight, nine,\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/04-ticker/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Ticker: Slide the Clock\n//\n//  Your goal is slide the placeholders every second.\n//  Please run the solution to see it in action.\n//\n//\n//  THIS IS A HARD EXERCISE:\n//  + It will take you days but it will be worth it.\n//  + For experienced developers, this can take an hour or so.\n//\n//\n//  1. You need to determine the starting and the ending digits to create\n//     the sliding effect.\n//\n//\n//  2. Each second, start from the next placeholder, skip the previous one.\n//     This means: Only draw the next placeholders.\n//\n//     Like this:\n//\n//     12:40:31\n//     2:40:31\n//     40:31\n//     0:31\n//     :31\n//     31\n//     1\n//\n//\n//  3. After the last placeholder is displayed, fill the lines for the missing\n//     placeholders, and then start from the first placeholder. Draw it to the\n//     right part of the screen.\n//\n//     Like this:\n//\n//     12:40:31\n//     2:40:31\n//     40:31\n//     0:31\n//     :31\n//     31\n//     1\n//            1\n//           12\n//          12:\n//         12:4\n//        12:40\n//       12:40:\n//      12:40:3\n//     12:40:31\n//\n//     As you can see, you need to draw the clock from the right part of the\n//     screen, beginning from the first placeholder.\n//\n//\n// HINTS\n//   + You would need to clear the screen inside the loop instead of once.\n//     Otherwise the previous placeholders will be left on the screen.\n//\n//\n// EXPECTED OUTPUT\n//   Please run the solution to see it in action. Do not look at the source-code\n//   though.\n// ---------------------------------------------------------\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tscreen.Clear()\n\n\tfor {\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tfor index, digit := range clock {\n\t\t\t\tnext := clock[index][line]\n\t\t\t\tif digit == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/04-ticker/placeholders.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype placeholder [5]string\n\nvar zero = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar one = placeholder{\n\t\"██ \",\n\t\" █ \",\n\t\" █ \",\n\t\" █ \",\n\t\"███\",\n}\n\nvar two = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n}\n\nvar three = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar four = placeholder{\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar five = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar six = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar seven = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar eight = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar nine = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar colon = placeholder{\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n}\n\nvar digits = [...]placeholder{\n\tzero, one, two, three, four, five, six, seven, eight, nine,\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/04-ticker/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tfor shift := 0; ; shift++ {\n\t\t// we need to clear the screen here.\n\t\t// or the previous character will be left on the screen\n\t\t//\n\t\t// alternative: you can fill the rest of the missing placeholders\n\t\t//              with empty lines\n\t\tscreen.Clear()\n\t\tscreen.MoveTopLeft()\n\n\t\tnow := time.Now()\n\t\thour, min, sec := now.Hour(), now.Minute(), now.Second()\n\n\t\tclock := [...]placeholder{\n\t\t\tdigits[hour/10], digits[hour%10],\n\t\t\tcolon,\n\t\t\tdigits[min/10], digits[min%10],\n\t\t\tcolon,\n\t\t\tdigits[sec/10], digits[sec%10],\n\t\t}\n\n\t\tfor line := range clock[0] {\n\t\t\tl := len(clock)\n\n\t\t\t// this sets the beginning and the ending placeholder positions (indexes).\n\t\t\t// shift%l prevents the indexing error.\n\t\t\ts, e := shift%l, l\n\n\t\t\t// to slide the placeholders from the right part of the screen.\n\t\t\t//\n\t\t\t// here, we assume that as if the clock's length is double of its length.\n\t\t\t// this makes things easy to manage: that's why: l*2 is there.\n\t\t\t//\n\t\t\t// shift is always increasing, for it's to go beyond the clock's length,\n\t\t\t// it should be equal or greater than l*2, right (after the remainder of course)?\n\t\t\t//\n\t\t\t// so, if the clock goes beyond its length; this code detects that,\n\t\t\t// and resets the starting position to the first placeholder's index,\n\t\t\t// and it keeps doing so until the clock is fully displayed again.\n\t\t\tif shift%(l*2) >= l {\n\t\t\t\ts, e = 0, s\n\t\t\t}\n\n\t\t\t// print empty lines for the missing place holders.\n\t\t\t// this creates the effect of moving placeholders from right to left.\n\t\t\t//\n\t\t\t// l-e can only be non-zero when the above if statement runs.\n\t\t\t// otherwise, l-e is always zero, because l == e.\n\t\t\t//\n\t\t\t// this is one of the other benefits of assuming the length of the\n\t\t\t// clock as the double of its length. otherwise, l-e would always be 0.\n\t\t\tfor j := 0; j < l-e; j++ {\n\t\t\t\tfmt.Print(\"     \")\n\t\t\t}\n\n\t\t\t// draw the digits starting from 's' to 'e'\n\t\t\tfor i := s; i < e; i++ {\n\t\t\t\tnext := clock[i][line]\n\t\t\t\tif clock[i] == colon && sec%2 == 0 {\n\t\t\t\t\tnext = \"   \"\n\t\t\t\t}\n\n\t\t\t\tfmt.Print(next, \"  \")\n\t\t\t}\n\t\t\tfmt.Println()\n\t\t}\n\n\t\ttime.Sleep(time.Second)\n\t}\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/04-ticker/solution/placeholders.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype placeholder [5]string\n\nvar zero = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar one = placeholder{\n\t\"██ \",\n\t\" █ \",\n\t\" █ \",\n\t\" █ \",\n\t\"███\",\n}\n\nvar two = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n}\n\nvar three = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar four = placeholder{\n\t\"█ █\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar five = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar six = placeholder{\n\t\"███\",\n\t\"█  \",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar seven = placeholder{\n\t\"███\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n\t\"  █\",\n}\n\nvar eight = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n}\n\nvar nine = placeholder{\n\t\"███\",\n\t\"█ █\",\n\t\"███\",\n\t\"  █\",\n\t\"███\",\n}\n\nvar colon = placeholder{\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n\t\" ░ \",\n\t\"   \",\n}\n\nvar digits = [...]placeholder{\n\tzero, one, two, three, four, five, six, seven, eight, nine,\n}\n"
  },
  {
    "path": "15-project-retro-led-clock/exercises/README.md",
    "content": "# Exercises\n\nThese exercises will reinforce your knowledge of manipulating arrays. You will prove yourself that you can write easy to maintain Go programs.\n\n1. **[Refactor](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/01-refactor)**\n\n  In this exercise, you will refactor the project to multiple files by moving\n  all the placeholders. This will make the project easy to maintain down the road.\n\n2. **[Set an Alarm](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/02-alarm)**\n\n  You will print \" ALARM! \" every 10 seconds.\n\n3. **[Split Second](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/03-split-second)**\n\n  You will display the split second in the clock, you will need to update the\n  clock every 1/10th of a second instead of every second.\n\n4. **[Ticker](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/04-ticker)**\n\n  This is a HARD EXERCISE. You will slide the clock animation from right-to-left. After this exercise, you will truly feel that you've mastered everything you've learned so far.\n"
  },
  {
    "path": "16-slices/01-slices-vs-arrays/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t{\n\t\t// its length is part of its type\n\t\tvar nums [5]int\n\t\tfmt.Printf(\"nums array: %#v\\n\", nums)\n\t}\n\n\t{\n\t\t// its length is not part of its type\n\t\tvar nums []int\n\t\tfmt.Printf(\"nums slice: %#v\\n\", nums)\n\n\t\tfmt.Printf(\"len(nums) : %d\\n\", len(nums))\n\n\t\t// won't work: the slice is nil.\n\t\t// fmt.Printf(\"nums[0]: %d\\n\", nums[0])\n\t\t// fmt.Printf(\"nums[1]: %d\\n\", nums[1])\n\t}\n}\n"
  },
  {
    "path": "16-slices/02-slices-vs-arrays/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar array [2]int\n\n\t// zero value of an array is zero-valued elements\n\tfmt.Printf(\"array       : %#v\\n\", array)\n\n\t// nope: arrays are fixed length\n\t// array[2] = 0\n\n\tvar slice []int\n\n\t// zero value of a slice is nil\n\tfmt.Println(\"slice == nil?\", slice == nil)\n\n\t// nope: they don't exist:\n\t// _ = slice[0]\n\t// _ = slice[1]\n\n\t// len function still works though\n\tfmt.Println(\"len(slice)  :\", len(slice))\n\n\t// array's length is part of its type\n\tfmt.Printf(\"array's type: %T\\n\", array)\n\n\t// whereas, slice's length isn't part of its type\n\tfmt.Printf(\"slice's type: %T\\n\", slice)\n}\n"
  },
  {
    "path": "16-slices/03-slices-vs-arrays-examples/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// STORY:\n// You want to list the books and games you have\n\nfunc main() {\n\tvar books [5]string\n\tbooks[0] = \"dracula\"\n\tbooks[1] = \"1984\"\n\tbooks[2] = \"island\"\n\n\tnewBooks := [5]string{\"ulysses\", \"fire\"}\n\tif books == newBooks {\n\t}\n\tbooks = newBooks\n\n\tgames := []string{\"pokemon\", \"sims\"}\n\tnewGames := []string{\"pacman\", \"doom\", \"pong\"}\n\tnewGames = games\n\tgames = nil\n\tgames = []string{}\n\n\tvar ok string\n\tfor i, game := range games {\n\t\tif game != newGames[i] {\n\t\t\tok = \"not \"\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif len(games) != len(newGames) {\n\t\tok = \"not \"\n\t}\n\n\tfmt.Printf(\"games and newGames are %sequal\\n\\n\", ok)\n\n\tfmt.Printf(\"books         : %#v\\n\", books)\n\tfmt.Printf(\"new books     : %#v\\n\", newBooks)\n\tfmt.Printf(\"games         : %T\\n\", games)\n\tfmt.Printf(\"new games     : %#v\\n\", newGames)\n\tfmt.Printf(\"games's length: %d\\n\", len(games))\n\tfmt.Printf(\"games's nil   : %t\\n\", games == nil)\n}\n"
  },
  {
    "path": "16-slices/04-slices-vs-arrays-unique-nums/01-with-arrays/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"time\"\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\tconst max = 5\n\tvar uniques [max]int\n\n\t// It's harder to make a program dynamic using arrays\n\t// max, _ := strconv.Atoi(os.Args[1])\n\t// var uniques [10]int\n\nloop:\n\tfor found := 0; found < max; {\n\t\tn := rand.Intn(max) + 1\n\t\tfmt.Print(n, \" \")\n\n\t\tfor _, u := range uniques {\n\t\t\tif u == n {\n\t\t\t\tcontinue loop\n\t\t\t}\n\t\t}\n\n\t\tuniques[found] = n\n\t\tfound++\n\t}\n\n\tfmt.Println(\"\\n\\nuniques:\", uniques)\n}\n"
  },
  {
    "path": "16-slices/04-slices-vs-arrays-unique-nums/02-with-slices/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n\t\"time\"\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\tmax, _ := strconv.Atoi(os.Args[1])\n\n\t// declare an uninitialized nil slice\n\tvar uniques []int\n\nloop:\n\t// you can still use the len function on a nil slice\n\tfor len(uniques) < max {\n\t\tn := rand.Intn(max) + 1\n\t\tfmt.Print(n, \" \")\n\n\t\tfor _, u := range uniques {\n\t\t\tif u == n {\n\t\t\t\tcontinue loop\n\t\t\t}\n\t\t}\n\n\t\t// append function can add new elements to a slice\n\t\tuniques = append(uniques, n)\n\n\t\t// a slice doesn't contain any elements right from the start\n\t\t// uniques[found] = n\n\t\t// found++\n\t}\n\n\tfmt.Println(\"\\n\\nuniques:\", uniques)\n\tfmt.Println(\"\\nlength of uniques:\", len(uniques))\n\n\tsort.Ints(uniques)\n\tfmt.Println(\"\\nsorted:\", uniques)\n\n\tnums := [5]int{5, 4, 3, 2, 1}\n\tsort.Ints(nums[:])\n\tfmt.Println(\"\\nnums:\", nums)\n}\n"
  },
  {
    "path": "16-slices/05-append/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\tnums := []int{1, 2, 3}\n\ts.Show(\"nums\", nums)\n\n\t_ = append(nums, 4)\n\ts.Show(\"nums\", nums)\n\n\tnums = append(nums, 4)\n\ts.Show(\"nums\", nums)\n\n\tnums = append(nums, 9)\n\ts.Show(\"nums\", nums)\n\n\tnums = append(nums, 4)\n\ts.Show(\"nums\", nums)\n\n\t// or:\n\t// nums = append(nums, 4, 9)\n\t// s.Show(\"nums\", nums)\n\n\tnums = []int{1, 2, 3}\n\ttens := []int{12, 13}\n\n\tnums = append(nums, tens...)\n\ts.Show(\"nums\", nums)\n}\n"
  },
  {
    "path": "16-slices/05-append/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\tvar todo []string\n\n\ttodo = append(todo, \"sing\")\n\n\t// you can only append elements with the same element type of the slice\n\t// todo = append(todo, 42)\n\n\ttodo = append(todo, \"run\")\n\n\t// append is a variadic function, so you can append multiple elements\n\ttodo = append(todo, \"code\", \"play\")\n\n\t// you can also append a slice to another slice using ellipsis: ...\n\ttomorrow := []string{\"see mom\", \"learn go\"}\n\ttodo = append(todo, tomorrow...)\n\t// todo = append(todo, \"see mom\", \"learn go\")\n\n\ts.Show(\"todo\", todo)\n}\n"
  },
  {
    "path": "16-slices/06-slice-expressions/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\tmsg := []byte{'h', 'e', 'l', 'l', 'o'}\n\ts.Show(\"msg\", msg)\n\n\ts.Show(\"msg[0:1]\", msg[0:1])\n\ts.Show(\"msg[0:2]\", msg[0:2])\n\ts.Show(\"msg[0:3]\", msg[0:3])\n\ts.Show(\"msg[0:4]\", msg[0:4])\n\ts.Show(\"msg[0:5]\", msg[0:5])\n\n\t// default indexes\n\ts.Show(\"msg[0:]\", msg[0:])\n\ts.Show(\"msg[:5]\", msg[:5])\n\ts.Show(\"msg[:]\", msg[:])\n\n\t// error: beyond\n\t// s.Show(\"msg\", msg)[:6]\n\n\ts.Show(\"msg[1:4]\", msg[1:4])\n\n\ts.Show(\"msg[1:5]\", msg[1:5])\n\ts.Show(\"msg[1:]\", msg[1:])\n\n\ts.Show(\"append(msg)\", append(msg[:4], '!'))\n}\n"
  },
  {
    "path": "16-slices/06-slice-expressions/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\t// think of this as search results of a search engine.\n\t// it could have been fetched from a database\n\titems := []string{\n\t\t\"pacman\", \"mario\", \"tetris\", \"doom\",\n\t\t\"galaga\", \"frogger\", \"asteroids\", \"simcity\",\n\t\t\"metroid\", \"defender\", \"rayman\", \"tempest\",\n\t\t\"ultima\",\n\t}\n\n\ts.MaxPerLine = 4\n\ts.Show(\"All items\", items)\n\n\ttop3 := items[:3]\n\ts.Show(\"Top 3 items\", top3)\n\n\tl := len(items)\n\n\t// you can use variables in a slice expression\n\tlast4 := items[l-4:]\n\ts.Show(\"Last 4 items\", last4)\n\n\t// reslicing: slicing another sliced slice\n\tmid := last4[1:3]\n\ts.Show(\"Last4[1:3]\", mid)\n\n\t// the same elements can be in different indexes\n\t// fmt.Println(items[9], last4[0])\n\n\t// slicing returns a slice with the same type of the sliced slice\n\tfmt.Printf(\"slicing : %T %[1]q\\n\", items[2:3])\n\n\t// indexing returns a single element with the type of the indexed slice's element type\n\tfmt.Printf(\"indexing: %T %[1]q\\n\", items[2])\n}\n"
  },
  {
    "path": "16-slices/07-slice-expressions-pagination/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\t// think of this as search results of a search engine.\n\t// it could have been fetched from a database\n\titems := []string{\n\t\t\"pacman\", \"mario\", \"tetris\", \"doom\",\n\t\t\"galaga\", \"frogger\", \"asteroids\", \"simcity\",\n\t\t\"metroid\", \"defender\", \"rayman\", \"tempest\",\n\t\t\"ultima\",\n\t}\n\n\t// s.Show(\"0:4\", items[0:4])\n\t// s.Show(\"4:8\", items[4:8])\n\t// s.Show(\"8:12\", items[8:12])\n\t// s.Show(\"12:13\", items[12:13])\n\t// s.Show(\"12:14\", items[12:14]) // error\n\n\tl := len(items)\n\n\tconst pageSize = 4\n\n\tfor from := 0; from < l; from += pageSize {\n\t\tto := from + pageSize\n\t\tif to > l {\n\t\t\tto = l\n\t\t}\n\n\t\t// fmt.Printf(\"%d:%d\\n\", from, to)\n\n\t\tcurrentPage := items[from:to]\n\n\t\thead := fmt.Sprintf(\"Page #%d\", (from/pageSize)+1)\n\t\ts.Show(head, currentPage)\n\t}\n}\n"
  },
  {
    "path": "16-slices/08-slice-internals-1-backing-array/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport s \"github.com/inancgumus/prettyslice\"\n\nfunc main() {\n\t// ages, first and last2 have the same backing arrays\n\tages := []int{35, 15, 25}\n\tfirst := ages[0:1]\n\tlast2 := ages[1:3]\n\n\tages[0] = 55\n\tages[1] = 10\n\tages[2] = 20\n\n\t// grades and ages have separate backing arrays\n\tgrades := []int{70, 99}\n\tgrades[0] = 50\n\n\ts.Show(\"ages\", ages)\n\ts.Show(\"ages[0:1]\", first)\n\ts.Show(\"ages[1:3]\", last2)\n\ts.Show(\"grades\", grades)\n\n\t// let's create a new scope\n\t// 'cause I'm going to use variables with the same name\n\t{\n\t\t// ages and agesArray have the same backing arrays\n\t\tagesArray := [3]int{35, 15, 25}\n\t\tages := agesArray[0:3]\n\n\t\tages[0] = 100\n\t\tages[2] = 50\n\n\t\ts.Show(\"agesArray\", agesArray[:])\n\t\ts.Show(\"agesArray's ages\", ages)\n\t}\n}\n"
  },
  {
    "path": "16-slices/08-slice-internals-1-backing-array/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\t// #1: arrays and non-empty slice literals create an array.\n\t// For the arrays, it's explicit, but for the slices,\n\t// it's done implicitly, behind the scenes.\n\n\tgrades := [...]float64{40, 10, 20, 50, 60, 70} // #1\n\t// grades := []float64{40, 10, 20, 50, 60, 70} // #4\n\n\t// #5: let's break the connection\n\t// #6: comment-out\n\t// var newGrades []float64\n\t// newGrades = append(newGrades, grades...)\n\n\t// #6: shortcut: []float64(nil) is a nil float64 slice\n\t// newGrades := append([]float64(nil), grades...)\n\n\t// #2: cheap: slicing doesn't allocate new memory (array).\n\t// front := grades[:3]\n\n\t// front := newGrades[:3] // #5\n\n\t// #3: sort its first segment\n\t// sort.Float64s(front)\n\n\t// #7: new slices look at the same backing array\n\t// front, front2, front3, newGrades, they all have the same backing array\n\t// front2 := front[:3]\n\t// front3 := front\n\n\ts.PrintBacking = true       // #1\n\ts.MaxPerLine = 7            // #1\n\ts.Show(\"grades\", grades[:]) // #1\n\t// s.Show(\"newGrades\", newGrades) // #5\n\t// s.Show(\"front\", front)         // #2\n\t// s.Show(\"front2\", front2)       // #7\n\t// s.Show(\"front3\", front3)       // #7\n}\n"
  },
  {
    "path": "16-slices/09-slice-internals-2-slice-header/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\t//\n\t// each int element is 4 bytes (on 64-bit)\n\t//\n\t// let's say the ages point to 1000th.\n\t// ages[1:] will point to 1004th\n\t// ages[2:] will point to 1008th and so on.\n\t//\n\t// they all will be looking at the same\n\t// backing array.\n\t//\n\n\tages := []int{35, 15, 25}\n\tred, green := ages[0:1], ages[1:3]\n\n\ts.Show(\"ages\", ages)\n\ts.Show(\"red\", red)\n\ts.Show(\"green\", green)\n\n\tfmt.Println(red[0])\n\t// fmt.Println(red[1]) // error\n\t// fmt.Println(red[2]) // error\n\n\t{\n\t\tvar ages []int\n\t\ts.Show(\"nil slice\", ages)\n\n\t\t// or just:\n\t\ts.Show(\"nil slice\", []int(nil))\n\t}\n}\n"
  },
  {
    "path": "16-slices/09-slice-internals-2-slice-header/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unsafe\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\n// type collection [4]string // #1\ntype collection []string // #2\n\n// go is pass by copy\n// only the slice header is copied: 3 integer fields (24 bytes)\n// think of passing an array with millions of elements instead.\n\nfunc main() {\n\t// SliceHeader lives here:\n\t// https://golang.org/src/runtime/slice.go\n\n\ts.PrintElementAddr = true\n\n\t// #1\n\tdata := collection{\"slices\", \"are\", \"awesome\", \"period\", \"!!\" /* #5 */}\n\n\t// data := collection{\"slices\", \"are\", \"awesome\", \"period\", \"!!\"}\n\n\tchange(data) // #1\n\n\ts.Show(\"main's data\", data)                           // #1\n\tfmt.Printf(\"main's data slice's header: %p\\n\", &data) // #3\n\n\t// ----------------------------------------------------------------------\n\t// #4\n\tarray := [...]string{\"slices\", \"are\", \"awesome\", \"period\", \"!!\" /* #5 */}\n\n\t// array's size depends on its elements\n\tfmt.Printf(\"array's size: %d bytes.\\n\", unsafe.Sizeof(array))\n\n\t// slice's size is always fixed: 24 bytes (on a 64-bit system) — slice value = slice header\n\tfmt.Printf(\"slice's size: %d bytes.\\n\", unsafe.Sizeof(data))\n}\n\n// #1\n// passed value will be copied in the function\nfunc change(data collection) {\n\t// data is a new variable inside the function:\n\t// var data collection\n\n\tdata[2] = \"brilliant!\"\n\n\ts.Show(\"change's data\", data)\n\tfmt.Printf(\"change's data slice's header: %p\\n\", &data) // #3\n}\n"
  },
  {
    "path": "16-slices/10-slice-internals-3-len-cap/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\ts.MaxPerLine = 6\n\ts.PrintBacking = true\n\n\tages := []int{35, 15, 25}\n\ts.Show(\"ages\", ages)\n\n\ts.Show(\"ages[0:0]\", ages[0:0])\n\n\tfor i := 1; i < 4; i++ {\n\t\ttxt := fmt.Sprintf(\"ages[%d:%d]\", 0, i)\n\t\ts.Show(txt, ages[0:i])\n\t}\n\n\ts.Show(\"append\", append(ages, 50))\n}\n"
  },
  {
    "path": "16-slices/10-slice-internals-3-len-cap/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\ts.PrintBacking = true\n\n\t// ----------------------------------------------------\n\t// #1 nil slice\n\tvar games []string // nil slice\n\ts.Show(\"games\", games)\n\n\t// ----------------------------------------------------\n\t// #2 empty slice\n\tgames = []string{} // empty slice\n\ts.Show(\"games\", games)\n\t// s.Show(\"another empty\", []int{})\n\n\t// ----------------------------------------------------\n\t// #3 non-empty slice\n\tgames = []string{\"pacman\", \"mario\", \"tetris\", \"doom\"}\n\ts.Show(\"games\", games)\n\n\t// ----------------------------------------------------\n\t// #4 reset the part using the games slice\n\t//    part is empty but its cap is still 4\n\tpart := games\n\ts.Show(\"part\", part)\n\n\tpart = games[:0]\n\ts.Show(\"part[:0]\", part)\n\ts.Show(\"part[:cap]\", part[:cap(part)])\n\n\tfor cap(part) != 0 {\n\t\tpart = part[1:cap(part)]\n\t\ts.Show(\"part\", part)\n\t}\n\n\t// #6 backing array's elements become inaccessible\n\t// games = games[len(games):]\n\n\t// ----------------------------------------------------\n\t// #5 part doesn't have any more capacity\n\t//    games slice is still intact\n\ts.Show(\"part\", part)\n\ts.Show(\"games\", games)\n}\n"
  },
  {
    "path": "16-slices/11-slice-internals-4-append/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\ts.PrintBacking = true\n\n\tages := []int{35, 15}\n\ts.Show(\"ages\", ages)\n\n\tages = append(ages, 5)\n\ts.Show(\"append(ages, 5)\", ages)\n}\n"
  },
  {
    "path": "16-slices/11-slice-internals-4-append/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\ts.PrintBacking = true\n\n\t// #1: a nil slice has no backing array\n\tvar nums []int\n\ts.Show(\"no backing array\", nums)\n\n\t// #2: creates a new backing array\n\tnums = append(nums, 1, 3)\n\ts.Show(\"allocates\", nums)\n\n\t// #3: creates a new backing array\n\tnums = append(nums, 2)\n\ts.Show(\"free capacity\", nums)\n\n\t// #4: uses the same backing array\n\tnums = append(nums, 4)\n\ts.Show(\"no allocation\", nums)\n\n\t// GOAL: append new odd numbers in the middle\n\t// [1 3 2 4] -> [1 3 7 9 2 4]\n\n\t// #5: [1 3 2 4] -> [1 3 2 4 2 4]\n\tnums = append(nums, nums[2:]...)\n\ts.Show(\"nums <- nums[2:]\", nums)\n\n\t// #6: overwrites: [1 3 2 4 2 4] -> [1 3 7 9]\n\tnums = append(nums[:2], 7, 9)\n\ts.Show(\"nums[:2] <- 7, 9\", nums)\n\n\t// #7: [1 3 7 9] -> [1 3 7 9 2 4]\n\tnums = nums[:6]\n\ts.Show(\"nums: extend\", nums)\n}\n\n// don't mind about these options\n// they're just for printing the slices nicely\nfunc init() {\n\ts.MaxPerLine = 10\n\ts.Width = 45\n}\n"
  },
  {
    "path": "16-slices/11-slice-internals-4-append/3-example-growth/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"math/rand\"\n\t\"time\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\ts.PrintBacking = true\n\ts.MaxPerLine = 30\n\ts.Width = 150\n\n\tvar nums []int\n\n\tscreen.Clear()\n\tfor cap(nums) <= 128 {\n\t\tscreen.MoveTopLeft()\n\n\t\ts.Show(\"nums\", nums)\n\t\tnums = append(nums, rand.Intn(9)+1)\n\n\t\ttime.Sleep(time.Second / 4)\n\t}\n}\n"
  },
  {
    "path": "16-slices/11-slice-internals-4-append/4-example-growth/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tages, oldCap := []int{1}, 1.\n\n\tfor len(ages) < 5e5 {\n\t\tages = append(ages, 1)\n\n\t\tc := float64(cap(ages))\n\t\tif c != oldCap {\n\t\t\tfmt.Printf(\"len:%-10d cap:%-10g growth:%.2f\\n\",\n\t\t\t\tlen(ages), c, c/oldCap)\n\t\t}\n\t\toldCap = c\n\t}\n}\n"
  },
  {
    "path": "16-slices/12-full-slice-expressions/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\ts.PrintBacking = true\n\n\tsliceable := []byte{'f', 'u', 'l', 'l'}\n\n\ts.Show(\"sliceable\", sliceable)\n\ts.Show(\"sliceable[0:3]\", sliceable[0:3])\n\ts.Show(\"sliceable[0:3:3]\", sliceable[0:3:3])\n\ts.Show(\"sliceable[0:2:2]\", sliceable[0:2:2])\n\ts.Show(\"sliceable[0:1:1]\", sliceable[0:1:1])\n\ts.Show(\"sliceable[1:3:3]\", sliceable[1:3:3])\n\ts.Show(\"sliceable[2:3:3]\", sliceable[2:3:3])\n\ts.Show(\"sliceable[2:3:4]\", sliceable[2:3:4])\n\ts.Show(\"sliceable[4:4:4]\", sliceable[4:4:4])\n}\n"
  },
  {
    "path": "16-slices/12-full-slice-expressions/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\ts.PrintBacking = true\n\n\tnums := []int{1, 3, 2, 4} // #1\n\t// odds := nums[:2]          // #2\n\t// odds := nums[:2:2]        // #4\n\t// odds = append(odds, 5, 7) // #3\n\n\t// odds := append(nums[:2:2], 5, 7) // #5\n\t// evens := append(nums[2:4], 6, 8) // #6\n\n\ts.Show(\"nums\", nums) // #1\n\t// s.Show(\"odds\", odds)   // #2\n\t// s.Show(\"evens\", evens) // #6\n}\n\n// don't mind about these options\n// they're just for printing the slices nicely\nfunc init() {\n\ts.MaxPerLine = 10\n\ts.Width = 55\n}\n"
  },
  {
    "path": "16-slices/13-make/1-theory/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\tprettyslice \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\tprettyslice.PrintBacking = true\n\n\tprettyslice.Show(\"make([]int, 3)\", make([]int, 3))\n\tprettyslice.Show(\"make([]int, 3, 5)\", make([]int, 3, 5))\n\n\ts := make([]int, 0, 5)\n\tprettyslice.Show(\"make([]int, 0, 5)\", s)\n\n\ts = append(s, 42)\n\tprettyslice.Show(\"s = append(s, 42)\", s)\n}\n"
  },
  {
    "path": "16-slices/13-make/2-example/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"strings\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\ts.PrintBacking = true\n\ts.MaxPerLine = 10\n\n\t// #1: assume that tasks can be a long list\n\t// ---------------------------------------------\n\ttasks := []string{\"jump\", \"run\", \"read\"}\n\n\t// #2: INEFFICIENT WAY\n\t// ---------------------------------------------\n\t// var upTasks []string\n\t// s.Show(\"upTasks\", upTasks)\n\n\t// for _, task := range tasks {\n\t// \tupTasks = append(upTasks, strings.ToUpper(task))\n\t// \ts.Show(\"upTasks\", upTasks)\n\t// }\n\n\t// #3: SO SO WAY:\n\t// ---------------------------------------------\n\t// upTasks := make([]string, len(tasks))\n\t// s.Show(\"upTasks\", upTasks)\n\n\t// for _, task := range tasks {\n\t// \tupTasks = append(upTasks, strings.ToUpper(task))\n\t// \ts.Show(\"upTasks\", upTasks)\n\t// }\n\n\t// #4: SO SO WAY 2:\n\t// ---------------------------------------------\n\t// upTasks := make([]string, len(tasks))\n\t// s.Show(\"upTasks\", upTasks)\n\n\t// for i, task := range tasks {\n\t// \tupTasks[i] = strings.ToUpper(task)\n\t// \ts.Show(\"upTasks\", upTasks)\n\t// }\n\n\t// #5: allocates a new array\n\t// upTasks = append(upTasks, \"PLAY\")\n\t// s.Show(\"upTasks\", upTasks)\n\n\t// #6: SO SO WAY 3\n\t// ---------------------------------------------\n\t// upTasks := make([]string, 0, len(tasks))\n\n\t// #7\n\t// upTasks = upTasks[:cap(upTasks)]\n\n\t// #6\n\t// s.Show(\"upTasks\", upTasks)\n\n\t// for i, task := range tasks {\n\t// \tupTasks[i] = strings.ToUpper(task)\n\t// \ts.Show(\"upTasks\", upTasks)\n\t// }\n\n\t// #8: THE BEST WAY\n\t// ---------------------------------------------\n\tupTasks := make([]string, 0, len(tasks))\n\n\ts.Show(\"upTasks\", upTasks)\n\n\tfor _, task := range tasks {\n\t\tupTasks = append(upTasks, strings.ToUpper(task))\n\t\ts.Show(\"upTasks\", upTasks)\n\t}\n}\n"
  },
  {
    "path": "16-slices/14-copy/01-usage/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\tevens := []int{2, 4}\n\todds := []int{3, 5, 7}\n\n\ts.Show(\"evens [before]\", evens)\n\ts.Show(\"odds  [before]\", odds)\n\n\tN := copy(evens, odds)\n\tfmt.Printf(\"%d element(s) are copied.\\n\", N)\n\n\ts.Show(\"evens [after]\", evens)\n\ts.Show(\"odds  [after]\", odds)\n}\n"
  },
  {
    "path": "16-slices/14-copy/02-hacker-incident/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\t// #1: received the raining probabilities\n\tdata := []float64{10, 25, 30, 50}\n\n\t// #2: received new data\n\t// newData := []float64{80, 90}\n\t// for i := 0; i < len(newData); i++ {\n\t// \tdata[i] = newData[i]\n\t// }\n\n\t// #3: use copy\n\t// copy(data, []float64{99, 100})\n\n\t// #4: received more data than the original\n\t// copy(data, []float64{10, 5, 15, 0, 20})\n\n\t// #5: returns the # of copied elements\n\t// n := copy(data, []float64{10, 5, 15, 0, 20})\n\t// fmt.Printf(\"%d probabilities copied.\\n\", n)\n\n\t// #6: (sometimes) use append instead of copy\n\t// data = append(data[:0], []float64{10, 5, 15, 0, 20}...)\n\n\t// #7: clone a slice using copy\n\t// saved := make([]float64, len(data))\n\t// copy(saved, data)\n\n\t// #9: clone a slice using append nil (I prefer this)\n\t// saved := append([]float64(nil), data...)\n\n\t// data[0] = 0 // #8\n\n\t// s.Show(\"Probabilities (saved)\", saved) // #7\n\n\t// #1: print the probabilities\n\ts.Show(\"Probabilities (data)\", data)\n\n\tfmt.Printf(\"Is it gonna rain? %.f%% chance.\\n\",\n\t\t(data[0]+data[1]+data[2]+data[3])/\n\t\t\tfloat64(len(data)))\n}\n"
  },
  {
    "path": "16-slices/15-multi-dimensional-slices/version-1/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// 1st day: $200, $100\n\t// 2nd day: $500\n\t// 3rd day: $50, $25, and $75\n\n\tspendings := [][]int{\n\t\t{200, 100},   // 1st day\n\t\t{500},        // 2nd day\n\t\t{50, 25, 75}, // 3rd day\n\t}\n\n\tfor i, daily := range spendings {\n\t\tvar total int\n\t\tfor _, spending := range daily {\n\t\t\ttotal += spending\n\t\t}\n\n\t\tfmt.Printf(\"Day %d: %d\\n\", i+1, total)\n\t}\n}\n"
  },
  {
    "path": "16-slices/15-multi-dimensional-slices/version-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tspendings := make([][]int, 0, 5)\n\n\tspendings = append(spendings, []int{200, 100})\n\tspendings = append(spendings, []int{25, 10, 45, 60})\n\tspendings = append(spendings, []int{5, 15, 35})\n\tspendings = append(spendings, []int{95, 10}, []int{50, 25})\n\n\tfor i, daily := range spendings {\n\t\tvar total int\n\t\tfor _, spending := range daily {\n\t\t\ttotal += spending\n\t\t}\n\n\t\tfmt.Printf(\"Day %d: %d\\n\", i+1, total)\n\t}\n}\n"
  },
  {
    "path": "16-slices/15-multi-dimensional-slices/version-3/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tspendings := fetch()\n\n\tfor i, daily := range spendings {\n\t\tvar total int\n\t\tfor _, spending := range daily {\n\t\t\ttotal += spending\n\t\t}\n\n\t\tfmt.Printf(\"Day %d: %d\\n\", i+1, total)\n\t}\n}\n\nfunc fetch() [][]int {\n\tcontent := `200 100\n25 10 45 60\n5 15 35\n95 10\n50 25`\n\n\tlines := strings.Split(content, \"\\n\")\n\n\tspendings := make([][]int, len(lines))\n\n\tfor i, line := range lines {\n\t\tfields := strings.Fields(line)\n\n\t\tspendings[i] = make([]int, len(fields))\n\n\t\tfor j, field := range fields {\n\t\t\tspending, _ := strconv.Atoi(field)\n\t\t\tspendings[i][j] = spending\n\t\t}\n\t}\n\n\treturn spendings\n}\n"
  },
  {
    "path": "16-slices/README.md",
    "content": "# WARNING\n\nFor the code in this section, you should install my prettyslice library.\n\n## STEPS\n1. Open your command-line\n2. Type: `go get -u github.com/inancgumus/prettyslice`\n3. That's all."
  },
  {
    "path": "16-slices/exercises/01-declare-nil/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Declare nil slices\n//\n//  1. Declare the following slices as nil slices:\n//\n//    1. The names of your friends (names slice)\n//\n//    2. The distances to locations (distances slice)\n//\n//    3. A data buffer (data slice)\n//\n//    4. Currency exchange ratios (ratios slice)\n//\n//    5. Up/Down status of web servers (alives slice)\n//\n//\n//  2. Print their type, length and whether they're equal to nil value or not.\n//\n//\n// EXPECTED OUTPUT\n//  names    : []string 0 true\n//  distances: []int 0 true\n//  data     : []uint8 0 true\n//  ratios   : []float64 0 true\n//  alives   : []bool 0 true\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "16-slices/exercises/01-declare-nil/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tnames     []string  // The names of your friends\n\t\tdistances []int     // The distances\n\t\tdata      []byte    // A data buffer\n\t\tratios    []float64 // Currency exchange ratios\n\t\talives    []bool    // Up/Down status of web servers\n\t)\n\n\tfmt.Printf(\"names    : %T %d %t\\n\", names, len(names), names == nil)\n\tfmt.Printf(\"distances: %T %d %t\\n\", distances, len(distances), distances == nil)\n\tfmt.Printf(\"data     : %T %d %t\\n\", data, len(data), data == nil)\n\tfmt.Printf(\"ratios   : %T %d %t\\n\", ratios, len(ratios), ratios == nil)\n\tfmt.Printf(\"alives   : %T %d %t\\n\", alives, len(alives), alives == nil)\n}\n"
  },
  {
    "path": "16-slices/exercises/02-empty/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Assign empty slices\n//\n//   Assign empty slices to all the slices that you've declared in the previous\n//   exercise, and print them here.\n//\n//\n// EXPECTED OUTPUT\n//  names    : []string 0 false\n//  distances: []int 0 false\n//  data     : []uint8 0 false\n//  ratios   : []float64 0 false\n//  alives   : []bool 0 false\n// ---------------------------------------------------------\n\nfunc main() {\n\tvar (\n\t\tnames     []string  // The names of your friends\n\t\tdistances []int     // The distances\n\t\tdata      []byte    // A data buffer\n\t\tratios    []float64 // Currency exchange ratios\n\t\talives    []bool    // Up/Down status of web servers\n\t)\n\n\tfmt.Printf(\"names    : %T %d %t\\n\", names, len(names), names == nil)\n\tfmt.Printf(\"distances: %T %d %t\\n\", distances, len(distances), distances == nil)\n\tfmt.Printf(\"data     : %T %d %t\\n\", data, len(data), data == nil)\n\tfmt.Printf(\"ratios   : %T %d %t\\n\", ratios, len(ratios), ratios == nil)\n\tfmt.Printf(\"alives   : %T %d %t\\n\", alives, len(alives), alives == nil)\n}\n"
  },
  {
    "path": "16-slices/exercises/02-empty/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tnames     []string  // The names of your friends\n\t\tdistances []int     // The distances\n\t\tdata      []byte    // A data buffer\n\t\tratios    []float64 // Currency exchange ratios\n\t\talives    []bool    // Up/Down status of web servers\n\t)\n\n\tnames = []string{}\n\tdistances = []int{}\n\tdata = []byte{}\n\tratios = []float64{}\n\talives = []bool{}\n\n\tfmt.Printf(\"names    : %T %d %t\\n\", names, len(names), names == nil)\n\tfmt.Printf(\"distances: %T %d %t\\n\", distances, len(distances), distances == nil)\n\tfmt.Printf(\"data     : %T %d %t\\n\", data, len(data), data == nil)\n\tfmt.Printf(\"ratios   : %T %d %t\\n\", ratios, len(ratios), ratios == nil)\n\tfmt.Printf(\"alives   : %T %d %t\\n\", alives, len(alives), alives == nil)\n}\n"
  },
  {
    "path": "16-slices/exercises/03-slice-literal/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Assign slice literals\n//\n//   1. Assign the following data using slice literals to the slices that\n//      you've declared in the first exercise.\n//\n//    1. The names of your three best friends (to the names slice)\n//\n//    2. The distances to five different locations (to the distances slice)\n//\n//    3. Five bytes of data (to the data slice)\n//\n//    4. Two currency exchange ratios (to the ratios slice)\n//\n//    5. Up/Down status of four different web servers (to the alives slice)\n//\n//  2. Print their type, length and whether they're equal to nil value or not\n//\n//  3. Compare the length of the distances and the data slices; print a message\n//     if they are equal (use an if statement).\n//\n//\n// EXPECTED OUTPUT\n//  names    : []string 3 false\n//  distances: []int 5 false\n//  data     : []uint8 5 false\n//  ratios   : []float64 2 false\n//  alives   : []bool 4 false\n//  The length of the distances and the data slices are the same.\n// ---------------------------------------------------------\n\nfunc main() {\n\tvar (\n\t\tnames     []string  // The names of your friends\n\t\tdistances []int     // The distances\n\t\tdata      []byte    // A data buffer\n\t\tratios    []float64 // Currency exchange ratios\n\t\talives    []bool    // Up/Down status of web servers\n\t)\n\n\tnames = []string{}\n\tdistances = []int{}\n\tdata = []byte{}\n\tratios = []float64{}\n\talives = []bool{}\n\n\tfmt.Printf(\"names    : %T %d %t\\n\", names, len(names), names == nil)\n\tfmt.Printf(\"distances: %T %d %t\\n\", distances, len(distances), distances == nil)\n\tfmt.Printf(\"data     : %T %d %t\\n\", data, len(data), data == nil)\n\tfmt.Printf(\"ratios   : %T %d %t\\n\", ratios, len(ratios), ratios == nil)\n\tfmt.Printf(\"alives   : %T %d %t\\n\", alives, len(alives), alives == nil)\n}\n"
  },
  {
    "path": "16-slices/exercises/03-slice-literal/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tnames     []string  // The names of your friends\n\t\tdistances []int     // The distances\n\t\tdata      []byte    // A data buffer\n\t\tratios    []float64 // Currency exchange ratios\n\t\talives    []bool    // Up/Down status of web servers\n\t)\n\n\tnames = []string{\"serpil\", \"ebru\", \"lina\"}\n\tdistances = []int{100, 200, 300, 400, 500}\n\tdata = []byte{'I', 'N', 'A', 'N', 'C'}\n\tratios = []float64{3.14, 6.28}\n\talives = []bool{true, false, false, true}\n\n\tfmt.Printf(\"names    : %T %d %t\\n\", names, len(names), names == nil)\n\tfmt.Printf(\"distances: %T %d %t\\n\", distances, len(distances), distances == nil)\n\tfmt.Printf(\"data     : %T %d %t\\n\", data, len(data), data == nil)\n\tfmt.Printf(\"ratios   : %T %d %t\\n\", ratios, len(ratios), ratios == nil)\n\tfmt.Printf(\"alives   : %T %d %t\\n\", alives, len(alives), alives == nil)\n\n\tif len(distances) == len(data) {\n\t\tfmt.Println(\"The length of the distances and the data slices are the same.\")\n\t}\n}\n"
  },
  {
    "path": "16-slices/exercises/04-declare-arrays-as-slices/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Declare the arrays as slices\n//\n//   1. First run the following program as it is\n//\n//   2. Then change the array declarations to slice declarations\n//\n//   3. Observe whether anything changes or not (on the surface :)).\n//\n// EXPECTED OUTPUT\n//  names    : []string [\"Einstein\" \"Tesla\" \"Shepard\"]\n//  distances: []int [50 40 75 30 125]\n//  data     : []uint8 [72 69 76 76 79]\n//  ratios   : []float64 [3.14]\n//  alives   : []bool [true false true false]\n//  zero     : []uint8 []\n// ---------------------------------------------------------\n\nfunc main() {\n\tnames := [3]string{\"Einstein\", \"Tesla\", \"Shepard\"}\n\tdistances := [...]int{50, 40, 75, 30, 125}\n\tdata := [5]byte{'H', 'E', 'L', 'L', 'O'}\n\tratios := [1]float64{3.14145}\n\talives := [...]bool{true, false, true, false}\n\tzero := [0]byte{}\n\n\tfmt.Printf(\"names    : %[1]T %[1]q\\n\", names)\n\tfmt.Printf(\"distances: %[1]T %[1]d\\n\", distances)\n\tfmt.Printf(\"data     : %[1]T %[1]d\\n\", data)\n\tfmt.Printf(\"ratios   : %[1]T %.2[1]f\\n\", ratios)\n\tfmt.Printf(\"alives   : %[1]T %[1]t\\n\", alives)\n\tfmt.Printf(\"zero     : %[1]T %[1]d\\n\", zero)\n}\n"
  },
  {
    "path": "16-slices/exercises/04-declare-arrays-as-slices/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tnames := []string{\"Einstein\", \"Tesla\", \"Shepard\"}\n\tdistances := []int{50, 40, 75, 30, 125}\n\tdata := []byte{'H', 'E', 'L', 'L', 'O'}\n\tratios := []float64{3.14145}\n\talives := []bool{true, false, true, false}\n\tzero := []byte{}\n\n\tfmt.Printf(\"names    : %[1]T %[1]q\\n\", names)\n\tfmt.Printf(\"distances: %[1]T %[1]d\\n\", distances)\n\tfmt.Printf(\"data     : %[1]T %[1]d\\n\", data)\n\tfmt.Printf(\"ratios   : %[1]T %.2[1]f\\n\", ratios)\n\tfmt.Printf(\"alives   : %[1]T %[1]t\\n\", alives)\n\tfmt.Printf(\"zero     : %[1]T %[1]d\\n\", zero)\n}\n"
  },
  {
    "path": "16-slices/exercises/05-fix-the-problems/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Fix the problems\n//\n//  1. Uncomment the code\n//\n//  2. Fix the problems\n//\n//  3. BONUS: Simplify the code\n//\n//\n// EXPECTED OUTPUT\n//   \"Einstein and Shepard and Tesla\"\n//   [\"Fire\" \"Kafka's Revenge\" \"Stay Golden\"]\n//   [1 2 3 5 6 7 8 9]\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var names []string\n\t// names := []string{}\n\t// names = [...]string{\n\t// \t\"Einstein\" \"Shepard\"\n\t// \t\"Tesla\"\n\t// }\n\n\t// -----------------------------------\n\t// var books []string = [3]string{\n\t// \t\"Stay Golden\",\n\t// \t\"Fire\",\n\t// \t\"Kafka's Revenge\",\n\t// }\n\n\t// sort.Strings(books)\n\n\t// -----------------------------------\n\t// // this time, do not change the nums array to a slice\n\t// nums := [...]int{5,1,7,3,8,2,6,9}\n\n\t// // use the slicing expression to change the nums array to a slice below\n\t// sort.Ints(nums)\n\n\t// -----------------------------------\n\t// Here: Use the strings.Join function to join the names\n\t//       (see the expected output)\n\t// fmt.Printf(\"%q\\n\", names)\n\n\t// fmt.Printf(\"%q\\n\", books)\n\t// fmt.Printf(\"%d\\n\", nums)\n}\n"
  },
  {
    "path": "16-slices/exercises/05-fix-the-problems/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tnames := []string{\"Einstein\", \"Shepard\", \"Tesla\"}\n\n\tbooks := []string{\"Stay Golden\", \"Fire\", \"Kafka's Revenge\"}\n\tsort.Strings(books)\n\n\tnums := [...]int{5, 1, 7, 3, 8, 2, 6, 9}\n\tsort.Ints(nums[:])\n\n\tfmt.Printf(\"%q\\n\", strings.Join(names, \" and \"))\n\tfmt.Printf(\"%q\\n\", books)\n\tfmt.Printf(\"%d\\n\", nums)\n}\n"
  },
  {
    "path": "16-slices/exercises/06-compare-the-slices/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Compare the slices\n//\n//  1. Split the namesA string and get a slice\n//\n//  2. Sort all the slices\n//\n//  3. Compare whether the slices are equal or not\n//\n//\n// EXPECTED OUTPUT\n//\n//   They are equal.\n//\n//\n// HINTS\n//\n//   1. strings.Split function splits a string and\n//      returns a string slice\n//\n//   2. Comparing slices: First check whether their length\n//      are the same or not; only then compare them.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// namesA := \"Da Vinci, Wozniak, Carmack\"\n\t// namesB := []string{\"Wozniak\", \"Da Vinci\", \"Carmack\"}\n}\n"
  },
  {
    "path": "16-slices/exercises/06-compare-the-slices/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tnamesA := \"Da Vinci, Wozniak, Carmack\"\n\tnamesB := []string{\"Wozniak\", \"Da Vinci\", \"Carmack\"}\n\n\tnamesC := strings.Split(namesA, \", \")\n\n\tsort.Strings(namesC)\n\tsort.Strings(namesB)\n\n\tif len(namesC) == len(namesB) {\n\t\tfor i := range namesC {\n\t\t\tif namesC[i] != namesB[i] {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tfmt.Println(\"They are equal.\")\n\t}\n}\n"
  },
  {
    "path": "16-slices/exercises/07-append/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Append\n//\n//  Please follow the instructions within the code below.\n//\n// EXPECTED OUTPUT\n//  They are equal.\n//\n// HINTS\n//  bytes.Equal function allows you to compare two byte\n//  slices easily. Check its documentation: go doc bytes.Equal\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 1. uncomment the code below\n\t// png, header := []byte{'P', 'N', 'G'}, []byte{}\n\n\t// 2. append elements to header to make it equal with the png slice\n\n\t// 3. compare the slices using the bytes.Equal function\n\n\t// 4. print whether they're equal or not\n}\n"
  },
  {
    "path": "16-slices/exercises/07-append/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n)\n\nfunc main() {\n\tpng, header := []byte{'P', 'N', 'G'}, []byte{}\n\n\theader = append(header, png...)\n\n\tif bytes.Equal(png, header) {\n\t\tfmt.Println(\"They are equal\")\n\t}\n}\n"
  },
  {
    "path": "16-slices/exercises/08-append-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Append #2\n//\n//  1. Create the following nil slices:\n//     + Pizza toppings\n//     + Departure times\n//     + Student graduation years\n//     + On/off states of lights in a room\n//\n//  2. Append them some elements (use your creativity!)\n//\n//  3. Print all the slices\n//\n//\n// EXPECTED OUTPUT\n// (Your output may change, mine is like so:)\n//\n//  pizza       : [pepperoni onions extra cheese]\n//\n//  graduations : [1998 2005 2018]\n//\n//  departures  : [2019-01-28 15:09:31.294594 +0300 +03 m=+0.000325020\n//  2019-01-29 15:09:31.294594 +0300 +03 m=+86400.000325020\n//  2019-01-30 15:09:31.294594 +0300 +03 m=+172800.000325020]\n//\n//  lights      : [true false true]\n//\n//\n// HINTS\n//  + For departure times, use the time.Time type. Check its documentation.\n//\n//      now := time.Now()     -> Gives you the current time\n//      now.Add(time.Hour*24) -> Gives you a time.Time 24 hours after `now`\n//\n//  + For graduation years, you can use the int type\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "16-slices/exercises/08-append-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\t// ------------------------------------------------------------\n\t// Create nil slices\n\t// ------------------------------------------------------------\n\n\t// Pizza toppings\n\tvar pizza []string\n\n\t// Departure times\n\tvar departures []time.Time\n\n\t// Student graduation years\n\tvar grads []int\n\n\t// On/off states of lights in a room\n\tvar lights []bool\n\n\t// ------------------------------------------------------------\n\t// Append them some elements (use your creativity!)\n\t// ------------------------------------------------------------\n\tpizza = append(pizza, \"pepperoni\", \"onions\", \"extra cheese\")\n\n\tnow := time.Now()\n\tdepartures = append(departures,\n\t\tnow,\n\t\tnow.Add(time.Hour*24), // 24 hours after `now`\n\t\tnow.Add(time.Hour*48)) // 48 hours after `now`\n\n\tgrads = append(grads, 1998, 2005, 2018)\n\n\tlights = append(lights, true, false, true)\n\n\t// ------------------------------------------------------------\n\t// Print the slices\n\t// ------------------------------------------------------------\n\n\tfmt.Printf(\"pizza       : %s\\n\", pizza)\n\tfmt.Printf(\"\\ngraduations : %d\\n\", grads)\n\tfmt.Printf(\"\\ndepartures  : %s\\n\", departures)\n\tfmt.Printf(\"\\nlights      : %t\\n\", lights)\n}\n"
  },
  {
    "path": "16-slices/exercises/09-append-3-fix/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Append #3 — Fix the problems\n//\n//  Fix the problems in the code below.\n//\n// BONUS\n//\n//  Simplify the code.\n//\n// EXPECTED OUTPUT\n//\n//  toppings: [black olives green peppers onions extra cheese]\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// toppings := []int{\"black olives\", \"green peppers\"}\n\n\t// var pizza [3]string\n\t// append(pizza, ...toppings)\n\t// pizza = append(toppings, \"onions\")\n\t// toppings = append(pizza, extra cheese)\n\n\t// fmt.Printf(\"pizza       : %s\\n\", pizza)\n}\n"
  },
  {
    "path": "16-slices/exercises/09-append-3-fix/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ttoppings := []string{\"black olives\", \"green peppers\"}\n\n\tvar pizza []string\n\tpizza = append(pizza, toppings...)\n\tpizza = append(pizza, \"onions\", \"extra cheese\")\n\n\tfmt.Printf(\"toppings: %s\\n\", pizza)\n}\n"
  },
  {
    "path": "16-slices/exercises/10-append-sort-nums/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Append and Sort Numbers\n//\n//  We'll have a []string that should contain numbers.\n//\n//  Your task is to convert the []string to an int slice.\n//\n//  1. Get the numbers from the command-line\n//\n//  2. Append them to an []int\n//\n//  3. Sort the numbers\n//\n//  4. Print them\n//\n//  5. Handle the error cases\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//    provide a few numbers\n//\n//  go run main.go 4 6 1 3 0 9 2\n//    [0 1 2 3 4 6 9]\n//\n//  go run main.go a b c\n//    []\n//\n//  go run main.go 4 a 1 c d 9\n//    [1 4 9]\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "16-slices/exercises/10-append-sort-nums/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) == 0 {\n\t\tfmt.Println(\"provide a few numbers\")\n\t\treturn\n\t}\n\n\tvar nums []int\n\tfor _, s := range args {\n\t\tn, err := strconv.Atoi(s)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tnums = append(nums, n)\n\t}\n\n\tsort.Ints(nums)\n\tfmt.Println(nums)\n}\n"
  },
  {
    "path": "16-slices/exercises/11-housing-prices/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Housing Prices\n//\n//  We have received housing prices. Your task is to load the data into\n//  appropriately typed slices then print them.\n//\n//  1. Check out the expected output\n//\n//\n//  2. Check out the code below\n//\n//     1. header   : stores the column headers\n//     2. data     : stores the real data related to each column\n//     3. separator: you will use it to separate the data\n//\n//\n//  3. Parse the data\n//\n//     1. Separate it into rows by using the newline character (\"\\n\")\n//\n//     2. For each row, separate it by using the separator (\",\")\n//\n//\n//  4. Load the data into distinct slices\n//\n//     1. Load the locations into a []string\n//     2. Load the sizes into []int\n//     3. Load the beds into []int\n//     4. Load the baths into []int\n//     5. Load the prices into []int\n//\n//\n//  5. Print the header\n//\n//     1. Separate it by using the separator\n//\n//     2. Print each column 15 character wide (\"%-15s\")\n//\n//\n//  6. Print the rows from the slices that you've created, line by line\n//\n//\n// EXPECTED OUTPUT\n//\n//  Location       Size           Beds           Baths          Price\n//  ===========================================================================\n//  New York       100            2              1              100000\n//  New York       150            3              2              200000\n//  Paris          200            4              3              400000\n//  Istanbul       500            10             5              1000000\n//\n//\n// HINTS\n//\n//  + strings.Split function can separate a string into a []string\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\theader = \"Location,Size,Beds,Baths,Price\"\n\t\tdata   = `New York,100,2,1,100000\nNew York,150,3,2,200000\nParis,200,4,3,400000\nIstanbul,500,10,5,1000000`\n\n\t\tseparator = \",\"\n\t)\n}\n"
  },
  {
    "path": "16-slices/exercises/11-housing-prices/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tconst (\n\t\theader = \"Location,Size,Beds,Baths,Price\"\n\t\tdata   = `New York,100,2,1,100000\nNew York,150,3,2,200000\nParis,200,4,3,400000\nIstanbul,500,10,5,1000000`\n\n\t\tseparator = \",\"\n\t)\n\n\tvar (\n\t\tlocs                       []string\n\t\tsizes, beds, baths, prices []int\n\t)\n\n\trows := strings.Split(data, \"\\n\")\n\n\tfor _, row := range rows {\n\t\tcols := strings.Split(row, separator)\n\n\t\tlocs = append(locs, cols[0])\n\n\t\tn, _ := strconv.Atoi(cols[1])\n\t\tsizes = append(sizes, n)\n\n\t\tn, _ = strconv.Atoi(cols[2])\n\t\tbeds = append(beds, n)\n\n\t\tn, _ = strconv.Atoi(cols[3])\n\t\tbaths = append(baths, n)\n\n\t\tn, _ = strconv.Atoi(cols[4])\n\t\tprices = append(prices, n)\n\t}\n\n\tfor _, h := range strings.Split(header, separator) {\n\t\tfmt.Printf(\"%-15s\", h)\n\t}\n\tfmt.Printf(\"\\n%s\\n\", strings.Repeat(\"=\", 75))\n\n\tfor i := range rows {\n\t\tfmt.Printf(\"%-15s\", locs[i])\n\t\tfmt.Printf(\"%-15d\", sizes[i])\n\t\tfmt.Printf(\"%-15d\", beds[i])\n\t\tfmt.Printf(\"%-15d\", baths[i])\n\t\tfmt.Printf(\"%-15d\", prices[i])\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "16-slices/exercises/12-housing-prices-averages/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Housing Prices and Averages\n//\n//  Use the previous exercise to solve this exercise (Housing Prices).\n//\n//  Your task is to print the averages of the sizes, beds, baths, and prices.\n//\n//\n// EXPECTED OUTPUT\n//\n//  Location       Size           Beds           Baths          Price\n//  ===========================================================================\n//  New York       100            2              1              100000\n//  New York       150            3              2              200000\n//  Paris          200            4              3              400000\n//  Istanbul       500            10             5              1000000\n//\n//  ===========================================================================\n//                 237.50         4.75           2.75           425000.00\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\theader = \"Location,Size,Beds,Baths,Price\"\n\t\tdata   = `New York,100,2,1,100000\nNew York,150,3,2,200000\nParis,200,4,3,400000\nIstanbul,500,10,5,1000000`\n\n\t\tseparator = \",\"\n\t)\n\n\t// Solve this exercise by using your previous solution for\n\t// the \"Housing Prices\" exercise.\n}\n"
  },
  {
    "path": "16-slices/exercises/12-housing-prices-averages/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tconst (\n\t\theader = \"Location,Size,Beds,Baths,Price\"\n\t\tdata   = `New York,100,2,1,100000\nNew York,150,3,2,200000\nParis,200,4,3,400000\nIstanbul,500,10,5,1000000`\n\n\t\tseparator = \",\"\n\t)\n\n\tvar (\n\t\tlocs                       []string\n\t\tsizes, beds, baths, prices []int\n\t)\n\n\trows := strings.Split(data, \"\\n\")\n\n\tfor _, row := range rows {\n\t\tcols := strings.Split(row, separator)\n\n\t\tlocs = append(locs, cols[0])\n\n\t\tn, _ := strconv.Atoi(cols[1])\n\t\tsizes = append(sizes, n)\n\n\t\tn, _ = strconv.Atoi(cols[2])\n\t\tbeds = append(beds, n)\n\n\t\tn, _ = strconv.Atoi(cols[3])\n\t\tbaths = append(baths, n)\n\n\t\tn, _ = strconv.Atoi(cols[4])\n\t\tprices = append(prices, n)\n\t}\n\n\tfor _, h := range strings.Split(header, separator) {\n\t\tfmt.Printf(\"%-15s\", h)\n\t}\n\tfmt.Printf(\"\\n%s\\n\", strings.Repeat(\"=\", 75))\n\n\tfor i := range rows {\n\t\tfmt.Printf(\"%-15s\", locs[i])\n\t\tfmt.Printf(\"%-15d\", sizes[i])\n\t\tfmt.Printf(\"%-15d\", beds[i])\n\t\tfmt.Printf(\"%-15d\", baths[i])\n\t\tfmt.Printf(\"%-15d\", prices[i])\n\t\tfmt.Println()\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// print the averages\n\t//\n\t// evil note:\n\t// later on, you will see how easy it would be to solve this\n\t// using the functions instead. there are a lot of repetitive code here.\n\t// -------------------------------------------------------------------------\n\tfmt.Printf(\"\\n%s\\n\", strings.Repeat(\"=\", 75))\n\n\t// jump over the location column\n\tfmt.Printf(\"%-15s\", \"\")\n\n\tvar sum int\n\n\tfor _, n := range sizes {\n\t\tsum += n\n\t}\n\tfmt.Printf(\"%-15.2f\", float64(sum)/float64(len(sizes)))\n\n\tsum = 0\n\tfor _, n := range beds {\n\t\tsum += n\n\t}\n\tfmt.Printf(\"%-15.2f\", float64(sum)/float64(len(beds)))\n\n\tsum = 0\n\tfor _, n := range baths {\n\t\tsum += n\n\t}\n\tfmt.Printf(\"%-15.2f\", float64(sum)/float64(len(baths)))\n\n\tsum = 0\n\tfor _, n := range prices {\n\t\tsum += n\n\t}\n\tfmt.Printf(\"%-15.2f\", float64(sum)/float64(len(prices)))\n\n\tfmt.Println()\n}\n"
  },
  {
    "path": "16-slices/exercises/13-slicing-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Slice the numbers\n//\n//   We've a string that contains even and odd numbers.\n//\n//   1. Convert the string to an []int\n//\n//   2. Print the slice\n//\n//   3. Slice it for the even numbers and print it (assign it to a new slice variable)\n//\n//   4. Slice it for the odd numbers and print it (assign it to a new slice variable)\n//\n//   5. Slice it for the two numbers at the middle\n//\n//   6. Slice it for the first two numbers\n//\n//   7. Slice it for the last two numbers (use the len function)\n//\n//   8. Slice the evens slice for the last one number\n//\n//   9. Slice the odds slice for the last two numbers\n//\n//\n// EXPECTED OUTPUT\n//   go run main.go\n//\n//     nums        : [2 4 6 1 3 5]\n//     evens       : [2 4 6]\n//     odds        : [1 3 5]\n//     middle      : [6 1]\n//     first 2     : [2 4]\n//     last 2      : [3 5]\n//     evens last 1: [6]\n//     odds last 2 : [3 5]\n//\n//\n// NOTE\n//\n//  You can also use my prettyslice package for printing the slices.\n//\n//\n// HINT\n//\n//  Find a function in the strings package for splitting the string into []string\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// uncomment the declaration below\n\t// data := \"2 4 6 1 3 5\"\n}\n"
  },
  {
    "path": "16-slices/exercises/13-slicing-basics/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tdata := \"2 4 6 1 3 5\"\n\tsplitted := strings.Fields(data)\n\n\tvar nums []int\n\tfor _, s := range splitted {\n\t\tn, _ := strconv.Atoi(s)\n\t\tnums = append(nums, n)\n\t}\n\n\t// rest of the code for this exercise\n\tfmt.Println(\"nums        :\", nums)\n\n\tevens, odds := nums[:3], nums[3:]\n\n\tfmt.Println(\"evens       :\", evens)\n\tfmt.Println(\"odds        :\", odds)\n\n\tfmt.Println(\"middle      :\", nums[2:4])\n\tfmt.Println(\"first 2     :\", nums[:2])\n\tfmt.Println(\"last 2      :\", nums[len(nums)-2:])\n\n\tfmt.Println(\"evens last 1:\", evens[len(evens)-1:])\n\tfmt.Println(\"odds last 2 :\", odds[len(odds)-2:])\n}\n"
  },
  {
    "path": "16-slices/exercises/14-slicing-by-args/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Slicing by arguments\n//\n//   We've a []string, you will get arguments from the command-line,\n//   then you will print only the elements that are requested.\n//\n//   1. Print the []string (it's in the code below)\n//\n//   2. Get the starting and stopping positions from the command-line\n//\n//   3. Print the []string slice by slicing it using the starting and stopping\n//      positions\n//\n//   4. Handle the error cases (see the expected output below)\n//\n//   5. Add new elements to the []string slice literal.\n//      Your program should work without changing the rest of the code.\n//\n//   6. Now, play with your program, get a deeper sense of how the slicing\n//      works.\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    Provide only the [starting] and [stopping] positions\n//\n//\n//  (error because: we expect only two arguments)\n//\n//  go run main.go 1 2 4\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    Provide only the [starting] and [stopping] positions\n//\n//\n//  (error because: starting index >= 0 && stopping pos <= len(slice) )\n//\n//  go run main.go -1 5\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    Wrong positions\n//\n//\n//  (error because: starting <= stopping)\n//\n//  go run main.go 3 2\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    Wrong positions\n//\n//\n//  go run main.go 0\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    [Normandy Verrikan Nexus Warsaw]\n//\n//\n//  go run main.go 1\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    [Verrikan Nexus Warsaw]\n//\n//\n//  go run main.go 2\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    [Nexus Warsaw]\n//\n//\n//  go run main.go 3\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    [Warsaw]\n//\n//\n//  go run main.go 4\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    []\n//\n//\n//  go run main.go 0 3\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    [Normandy Verrikan Nexus]\n//\n//\n//  go run main.go 1 3\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    [Verrikan Nexus]\n//\n//\n//  go run main.go 1 2\n//    [\"Normandy\" \"Verrikan\" \"Nexus\" \"Warsaw\"]\n//\n//    [Verrikan]\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// uncomment the slice below\n\t// ships := []string{\"Normandy\", \"Verrikan\", \"Nexus\", \"Warsaw\"}\n}\n"
  },
  {
    "path": "16-slices/exercises/14-slicing-by-args/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tships := []string{\"Normandy\", \"Verrikan\", \"Nexus\", \"Warsaw\"}\n\n\tfmt.Printf(\"%q\\n\\n\", ships)\n\n\tfrom, to := 0, len(ships)\n\n\tswitch poss := os.Args[1:]; len(poss) {\n\tdefault:\n\t\tfallthrough\n\tcase 0:\n\t\tfmt.Println(\"Provide only the [starting] and [stopping] positions\")\n\t\treturn\n\tcase 2:\n\t\tto, _ = strconv.Atoi(poss[1])\n\t\tfallthrough\n\tcase 1:\n\t\tfrom, _ = strconv.Atoi(poss[0])\n\t}\n\n\tif l := len(ships); from < 0 || from > l || to > l || from > to {\n\t\tfmt.Println(\"Wrong positions\")\n\t\treturn\n\t}\n\n\tfmt.Println(ships[from:to])\n}\n"
  },
  {
    "path": "16-slices/exercises/15-slicing-housing-prices/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Slicing the Housing Prices\n//\n//  We have received housing prices. Your task is to print only the requested\n//  columns of data (see the expected output).\n//\n//  1. Separate the data by the newline (\"\\n\") -> rows\n//\n//  2. Separate each row of the data by the separator (\",\") -> columns\n//\n//  3. Find the from and to positions inside the columns depending\n//     on the command-line arguments.\n//\n//  4. Print only the requested column headers and their data\n//\n//\n// RESTRICTIONS\n//\n//  + You should use slicing when printing the columns.\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//    Location       Size           Beds           Baths          Price\n//\n//    New York       100            2              1              100000\n//    New York       150            3              2              200000\n//    Paris          200            4              3              400000\n//    Istanbul       500            10             5              1000000\n//\n//\n//  go run main.go Location\n//    Location       Size           Beds           Baths          Price\n//\n//    New York       100            2              1              100000\n//    New York       150            3              2              200000\n//    Paris          200            4              3              400000\n//    Istanbul       500            10             5              1000000\n//\n//\n//  NOTE : Finds the position of the Size column and slices the columns\n//         appropriately.\n//\n//  go run main.go Size\n//    Size           Beds           Baths          Price\n//\n//    100            2              1              100000\n//    150            3              2              200000\n//    200            4              3              400000\n//    500            10             5              1000000\n//\n//\n//  NOTE : Finds the positions of the Size and Baths columns and\n//         slices the columns appropriately.\n//\n//  go run main.go Size Baths\n//    Size           Beds           Baths\n//\n//    100            2              1\n//    150            3              2\n//    200            4              3\n//    500            10             5\n//\n//\n//  go run main.go Beds Price\n//    Beds           Baths          Price\n//\n//    2              1              100000\n//    3              2              200000\n//    4              3              400000\n//    10             5              1000000\n//\n//\n//  Note : It works even if the given column name does not exist.\n//\n//  go run main.go Beds NotExist\n//    Beds           Baths          Price\n//\n//    2              1              100000\n//    3              2              200000\n//    4              3              400000\n//    10             5              1000000\n//\n//\n//  go run main.go NotExist NotExist\n//    Location       Size           Beds           Baths          Price\n//\n//    New York       100            2              1              100000\n//    New York       150            3              2              200000\n//    Paris          200            4              3              400000\n//    Istanbul       500            10             5              1000000\n//\n//\n// Note : It works even if the Price's index > Size's index\n//\n//        In that case, it resets the invalid starting position to 0.\n//\n//        But it still uses the Size column.\n//\n//  go run main.go Price Size\n//    Location       Size\n//\n//    New York       100\n//    New York       150\n//    Paris          200\n//    Istanbul       500\n//\n//\n// HINTS\n//\n//  + strings.Split function can separate a string into a []string\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\tdata = `Location,Size,Beds,Baths,Price\nNew York,100,2,1,100000\nNew York,150,3,2,200000\nParis,200,4,3,400000\nIstanbul,500,10,5,1000000`\n\n\t\tseparator = \",\"\n\t)\n}\n"
  },
  {
    "path": "16-slices/exercises/15-slicing-housing-prices/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\tconst (\n\t\tdata = `Location,Size,Beds,Baths,Price\nNew York,100,2,1,100000\nNew York,150,3,2,200000\nParis,200,4,3,400000\nIstanbul,500,10,5,1000000`\n\n\t\tseparator = \",\"\n\t)\n\n\t// parse the data\n\trows := strings.Split(data, \"\\n\")\n\tcols := strings.Split(rows[0], separator)\n\n\t// default case: slice for all the columns\n\tfrom, to := 0, len(cols)\n\n\t// find the from and to positions depending on the command-line arguments\n\targs := os.Args[1:]\n\tfor i, v := range cols {\n\t\tl := len(args)\n\n\t\tif l >= 1 && v == args[0] {\n\t\t\tfrom = i\n\t\t}\n\n\t\tif l == 2 && v == args[1] {\n\t\t\tto = i + 1 // +1 because the stopping index is a position\n\t\t}\n\t}\n\n\t// \"from\" cannot be greater than or equal to \"to\": reset invalid arg to 0\n\tif from >= to {\n\t\tfrom = 0\n\t}\n\n\tfor i, row := range rows {\n\t\tcols := strings.Split(row, separator)\n\n\t\t// print only the requested columns\n\t\tfor _, h := range cols[from:to] {\n\t\t\tfmt.Printf(\"%-15s\", h)\n\t\t}\n\t\tfmt.Println()\n\n\t\t// print extra new line for the header\n\t\tif i == 0 {\n\t\t\tfmt.Println()\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "16-slices/exercises/16-internals-backing-array-fix/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Fix the backing array problem\n//\n//  Ensure that changing the elements of the `mine` slice\n//  does not change the elements of the `nums` slice.\n//\n//\n// CURRENT OUTPUT (INCORRECT)\n//\n//  Mine         : [-50 -100 -150 25 30 50]\n//  Original nums: [-50 -100 -150]\n//\n//\n// EXPECTED OUTPUT\n//\n//  Mine         : [-50 -100 -150]\n//  Original nums: [56 89 15]\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DON'T TOUCH THE FOLLOWING CODE\n\tnums := []int{56, 89, 15, 25, 30, 50}\n\n\t// ----------------------------------------\n\t// ONLY ADD YOUR CODE HERE\n\t//\n\t// Ensure that nums slice never changes even though\n\t// the mine slice changes.\n\tmine := nums\n\t// ----------------------------------------\n\n\t// DON'T TOUCH THE FOLLOWING CODE\n\t//\n\t// This code changes the elements of the nums\n\t// slice.\n\t//\n\tmine[0], mine[1], mine[2] = -50, -100, -150\n\n\tfmt.Println(\"Mine         :\", mine)\n\tfmt.Println(\"Original nums:\", nums[:3])\n}\n"
  },
  {
    "path": "16-slices/exercises/16-internals-backing-array-fix/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tnums := []int{56, 89, 15, 25, 30, 50}\n\n\t// ----------------------------------------\n\t// breaks the connection:\n\t// mine and nums now have different backing arrays\n\n\t// verbose solution:\n\t// var mine []int\n\t// mine = append(mine, nums[:3]...)\n\n\t// better solution (almost the same thing):\n\tmine := append([]int(nil), nums[:3]...)\n\t// ----------------------------------------\n\n\tmine[0], mine[1], mine[2] = -50, -100, -150\n\tfmt.Println(\"Mine         :\", mine)\n\tfmt.Println(\"Original nums:\", nums[:3])\n}\n"
  },
  {
    "path": "16-slices/exercises/17-internals-backing-array-sort/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Sort the backing array\n//\n//  1. Sort only the middle 3 items.\n//\n//  2. All the slices should see your changes.\n//\n//\n// RESTRICTION\n//\n//  Do not sort manually. Sort by using the sort package.\n//\n//\n// EXPECTED OUTPUT\n//\n//  Original: [pacman mario tetris doom galaga frogger asteroids simcity metroid defender rayman tempest ultima]\n//\n//  Sorted  : [pacman mario tetris doom galaga asteroids frogger simcity metroid defender rayman tempest ultima]\n//\n//\n// HINT:\n//\n//   Middle items are         : [frogger asteroids simcity]\n//\n//   After sorting they become: [asteroids frogger simcity]\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\titems := []string{\n\t\t\"pacman\", \"mario\", \"tetris\", \"doom\", \"galaga\", \"frogger\",\n\t\t\"asteroids\", \"simcity\", \"metroid\", \"defender\", \"rayman\",\n\t\t\"tempest\", \"ultima\",\n\t}\n\n\tfmt.Println(\"Original:\", items)\n\t// ADD YOUR CODE HERE\n\tfmt.Println()\n\tfmt.Println(\"Sorted  :\", items)\n}\n"
  },
  {
    "path": "16-slices/exercises/17-internals-backing-array-sort/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sort\"\n)\n\nfunc main() {\n\titems := []string{\n\t\t\"pacman\", \"mario\", \"tetris\", \"doom\", \"galaga\", \"frogger\",\n\t\t\"asteroids\", \"simcity\", \"metroid\", \"defender\", \"rayman\",\n\t\t\"tempest\", \"ultima\",\n\t}\n\n\tfmt.Println(\"Original:\", items)\n\n\tmid := len(items) / 2\n\tsmid := items[mid-1 : mid+2]\n\n\t// sorting the smid will affect the items\n\t// as well. their backing array is the same.\n\tsort.Strings(smid)\n\n\tfmt.Println()\n\tfmt.Println(\"Sorted  :\", items)\n}\n"
  },
  {
    "path": "16-slices/exercises/18-internals-slice-header/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n\t\"runtime/debug\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Observe the memory allocations\n//\n//  In this exercise, your goal is to observe the memory allocation\n//  differences between arrays and slices.\n//\n//  You will create, assign arrays and slices then you will print\n//  the memory usage of your program on each step.\n//\n//  Please follow the instructions inside the code.\n//\n//\n// EXPECTED OUTPUT\n//\n//  Note that, your memory usage numbers may vary. However, the size of the\n//  arrays and slices should be the same on your own system as well\n//  (if you're on a 64-bit machine).\n//\n//\n//  [initial memory usage]\n//          > Memory Usage: 104 KB\n//  [after declaring an array]\n//          > Memory Usage: 78235 KB\n//  [after copying the array]\n//          > Memory Usage: 156365 KB\n//  [inside passArray]\n//          > Memory Usage: 234495 KB\n//  [after slicings]\n//          > Memory Usage: 234497 KB\n//  [inside passSlice]\n//          > Memory Usage: 234497 KB\n//\n//  Array's size : 80000000 bytes.\n//  Array2's size: 80000000 bytes.\n//  Slice1's size: 24 bytes.\n//  Slice2's size: 24 bytes.\n//  Slice3's size: 24 bytes.\n//\n//\n// HINTS\n//\n//  I've declared a few functions to help you.\n//\n//    report function:\n//    - Prints the memory usage.\n//    - Just call it with a message that matches to the expected output.\n//\n//    passArray function:\n//    - It automatically prints the memory usage.\n//    - Accepts a [size]int array, so you can pass your array to it.\n//\n//    passSlice function:\n//    - It automatically prints the memory usage.\n//    - Accepts an int slice, so you can pass it one of your slices.\n//\n// ---------------------------------------------------------\n\nconst size = 1e7\n\nfunc main() {\n\t// don't worry about this code.\n\t// it stops the garbage collector: prevents cleaning up the memory.\n\t// see the link if you're curious:\n\t// https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)\n\tdebug.SetGCPercent(-1)\n\n\t// run the program to see the initial memory usage.\n\treport(\"initial memory usage\")\n\n\t// 1. allocate an array with 10 million int elements\n\t//    the array's size will be equal to ~80MB\n\t//    hint: use the `size` constant above.\n\n\t// 2. print the memory usage (use the report func).\n\n\t// 3. copy the array to a new array.\n\n\t// 4. print the memory usage\n\n\t// 5. pass the array to the passArray function\n\n\t// 6. convert one of the arrays to a slice\n\n\t// 7. slice only the first 1000 elements of the array\n\n\t// 8. slice only the elements of the array between 1000 and 10000\n\n\t// 9. print the memory usage (report func)\n\n\t// 10. pass the one of the slices to the passSlice function\n\n\t// 11. print the sizes of the arrays and slices\n\t//     hint: use the unsafe.Sizeof function\n\t//     see more here: https://golang.org/pkg/unsafe/#Sizeof\n}\n\n// passes [size]int array — about 80MB!\n//\n// observe that passing an array to a function (or assigning it to a variable)\n// affects the memory usage dramatically\nfunc passArray(items [size]int) {\n\titems[0] = 100\n\treport(\"inside passArray\")\n}\n\n// only passes 24-bytes of slice header\n//\n// observe that passing a slice doesn't affect the memory usage\nfunc passSlice(items []int) {\n\titems[0] = 100\n\treport(\"inside passSlice\")\n}\n\n// reports the current memory usage\n// don't worry about this code\nfunc report(msg string) {\n\tvar m runtime.MemStats\n\truntime.ReadMemStats(&m)\n\tfmt.Printf(\"[%s]\\n\", msg)\n\tfmt.Printf(\"\\t> Memory Usage: %v KB\\n\", m.Alloc/1024)\n}\n"
  },
  {
    "path": "16-slices/exercises/18-internals-slice-header/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n\t\"runtime/debug\"\n\t\"unsafe\"\n)\n\nconst size = 1e7\n\nfunc main() {\n\tdebug.SetGCPercent(-1)\n\n\treport(\"initial memory usage\")\n\n\tvar array [size]int\n\treport(\"after declaring an array\")\n\n\tarray2 := array\n\treport(\"after copying the array\")\n\n\tpassArray(array)\n\n\tslice1 := array[:]\n\tslice2 := array[:1e3]\n\tslice3 := array[1e3:1e4]\n\treport(\"after slicings\")\n\n\tpassSlice(slice3)\n\n\tfmt.Println()\n\tfmt.Printf(\"Array's size : %d bytes.\\n\", unsafe.Sizeof(array))\n\tfmt.Printf(\"Array2's size: %d bytes.\\n\", unsafe.Sizeof(array2))\n\tfmt.Printf(\"Slice1's size: %d bytes.\\n\", unsafe.Sizeof(slice1))\n\tfmt.Printf(\"Slice2's size: %d bytes.\\n\", unsafe.Sizeof(slice2))\n\tfmt.Printf(\"Slice3's size: %d bytes.\\n\", unsafe.Sizeof(slice3))\n}\n\nfunc passArray(items [size]int) {\n\titems[0] = 100\n\treport(\"inside passArray\")\n}\n\nfunc passSlice(items []int) {\n\treport(\"inside passSlice\")\n}\n\nfunc report(msg string) {\n\tvar m runtime.MemStats\n\truntime.ReadMemStats(&m)\n\tfmt.Printf(\"[%s]\\n\", msg)\n\tfmt.Printf(\"\\t> Memory Usage: %v KB\\n\", m.Alloc/1024)\n}\n"
  },
  {
    "path": "16-slices/exercises/19-observe-len-cap/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Observe the length and capacity\n//\n//  Follow the instructions inside the code below to\n//  gain more intuition about the length and capacity of a slice.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// --- #1 ---\n\t// 1. create a new slice named: games\n\t//\n\t// 2. print the length and capacity of the games slice\n\t//\n\t// 3. comment out the games slice\n\t//    then declare it as an empty slice\n\t//\n\t// 4. print the length and capacity of the games slice\n\t//\n\t// 5. append the elements: \"pacman\", \"mario\", \"tetris\", \"doom\"\n\t//\n\t// 6. print the length and capacity of the games slice\n\t//\n\t// 7. comment out everything\n\t//\n\t// 8. declare the games slice again using a slice literal\n\t//    (use the same elements from step 5)\n\n\t// --- #2 ---\n\t// 1. use a loop from 0 to 4 to slice the games slice, element by element.\n\t//\n\t// 2. print its length and capacity along the way (in the loop).\n\n\tfmt.Println()\n\t// for ... {\n\t// \tfmt.Printf(\"games[:%d]'s len: %d cap: %d\\n\", ...)\n\t// }\n\n\t// --- #3 ---\n\t// 1. slice the games slice up to zero element\n\t//    (save the result to a new slice named: \"zero\")\n\t//\n\t// 2. print the games and the new slice's len and cap\n\t//\n\t// 3. append a new element to the new slice\n\t//\n\t// 4. print the new slice's lens and caps\n\t//\n\t// 5. repeat the last two steps 5 times (use a loop)\n\t//\n\t// 6. notice the growth of the capacity after the 5th append\n\t//\n\t// Use this slice's elements to append to the new slice:\n\t// []string{\"ultima\", \"dagger\", \"pong\", \"coldspot\", \"zetra\"}\n\tfmt.Println()\n\n\t// zero := ...\n\t// fmt.Printf(\"games's     len: %d cap: %d\\n\", ...)\n\t// fmt.Printf(\"zero's      len: %d cap: %d\\n\", ...)\n\n\t// for ... {\n\t//   ...\n\t//   fmt.Printf(\"zero's      len: %d cap: %d\\n\", ...)\n\t// }\n\n\t// --- #4 ---\n\t// using a range loop, slice the zero slice element by element,\n\t// and print its length and capacity along the way.\n\t//\n\t// observe that, the range loop only loops for the length, not the cap.\n\tfmt.Println()\n\n\t// for ... {\n\t//   s := zero[:n]\n\t//   fmt.Printf(\"zero[:%d]'s  len: %d cap: %d\\n\", ...)\n\t// }\n\n\t// --- #5 ---\n\t// 1. do the 3rd step above again but this time, start by slicing\n\t//    the zero slice up to its capacity (use the cap function).\n\t//\n\t// 2. print the elements of the zero slice in the loop.\n\tfmt.Println()\n\n\t// zero = ...\n\t// for ... {\n\t//   fmt.Printf(\"zero[:%d]'s  len: %d cap: %d - %q\\n\", ...)\n\t// }\n\n\t// --- #6 ---\n\t// 1. change the one of the elements of the zero slice\n\t//\n\t// 2. change the same element of the games slice\n\t//\n\t// 3. print the games and the zero slices\n\t//\n\t// 4. observe that they don't have the same backing array\n\tfmt.Println()\n\t// ...\n\t// fmt.Printf(\"zero  : %q\\n\", zero)\n\t// fmt.Printf(\"games : %q\\n\", games)\n\n\t// --- #7 ---\n\t// try to slice the games slice beyond its capacity\n}\n"
  },
  {
    "path": "16-slices/exercises/19-observe-len-cap/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// --- #1 ---\n\t// var games []string\n\t// fmt.Printf(\"games's len    : %d cap: %d\\n\", len(games), cap(games))\n\n\t// games := []string{}\n\t// fmt.Printf(\"games's len    : %d cap: %d\\n\", len(games), cap(games))\n\n\t// games = append(games, \"pacman\", \"mario\", \"tetris\", \"doom\")\n\t// fmt.Printf(\"games's len    : %d cap: %d\\n\", len(games), cap(games))\n\n\tgames := []string{\"pacman\", \"mario\", \"tetris\", \"doom\"}\n\tfmt.Printf(\"games's len    : %d cap: %d\\n\", len(games), cap(games))\n\n\t// --- #2 ---\n\tfmt.Println()\n\n\tfor i := 0; i <= len(games); i++ {\n\t\ts := games[:i]\n\t\tfmt.Printf(\"games[:%d]'s len: %d cap: %d\\n\", i, len(s), cap(s))\n\t}\n\n\t// --- #3 ---\n\tfmt.Println()\n\n\tzero := games[:0]\n\tfmt.Printf(\"games's     len: %d cap: %d\\n\", len(games), cap(games))\n\tfmt.Printf(\"zero's      len: %d cap: %d\\n\", len(zero), cap(zero))\n\n\tfor _, v := range []string{\"ultima\", \"dagger\", \"pong\", \"coldspot\", \"zetra\"} {\n\t\tzero = append(zero, v)\n\t\tfmt.Printf(\"zero's      len: %d cap: %d\\n\", len(zero), cap(zero))\n\t}\n\n\t// --- #4 ---\n\tfmt.Println()\n\n\tfor n := range zero {\n\t\ts := zero[:n]\n\t\tfmt.Printf(\"zero[:%d]'s  len: %d cap: %d\\n\", n, len(s), cap(s))\n\t}\n\n\t// --- #5 ---\n\tfmt.Println()\n\n\tzero = zero[:cap(zero)]\n\tfor n := range zero {\n\t\ts := zero[:n]\n\t\tfmt.Printf(\"zero[:%d]'s  len: %d cap: %d - %q\\n\", n, len(s), cap(s), s)\n\t}\n\n\t// --- #6 ---\n\tfmt.Println()\n\n\tzero[0] = \"command & conquer\"\n\tgames[0] = \"red alert\"\n\tfmt.Printf(\"zero  : %q\\n\", zero)\n\tfmt.Printf(\"games : %q\\n\", games)\n\n\t// --- #7 ---\n\t// uncomment and see the error.\n\t// _ = games[:cap(games)+1]\n\t// or:\n\t// _ = games[:5]\n}\n"
  },
  {
    "path": "16-slices/exercises/20-observe-the-cap-growth/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Observe the capacity growth\n//\n//  Write a program that appends elements to a slice\n//  10 million times in a loop. Observe how the capacity of\n//  the slice changes.\n//\n//\n// STEPS\n//\n//  1. Create a nil slice\n//\n//  2. Loop 1e7 times\n//\n//  3. On each iteration: Append an element to the slice\n//\n//  4. Print the length and capacity of the slice \"only\"\n//     when its capacity changes.\n//\n//  BONUS: Print also the growth rate of the capacity.\n//\n//\n// EXPECTED OUTPUT\n//\n//  len:0               cap:0               growth:NaN\n//  len:1               cap:1               growth:+Inf\n//  len:2               cap:2               growth:2.00\n//  ... and so on.\n//\n// ---------------------------------------------------------\n\nfunc main() {}\n"
  },
  {
    "path": "16-slices/exercises/20-observe-the-cap-growth/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tnums   []int\n\t\toldCap float64\n\t)\n\n\t// loop 10 million times\n\tfor len(nums) < 1e7 {\n\t\t// get the capacity\n\t\tc := float64(cap(nums))\n\n\t\t// only print when the capacity changes\n\t\tif c == 0 || c != oldCap {\n\t\t\t// print also the growth ratio: c/oldCap\n\t\t\tfmt.Printf(\"len:%-15d cap:%-15g growth:%-15.2f\\n\",\n\t\t\t\tlen(nums), c, c/oldCap)\n\t\t}\n\n\t\t// keep track of the previous capacity\n\t\toldCap = c\n\n\t\t// append an arbitrary element to the slice\n\t\tnums = append(nums, 1)\n\t}\n}\n"
  },
  {
    "path": "16-slices/exercises/21-correct-the-lyric/hints.md",
    "content": "# Hints\n\nYou can use the following slice operations to solve the exercise:\n\n+ Prepends \"value\" to the slice:\n  ```go\n  slice = append([]string{\"value\"}, slice...)\n  ```\n\n+ Appends some part (N to M) of the same slice to itself:\n  ```go\n  slice = append(slice, slice[N:M]...)\n  ```\n+ Copies the last part of the slice starting from M to the first part of the slice until N:\n  ```go\n  slice = append(slice[:N], slice[M:]...)\n  ```\n"
  },
  {
    "path": "16-slices/exercises/21-correct-the-lyric/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Correct the lyric\n//\n//  You have a slice that contains the words of Beatles'\n//  legendary song: Yesterday. However, the order of the\n//  words are incorrect.\n//\n// CURRENT OUTPUT\n//\n//  [all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay]\n//\n// EXPECTED OUTPUT\n//\n//  [yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday]\n//\n//\n// STEPS\n//\n//  INITIAL SLICE:\n//    [all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay]\n//\n//\n//  1. Prepend \"yesterday\" to the `lyric` slice.\n//\n//     RESULT SHOULD BE:\n//     [yesterday all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay]\n//\n//\n//  2. Put the words to the correct positions in the `lyric` slice.\n//\n//     RESULT SHOULD BE:\n//     [yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday]\n//\n//\n//  3. Print the `lyric` slice.\n//\n//\n// BONUS\n//\n//   + Think about when does the append allocate a new backing array.\n//\n//   + Check whether your conclusions are correct.\n//\n//\n// HINTS\n//\n//   If you get stuck, check out the hints.md file.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DON'T TOUCH THIS:\n\tlyric := strings.Fields(`all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay`)\n\n\t// ADD YOUR CODE BELOW:\n\t// ...\n\tfmt.Printf(\"%s\\n\", lyric)\n}\n"
  },
  {
    "path": "16-slices/exercises/21-correct-the-lyric/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// --- Correct Lyric ---\n\t// yesterday all my troubles seemed so far away\n\t// now it looks as though they are here to stay\n\t// oh I believe in yesterday\n\tlyric := strings.Fields(`all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay`)\n\n\t// ------------------------------------------------------------------------\n\t// #1: Prepend \"yesterday\" to `lyric`\n\t// ------------------------------------------------------------------------\n\n\t//\n\t// --- BEFORE ---\n\t// all my troubles seemed so far away oh I believe in yesterday\n\t//\n\t// --- AFTER ---\n\t// yesterday all my troubles seemed so far away oh I believe in yesterday\n\t//\n\t// (warning: allocates a new backing array)\n\t//\n\tlyric = append([]string{\"yesterday\"}, lyric...)\n\n\t// ------------------------------------------------------------------------\n\t// #2: Put the words to the correct positions in the `lyric` slice.\n\t// ------------------------------------------------------------------------\n\n\t//\n\t// yesterday all my troubles seemed so far away oh I believe in yesterday\n\t//                                              |               |\n\t//                                              v               v\n\t//                                       index: 8          pos: 13\n\t//\n\tconst N, M = 8, 13\n\n\t// --- BEFORE ---\n\t//\n\t// yesterday all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay\n\t//\n\t// --- AFTER ---\n\t// yesterday all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay oh I believe in yesterday\n\t//                                              ^\n\t//\n\t//                                              |\n\t//                                              +--- duplicate\n\t//\n\t// (warning: allocates a new backing array)\n\tlyric = append(lyric, lyric[N:M]...)\n\n\t//\n\t// --- BEFORE ---\n\t// yesterday all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay oh I believe in yesterday\n\t//\n\t// --- AFTER ---\n\t// yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday\n\t//\n\t// (does not allocate a new backing array because cap(lyric[:N]) > M)\n\t//\n\tlyric = append(lyric[:N], lyric[M:]...)\n\n\t// ------------------------------------------------------------------------\n\t// #3: Print\n\t// ------------------------------------------------------------------------\n\tfmt.Printf(\"%s\\n\", lyric)\n}\n"
  },
  {
    "path": "16-slices/exercises/22-adv-ops-practice/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Practice advanced slice operations\n//\n//  Please follow the directions in the following code.\n//\n//  To see the expected output, please run:\n//\n//    go run solution/main.go\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ########################################################\n\t//\n\t// #1: Create a string slice: `names` with a length and\n\t//     capacity of 5, and print it.\n\t//\n\t//\n\t// ...\n\t// s.Show(\"1st step\", names)\n\n\t// ########################################################\n\t//\n\t// #2: Append the following names to the names slice:\n\t//\n\t//     \"einstein\", \"tesla\", \"aristotle\"\n\t//\n\t//     Print the names slice.\n\t//\n\t//     Observe how the slice and its backing array change.\n\t//\n\t//\n\t// ...\n\t// s.Show(\"2nd step\", names)\n\n\t// ########################################################\n\t//\n\t// #3: Overwrite the name slice by creating a new slice\n\t//     using make().\n\t//\n\t//     Adjust the make() function so that it creates a\n\t//     slice with capacity of 5, and puts the slice pointer\n\t//     to the first index.\n\t//\n\t//     Then append the following names to the slice:\n\t//\n\t//     \"einstein\", \"tesla\", \"aristotle\"\n\t//\n\t//     Expected output:\n\t//     [\"einstein\", \"tesla\", \"aristotle\" \"\" \"\"]\n\t//\n\t//\n\t// ...\n\t// s.Show(\"3rd step\", names)\n\n\t// ########################################################\n\t//\n\t// #4: Copy only the first two elements of the following\n\t//     array to the last two elements of the `names` slice.\n\t//\n\t//     Print the names slice, you should see 5 elements.\n\t//     So, do not forget extending the slice.\n\t//\n\t//     Observe how its backing array stays the same.\n\t//\n\t//\n\t// Array (uncomment):\n\t// moreNames := [...]string{\"plato\", \"khayyam\", \"ptolemy\"}\n\t//\n\t// ...\n\t//\n\t// s.Show(\"4th step\", names)\n\n\t// ########################################################\n\t//\n\t// #5:  Only copy the last 3 elements of the `names` slice\n\t//      to a new slice: `clone`.\n\t//\n\t//     Append the first two elements of the `names` to the\n\t//    `clone`.\n\t//\n\t//     Ensure that after appending no new backing array\n\t//     allocations occur for the `clone` slice.\n\t//\n\t//     Print the clone slice before and after the append.\n\t//\n\t//\n\t// ...\n\t// s.Show(\"5th step (before append)\", clone)\n\t//\n\t// ...\n\t// s.Show(\"5th step (after append)\", clone)\n\n\t// ########################################################\n\t//\n\t// #6: Slice the `clone` slice between 2nd and 4th (inclusive)\n\t//     elements into a new slice: `sliced`.\n\t//\n\t//     Append \"hypatia\" to the `sliced`.\n\t//\n\t//     Ensure that new backing array allocation \"occurs\".\n\t//\n\t//       Change the 3rd element of the `clone` slice\n\t//       to \"elder\".\n\t//\n\t//       Doing so should not change any elements of\n\t//       the `sliced` slice.\n\t//\n\t//     Print the `clone` and `sliced` slices.\n\t//\n\t//\n\t// ...\n\t// s.Show(\"6th step\", clone, sliced)\n}\n\n//\n// Don't mind about this function.\n//\n// For printing the slices: You can either use the\n// prettyslice package or `fmt.Printf`.\n//\nfunc init() {\n\ts.PrintBacking = true // prints the backing array\n\ts.MaxPerLine = 10     // prints 10 slice elements per line\n\ts.Width = 60          // prints 60 character per line\n}\n"
  },
  {
    "path": "16-slices/exercises/22-adv-ops-practice/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\t// ########################################################\n\t//\n\t// #1: Create a string slice: `names` with a length and\n\t//     capacity of 5, and print it.\n\t//\n\tnames := make([]string, 5)\n\ts.Show(\"1st step\", names)\n\n\t// ########################################################\n\t//\n\t// #2: Append the following names to the names slice:\n\t//\n\t//     \"einstein\", \"tesla\", \"aristotle\"\n\t//\n\t//     Print the names slice.\n\t//\n\t//     Observe how the slice and its backing array change.\n\t//\n\t//     Expected output:\n\t//     [\"\" \"\" \"\" \"\" \"\" \"einstein\", \"tesla\", \"aristotle\"]\n\t//\n\tnames = append(names, \"einstein\", \"tesla\", \"aristotle\")\n\ts.Show(\"2nd step\", names)\n\n\t// ########################################################\n\t//\n\t// #3: Overwrite the name slice by creating a new slice\n\t//     using make().\n\t//\n\t//     Adjust the make() function so that it creates a\n\t//     slice with capacity of 5, and puts the slice pointer\n\t//     to the first index.\n\t//\n\t//     Then append the following names to the slice:\n\t//\n\t//     \"einstein\", \"tesla\", \"aristotle\"\n\t//\n\t//     Expected output:\n\t//     [\"einstein\", \"tesla\", \"aristotle\" \"\" \"\"]\n\t//\n\t//     So: Overwrite and print the names slice.\n\t//\n\tnames = make([]string, 0, 5)\n\tnames = append(names, \"einstein\", \"tesla\", \"aristotle\")\n\ts.Show(\"3rd step\", names)\n\n\t// ########################################################\n\t//\n\t// #4: Copy only the first two elements of the following\n\t//     array to the last two elements of the `names` slice.\n\t//\n\t//     Print the names slice, you should see 5 elements.\n\t//     So, do not forget extending the slice.\n\t//\n\t//     Observe how its backing array stays the same.\n\t//\n\tmoreNames := [...]string{\"plato\", \"khayyam\", \"ptolemy\"}\n\tcopy(names[3:5], moreNames[:2])\n\tnames = names[:cap(names)]\n\n\ts.Show(\"4th step\", names)\n\n\t// ########################################################\n\t//\n\t// #5:  Only copy the last 3 elements of the `names` slice\n\t//      to a new slice: `clone`.\n\t//\n\t//     Append the first two elements of the `names` to the\n\t//    `clone`.\n\t//\n\t//     Ensure that after appending no new backing array\n\t//     allocations occur for the `clone` slice.\n\t//\n\t//     Print the clone slice before and after the append.\n\t//\n\tclone := make([]string, 3, 5)\n\tcopy(clone, names[len(names)-3:])\n\ts.Show(\"5th step (before append)\", clone)\n\n\tclone = append(clone, names[:2]...)\n\ts.Show(\"5th step (after append)\", clone)\n\n\t// ########################################################\n\t//\n\t// #6: Slice the `clone` slice between 2nd and 4th (inclusive)\n\t//     elements into a new slice: `sliced`.\n\t//\n\t//     Append \"hypatia\" to the `sliced`.\n\t//\n\t//     Ensure that new backing array allocation \"occurs\".\n\t//\n\t//       Change the 3rd element of the `clone` slice\n\t//       to \"elder\".\n\t//\n\t//       Doing so should not change any elements of\n\t//       the `sliced` slice.\n\t//\n\t//     Print the `clone` and `sliced` slices.\n\t//\n\t//\n\tsliced := clone[1:4:4]\n\tsliced = append(sliced, \"hypatia\")\n\tclone[2] = \"elder\"\n\n\ts.Show(\"6th step\", clone, sliced)\n}\n\n//\n// Don't mind about this function.\n//\n// For printing the slices: You can either use the\n// prettyslice package or `fmt.Printf`.\n//\nfunc init() {\n\ts.PrintBacking = true // prints the backing array\n\ts.MaxPerLine = 10     // prints 10 slice elements per line\n\ts.Width = 60          // prints 60 character per line\n}\n"
  },
  {
    "path": "16-slices/exercises/23-limit-the-backing-array-sharing/api/api.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage api\n\nvar temps = []int{5, 10, 3, 25, 45, 80, 90}\n\n// Read returns a slice of elements from the temps slice.\nfunc Read(start, stop int) []int {\n\t// ----------------------------------------\n\t// RESTRICTIONS — ONLY ADD YOUR CODE IN THIS AREA\n\n\tportion := temps[start:stop]\n\n\t// RESTRICTIONS — ONLY ADD YOUR CODE IN THIS AREA\n\t// ----------------------------------------\n\n\treturn portion\n}\n\n// All returns the temps slice\nfunc All() []int {\n\treturn temps\n}\n"
  },
  {
    "path": "16-slices/exercises/23-limit-the-backing-array-sharing/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/inancgumus/learngo/16-slices/exercises/23-limit-the-backing-array-sharing/api\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Limit the backing array sharing\n//\n//  GOAL\n//\n//    Limit the capacity of the slice that is returned\n//    from the `Read` function. Read on for more details.\n//\n//\n//  BEFORE YOU START\n//\n//    In this exercise: API means the api package. It's in the\n//    api folder. You need to change the code in the `api/api.go`\n//    to solve this exercise, and you need import the api\n//    package.\n//\n//\n//  WHAT IS THE PROBLEM?\n//\n//    `Read` function of the api package returns a portion of\n//    its `temps` slice. Below, `main()` saves it to the\n//    `received` slice.\n//\n//    `main()` appends to the `received` slice but doing so\n//    also changes the backing array of the `temps` slice.\n//    We don't want that.\n//\n//    `main()` can change the part of the `temps` slice\n//    that is returned from the `Read()`, but it shouldn't\n//    be able to change the elements in the rest of the\n//    `temps`.\n//\n//\n//  WHAT YOU NEED TO DO?\n//\n//    So you need to limit the capacity of the returned\n//    slice somehow. Remember: `received` and `temps`\n//    share the same backing array. So, appending to it\n//    can overwrite the same backing array.\n//\n//\n// CURRENT\n//\n//                           | |\n//                           v v\n//   api.temps     : [5 10 3 1 3 80 90]\n//   main.received : [5 10 3 1 3]\n//                           ^ ^ append changes the `temps`\n//                               slice's backing array.\n//\n//\n//\n// EXPECTED\n//\n//   The corrected api package does not allow the `main()` to\n//   change unreturned portion of the temps slice's backing array.\n//                           |  |\n//                           v  v\n//   api.temps     : [5 10 3 25 45 80 90]\n//   main.received : [5 10 3 1 3]\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// DO NOT CHANGE ANYTHING IN THIS CODE.\n\n\t// get the first three elements from api.temps\n\treceived := api.Read(0, 3)\n\n\t// append changes the api package's temps slice's\n\t// backing array as well.\n\treceived = append(received, []int{1, 3}...)\n\n\tfmt.Println(\"api.temps     :\", api.All())\n\tfmt.Println(\"main.received :\", received)\n}\n"
  },
  {
    "path": "16-slices/exercises/23-limit-the-backing-array-sharing/solution/api/api.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage api\n\nvar temps = []int{5, 10, 3, 25, 45, 80, 90}\n\n// Read returns a slice of elements from the temps slice.\nfunc Read(start, stop int) []int {\n\t//\n\t// The third index prevents the `main()` from\n\t// overwriting the original temps slice's\n\t// backing array. It limits the capacity of the\n\t// returned slice. See the full slice expressions\n\t// lecture for more details.\n\t//\n\tportion := temps[start:stop:stop]\n\n\treturn portion\n}\n\n// All returns the temps slice\nfunc All() []int {\n\treturn temps\n}\n"
  },
  {
    "path": "16-slices/exercises/23-limit-the-backing-array-sharing/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/inancgumus/learngo/16-slices/exercises/23-limit-the-backing-array-sharing/solution/api\"\n)\n\nfunc main() {\n\treceived := api.Read(0, 3)\n\n\treceived = append(received, []int{1, 3}...)\n\n\tfmt.Println(\"api.temps     :\", api.All())\n\tfmt.Println(\"main.received :\", received)\n}\n"
  },
  {
    "path": "16-slices/exercises/24-fix-the-memory-leak/api/api.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage api\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"runtime\"\n)\n\n// DO NOT TOUCH THIS FILE BUT YOU CAN READ IT\n\n// Read returns a huge slice (allocates ~65 MB of memory)\nfunc Read() []int {\n\t// 2 << 22 means 2^(22 + 1)\n\t// See this: https://en.wikipedia.org/wiki/Arithmetic_shift\n\n\t// Perm function returns a slice with random integers in it.\n\t// Here it returns a slice with random integers that contains\n\t// 8,388,608 elements. One int value is 8 bytes.\n\t// So: 8,388,608 * 8 = ~65MB\n\treturn rand.Perm(2 << 22)\n}\n\n// Report cleans the memory and prints the current memory usage\n// Don't worry about this code. You don't need to understand it.\n//\n// However, if you're curious, read on.\n//\n// The following code runs the garbage collector to clean\n// up the allocated resources, and then it reads the current\n// memory statistics into the m variable.\nfunc Report() {\n\tvar m runtime.MemStats\n\truntime.GC()\n\truntime.ReadMemStats(&m)\n\tfmt.Printf(\" > Memory Usage: %v KB\\n\", m.Alloc/1024)\n}\n"
  },
  {
    "path": "16-slices/exercises/24-fix-the-memory-leak/hints.md",
    "content": "# Hints\n\n+ `millions` slice's backing array uses 65 MB of memory.\n\n+ `make` a new slice with 10 elements with a new backing array.\n\n  + `copy` the last 10 elements of the `millions` slice to the new slice.\n\n  + So you will have slice with a new backing array only with 10 elements.\n\n  + Then overwrite the `millions` slice by simply `assigning` `last10` slice to it.\n\n+ **Remember:** slice ~= pointer to a backing array.\n\n  If you overwrite the slice, it will lose that\n  pointer. So Go can collect the unused memory."
  },
  {
    "path": "16-slices/exercises/24-fix-the-memory-leak/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\n\t\"github.com/inancgumus/learngo/16-slices/exercises/24-fix-the-memory-leak/api\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Fix the memory leak\n//\n//  WARNING\n//\n//    This is a very difficult exercise. You need to\n//    do some research on your own to solve it. Please don't\n//    get discouraged if you can't solve it yet.\n//\n//\n//  GOAL\n//\n//    In this exercise, your goal is to reduce the memory\n//    usage. To do that, you need to find and fix the memory\n//    leak within `main()`.\n//\n//\n//  PROBLEM\n//\n//    `main()` calls `api.Report()` that reports the current\n//    memory usage.\n//\n//    After that, `main()` calls `api.Read()` that returns\n//    a slice with 10 millions of elements. But you only need\n//    the last 10 elements of the returned slice.\n//\n//\n//  WHAT YOU NEED TO DO\n//\n//    You only need to change the code in `main()`. Please\n//    do not touch the code in `api/api.go`.\n//\n//\n//  CURRENT OUTPUT\n//\n//    > Memory Usage: 113 KB\n//\n//    Last 10 elements: [...]\n//\n//    > Memory Usage: 65651 KB\n//\n//      + Before `api.Read()` call: It uses 113 KB of memory.\n//\n//      + After `api.Read()` call : It uses  65 MB of memory.\n//\n//      + This means that, `main()` never releases the memory.\n//        This is the leak.\n//\n//      + Your goal is to release the unused memory. Remember,\n//        you only need 10 elements but in the current code\n//        below you have a slice with 10 millions of elements.\n//\n//\n//  EXPECTED OUTPUT\n//\n//    > Memory Usage: 116 KB\n//\n//    Last 10 elements: [...]\n//\n//    > Memory Usage: 118 KB\n//\n//      + In the expected output, `main()` releases the memory.\n//\n//        It no longer uses 65 MB of memory. Instead, it only\n//        uses 118 KB of memory. That's why the second\n//        `api.Report()` call reports 118 KB.\n//\n//\n//  ADDITIONAL NOTE\n//\n//    Memory leak means: Your program is using unnecessary\n//    computer memory. It doesn't release memory that is\n//    no longer needed.\n//\n//    See this for more information:\n//    https://en.wikipedia.org/wiki/Memory_leak\n//\n//\n//  HINTS\n//\n//    Check out `hints.md` file if you get stuck.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// reports the initial memory usage\n\tapi.Report()\n\n\t// returns a slice with 10 million elements.\n\t// it allocates 65 MB of memory space.\n\tmillions := api.Read()\n\n\t// -----------------------------------------------------\n\t// ✪ ONLY CHANGE THE CODE IN THIS AREA ✪\n\n\tlast10 := millions[len(millions)-10:]\n\n\tfmt.Printf(\"\\nLast 10 elements: %d\\n\\n\", last10)\n\n\t// ✪ ONLY CHANGE THE CODE IN THIS AREA ✪\n\t// -----------------------------------------------------\n\n\tapi.Report()\n\n\t// don't worry about this code.\n\tfmt.Fprintln(ioutil.Discard, millions[0])\n}\n"
  },
  {
    "path": "16-slices/exercises/24-fix-the-memory-leak/solution/api/api.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage api\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"runtime\"\n)\n\n// DO NOT TOUCH THIS FILE BUT YOU CAN READ IT\n\n// Read returns a huge slice (allocates ~65 MB of memory)\nfunc Read() []int {\n\t// 2 << 22 means 2^(22 + 1)\n\t// See this: https://en.wikipedia.org/wiki/Arithmetic_shift\n\n\t// Perm function returns a slice with random integers in it.\n\t// Here it returns a slice with random integers that contains\n\t// 8,388,608 elements. One int value is 8 bytes.\n\t// So: 8,388,608 * 8 = ~65MB\n\treturn rand.Perm(2 << 22)\n}\n\n// Report cleans the memory and prints the current memory usage\n// Don't worry about this code. You don't need to understand it.\n//\n// However, if you're curious, read on.\n//\n// The following code runs the garbage collector to clean\n// up the allocated resources, and then it reads the current\n// memory statistics into the m variable.\nfunc Report() {\n\tvar m runtime.MemStats\n\truntime.GC()\n\truntime.ReadMemStats(&m)\n\tfmt.Printf(\" > Memory Usage: %v KB\\n\", m.Alloc/1024)\n}\n"
  },
  {
    "path": "16-slices/exercises/24-fix-the-memory-leak/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\n\t\"github.com/inancgumus/learngo/16-slices/exercises/24-fix-the-memory-leak/solution/api\"\n)\n\nfunc main() {\n\t// reports the initial memory usage\n\tapi.Report()\n\n\t// returns a slice with 10 million elements.\n\t// it allocates 65 MB of memory space.\n\tmillions := api.Read()\n\n\t// ------------------------------------------------------\n\n\t// SOLUTION #1:\n\t// Copy the last 10 elements of the returned slice\n\t// to a new slice. This will create a new backing array\n\t// only with 10 elements.\n\tlast10 := make([]int, 10)\n\tcopy(last10, millions[len(millions)-10:])\n\n\t// Make the millions slice lose reference to its backing array\n\t// so that its backing array can be cleaned up from memory.\n\tmillions = last10\n\n\t// SOLUTION #2:\n\t// Similar to the 1st solution. It does the same thing.\n\t// But this code is more concise. Use this one.\n\n\t// millions = append([]int(nil), millions[len(millions)-10:]...)\n\n\tfmt.Printf(\"\\nLast 10 elements: %d\\n\\n\", last10)\n\n\t// ------------------------------------------------------\n\n\tapi.Report()\n\n\t// don't worry about this code yet.\n\tfmt.Fprintln(ioutil.Discard, millions[0])\n}\n"
  },
  {
    "path": "16-slices/exercises/25-add-lines/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Add a newline after each sentence\n//\n//  You have a slice that contains Beatles' awesome song:\n//  Yesterday. You want to add newlines after each sentence.\n//\n//  So, create a new slice and copy every words into it. Lastly,\n//  after each sentence, add a newline character ('\\n').\n//\n//\n// ORIGINAL SLICE:\n//\n//   [yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday]\n//\n// EXPECTED SLICE (NEW):\n//\n//   [yesterday all my troubles seemed so far \\n away now it looks as though they are here to stay \\n oh I believe in yesterday \\n]\n//\n//\n// CURRENT OUTPUT\n//\n//  yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday\n//\n// EXPECTED OUTPUT\n//\n//  yesterday all my troubles seemed so far away\n//  now it looks as though they are here to stay\n//  oh I believe in yesterday\n//\n//\n// RESTRICTIONS\n//\n//  + Don't use `append()`, use `copy()` instead.\n//\n//  + Don't cheat like this:\n//\n//    fmt.Println(lyric[:8])\n//    fmt.Println(lyric[8:18])\n//    fmt.Println(lyric[18:23])\n//\n//  + Create a new slice that contains the sentences\n//    with line endings.\n//\n//\n// NOTE\n//\n// If the program does not work, please update your\n// local copy of the prettyslice package:\n//\n//   go get -u github.com/inancgumus/prettyslice\n//\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// You need to add a newline after each sentence in another slice.\n\t// Don't touch the following code.\n\tlyric := strings.Fields(`yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday`)\n\n\t// ===================================\n\t//\n\t// ~~~ CHANGE THIS CODE ~~~\n\t//\n\tfix := lyric\n\t//\n\t// ===================================\n\n\t// Currently, it prints every sentence on the same line.\n\t// Don't touch the following code.\n\ts.Show(\"fix slice\", fix)\n\n\tfor _, w := range fix {\n\t\tfmt.Print(w)\n\t\tif w != \"\\n\" {\n\t\t\tfmt.Print(\" \")\n\t\t}\n\t}\n}\n\nfunc init() {\n\t//\n\t// YOU DON'T NEED TO TOUCH THIS\n\t//\n\t// This initializes some options for the prettyslice package.\n\t// You can change the options if you want.\n\t//\n\t// This code runs before the main function above.\n\t//\n\t// s.Colors(false)     // if your editor is light background color then enable this\n\t//\n\ts.PrintBacking = true  // prints the backing arrays\n\ts.MaxPerLine = 5       // prints max 15 elements per line\n\ts.SpaceCharacter = '⏎' // print this instead of printing a newline (for debugging)\n}\n"
  },
  {
    "path": "16-slices/exercises/25-add-lines/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nfunc main() {\n\tlyric := strings.Fields(`yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday`)\n\n\t// `+3` because we're going to add 3 newline characters to the fix slice.\n\tfix := make([]string, len(lyric)+3)\n\n\t//\n\t// USE A SLICE TO STORE WHERE EACH SENTENCE ENDS\n\t//\n\t// + The first sentence has 8 words so its cutting index is 8.\n\t//\n\t//   yesterday all my troubles seemed so far away now it looks as though they are here to stay\n\t//                                               |\n\t//                                               v\n\t//                                cutting index: 8\n\t//\n\t//\n\t// + The second sentence has 10 words so its cutting index is 10.\n\t//\n\t//   now it looks as though they are here to stay oh I believe in yesterday\n\t//                                               |\n\t//                                               v\n\t//                                cutting index: 10\n\t//\n\t//\n\t// + The last sentence has 5 words so its cutting index is 5.\n\t//\n\t//   oh I believe in yesterday\n\t//                            |\n\t//                            v\n\t//             cutting index: 5\n\t//\n\tcutpoints := []int{8, 10, 5}\n\n\t//\n\t// `n` tracks how much we've moved inside the `lyric` slice.\n\t//\n\t// `i` tracks the sentence that we're on.\n\t//\n\tfor i, n := 0, 0; n < len(lyric); i++ {\n\t\t//\n\t\t// copy to `fix` from the `lyric`\n\t\t//\n\t\t//   destination:\n\t\t//     fix[n+i] because we don't want to delete the previous copy.\n\t\t//     it moves sentence by sentence, using the cutpoints.\n\t\t//\n\t\t//   source:\n\t\t//     lyric[n:n+cutpoints[i]] because we want copy the next sentence\n\t\t//     beginning from the number of the last copied elements to the\n\t\t//     n+next cutpoint (the next sentence).\n\t\t//\n\t\tn += copy(fix[n+i:], lyric[n:n+cutpoints[i]])\n\n\t\t//\n\t\t// add a newline after each sentence.\n\t\t//\n\t\t// notice that the '\\n' position slides as we move over.\n\t\t// that's why it's: `n+i`.\n\t\t//\n\t\tfix[n+i] = \"\\n\"\n\n\t\t// uncomment to see how the fix slice changes.\n\t\t// s.Show(\"fix slice\", fix)\n\t}\n\n\ts.Show(\"fix slice\", fix)\n\n\t// print the sentences\n\tfor _, w := range fix {\n\t\tfmt.Print(w)\n\t\tif w != \"\\n\" {\n\t\t\tfmt.Print(\" \")\n\t\t}\n\t}\n}\n\nfunc init() {\n\t//\n\t// YOU DON'T NEED TO TOUCH THIS\n\t//\n\t// This initializes some options for the prettyslice package.\n\t// You can change the options if you want.\n\t//\n\t// This code runs before the main function above.\n\t//\n\t// s.Colors(false)     // if your editor is light background color then enable this\n\ts.PrintBacking = true  // prints the backing arrays\n\ts.MaxPerLine = 5       // prints max 15 elements per line\n\ts.SpaceCharacter = '⏎' // print this instead of printing a newline (for debugging)\n}\n"
  },
  {
    "path": "16-slices/exercises/26-print-daily-requests/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Print daily requests\n//\n//  You've got request logs of a web server. The log data\n//  contains 8-hourly totals per each day. It is stored\n//  in the `reqs` slice.\n//\n//  Find and print the total requests per day, as well as\n//  the grand total.\n//\n//  See the `reqs` slice and the steps in the code below.\n//\n//\n// RESTRICTIONS\n//\n//   1. You need to produce the daily slice, don't just loop\n//      and print the element totals directly. The goal is\n//      gaining more experience in slice operations.\n//\n//   2. Your code should work even if you add to or remove the\n//      existing elements from the `reqs` slice.\n//\n//      For example, after solving the exercise, try it with\n//      this new data:\n//\n//      reqs := []int{\n// \t      500, 600, 250,\n// \t      200, 400, 50,\n// \t      900, 800, 600,\n// \t      750, 250, 100,\n// \t      150, 654, 235,\n// \t      320, 534, 765,\n// \t      121, 876, 285,\n// \t      543, 642,\n// \t      // the last element is missing (your code should be able to handle this)\n// \t      // that is why you shouldn't calculate the `size` below manually.\n//      }\n//\n//      The grand total of the new data should be 10525.\n//\n//\n// EXPECTED OUTPUT\n//\n//   Please run `solution/main.go` to see the expected\n//   output.\n//\n//   go run solution/main.go\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// There are 3 request totals per day (8-hourly)\n\tconst N = 3\n\n\t// DAILY REQUESTS DATA (8-HOURLY TOTALS PER DAY)\n\treqs := []int{\n\t\t500, 600, 250, // 1st day: 1350 requests\n\t\t200, 400, 50, // 2nd day: 650 requests\n\t\t900, 800, 600, // 3rd day: 2300 requests\n\t\t750, 250, 100, // 4th day: 1100 requests\n\t\t// grand total: 5400 requests\n\t}\n\n\t// ================================================\n\t// #1: Make a new slice with the exact size needed.\n\n\t_ = reqs // remove this when you start\n\n\tsize := 0 // you need to find the size.\n\tdaily := make([][]int, 0, size)\n\n\t// ================================================\n\n\t// ================================================\n\t// #2: Group the `reqs` per day into the slice: `daily`.\n\t//\n\t// So the daily will be:\n\t// [\n\t//  [500, 600, 250]\n\t//  [200, 400, 50]\n\t//  [900, 800, 600]\n\t//  [750, 250, 100]\n\t// ]\n\n\t_ = daily // remove this when you start\n\n\t// ================================================\n\t// #3: Print the results\n\n\t// Print a header\n\tfmt.Printf(\"%-10s%-10s\\n\", \"Day\", \"Requests\")\n\tfmt.Println(strings.Repeat(\"=\", 20))\n\n\t// Loop over the daily slice and its inner slices to find\n\t// the daily totals and the grand total.\n\t// ...\n\n\t// ================================================\n}\n"
  },
  {
    "path": "16-slices/exercises/26-print-daily-requests/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// There are 3 request totals per day\n\tconst N = 3\n\n\t// DAILY REQUESTS DATA (PER 8-HOUR)\n\treqs := []int{\n\t\t500, 600, 250, // 1st day: 1350 requests\n\t\t200, 400, 50, // 2nd day: 650 requests\n\t\t900, 800, 600, // 3rd day: 2300 requests\n\t\t750, 250, 100, // 4th day: 1100 requests\n\t\t// grand total: 5400 requests\n\t}\n\n\t// ALSO TRY IT WITH THIS DATA:\n\t// reqs = []int{\n\t// \t500, 600, 250,\n\t// \t200, 400, 50,\n\t// \t900, 800, 600,\n\t// \t750, 250, 100,\n\t// \t150, 654, 235,\n\t// \t320, 534, 765,\n\t// \t121, 876, 285,\n\t// \t543, 642,\n\t// }\n\n\t// ================================================\n\t// Allocate a slice efficiently with the exact size needed.\n\t//\n\t// Find the `size` automatically using the `reqs` slice.\n\t// Do not type it manually.\n\t//\n\tl := len(reqs)\n\tsize := l / N\n\tif l%N != 0 {\n\t\tsize++\n\t}\n\tdaily := make([][]int, 0, size)\n\t//\n\t// ================================================\n\n\t// ================================================\n\t// Group the `reqs` per day into the slice: `daily`.\n\t//\n\t// So the daily will be:\n\t// [\n\t//  [500, 600, 250]\n\t//  [200, 400, 50]\n\t//  [900, 800, 600]\n\t//  [750, 250, 100]\n\t// ]\n\t//\n\tfor N <= len(reqs) {\n\t\tdaily = append(daily, reqs[:N]) // append the daily requests\n\t\treqs = reqs[N:]                 // move the slice pointer for the next day\n\t}\n\n\t// add the residual data\n\tif len(reqs) > 0 {\n\t\tdaily = append(daily, reqs)\n\t}\n\n\t// ================================================\n\n\t// ================================================\n\t// Print the header\n\tfmt.Printf(\"%-10s%-10s\\n\", \"Day\", \"Requests\")\n\tfmt.Println(strings.Repeat(\"=\", 20))\n\n\t// Print the data per day along with the totals\n\tvar grand int\n\n\tfor i, day := range daily {\n\t\tvar sum int\n\n\t\tfor _, req := range day {\n\t\t\tsum += req\n\t\t\tfmt.Printf(\"%-10d%-10d\\n\", i+1, req)\n\t\t}\n\n\t\tfmt.Printf(\"%9s %-10d\\n\\n\", \"TOTAL:\", sum)\n\n\t\tgrand += sum\n\t}\n\n\tfmt.Printf(\"%9s %-10d\\n\", \"GRAND:\", grand)\n\t// ================================================\n}\n"
  },
  {
    "path": "16-slices/exercises/README.md",
    "content": "# Slice Exercises\n\n## Exercises Level I - Basics — Warm-Up\n\nLet's reinforce your basic knowledge of slices.\n\n1. **[Declare nil slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/01-declare-nil)**\n\n2. **[Assign empty slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/02-empty)**\n\n3. **[Assign slice literals](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/03-slice-literal)**\n\n4. **[Declare the arrays as slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/04-declare-arrays-as-slices)**\n\n5. **[Fix the Problems](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/05-fix-the-problems)**\n\n6. **[Compare the slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/06-compare-the-slices)**\n\n---\n\n## Exercises Level II - Appending\n\nDiscover the power of the append function.\n\n1. **[Append #1 — Append and compare byte slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/07-append)**\n\n2. **[Append #2 — Append to a nil slice](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/08-append-2)**\n\n3. **[Append #3 — Fix the problems](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/09-append-3-fix)**\n\n4. **[Append and Sort Numbers](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/10-append-sort-nums)**\n\n5. **[Housing Prices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/11-housing-prices)**\n\n6. **[Housing Prices and Averages](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/12-housing-prices-averages)**\n\n\n---\n\n## Exercises Level III - Slicing\n\nDiscover the power of slicing.\n\n1. **[Slice the numbers](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/13-slicing-basics)**\n\n2. **[Slicing by arguments](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/14-slicing-by-args)**\n\n3. **[Slicing the Housing Prices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/15-slicing-housing-prices)**\n\n---\n\n## Exercises Level IV - Internals\n\nPeek into the internals of the slices and gain more insight. This is necessary for complete command of the slices.\n\n1. **[Fix the backing array problems](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/16-internals-backing-array-fix)**\n\n2. **[Sort the backing array](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/17-internals-backing-array-sort)**\n\n3. **[Observe the memory allocations](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/18-internals-slice-header)**\n\n4. **[Observe the length and capacity](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/19-observe-len-cap)**\n\n5. **[Observe the capacity growth](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/20-observe-the-cap-growth)**\n\n6. **[Correct the lyric](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/21-correct-the-lyric)**\n\n---\n\n## Exercises Level V - Advanced Operations\n\nCommonly used and more advanced operations are available to slices. Now, it's time to test yourself and fix some common problems.\n\n★ WARNING ★\nPlease update your local copy of the prettyslice package for some examples to work. [Please find the intructions how to do so here](../README.md).\n\n1. **[Practice Advanced Slice Operations](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/22-adv-ops-practice)**\n\n    Let's warm you up for the advanced slice operations, and reinforce your neurons.\n\n2. **[Limit the backing array sharing](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/23-limit-the-backing-array-sharing)**\n\n    Your package needs to control the slices that it shares with the outside world.\n\n3. **[Fix the Memory Leak](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/24-fix-the-memory-leak)**\n\n    A slice retrieved from a package causes a memory leak in your program. You need to fix it.\n\n4. **[Add a newline after each sentence](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/25-add-lines)**\n\n    Use the power of the `copy()` function and add newlines into a new buffer from a string slice. This exercise is more tricky than you might think.\n\n5. **[Print Daily Requests](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/26-print-daily-requests)**\n\n    Group the web request logs into a multi-dimensional slice. Allocate a slice with the exact size needed by doing some wizardary calculations. And lastly, pretty print the result.\n"
  },
  {
    "path": "16-slices/questions/1-slices-vs-arrays.md",
    "content": "# Slices vs Arrays Quiz\n\n## Why you want to use a slice instead of an array?\n1. I like arrays more\n2. I want to create a dynamic collection, so I need an array\n3. A slice's length is dynamic, so I can create dynamic collections *CORRECT*\n\n\n## Where does the length of a slice belong to?\n1. Compile-Time\n2. Runtime *CORRECT*\n3. Walk-Time\n4. Sleep-Time\n\n> **2:** A slice's length is not a part of its type. So its length can change at runtime.\n\n\n## Which function call below is correct?\n```go\n// Let's say there's a function like this.\nfunc sort(nums []int) {\n    // ...\n}\n```\n1. sort([...]int{3, 1, 6})\n2. sort([]int32{3, 1, 6})\n3. sort([]int{3, 1, 6}) *CORRECT*\n\n> **1:** You can't call the sort function using an array. It expects an int slice.\n> \n> **2:** You can't call the sort function using an int32 slice. It expects an int slice.\n> \n> **3:** That's right! You can pass an int slice to the sort function.\n\n\n## What is the zero value of this slice?\n```go\nvar tasks []string\n```\n1. 0\n2. 1\n3. nil *CORRECT*\n4. unknown\n\n> **3:** This is a nil slice. Unlike an array, a slice's zero value is nil.\n\n\n## What does this code print?\n```go\nvar tasks []string\nfmt.Println(len(tasks))\n```\n\n1. 0 *CORRECT*\n2. 1\n3. nil\n4. It doesn't work.\n\n> **1:** Yes, you can use the len function on a nil slice. It returns 0 because the slice doesn't contain any elements yet.\n\n\n## What does this code print?\n```go\nvar tasks []string\nfmt.Println(tasks[0])\n```\n\n1. 0\n2. 1\n3. nil\n4. It doesn't work. *CORRECT*\n\n> **4:** You can't get an element that does not exist. A nil slice does not contain any elements.\n\n\n## Which declaration below is a correct slice declaration?\n1. [...]int{}\n2. [2]string{\"hello\", \"world\"}\n3. []string{\"hello\", \"world\"} *CORRECT*\n4. string[2]{\"hello\", world\"}\n\n\n## This code doesn't work, why?\n```go\ncolors := []string{\"red\", \"blue\", \"green\"}\ntones := []string{\"dark\", \"light\"}\n\nif colors == tones {\n    // ...\n}\n```\n\n1. The slices have different lengths\n2. If statement doesn't contain any statements\n3. Slices cannot be compared *CORRECT*\n\n> **3:** That's right! A slice value can only be compared to a nil value.\n\n\n## What is the length of this slice?\n```go\n[]uint64{}\n```\n\n1. 64\n2. 1\n3. 0 *CORRECT*\n4. Error\n\n> **3:** That's right. This is an empty slice, it doesn't contain any elements.\n\n\n## What is the length of this slice?\n```go\n[]string{\"I'm\", \"going\", \"to\", \"stay\", \"\\\"here\\\"\"}\n```\n\n1. 0\n2. 1\n3. 2\n4. 3\n5. 4\n6. 5 *CORRECT*\n"
  },
  {
    "path": "16-slices/questions/2-appending.md",
    "content": "# Appending Quiz\n\n## How does the append function work?\n1. It appends new elements to the given slice on the fly and returns a new slice, normally, it doesn't change the given slice *CORRECT*\n2. It appends new elements to the given slice and returns the existing slice\n3. It appends new elements to the given slice and returns a new slice, it also changes the given slice\n\n> **1:** Yes, the append function doesn't change the given slice unless you overwrite the result of the append function back to the original slice.  Most of the times, this is true.\n>\n> **2:** It doesn't return the existing slice, it returns a new slice. That's why you usually save the result of the append back to the original slice.\n> \n> **3:** It doesn't change the given slice, it creates and returns a new slice. Most of the times, this is true.\n\n\n## When you call the append function, where does it append the new elements?\n1. It appends them at the beginning of the given slice\n2. It appends them at the middle of the given slice\n3. It appends them after the length of the given slice *CORRECT*\n\n> **3:** Yes! The append function appends the new elements by looking at the length of the given slice and then returns a new slice with the newly appended elements.\n\n\n## What's the problem with the following code?\n```go\nnums := []int{9, 7, 5}\nappend(nums, []int{2, 4, 6}...)\n\nfmt.Println(nums[3])\n```\n1. It can't append to an int slice\n2. It can't append a slice to another slice\n3. It tries to get an element that doesn't exist yet *CORRECT*\n\n> **3:** That's right. The append function returns a new slice with the newly added elements. But here, the code doesn't save the result of the append, so the nums slice only has 3 elements. So, `nums[3]` is invalid, because there are only 3 elements in the nums slice.\n\n\n## What does this program print?\n```go\nnums := []int{9, 7, 5}\nevens := append(nums, []int{2, 4, 6}...)\n\nfmt.Println(nums, evens)\n```\n1. [9 7 5] [2 4 6]\n2. [9 7 5] [9 7 5 2 4 6] *CORRECT*\n3. [9 7 5 2 4 6] [2 4 6]\n4. [9 7 5 2 4 6] [9 7 5 2 4 6]\n\n> **2:** It appends the new elements to the nums slice but it saves the returned slice to the evens slice. So, the nums slice doesn't change. That's why, it prints the original elements from the nums slice first, then it prints the evens slice with the newly added elements.\n>\n> **3, 4:** It doesn't save the result of the append call back into the nums slice, so the nums slice doesn't contain the new elements.\n\n\n## What does this program print?\n```go\nnums := []int{9, 7, 5}\nnums = append(nums, 2, 4, 6)\n\nfmt.Println(nums)\n```\n1. [9 7 5 2 4 6] *CORRECT*\n2. [9 7 5]\n3. [2 4 6]\n4. [2 4 6 9 7 5]\n\n> **1:** It overwrites the nums slice with the new slice that is returned from the append function. So the nums slice has got the newly appended elements."
  },
  {
    "path": "16-slices/questions/3-slicing.md",
    "content": "# Slicing Quiz\n\n## What does this code print?\n```go\nnums := []int{9, 7, 5}\nnums = append(nums, 2, 4, 6)\n\nfmt.Println(nums[2:4])\n```\n1. [9 7 5 2 4 6]\n2. [5 2] *CORRECT*\n3. [4 6]\n4. [7 2]\n5. [9 7]\n\n> **2:** nums is [9 7 5 2 4 6]. So, nums[2:4] is [5 2]. Remember, in nums[2:4] -> 2 is the starting index, so nums[2] is 5; And 4 is the stopping position, so nums[4-1] is 2 (-1 because the stopping position is the element position). So, nums[2:4] returns a new slice that contains the elements at the middle of the nums slice.\n\n\n## What does this code print?\n```go\nnums := []int{9, 7, 5}\nnums = append(nums, 2, 4, 6)\n\nfmt.Println(nums[:2])\n```\n1. [9 7 5 2 4 6]\n2. [5 2]\n3. [4 6]\n4. [7 2]\n5. [9 7] *CORRECT*\n\n> **5:** nums is [9 7 5 2 4 6]. So, nums[:2] is nums[0:2] which in turn returns [9 7].\n\n\n## What does this code print?\n```go\nnums := []int{9, 7, 5}\nnums = append(nums, 2, 4, 6)\n\nfmt.Println(nums[len(nums)-2:])\n```\n1. [9 7 5 2 4 6]\n2. [5 2]\n3. [4 6] *CORRECT*\n4. [7 2]\n5. [9 7]\n\n> **3:** nums is [9 7 5 2 4 6]. So, nums[len(nums)-2:] is nums[4:6] (len(nums) is 6) which in turn returns [4 6].\n\n\n## What does this code print?\n```go\nnames := []string{\"einstein\", \"rosen\", \"newton\"}\nnames = names[:]\nfmt.Println(names[:1])\n```\n1. [einstein rosen newton]\n2. [einstein rosen]\n3. [einstein] *CORRECT*\n4. []\n\n> **3:** names[:] is names[0:3] -> [einstein rosen newton]. names[:1] is names[0:1] -> [einstein].\n\n\n## What is the type of the marked expression below?\n```go\nnames := []string{\"einstein\", \"rosen\", \"newton\"}\nnames[2:3] // <- marked\n```\n\n1. []string *CORRECT*\n2. string\n3. names\n4. []int\n\n> **1:** Yes! A slicing expression returns a slice.\n> \n> **2:** Remember, a slicing expression returns a slice. Did I give you the answer? Oops.\n\n\n## What is the type of the marked expression below?\n```go\nnames := []string{\"einstein\", \"rosen\", \"newton\"}\nnames[2] // <- marked\n```\n\n1. []string\n2. string *CORRECT*\n3. names\n4. []int\n\n> **1:** Remember, an index expression returns an element value, not a slice.\n> \n> **2:** Yep! An index expression returns an element value. The element type of the []string slice is string, so the returned value is a string value.\n\n\n## Which index expression returns the \"rosen\" element?\n```go\nnames := []string{\"einstein\", \"rosen\", \"newton\"}\nnames = names[1:len(names) - 1]\n```\n1. names[0] *CORRECT*\n2. names[1]\n3. names[2]\n\n> **1:** That's right: names2 is [\"rosen\"] after the slicing.\n> \n> **2:** That's not right. Remember, indexes are relative to a slice. names is [\"einstein\" \"rosen\" \"newton\"] but names[1:len(names)-1] is [\"rosen\"]. So, names2[1] is an error, it's because, the length of the last slice is 1.\n\n\n## What does this code print?\n```go\nnames := []string{\"einstein\", \"rosen\", \"newton\"}\nnames = names[1:]\nnames = names[1:]\nfmt.Println(names)\n```\n1. [einstein rosen newton]\n2. [rosen newton]\n3. [newton] *CORRECT*\n4. []\n\n> **3:** Remember, slicing returns a new slice. Here, each `names = names[1:]` statement overwrites the names slice with the newly returned slice from the slicing. At first, the names was [einstein rosen newton]. After the first slicing, the names becomes [rosen newton]. After the second slicing, names becomes [newton]. See this for the complete explanation: https://play.golang.org/p/EsEHrSeByFR\n\n\n## What does this code print?\n```go\ni := 2\ns := fmt.Sprintf(\"i = %d * %d = %d\", i, i, i*i)\nfmt.Print(s)\n```\n\n1. i = i * i = i*i\n2. i = %d * %d = %d\n3. i = 2 * 2 = 2\n4. i = 2 * 2 = 4 *CORRECT*\n\n> **4:** Awesome! Sprintf works just like Printf. Instead of printing the result to standard out (usually to command-line prompt), it returns a string value."
  },
  {
    "path": "16-slices/questions/4-backing-array.md",
    "content": "# Backing Array Quiz\n\n## Where does a slice store its elements?\n1. In the slice value\n2. In a global backing array that is shared by all the slices\n3. In a backing array that is specific to a slice\n4. In a backing array that the slice references *CORRECT*\n\n> **1:** A slice value doesn't store any elements. It's just a simple data structure.\n> \n> **2:** There is not a global backing array.\n> \n> **3:** A backing array can be shared among slices. It may not be specific to a slice.\n> \n> **4:** Yep! A slice stores its elements in a backing that the slice references (or points to).\n> \n\n\n## When you slice a slice, what value does it return?\n```go\n// example:\ns := []string{\"I'm\", \"a\", \"slice\"}\ns[2:] // <-- slicing\n```\n1. It returns a new slice value with a new backing array\n2. It returns the existing slice value with a new backing array\n3. It returns a new slice value with the same backing array *CORRECT*\n\n> **3:** Yes! Slicing returns a new slice that references to some segment of the same backing array.\n\n\n## Why are slicing and indexing a slice efficient?\n1. Slices are fast\n2. Backing arrays are contiguous in memory *CORRECT*\n3. Go uses clever algorithms\n\n> **2:** Yes. A slice's backing array is contiguous in memory. So, accessing an element of a slice is very fast. Go can look at a specific memory location to find an element's value very fast.\n\n\n## Which one is the backing array of \"slice2\"?\n```go\narr := [...]int{1, 2, 3}\nslice1 := arr[2:3]\nslice2 := slice1[:1]\n```\n\n1. arr *CORRECT*\n2. slice1\n3. slice2\n4. A hidden backing array\n\n> **1:** Yes! When a slice is created by slicing an array, that array becomes the backing array of that slice.\n> \n> **4:** Nope. That only happens when a slice doesn't being created from an array.\n>\n\n\n## Which one is the backing array of \"slice\"?\n```go\narr := [...]int{1, 2, 3}\nslice := []int{1, 2, 3}\n```\n\n1. arr\n2. slice1\n3. slice2\n4. A hidden backing array *CORRECT*\n\n> **1:** Nope, the slice hasn't created by slicing an array.\n> \n> **4:** Yes! A slice literal always creates a new hidden array.\n>\n\n\n## Which answer is correct for the following slices?\n```go\nslice1 := []int{1, 2, 3}\nslice2 := []int{1, 2, 3}\n```\n1. Their backing array is the same.\n2. Their backing arrays are different. *CORRECT*\n3. They don't have any backing arrays.\n\n> **2:** That's right. A slice literal always creates a new backing array.\n\n\n## Which answer is correct for the following slices?\n```go\nslice1 := []int{1, 2, 3}\nslice2 := []int{1, 2, 3}\nslice3 := slice1[:]\nslice4 := slice2[:]\n```\n1. slice1 and slice2 have the same backing arrays.\n2. slice1 and slice3 have the same backing arrays. *CORRECT*\n3. slice1 and slice4 have the same backing arrays.\n4. slice3 and slice4 have the same backing arrays.\n\n> **2:** Yep! A slice that is being created by slicing shares the same backing with the sliced slice. Here, slice3 is being created from slice1. That is also true for slice2 and slice4.\n\n\n## What does the backing array of the nums slice look like?\n```go\nnums := []int{9, 7, 5, 3, 1}\nnums = nums[:1]\n\t\nfmt.Println(nums) // prints: [9]\n```\n1. [9 7 5 3 1] *CORRECT*\n2. [7 5 3 1]\n3. [9]\n4. []\n\n\n## What does this code print?\n```go\narr   := [...]int{9, 7, 5, 3, 1}\nnums  := arr[2:]\nnums2 := nums[1:]\n\narr[2]++\nnums[1]  -= arr[4] - 4\nnums2[1] += 5\n\nfmt.Println(nums)\n```\n1. [5 3 1]\n2. [6 6 6] *CORRECT*\n3. [9 7 5]\n\n> **2:** Yes! Because the backing array of `nums` and `nums2` is the same: `arr`. See the explanation here: https://play.golang.org/p/xTy0W0S_8PN\n"
  },
  {
    "path": "16-slices/questions/5-slice-header.md",
    "content": "# Slice Header Quiz\n\n## What is a slice header?\n1. The first element of a slice value\n2. The first element of the backing array\n3. A tiny data structure that describes all or some part of a backing array *CORRECT*\n4. A data structure that contains the elements of a slice\n\n> **3:** Yes! It's just a tiny data structure with three numeric fields.\n> \n> **4:** A slice doesn't contain any elements on its own.\n\n\n## What are the fields of a slice value?\n1. Pointer, length, and capacity *CORRECT*\n2. Length and capacity\n3. Only a pointer\n\n\n## Which slice value does the following slice header describe?\nSLICE HEADER:\n+ Pointer : 100th\n+ Length  : 5\n+ Capacity: 10\n\nAssume that the backing array is this one:\n```go\nvar array [10]string\n```\n1. array[5:]\n2. array[:5] *CORRECT*\n3. array[3:]\n4. array[100:]\n\n> **1**: This slice's capacity is 5, it can only see the elements beginning with the 6th element.\n> \n> **2**: That's right. `array[:5]` returns a slice with the first 5 elements of the `array` (len is 5), but there are 5 more elements in the backing array of that slice, so in total its capacity is 10.\n> \n> **3**: This slice's capacity is 7, it can only see the elements beginning with the 4th element.\n> \n> **4**: This is an error. The backing array doesn't have 100 elements.\n> \n\n\n## Which one is the slice header of the following slice?\n```go\nvar tasks []string\n```\n1. Pointer: 0, Length: 0, Capacity: 0 *CORRECT*\n2. Pointer: 10, Length: 5, Capacity: 10\n3. Pointer: 0, Length: 1, Capacity: 1\n\n> **1:** A nil slice doesn't have backing array, so all the fields are equal to zero.\n\n\n## What is the total memory usage of this code?\n```go\nvar array [1000]int64\n\narray2 := array\nslice := array2[:]\n```\n\n1. 1024 bytes\n2. 2024 bytes\n3. 3000 bytes\n4. 16024 bytes *CORRECT*\n\n> **4:** `array` is 1000 x int64 (8 bytes) = 8000 bytes. Assigning an array copies all its elements, so `array2` adds additional 8000 bytes. A slice doesn't store anything on its own. Here, it's being created from array2, so it doesn't allocate a backing array as well. A slice header's size is 24 bytes. So in total: This program allocates 16024 bytes.\n\n\n## What value does this code pass to the sort.Ints function?\n```go\nnums := []int{9, 7, 5, 3, 1}\nsort.Ints(nums)\n```\n1. [9 7 5 3 1] — All the values of the nums slice\n2. A pointer to the backing array of the nums slice\n3. A pointer, length and capacity as three different arguments\n4. The slice header that is stored in the nums variable *CORRECT*\n\n> **1:** No, a slice value doesn't contain any elements. So it cannot pass the elements.\n> \n> **2:** Sorry but not only that.\n> \n> **3:** Nope. Remember, they are packed in a tiny data structure called the ....?\n> \n> **4:** Yep! A slice value is a slice header (pointer, length and capacity). A slice variable stores the slice header.\n> \n\n"
  },
  {
    "path": "16-slices/questions/6-capacity.md",
    "content": "# Capacity and Append Mechanics Quiz\n\n## What is the difference between the length and capacity of a slice?\n1. They are the same\n2. The length is always greater than the capacity\n3. The capacity is always greater than the capacity\n4. The length describes the length of a slice but a capacity describes the length of the backing array beginning from the first element of the slice *CORRECT*\n\n> **2:** The length is never greater than the capacity.\n> \n> **3:** The length and capacity of a slice can be equal.\n\n\n## What is the capacity of a nil slice?\n1. It is equal to its length + 1\n2. It is nil\n3. 0 *CORRECT*\n4. 1\n\n> **2:** The capacity's type is int, it cannot be nil.\n\n\n## What are the length and capacity of the slice value?\n```go\n[]string{\"I\", \"have\", \"a\", \"great\", \"capacity\"}\n```\n1. Length: 5 - Capacity: 5 *CORRECT*\n2. Length: 0 - Capacity: 5\n3. Length: 5 - Capacity: 10\n4. Length: 10 - Capacity: 10\n\n> **1:** That's right! A slice literal creates a new slice value with equal length and capacity.\n\n\n## What are the length and capacity of the 'words' slice?\n```go\nwords := []string{\"lucy\", \"in\", \"the\", \"sky\", \"with\", \"diamonds\"}\nwords = words[:0]\n```\n1. Length: 0 - Capacity: 0\n2. Length: 6 - Capacity: 6\n3. Length: 0 - Capacity: 6 *CORRECT*\n4. Length: 5 - Capacity: 10\n\n> **3:** Right! `words[:0]` slices for 0 elements, which in turn returns a slice with zero-length. Because the `words` slice points to the same backing array, its capacity is equal to 6.\n\n\n## What are the length and capacity of the 'words' slice?\n```go\nwords := []string{\"lucy\", \"in\", \"the\", \"sky\", \"with\", \"diamonds\"}\nwords = words[0:]\n```\n1. Length: 0 - Capacity: 0\n2. Length: 6 - Capacity: 6 *CORRECT* \n3. Length: 0 - Capacity: 6\n4. Length: 5 - Capacity: 10\n\n> **2:** Right! `words[0:]` slices for the rest of the elements, which in turn returns a slice with the same length as the original slice: 6. Beginning from the first array element, the `words` slice's backing array contains 6 elements; so its capacity is also 6.\n\n\n## What are the length and capacity of the 'words' slice?\n```go\nwords := []string{\"lucy\", \"in\", \"the\", \"sky\", \"with\", \"diamonds\"}\nwords = words[2:cap(words)-2]\n```\n1. Length: 4 - Capacity: 6\n2. Length: 6 - Capacity: 4\n3. Length: 2 - Capacity: 6\n4. Length: 2 - Capacity: 4 *CORRECT*\n\n> **4:** Right! `words[2:cap(words)-2]` is equal to `words = words[2:4]`, so it returns: `[\"the\" \"sky\"]`. So, its length is 2. But there are 4 more elements (`[\"the\" \"sky\" \"with\" \"diamonds\"]`) in the backing array, so the capacity is 4.\n\n\n"
  },
  {
    "path": "16-slices/questions/7-mechanics-of-append.md",
    "content": "# The Mechanics of Append Quiz\n\n## Which append call below allocates a new backing array for the following slice?\n```go\nwords := []string{\"lucy\", \"in\", \"the\", \"sky\", \"with\", \"diamonds\"}\n```\n1. words = append(words[:3], \"crystals\")\n2. words = append(words[:4], \"crystals\")\n3. words = append(words[:5], \"crystals\")\n4. words = append(words[:5], \"crystals\", \"and\", \"diamonds\") *CORRECT*\n\n> **1:** No, it just overwrites the 4th element.\n> \n> **2:** No, it just overwrites the 5th element.\n> \n> **3:** No, it just overwrites the last element.\n> \n> **4:** Yes, it overwrites the last element, then it adds two element. However, there is not enough space to do that, so it allocates a new backing array.\n\n\n## What does the program print?\n```go\nwords := []string{\"lucy\", \"in\", \"the\", \"sky\", \"with\", \"diamonds\"}\nwords = append(words[:1], \"is\", \"everywhere\")\nwords = append(words, words[len(words)+1:cap(words)]...)\n```\n1. lucy in the sky with diamonds\n2. lucy is everywhere in the sky with diamonds\n3. lucy is everywhere with diamonds *CORRECT*\n4. lucy is everywhere\n\n> **3:** line #2 overwrites the 2nd and 3rd elements. line #3 appends [\"with\" \"diamonds\"] after the [\"lucy\" \"is\" \"everwhere\"].\n\n\n## What are the length and capacity of the words slice?\n```go\n// The words slice has 1023 elements.\n//\n// Tip: The keyed slice works like the same as a keyed array.\n// If you don't remember how it works, please check out the keyed elements in the arrays section.\n//\nwords := []string{1022: \"\"}\nwords = append(words, \"boom!\")\n```\n1. Length: 1024 - Capacity: 1024\n2. Length: 1025 - Capacity: 1025\n3. Length: 1025 - Capacity: 1280\n4. Length: 1024 - Capacity: 2048 *CORRECT*\n\n> **4:** That's right! Append function grows by doubling the capacity of the previous slice.\n\n\n## What are the length and capacity of the words slice?\n```go\n// The words slice has 1024 elements.\n//\n// Tip: The keyed slice works like the same as a keyed array.\n// If you don't remember how it works, please check out the keyed elements in the arrays section.\n//\nwords := []string{1023: \"\"}\nwords = append(words, \"boom!\")\n```\n1. Length: 1024 - Capacity: 1024\n2. Length: 1025 - Capacity: 1025\n3. Length: 1025 - Capacity: 1280 *CORRECT*\n4. Length: 1025 - Capacity: 2048\n\n> **3, 4:** After 1024 elements, the append function grows at a slower rate, about 25%."
  },
  {
    "path": "16-slices/questions/8-advanced-ops.md",
    "content": "# Advanced Slice Operations Quiz\n\n## What are the length and capacity of the 'part' slice?\n```go\nlyric := []string{\"show\", \"me\", \"my\", \"silver\", \"lining\"}\npart  := lyric[1:3:5]\n```\n1. Length: 1 - Capacity: 5\n2. Length: 1 - Capacity: 3\n3. Length: 3 - Capacity: 5\n4. Length: 2 - Capacity: 4 *CORRECT*\n\n> **4:** General Formula: `[low:high:max]` => `length = high - max` and `capacity = max - low`. `lyric[1:3]` is `[\"me\" \"my\"]`. `lyric[1:3:5]` is `[\"me\" \"my\" \"silver\" \"lining\"]`. So, `[1:3]` is the returned slice, length: 2. `[1:3:5]` limits the capacity to four because after the 1st element there are only four more elements.\n\n\n## What are the lengths and capacities of the slices below?\n```go\nlyric := []string{\"show\", \"me\", \"my\", \"silver\", \"lining\"}\npart  := lyric[:2:2]\npart   = append(part, \"right\", \"place\")\n```\n1. lyric's len: 5, cap: 5 — part's len: 5, cap: 5\n2. lyric's len: 3, cap: 1 — part's len: 2, cap: 3\n3. lyric's len: 5, cap: 5 — part's len: 4, cap: 4 *CORRECT*\n4. lyric's len: 3, cap: 1 — part's len: 2, cap: 3\n\n> **3:** `lyric[:2:2]` = [\"show\" \"me\"]. After the append the part becomes: [\"show\" \"me\" \"right\" \"place\"] — so it allocates a new backing array. `lyric` stays the same: `[\"show\" \"me\" \"my\" \"silver\" \"lining\"]`.\n\n\n## When you might want to use the make function?\n1. To preallocate a backing array for a slice with a definite length *CORRECT*\n2. To create a slice faster\n3. To use less memory\n\n> **1:** Yes! You can use the make function to preallocate a backing array for a slice upfront.\n\n\n## What does the program print?\n```go\ntasks := make([]string, 2)\ntasks  = append(tasks, \"hello\", \"world\")\n\nfmt.Printf(\"%q\\n\", tasks)\n```\n1. [\"\" \"\" \"hello\" \"world\"] *CORRECT*\n2. [\"hello\" \"world\"]\n3. [\"hello\" \"world\" \"\" \"\"]\n\n> **1:** `make([]string, 2)` creates a slice with len: 2 and cap: 2, and it sets all the elements to their zero-values. `append()` appends after the length of the slice (after the first two elements). That's why the first two elements are zero-valued strings but the last two elements are the newly appended elements.\n\n\n## What does the program print?\n```go\ntasks := make([]string, 0, 2)\ntasks  = append(tasks, \"hello\", \"world\")\n\nfmt.Printf(\"%q\\n\", tasks)\n```\n1. [\"\" \"\" \"hello\" \"world\"]\n2. [\"hello\" \"world\"] *CORRECT*\n3. [\"hello\" \"world\" \"\" \"\"]\n\n> **2:** `make([]string, 0, 2)` creates a slice with len: 0 and cap: 2. `append()` appends after the length of the slice (at the beginning). That's why the first two elements are overwritten with the newly appended elements. This is a common usage pattern when you want to use the `make` and the `append` functions together.\n\n\n## What does the program print?\n```go\nlyric := []string{\"le\", \"vent\", \"nous\", \"portera\"}\nn := copy(lyric, make([]string, 4))\n\nfmt.Printf(\"%d %q\\n\", n, lyric)\n\n// -- USEFUL INFORMATION (but not required to solve the question) --\n//      In the following `copy` operation, `make` won't allocate\n//      a slice with a new backing array up to 32768 bytes\n//      (one string value is 8 bytes on a 64-bit machine).\n//\n//      This is an optimization made by the Go compiler.\n```\n1. 4 [\"le\" \"vent\" \"le\" \"vent\"]\n2. 4 [\"le\" \"vent\" \"nous\" \"portera\"]\n3. 4 [\"\" \"\" \"\" \"\"] *CORRECT*\n4. 0 []\n\n> **3:** `copy` copies a newly created slice with four elements (`make([]string, 4)`) onto `lyric` slice. They both have 4 elements, so the `copy` copies 4 elements. Remember: `make()` initializes a slice with zero-values of its element type. Here, this operation clears all the slice elements to their zero-values.\n\n\n## What does the program print?\n```go\nspendings := [][]int{{200, 100}, {}, {50, 25, 75}, {500}}\ntotal := spendings[2][1] + spendings[3][0] + spendings[0][0]\n\nfmt.Printf(\"%d\\n\", total)\n```\n1. 725 *CORRECT*\n2. 650\n3. 500\n4. 750\n\n> **1:** `spendings[2][1]` = 25. `spendings[3][0]` = 500. `spendings[0][0]` = 200. 25 + 500 + 200 = 725\n\n\n## What does the program print?\n```go\nspendings := [][]int{{1,2}}\n    \n// REMEMBER: %T prints the type of a given value\nfmt.Printf(\"%T - \", spendings)\nfmt.Printf(\"%T - \", spendings[0])\nfmt.Printf(\"%T\", spendings[0][0])\n```\n1. [][]int{{1, 2}} - []int{1, 2} - int(2)\n2. [][]int - []int - int *CORRECT*\n3. []int - int - 2\n4. [][]int - [][]int - []int\n\n> **2:** `spendings` is a 2-dimensional int slice, so its type is [][]int. Its element type is: `[]int`, so: `spendings[0]` is `[]int`. `spendings[0]`'s element type is: `int`. So `spendings[0][0]`'s type is `int`.\n\n\n## What is the 'element type' of the slice?\n```go\n[][][3]int{{{10, 5, 9}}}\n```    \n1. [][][3]int\n2. [][]int\n3. [][3]int *CORRECT*\n4. [3]int\n\n> **3:** `[][][3]int` is a multi-dimensional slice of `[][3]int` elements. `[][3]int` is a multi-dimensional slice of `[3]int` elements. `[3]int` is an array of 3 `int` values."
  },
  {
    "path": "16-slices/questions/README.md",
    "content": "# Slice Quizzes\n\n* [Slices vs Arrays](1-slices-vs-arrays.md)\n\n* [Appending](2-appending.md)\n\n* [Slicing](3-slicing.md)\n\n* [Backing Array](4-backing-array.md)\n\n* [Slice Header](5-slice-header.md)\n\n* [Capacity](6-capacity.md)\n\n* [The Mechanics of Append](7-mechanics-of-append.md)\n\n* [Advanced Slice Operations](8-advanced-ops.md)"
  },
  {
    "path": "17-project-empty-file-finder/01-fetch-the-files/files/empty1.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/01-fetch-the-files/files/empty2.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/01-fetch-the-files/files/empty3.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/01-fetch-the-files/files/nonEmpty1.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/01-fetch-the-files/files/nonEmpty2.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/01-fetch-the-files/files/nonEmpty3.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/01-fetch-the-files/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) == 0 {\n\t\tfmt.Println(\"Provide a directory\")\n\t\treturn\n\t}\n\n\tfiles, err := ioutil.ReadDir(args[0])\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfor _, file := range files {\n\t\tif file.Size() == 0 {\n\t\t\tname := file.Name()\n\t\t\tfmt.Println(name)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "17-project-empty-file-finder/02-write-to-a-file/files/empty1.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/02-write-to-a-file/files/empty2.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/02-write-to-a-file/files/empty3.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/02-write-to-a-file/files/nonEmpty1.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/02-write-to-a-file/files/nonEmpty2.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/02-write-to-a-file/files/nonEmpty3.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/02-write-to-a-file/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) == 0 {\n\t\tfmt.Println(\"Provide a directory\")\n\t\treturn\n\t}\n\n\tfiles, err := ioutil.ReadDir(args[0])\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tvar names []byte\n\n\tfor _, file := range files {\n\t\tif file.Size() == 0 {\n\t\t\tname := file.Name()\n\n\t\t\tfmt.Println(cap(names))\n\t\t\tnames = append(names, name...)\n\t\t\tnames = append(names, '\\n')\n\t\t}\n\t}\n\n\terr = ioutil.WriteFile(\"out.txt\", names, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%s\", names)\n}\n\n// See: https://www.tutorialspoint.com/unix/unix-file-permission.htm\n// See: http://permissions-calculator.org/\n"
  },
  {
    "path": "17-project-empty-file-finder/03-optimize/files/empty1.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/03-optimize/files/empty2.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/03-optimize/files/empty3.txt",
    "content": ""
  },
  {
    "path": "17-project-empty-file-finder/03-optimize/files/nonEmpty1.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/03-optimize/files/nonEmpty2.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/03-optimize/files/nonEmpty3.txt",
    "content": "learngoprogramming.com\n"
  },
  {
    "path": "17-project-empty-file-finder/03-optimize/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) == 0 {\n\t\tfmt.Println(\"Provide a directory\")\n\t\treturn\n\t}\n\n\tfiles, err := ioutil.ReadDir(args[0])\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// 1st: You can also take the average of the total file length\n\t//      across platforms. It's about 255.\n\t//\n\t// https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits\n\t//\n\t// BTRFS   255 bytes\n\t// exFAT   255 UTF-16 characters\n\t// ext2    255 bytes\n\t// ext3    255 bytes\n\t// ext3cow 255 bytes\n\t// ext4    255 bytes\n\t// FAT32   255 bytes\n\t// NTFS    255 characters\n\t// XFS     255 bytes\n\t//\n\t// total := len(files) * 256\n\n\t// 1st B: To be exact, find the total size of all the empty files\n\tvar total int\n\tfor _, file := range files {\n\t\tif file.Size() == 0 {\n\t\t\t// +1 for the newline character\n\t\t\t// when printing the filename afterward\n\t\t\ttotal += len(file.Name()) + 1\n\t\t}\n\t}\n\tfmt.Printf(\"Total required space: %d bytes.\\n\", total)\n\n\t// 2nd: allocate a large enough byte slice in one go\n\tnames := make([]byte, 0, total)\n\n\tfor _, file := range files {\n\t\tif file.Size() == 0 {\n\t\t\tname := file.Name()\n\n\t\t\tnames = append(names, name...)\n\t\t\tnames = append(names, '\\n')\n\t\t}\n\t}\n\n\terr = ioutil.WriteFile(\"out.txt\", names, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%s\", names)\n}\n\n// See: https://www.tutorialspoint.com/unix/unix-file-permission.htm\n// See: http://permissions-calculator.org/\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/1-sort-to-a-file/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Sort and write items to a file\n//\n//  1. Get arguments from command-line\n//\n//  2. Sort them\n//\n//  3. Write the sorted slice to a file\n//\n//\n// EXPECTED OUTPUT\n//\n//   go run main.go\n//     Send me some items and I will sort them\n//\n//   go run main.go orange banana apple\n//\n//   cat sorted.txt\n//     apple\n//     banana\n//     orange\n//\n//\n// HINTS\n//\n//   + REMEMBER: os.Args is a []string\n//\n//   + String slices are sortable using `sort.Strings`\n//\n//   + Use ioutil.WriteFile to write to a file.\n//\n//   + But you need to convert []string to []byte to be able to\n//     write it to a file using the ioutil.WriteFile.\n//\n//   + To do that, create a new []byte and append the elements of your\n//     []string.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/1-sort-to-a-file/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"sort\"\n)\n\nfunc main() {\n\titems := os.Args[1:]\n\tif len(items) == 0 {\n\t\tfmt.Println(\"Send me some items and I will sort them\")\n\t\treturn\n\t}\n\n\tsort.Strings(items)\n\n\tvar data []byte\n\tfor _, s := range items {\n\t\tdata = append(data, s...)\n\t\tdata = append(data, '\\n')\n\t}\n\n\terr := ioutil.WriteFile(\"sorted.txt\", data, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/2-sort-to-a-file-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"sort\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Sort and write items to a file with their ordinals\n//\n//  Use the previous exercise.\n//\n//  This time, print the sorted items with ordinals\n//  (see the expected output)\n//\n//\n// EXPECTED OUTPUT\n//\n//   go run main.go\n//     Send me some items and I will sort them\n//\n//   go run main.go orange banana apple\n//\n//   cat sorted.txt\n//     1. apple\n//     2. banana\n//     3. orange\n//\n//\n// HINTS\n//\n//   ONLY READ THIS IF YOU GET STUCK\n//\n//   + You can use strconv.AppendInt function to append an int\n//     to a byte slice. strconv contains a lot of functions for appending\n//     other basic types to []byte slices as well.\n//\n//   + You can append individual characters to a byte slice using\n//     rune literals (because: rune literal are typeless numerics):\n//\n//     var slice []byte\n//     slice = append(slice, 'h', 'i', ' ', '!')\n//     fmt.Printf(\"%s\\n\", slice)\n//\n//     Above code prints: hi !\n// ---------------------------------------------------------\n\nfunc main() {\n\titems := os.Args[1:]\n\tif len(items) == 0 {\n\t\tfmt.Println(\"Send me some items and I will sort them\")\n\t\treturn\n\t}\n\n\tsort.Strings(items)\n\n\tvar data []byte\n\tfor _, s := range items {\n\t\tdata = append(data, s...)\n\t\tdata = append(data, '\\n')\n\t}\n\n\terr := ioutil.WriteFile(\"sorted.txt\", data, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/2-sort-to-a-file-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n)\n\nfunc main() {\n\titems := os.Args[1:]\n\tif len(items) == 0 {\n\t\tfmt.Println(\"Send me some items and I will sort them\")\n\t\treturn\n\t}\n\n\tsort.Strings(items)\n\n\tvar data []byte\n\tfor i, s := range items {\n\t\tdata = strconv.AppendInt(data, int64(i+1), 10)\n\t\tdata = append(data, '.', ' ')\n\t\tdata = append(data, s...)\n\t\tdata = append(data, '\\n')\n\t}\n\n\terr := ioutil.WriteFile(\"sorted.txt\", data, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Find and write the names of subdirectories to a file\n//\n//  Create a program that can get multiple directory paths from\n//  the command-line, and prints only their subdirectories into a\n//  file named: dirs.txt\n//\n//\n//  1. Get the directory paths from command-line\n//\n//  2. Append the names of subdirectories inside each directory\n//     to a byte slice\n//\n//  3. Write that byte slice to dirs.txt file\n//\n//\n// EXPECTED OUTPUT\n//\n//   go run main.go\n//     Please provide directory paths\n//\n//   go run main.go dir/ dir2/\n//\n//   cat dirs.txt\n//\n//     dir/\n//             subdir1/\n//             subdir2/\n//\n//     dir2/\n//             subdir1/\n//             subdir2/\n//             subdir3/\n//\n//\n// HINTS\n//\n//   ONLY READ THIS IF YOU GET STUCK\n//\n//   + Get all the files in a directory using ioutil.ReadDir\n//     (A directory is also a file)\n//\n//   + You can use IsDir method of a FileInfo value to detect\n//     whether a file is a directory or not.\n//\n//     Check out its documentation:\n//\n//     go doc os.FileInfo.IsDir\n//\n//     # or using godocc\n//     godocc os.FileInfo.IsDir\n//\n//   + You can use '\\t' escape sequence for indenting the subdirs.\n//\n//   + You can find a sample directory structure under:\n//     solution/ directory\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dir/.gitignore",
    "content": "*\n!subdir1\n!subdir2\n!.gitignore\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dir/subdir1/.gitignore",
    "content": "*\n!.gitignore\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dir/subdir2/.gitignore",
    "content": "*\n!.gitignore\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/.gitignore",
    "content": "*\n!subdir1\n!subdir2\n!subdir3\n!.gitignore\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir1/.gitignore",
    "content": "*\n!.gitignore\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir2/.gitignore",
    "content": "*\n!.gitignore\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir3/.gitignore",
    "content": "*\n!.gitignore\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/dirs.txt",
    "content": "dir/\n\tsubdir1/\n\tsubdir2/\n\ndir2/\n\tsubdir1/\n\tsubdir2/\n\tsubdir3/\n\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/3-print-directories/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n)\n\nfunc main() {\n\tpaths := os.Args[1:]\n\tif len(paths) == 0 {\n\t\tfmt.Println(\"Please provide directory paths\")\n\t\treturn\n\t}\n\n\tvar dirs []byte\n\n\tfor _, dir := range paths {\n\t\tfiles, err := ioutil.ReadDir(dir)\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t\treturn\n\t\t}\n\n\t\tdirs = append(dirs, dir...)\n\t\tdirs = append(dirs, '\\n')\n\n\t\tfor _, file := range files {\n\t\t\tif file.IsDir() {\n\t\t\t\tdirs = append(dirs, '\\t')\n\t\t\t\tdirs = append(dirs, file.Name()...)\n\t\t\t\tdirs = append(dirs, '/', '\\n')\n\t\t\t}\n\t\t}\n\n\t\tdirs = append(dirs, '\\n')\n\t}\n\n\terr := ioutil.WriteFile(\"dirs.txt\", dirs, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n"
  },
  {
    "path": "17-project-empty-file-finder/exercises/README.md",
    "content": "# Empty File Finder Exercises\n\n1. **[Sort and write items to a file](https://github.com/inancgumus/learngo/tree/master/17-project-empty-file-finder/exercises/1-sort-to-a-file)**\n\n2. **[Sort and write items to a file with their ordinals](https://github.com/inancgumus/learngo/tree/master/17-project-empty-file-finder/exercises/2-sort-to-a-file-2)**\n\n3. **[Find and write the names of subdirectories to a file](https://github.com/inancgumus/learngo/tree/master/17-project-empty-file-finder/exercises/3-print-directories)**\n"
  },
  {
    "path": "18-project-bouncing-ball/01-draw-the-board/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tconst (\n\t\twidth  = 50\n\t\theight = 10\n\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\t)\n\n\tvar cell rune // current cell (for caching)\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// draw a smiley\n\tboard[12][2] = true\n\tboard[16][2] = true\n\tboard[14][4] = true\n\tboard[10][6] = true\n\tboard[18][6] = true\n\tboard[12][7] = true\n\tboard[14][7] = true\n\tboard[16][7] = true\n\n\t// print the board directly to the console\n\tfor y := range board[0] {\n\t\tfor x := range board {\n\t\t\tcell = cellEmpty\n\t\t\tif board[x][y] {\n\t\t\t\tcell = cellBall\n\t\t\t}\n\t\t\tfmt.Print(string(cell), \" \")\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/02-add-a-buffer/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tconst (\n\t\twidth  = 50\n\t\theight = 10\n\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\t)\n\n\tvar cell rune // current cell (for caching)\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, width*height)\n\n\t// draw a smiley\n\tboard[12][2] = true\n\tboard[16][2] = true\n\tboard[14][4] = true\n\tboard[10][6] = true\n\tboard[18][6] = true\n\tboard[12][7] = true\n\tboard[14][7] = true\n\tboard[16][7] = true\n\n\t// use the loop for measuring the performance difference\n\tfor i := 0; i < 1000; i++ {\n\t\t// rewind the buffer so that the program reuses it\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\t// fmt.Print(string(cell), \" \")\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\t// fmt.Println()\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tfmt.Print(string(buf))\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/03-animate/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tconst (\n\t\twidth  = 50\n\t\theight = 10\n\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\t)\n\n\tvar (\n\t\tpx, py int    // ball position\n\t\tvx, vy = 1, 1 // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, width*height)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-1 {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-1 {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tboard[x][y] = false\n\t\t\t}\n\t\t}\n\n\t\t// put the new ball\n\t\tboard[px][py] = true\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/README.md",
    "content": "# Bouncing Ball Challenge Tips\n\nUse the following tips only when you get stuck. This document isn't in a particular order, please do not follow it like so.\n\n## CALCULATING THE VELOCITY\n\nYou can use velocity to change the ball's speed and position. In my example, the speed is constant, so I always use unit value: 1.\n\n* On each loop step: Add velocities to ball's position. This will make the ball move.\n\n* **Velocity means: Speed and Direction**\n\n  * X velocity =  1 -> _ball moves right_\n  * X velocity = -1 -> _ball moves left_\n  * Y velocity =  1 -> _ball moves down_\n  * Y velocity = -1 -> _ball moves up_\n\n* **For more information on graphics and velocity:**\n\n  * [Youtube: Crash Course: 2D Graphics](https://www.youtube.com/watch?v=7Jr0SFMQ4Rs&t=529)\n\n  * [Youtube: Crash Course: Velocity](https://www.youtube.com/watch?v=ZM8ECpBuQYE)\n\n## CREATING THE BOARD\n\nI use `[][]bool` for the board but you can use anything you like. For example, you can directly use `[][]rune` or `[]rune`. Experiment with them and decide which one is the best for you.\n\n## CLEARING THE SCREEN\n\n* Before the loop, clear the screen once by using my [screen package](https://github.com/inancgumus/screen), click on the link. You can find its [documentation here](https://godoc.org/github.com/inancgumus/screen).\n\n* After each loop step, move the cursor to the top-left position by using the screen package. So that you can draw the animation frame all over again in the same position.\n\n* You can find more information about the screen package and screen clearing in the [Retro Clock project section lectures](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock).\n\n## DRAWING THE BOARD\n\nInstead of drawing the board and the ball to the screen everytime, you will fill a buffer, and when you complete, you can draw the board and the ball once by printing the buffer. I use a `[]rune` slice as a buffer because `rune` can store an emoji character.\n\n* Make a large enough rune slice named `buf` using the `make` function.\n\n  * **HINT:** `width * height` will give you a large enough buffer.\n\n  * **TIP:** You could also use `string` concatenation to draw into a `string` buffer but it would be inefficient.\n\n  * You will find more information about bytes and runes in the strings section.\n\n```go\n// TIP for converting the buffer\nvar buffer []rune\n\n// For printing, you can convert a rune slice to a string like so:\nstr := string(buffer)\n```\n\n## SLOWING DOWN THE SPEED\n\nCall the `time.Sleep` function to slow down the speed of the loop a little bit, so you can see the ball :)\n\n```go\ntime.Sleep(time.Second / 20)\n```\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/01-find-the-bug/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Find the Bug\n//\n//  As I've annotated in the lectures, there is a bug\n//  in this code. Please find the bug and fix it.\n//\n//\n// HINT #1\n//\n//  💀 Read this only if you get stuck.\n//\n//  Print the width*height and the capacity of the drawing buffer\n//  after a single drawing loop ends. You might be surprised.\n//\n//\n// HINT #2\n//\n//  💀 Read this only if you get stuck.\n//\n//  The bug is in the drawing buffer. It doesn't include the\n//  newline and space characters when creating the buffer. So\n//  the buffer is not large enough to hold all the characters.\n//  So new backing arrays are getting allocated.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\twidth  = 50\n\t\theight = 10\n\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\t)\n\n\tvar (\n\t\tpx, py int    // ball position\n\t\tvx, vy = 1, 1 // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, width*height)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-1 {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-1 {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tboard[x][y] = false\n\t\t\t}\n\t\t}\n\n\t\t// put the new ball\n\t\tboard[px][py] = true\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/01-find-the-bug/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tconst (\n\t\twidth  = 50\n\t\theight = 10\n\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\n\t\t// drawing buffer length\n\t\t// *2 for extra spaces\n\t\t// +1 for newlines\n\t\tbufLen = (width*2 + 1) * height\n\t)\n\n\tvar (\n\t\tpx, py int    // ball position\n\t\tvx, vy = 1, 1 // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// create a drawing buffer\n\t// BUG FIXED!\n\tbuf := make([]rune, 0, bufLen)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-1 {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-1 {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tboard[x][y] = false\n\t\t\t}\n\t\t}\n\n\t\t// put the new ball\n\t\tboard[px][py] = true\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/02-width-and-height/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Adjust the width and height automatically\n//\n//    Instead of setting the width and height manually,\n//    you need to get the width and height of the terminal\n//    screen from your operating system.\n//\n//  1. Update your program to use my screen package.\n//     It offers an easy way to get the width and height.\n//\n//     go get -u https://github.com/inancgumus/screen\n//\n//  2. Read the package's documentation and find a way to\n//     get the screen size: width and height.\n//\n//     The documentation is here:\n//     https://godoc.org/github.com/inancgumus/screen\n//\n//  3. Use it to set the board's dimensions.\n//\n//\n// OPTIONAL EXERCISE\n//\n//  1. When you set the width, you may see that the ball\n//     goes beyond the left and right borders. This happens\n//     because the ball emoji spans to multiple console\n//     columns (or cells). Ordinary characters have a\n//     single column.\n//\n//     1. Get the width of the ball emoji using a function\n//        from the following package:\n//\n//        go get -u github.com/mattn/go-runewidth\n//\n//     2. Divide the width using the rune width of the\n//        ball emoji.\n//\n//  2. Your terminal may have borders, so reduce the\n//     height by taking into account the height of\n//     your terminal borders.\n//\n//\n// EXPECTED OUTPUT\n//\n//  When you run the program, the ball should start\n//  animating across the total width and height of your\n//  terminal screen dynamically.\n//\n//  Currently you set width and height manually, so it\n//  wasn't matter whether your terminal was bigger or\n//  smaller, but now it will be!\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\twidth  = 50\n\t\theight = 10\n\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\n\t\t// drawing buffer length\n\t\t//\n\t\t// *2 for extra spaces\n\t\t// +1 for newlines\n\t\tbufLen = (width*2 + 1) * height\n\t)\n\n\tvar (\n\t\tpx, py int    // ball position\n\t\tvx, vy = 1, 1 // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, bufLen)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-1 {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-1 {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tboard[x][y] = false\n\t\t\t}\n\t\t}\n\n\t\t// put the new ball\n\t\tboard[px][py] = true\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/02-width-and-height/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/mattn/go-runewidth\"\n\n\t\"github.com/inancgumus/screen\"\n)\n\nfunc main() {\n\tconst (\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\t)\n\n\tvar (\n\t\tpx, py int    // ball position\n\t\tvx, vy = 1, 1 // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// you can get the width and height using the screen package easily:\n\twidth, height := screen.Size()\n\n\t// get the rune width of the ball emoji\n\tballWidth := runewidth.RuneWidth(cellBall)\n\n\t// adjust the width and height\n\twidth /= ballWidth\n\theight-- // there is a 1 pixel border in my terminal\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// drawing buffer length\n\t// *2 for extra spaces\n\t// +1 for newlines\n\tbufLen := (width*2 + 1) * height\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, bufLen)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-1 {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-1 {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tboard[x][y] = false\n\t\t\t}\n\t\t}\n\n\t\t// put the new ball\n\t\tboard[px][py] = true\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/03-previous-positions/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n\t\"github.com/mattn/go-runewidth\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Previous positions\n//\n//  Let's optimize the program once more. This time you're\n//  going to optimize the clearing off the previous positions.\n//\n//  1. Find the code below marked as \"remove the previous ball\"\n//\n//  2. Instead of clearing every position on the board to false,\n//     only set the previous position to false. So, don't use\n//     a loop, remove it.\n//\n//  3. Change the velocity of the ball like so:\n//\n//     vx, vy = 5, 2\n//\n//  4. Run the program and solve the problem\n//\n//\n// HINT\n//\n//  Don't forget saving the previous position.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\t)\n\n\tvar (\n\t\tpx, py int    // ball position\n\t\tvx, vy = 1, 1 // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// you can get the width and height using the screen package easily:\n\twidth, height := screen.Size()\n\n\t// get the rune width of the ball emoji\n\tballWidth := runewidth.RuneWidth(cellBall)\n\n\t// adjust the width and height\n\twidth /= ballWidth\n\theight-- // there is a 1 pixel border in my terminal\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// drawing buffer length\n\t// *2 for extra spaces\n\t// +1 for newlines\n\tbufLen := (width*2 + 1) * height\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, bufLen)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-1 {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-1 {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tboard[x][y] = false\n\t\t\t}\n\t\t}\n\n\t\t// put the new ball\n\t\tboard[px][py] = true\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/03-previous-positions/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n\t\"github.com/mattn/go-runewidth\"\n)\n\nfunc main() {\n\tconst (\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\n\t\t// initial velocities\n\t\tivx, ivy = 5, 2\n\t)\n\n\tvar (\n\t\tpx, py   int        // ball position\n\t\tppx, ppy int        // previous ball position\n\t\tvx, vy   = ivx, ivx // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// you can get the width and height using the screen package easily:\n\twidth, height := screen.Size()\n\n\t// get the rune width of the ball emoji\n\tballWidth := runewidth.RuneWidth(cellBall)\n\n\t// adjust the width and height\n\twidth /= ballWidth\n\theight-- // there is a 1 pixel border in my terminal\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// drawing buffer length\n\t// *2 for extra spaces\n\t// +1 for newlines\n\tbufLen := (width*2 + 1) * height\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, bufLen)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-ivx {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-ivx {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball and put the new ball\n\t\tboard[px][py], board[ppx][ppy] = true, false\n\n\t\t// save the previous positions\n\t\tppx, ppy = px, py\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/04-single-dimensional/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n\t\"github.com/mattn/go-runewidth\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: Single Dimensional\n//\n//  In this exercise you will understand why I use\n//  a multi-dimensional board slice instead of a\n//  single-dimensional one.\n//\n//  1. Remove this:\n//     board := make([][]bool, width)\n//\n//  2. Use this:\n//     board := make([]bool, width*height)\n//\n//  3. Adjust the rest of the operations in the code to work\n//     with this single-dimensional slice.\n//\n//     You'll see how hard it becomes to work with it.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\n\t\t// initial velocities\n\t\tivx, ivy = 5, 2\n\t)\n\n\tvar (\n\t\tpx, py   int        // ball position\n\t\tppx, ppy int        // previous ball position\n\t\tvx, vy   = ivx, ivy // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// you can get the width and height using the screen package easily:\n\twidth, height := screen.Size()\n\n\t// get the rune width of the ball emoji\n\tballWidth := runewidth.RuneWidth(cellBall)\n\n\t// adjust the width and height\n\twidth /= ballWidth\n\theight-- // there is a 1 pixel border in my terminal\n\n\t// create the board\n\tboard := make([][]bool, width)\n\tfor column := range board {\n\t\tboard[column] = make([]bool, height)\n\t}\n\n\t// drawing buffer length\n\t// *2 for extra spaces\n\t// +1 for newlines\n\tbufLen := (width*2 + 1) * height\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, bufLen)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-ivx {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-ivy {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball and put the new ball\n\t\tboard[px][py], board[ppx][ppy] = true, false\n\n\t\t// save the previous positions\n\t\tppx, ppy = px, py\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := range board[0] {\n\t\t\tfor x := range board {\n\t\t\t\tcell = cellEmpty\n\t\t\t\tif board[x][y] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/04-single-dimensional/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n\t\"github.com/mattn/go-runewidth\"\n)\n\nfunc main() {\n\tconst (\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\n\t\t// initial velocities\n\t\tivx, ivy = 5, 2\n\t)\n\n\tvar (\n\t\tpx, py   int        // ball position\n\t\tppx, ppy int        // previous ball position\n\t\tvx, vy   = ivx, ivy // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\t// you can get the width and height using the screen package easily:\n\twidth, height := screen.Size()\n\n\t// get the rune width of the ball emoji\n\tballWidth := runewidth.RuneWidth(cellBall)\n\n\t// adjust the width and height\n\twidth /= ballWidth\n\theight-- // there is a 1 pixel border in my terminal\n\n\t// create a single-dimensional board\n\tboard := make([]bool, width*height)\n\n\t// drawing buffer length\n\t// *2 for extra spaces\n\t// +1 for newlines\n\tbufLen := (width*2 + 1) * height\n\n\t// create a drawing buffer\n\tbuf := make([]rune, 0, bufLen)\n\n\t// clear the screen once\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-ivx {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-ivy {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// calculate the new and the previous ball positions\n\t\tpos := py*width + px\n\t\tppos := ppy*width + ppx\n\n\t\t// remove the previous ball and put the new ball\n\t\tboard[pos], board[ppos] = true, false\n\n\t\t// save the previous positions\n\t\tppx, ppy = px, py\n\n\t\t// rewind the buffer (allow appending from the beginning)\n\t\tbuf = buf[:0]\n\n\t\t// draw the board into the buffer\n\t\tfor y := 0; y < height; y++ {\n\t\t\tfor x := 0; x < width; x++ {\n\t\t\t\tcell = cellEmpty\n\n\t\t\t\tif board[y*width+x] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\t// print the buffer\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\t// slow down the animation\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/05-no-slice/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n\t\"github.com/mattn/go-runewidth\"\n)\n\n// ---------------------------------------------------------\n// EXERCISE: No Slice\n//\n//   Can you modify the program so that it doesn't use a\n//   slice for the board. You can use a slice for the buffer\n//   though.\n//\n//   In this exercise, you'll understand that you don't\n//   have to use slices in any problem you encounter with.\n//\n//   See what it feels like not using a slice for this\n//   solution.\n//\n//   Think about why you have to use a slice for the buffer?\n//\n//   Can there be any other solution?\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst (\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\n\t\tivx, ivy = 1, 1 // initial velocities\n\t)\n\n\tvar (\n\t\tpx, py   int        // ball position\n\t\tppx, ppy int        // previous ball position\n\t\tvx, vy   = ivx, ivy // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\twidth, height := screen.Size()\n\twidth /= runewidth.RuneWidth(cellBall)\n\theight-- // there is a 1 pixel border in my terminal\n\n\t// REMOVE THIS: create a single-dimensional board\n\tboard := make([]bool, width*height)\n\n\t// create a drawing buffer\n\t// *2 for extra spaces\n\t// +1 for newlines\n\tbuf := make([]rune, 0, (width*2+1)*height)\n\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-ivx {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-ivy {\n\t\t\tvy *= -1\n\t\t}\n\n\t\t// remove the previous ball and put the new ball\n\t\tpos := py*width + px\n\t\tppos := ppy*width + ppx\n\t\tppx, ppy = px, py\n\n\t\tboard[pos], board[ppos] = true, false\n\n\t\tbuf = buf[:0]\n\n\t\tfor y := 0; y < height; y++ {\n\t\t\tfor x := 0; x < width; x++ {\n\t\t\t\tcell = cellEmpty\n\n\t\t\t\tif board[y*width+x] {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/05-no-slice/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/inancgumus/screen\"\n\t\"github.com/mattn/go-runewidth\"\n)\n\nfunc main() {\n\tconst (\n\t\tcellEmpty = ' '\n\t\tcellBall  = '⚾'\n\n\t\tmaxFrames = 1200\n\t\tspeed     = time.Second / 20\n\n\t\t// initial velocities\n\t\tivx, ivy = 1, 1\n\t)\n\n\tvar (\n\t\tpx, py int        // ball position\n\t\tvx, vy = ivx, ivy // velocities\n\n\t\tcell rune // current cell (for caching)\n\t)\n\n\twidth, height := screen.Size()\n\twidth /= runewidth.RuneWidth(cellBall)\n\theight-- // there is a 1 pixel border in my terminal\n\n\t// create a drawing buffer\n\t// *2 for extra spaces\n\t// +1 for newlines\n\tbuf := make([]rune, 0, (width*2+1)*height)\n\n\tscreen.Clear()\n\n\tfor i := 0; i < maxFrames; i++ {\n\t\t// calculate the next ball position\n\t\tpx += vx\n\t\tpy += vy\n\n\t\t// when the ball hits a border reverse its direction\n\t\tif px <= 0 || px >= width-1 {\n\t\t\tvx *= -1\n\t\t}\n\t\tif py <= 0 || py >= height-1 {\n\t\t\tvy *= -1\n\t\t}\n\n\t\tbuf = buf[:0]\n\n\t\tfor y := 0; y < height; y++ {\n\t\t\tfor x := 0; x < width; x++ {\n\t\t\t\tcell = cellEmpty\n\n\t\t\t\tif px == x && py == y {\n\t\t\t\t\tcell = cellBall\n\t\t\t\t}\n\n\t\t\t\tbuf = append(buf, cell, ' ')\n\t\t\t}\n\t\t\tbuf = append(buf, '\\n')\n\t\t}\n\n\t\tscreen.MoveTopLeft()\n\t\tfmt.Print(string(buf))\n\n\t\ttime.Sleep(speed)\n\t}\n}\n"
  },
  {
    "path": "18-project-bouncing-ball/exercises/README.md",
    "content": "# Bouncing Ball Exercises\n\n1. **[Find the Bug](https://github.com/inancgumus/learngo/tree/master/18-project-bouncing-ball/exercises/01-find-the-bug)**\n\n    There is a bug in the bouncing ball code. Test yourself that you really understand how the backing arrays work.\n\n\n2. **[Adjust the width and height automatically](https://github.com/inancgumus/learngo/tree/master/18-project-bouncing-ball/exercises/02-width-and-height)**\n\n    In this exercise, your goal is getting the width and height of the terminal screen from your operating system (instead of setting the width and height manually).\n\n3. **[Previous positions](https://github.com/inancgumus/learngo/tree/master/18-project-bouncing-ball/exercises/03-previous-positions)**\n\n    Let's optimize the program once more. This time you're going to optimize the clearing off the previous positions.\n\n4. **[Use a single dimensional slice](https://github.com/inancgumus/learngo/tree/master/18-project-bouncing-ball/exercises/04-single-dimensional)**\n\n    For the board slice, instead of using a multi-dimensional slice, let's use a single-dimensional slice. In this exercise, you'll understand and deeply internalize why I've used a multi-dimensional board slice.\n\n5. **[Don't use a slice for the board](https://github.com/inancgumus/learngo/tree/master/18-project-bouncing-ball/exercises/05-no-slice)**\n\n    Expand your horizon: Don't use a slice for the board. You only need a slice for the buffer, only that."
  },
  {
    "path": "19-strings-runes-bytes/01-bytes-runes-strings-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tstr := \"hey\"\n\tbytes := []byte{104, 101, 121}\n\n\t// same as: []byte(\"hey\")\n\tfmt.Printf(`\"hey\" as bytes   : %d`+\"\\n\", []byte(str))\n\n\t// same as: string([]byte{104, 101, 121})\n\tfmt.Printf(\"bytes as string  : %q\\n\", string(bytes))\n\n\t// runes are unicode codepoints (numbers)\n\tfmt.Println()\n\tfmt.Printf(\"%c                : %[1]d\\n\", 'h')\n\tfmt.Printf(\"%c                : %[1]d\\n\", 'e')\n\tfmt.Printf(\"%c                : %[1]d\\n\", 'y')\n\n\t// a rune literal is typeless\n\t// you can put it in any numeric type\n\tvar (\n\t\tanInt   int   = 'h'\n\t\tanInt8  int8  = 'h'\n\t\tanInt16 int16 = 'h'\n\t\tanInt32 int32 = 'h'\n\n\t\t// rune literal's default type is: rune\n\t\t// so, you don't need to specify it.\n\t\t// aRune   rune  = 'h'\n\t\taRune = 'h'\n\n\t\t// and so on...\n\t)\n\n\tfmt.Println()\n\tfmt.Printf(\"rune literals are typeless:\\n\\t%T %T %T %T %T\\n\",\n\t\tanInt, anInt8, anInt16, anInt32, aRune)\n\n\tfmt.Println()\n\n\t// all are the same rune\n\n\t// beginning with go 1.13 you can type: 0b0110_1000 instead\n\t// fmt.Printf(\"%q as binary: %08[1]b\\n\", 0b0110_1000)\n\tfmt.Printf(\"%q in decimal: %[1]d\\n\", 104)\n\tfmt.Printf(\"%q in binary : %08[1]b\\n\", 'h')\n\tfmt.Printf(\"%q in hex    : 0x%[1]x\\n\", 0x68)\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/02-bytes-runes-strings-charset-table/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tvar start, stop int\n\n\tif args := os.Args[1:]; len(args) == 2 {\n\t\tstart, _ = strconv.Atoi(args[0])\n\t\tstop, _ = strconv.Atoi(args[1])\n\t}\n\n\tif start == 0 || stop == 0 {\n\t\tstart, stop = 'A', 'Z'\n\t}\n\n\tfmt.Printf(\"%-10s %-10s %-10s %-12s\\n%s\\n\",\n\t\t\"literal\", \"dec\", \"hex\", \"encoded\",\n\t\tstrings.Repeat(\"-\", 45))\n\n\tfor n := start; n <= stop; n++ {\n\t\tfmt.Printf(\"%-10c %-10[1]d %-10[1]x % -12x\\n\", n, string(n))\n\t}\n}\n\n/*\nEXAMPLE UNICODE BLOCKS\n\n1 byte\n------------------------------------------------------------\nasciiStart     = '\\u0001'      ->  32\nasciiStop      = '\\u007f'      ->  127\n\nupperCaseStart = '\\u0041'      ->  65\nupperCaseStop  = '\\u005a'      ->  90\n\nlowerCaseStart = '\\u0061'      ->  97\nlowerCaseStop  = '\\u007a'      ->  122\n\n\n2 bytes\n------------------------------------------------------------\nlatin1Start    = '\\u0080'      ->  161\nlatin1Stop     = '\\u00ff'      ->  255\n\n\n3 bytes\n------------------------------------------------------------\ndingbatStart   = '\\u2700'      ->  9984\ndingbatStop    = '\\u27bf'      ->  10175\n\n\n4 bytes\n------------------------------------------------------------\nemojiStart     = '\\U0001f600'  ->  128512\nemojiStop      = '\\U0001f64f'  ->  128591\n*/\n"
  },
  {
    "path": "19-strings-runes-bytes/03-bytes-runes-strings-examples/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unicode/utf8\"\n\t\"unsafe\"\n)\n\nfunc main() {\n\tstr := \"Yūgen ☯ 💀\"\n\n\t// can't change a string\n\t// a string is a read-only byte-slice\n\t// str[0] = 'N'\n\t// str[1] = 'o'\n\n\tbytes := []byte(str)\n\n\t// can change a byte slice\n\t// bytes[0] = 'N'\n\t// bytes[1] = 'o'\n\n\tstr = string(bytes)\n\n\tfmt.Printf(\"%s\\n\", str)\n\tfmt.Printf(\"\\t%d bytes\\n\", len(str))\n\tfmt.Printf(\"\\t%d runes\\n\", utf8.RuneCountInString(str))\n\tfmt.Printf(\"% x\\n\", bytes)\n\tfmt.Printf(\"\\t%d bytes\\n\", len(bytes))\n\tfmt.Printf(\"\\t%d runes\\n\", utf8.RuneCount(bytes))\n\n\t// fmt.Println()\n\t// for i, r := range str {\n\t// \tfmt.Printf(\"str[%2d] = % -12x = %q\\n\", i, string(r), r)\n\t// }\n\n\tfmt.Println()\n\tfmt.Printf(\"1st byte   : %c\\n\", str[0])           // ok\n\tfmt.Printf(\"2nd byte   : %c\\n\", str[1])           // not ok\n\tfmt.Printf(\"2nd rune   : %s\\n\", str[1:3])         // ok\n\tfmt.Printf(\"last rune  : %s\\n\", str[len(str)-4:]) // ok\n\n\t// disadvantage: each one is 4 bytes\n\trunes := []rune(str)\n\n\tfmt.Println()\n\tfmt.Printf(\"%s\\n\", str)\n\tfmt.Printf(\"\\t%d bytes\\n\", int(unsafe.Sizeof(runes[0]))*len(runes))\n\tfmt.Printf(\"\\t%d runes\\n\", len(runes))\n\n\tfmt.Printf(\"1st rune   : %c\\n\", runes[0])\n\tfmt.Printf(\"2nd rune   : %c\\n\", runes[1])\n\tfmt.Printf(\"first five : %c\\n\", runes[:5])\n\n\tfmt.Println()\n\n\tword := \"öykü\"\n\tfmt.Printf(\"%q in runes: %c\\n\", word, []rune(word))\n\tfmt.Printf(\"%q in bytes: % [1]x\\n\", word)\n\n\tfmt.Printf(\"%s %s\\n\", word[:2], []byte{word[0], word[1]}) // ö\n\tfmt.Printf(\"%c\\n\", word[2])                               // y\n\tfmt.Printf(\"%c\\n\", word[3])                               // k\n\tfmt.Printf(\"%s %s\\n\", word[4:], []byte{word[4], word[5]}) // ü\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/04-rune-decoding/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unicode/utf8\"\n)\n\nfunc main() {\n\tconst text = `Galaksinin Batı Sarmal Kolu'nun bir ucunda, haritası bile çıkarılmamış ücra bir köşede, gözlerden uzak, küçük ve sarı bir güneş vardır.\n\nBu güneşin yörüngesinde, kabaca yüz kırksekiz milyon kilometre uzağında, tamamıyla önemsiz ve mavi-yeşil renkli, küçük bir gezegen döner.\n\nGezegenin maymun soyundan gelen canlıları öyle ilkeldir ki dijital kol saatinin hâlâ çok etkileyici bir buluş olduğunu düşünürler.`\n\n\tr, size := utf8.DecodeRuneInString(\"öykü\")\n\tfmt.Printf(\"rune: %c size: %d bytes.\\n\", r, size)\n\n\tr, size = utf8.DecodeRuneInString(\"ykü\")\n\tfmt.Printf(\"rune: %c size: %d bytes.\\n\", r, size)\n\n\tr, size = utf8.DecodeRuneInString(\"kü\")\n\tfmt.Printf(\"rune: %c size: %d bytes.\\n\", r, size)\n\n\tr, size = utf8.DecodeRuneInString(\"ü\")\n\tfmt.Printf(\"rune: %c size: %d bytes.\\n\", r, size)\n\n\t// for range loop automatically decodes the runes\n\t//   but it gives you the position of the current rune\n\t//   instead of its size.\n\n\t// for _, r := range text {}\n\tfor i := 0; i < len(text); {\n\t\tr, size := utf8.DecodeRuneInString(text[i:])\n\t\tfmt.Printf(\"%c\", r)\n\n\t\ti += size\n\t}\n\tfmt.Println()\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/04-rune-decoding/02/benchmarks/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"testing\"\n\t\"unicode\"\n\t\"unicode/utf8\"\n)\n\n/*\nLet's run this program to see the speed differences.\n\nbenchDecoder  30000000          46.2 ns/op --> BEST\nbenchForRange 30000000          53.0 ns/op --> MEDIOCRE\nbenchConcater 20000000          93.7 ns/op --> WORST\n*/\n\nvar word = []byte(\"öykü\")\n\nfunc decoder(w []byte) {\n\t_, size := utf8.DecodeRune(word)\n\tcopy(w[:size], bytes.ToUpper(w[:size]))\n}\n\nfunc forRange(w []byte) {\n\tvar size int\n\tfor i := range string(w) {\n\t\tif i > 0 {\n\t\t\tsize = i\n\t\t\tbreak\n\t\t}\n\t}\n\tcopy(w[:size], bytes.ToUpper(w[:size]))\n}\n\nvar globalString string\n\nfunc concater(w []byte) {\n\trunes := []rune(string(w))\n\trunes[0] = unicode.ToUpper(runes[0])\n\tglobalString = string(runes)\n}\n\nfunc bench(technique func([]byte)) testing.BenchmarkResult {\n\treturn testing.Benchmark(func(b *testing.B) {\n\t\tfor i := 0; i < b.N; i++ {\n\t\t\ttechnique(word)\n\t\t}\n\t})\n}\n\nfunc main() {\n\tfmt.Println(\"benchDecoder\", bench(decoder))\n\tfmt.Println(\"benchForRange\", bench(forRange))\n\tfmt.Println(\"benchConcater\", bench(concater))\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/04-rune-decoding/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"unicode/utf8\"\n)\n\nfunc main() {\n\tword := []byte(\"öykü\")\n\tfmt.Printf(\"%s = % [1]x\\n\", word)\n\n\t// how to make the first rune uppercase?\n\n\t// you need to find the starting and ending position of the first rune\n\n\t// 1st way: `for range`\n\t// you can't get the runes by ranging over a byte slice\n\t// first, you need to convert it to a string\n\tvar size int\n\tfor i := range string(word) {\n\t\tif i > 0 {\n\t\t\tsize = i\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// 2nd way: let's do it using the utf8 package's DecodeRune function\n\t_, size = utf8.DecodeRune(word)\n\n\t// overwrite the current bytes with the new uppercased bytes\n\tcopy(word[:size], bytes.ToUpper(word[:size]))\n\n\t// to get printed bytes/runes need to be encoded in a string\n\tfmt.Printf(\"%s = % [1]x\\n\", word)\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/05-internals/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unsafe\"\n)\n\nfunc main() {\n\t// empty := \"\"\n\t// dump(empty)\n\n\thello := \"hello\"\n\tdump(hello)\n\tdump(\"hello\")\n\tdump(\"hello!\")\n\n\tfor i := range hello {\n\t\tdump(hello[i : i+1])\n\t}\n\n\tdump(string([]byte(hello)))\n\tdump(string([]byte(hello)))\n\tdump(string([]rune(hello)))\n}\n\n// StringHeader is used by a string value\n// In practice, you should use: reflect.Header\ntype StringHeader struct {\n\t// points to a backing array's item\n\tpointer uintptr // where it starts\n\tlength  int     // where it ends\n}\n\n// dump prints the string header of a string value\nfunc dump(s string) {\n\tptr := *(*StringHeader)(unsafe.Pointer(&s))\n\tfmt.Printf(\"%q: %+v\\n\", s, ptr)\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/exercises/01-convert/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Convert the strings\n//\n//   1. Loop over the words slice\n//\n//   2. In the loop:\n//      1. Convert each string value to a byte slice\n//      2. Print the byte slice\n//      3. Append the byte slice to the `bwords`\n//\n//   3. Print the words using the `bwords`\n//\n// EXPECTED OUTPUT\n//  [103 111 112 104 101 114]\n//  [112 114 111 103 114 97 109 109 101 114]\n//  [103 111 32 108 97 110 103 117 97 103 101]\n//  [103 111 32 115 116 97 110 100 97 114 100 32 108 105 98 114 97 114 121]\n//  gopher\n//  programmer\n//  go language\n//  go standard library\n// ---------------------------------------------------------\n\nfunc main() {\n\t// Please uncomment the code below\n\n\t// words := []string{\n\t// \t\"gopher\",\n\t// \t\"programmer\",\n\t// \t\"go language\",\n\t// \t\"go standard library\",\n\t// }\n\n\t// var bwords [][]byte\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/exercises/01-convert/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\twords := []string{\n\t\t\"gopher\",\n\t\t\"programmer\",\n\t\t\"go language\",\n\t\t\"go standard library\",\n\t}\n\n\tvar bwords [][]byte\n\tfor _, w := range words {\n\t\tbw := []byte(w)\n\n\t\tfmt.Println(bw)\n\n\t\tbwords = append(bwords, bw)\n\t}\n\n\tfor _, w := range bwords {\n\t\tfmt.Println(string(w))\n\t}\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/exercises/02-print-the-runes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Print the runes\n//\n//  1. Loop over the \"console\" word and print its runes one by one,\n//     in decimals, hexadecimals and binary.\n//\n//  2. Manually put the runes of the \"console\" word to a byte slice, one by one.\n//\n//     As the elements of the byte slice use only the rune literals.\n//\n//     Print the byte slice.\n//\n//  3. Repeat the step 2 but this time, as the elements of the byte slice,\n//     use only decimal numbers.\n//\n//  4. Repeat the step 2 but this time, as the elements of the byte slice,\n//     use only hexadecimal numbers.\n//\n//\n// EXPECTED OUTPUT\n//   Run the solution to see the expected output.\n// ---------------------------------------------------------\n\nfunc main() {\n\tconst word = \"console\"\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/exercises/02-print-the-runes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tconst word = \"console\"\n\n\tfor _, w := range word {\n\t\tfmt.Printf(\"%c\\n\", w)\n\t\tfmt.Printf(\"\\tdecimal: %[1]d\\n\", w)\n\t\tfmt.Printf(\"\\thex    : 0x%[1]x\\n\", w)\n\t\tfmt.Printf(\"\\tbinary : 0b%08[1]b\\n\", w)\n\t}\n\n\t// print the word manually using runes\n\tfmt.Printf(\"with runes       : %s\\n\",\n\t\tstring([]byte{'c', 'o', 'n', 's', 'o', 'l', 'e'}))\n\n\t// print the word manually using decimals\n\tfmt.Printf(\"with decimals    : %s\\n\",\n\t\tstring([]byte{99, 111, 110, 115, 111, 108, 101}))\n\n\t// print the word manually using hexadecimals\n\tfmt.Printf(\"with hexadecimals: %s\\n\",\n\t\tstring([]byte{0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65}))\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/exercises/03-rune-manipulator/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Rune Manipulator\n//\n//  Please read the comments inside the following code.\n//\n// EXPECTED OUTPUT\n//  Please run the solution.\n// ---------------------------------------------------------\n\nfunc main() {\n\twords := []string{\n\t\t\"cool\",\n\t\t\"güzel\",\n\t\t\"jīntiān\",\n\t\t\"今天\",\n\t\t\"read 🤓\",\n\t}\n\n\t_ = words\n\n\t// Print the byte and rune length of the strings\n\t// Hint: Use len and utf8.RuneCountInString\n\n\t// Print the bytes of the strings in hexadecimal\n\t// Hint: Use % x verb\n\n\t// Print the runes of the strings in hexadecimal\n\t// Hint: Use % x verb\n\n\t// Print the runes of the strings as rune literals\n\t// Hint: Use for range\n\n\t// Print the first rune and its byte size of the strings\n\t// Hint: Use utf8.DecodeRuneInString\n\n\t// Print the last rune of the strings\n\t// Hint: Use utf8.DecodeLastRuneInString\n\n\t// Slice and print the first two runes of the strings\n\n\t// Slice and print the last two runes of the strings\n\n\t// Convert the string to []rune\n\t// Print the first and last two runes\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/exercises/03-rune-manipulator/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unicode/utf8\"\n)\n\nfunc main() {\n\twords := []string{\n\t\t\"cool\",\n\t\t\"güzel\",\n\t\t\"jīntiān\",\n\t\t\"今天\",\n\t\t\"read 🤓\",\n\t}\n\n\tfor _, s := range words {\n\t\tfmt.Printf(\"%q\\n\", s)\n\n\t\t// Print the byte and rune length of the strings\n\t\t// Hint: Use len and utf8.RuneCountInString\n\t\tfmt.Printf(\"\\thas %d bytes and %d runes\\n\",\n\t\t\tlen(s), utf8.RuneCountInString(s))\n\n\t\t// Print the bytes of the strings in hexadecimal\n\t\t// Hint: Use % x verb\n\t\tfmt.Printf(\"\\tbytes   : % x\\n\", s)\n\n\t\t// Print the runes of the strings in hexadecimal\n\t\t// Hint: Use % x verb\n\t\tfmt.Print(\"\\trunes   :\")\n\t\tfor _, r := range s {\n\t\t\tfmt.Printf(\"% x\", r)\n\t\t}\n\t\tfmt.Println()\n\n\t\t// Print the runes of the strings as rune literals\n\t\t// Hint: Use for range\n\t\tfmt.Print(\"\\trunes   :\")\n\t\tfor _, r := range s {\n\t\t\tfmt.Printf(\"%q\", r)\n\t\t}\n\t\tfmt.Println()\n\n\t\t// Print the first rune and its byte size of the strings\n\t\t// Hint: Use utf8.DecodeRuneInString\n\t\tr, size := utf8.DecodeRuneInString(s)\n\t\tfmt.Printf(\"\\tfirst   : %q (%d bytes)\\n\", r, size)\n\n\t\t// Print the last rune of the strings\n\t\t// Hint: Use utf8.DecodeLastRuneInString\n\t\tr, size = utf8.DecodeLastRuneInString(s)\n\t\tfmt.Printf(\"\\tlast    : %q (%d bytes)\\n\", r, size)\n\n\t\t// Slice and print the first two runes of the strings\n\t\t_, first := utf8.DecodeRuneInString(s)\n\t\t_, second := utf8.DecodeRuneInString(s[first:])\n\t\tfmt.Printf(\"\\tfirst 2 : %q\\n\", s[:first+second])\n\n\t\t// Slice and print the last two runes of the strings\n\t\t_, last1 := utf8.DecodeLastRuneInString(s)\n\t\t_, last2 := utf8.DecodeLastRuneInString(s[:len(s)-last1])\n\t\tfmt.Printf(\"\\tlast 2  : %q\\n\", s[len(s)-last2-last1:])\n\n\t\t// Convert the string to []rune\n\t\t// Print the first and last two runes\n\t\trs := []rune(s)\n\t\tfmt.Printf(\"\\tfirst 2 : %q\\n\", string(rs[:2]))\n\t\tfmt.Printf(\"\\tlast 2  : %q\\n\", string(rs[len(rs)-2:]))\n\t}\n}\n"
  },
  {
    "path": "19-strings-runes-bytes/exercises/README.md",
    "content": "# Strings, bytes, and runes exercises\n\n1. **[Convert](https://github.com/inancgumus/learngo/tree/master/19-strings-runes-bytes/exercises/01-convert)**\n\n    Use []byte <-> string conversions.\n\n2. **[Print the Runes](https://github.com/inancgumus/learngo/tree/master/19-strings-runes-bytes/exercises/02-print-the-runes)**\n\n    Use Printf verbs.\n\n3. **[Rune Manipulator](https://github.com/inancgumus/learngo/tree/master/19-strings-runes-bytes/exercises/03-rune-manipulator)**\n\n    Use utf8 package, indexing and slicing."
  },
  {
    "path": "19-strings-runes-bytes/questions/README.md",
    "content": "# Strings, Runes and Bytes Quiz\n\n## Which byte slice below equals to the \"keeper\" string?\n```go\n// Here are the corresponding code points for the runes of \"keeper\":\n// k => 107\n// e => 101\n// p => 112\n// r => 114\n```\n1. []byte{107, 101, 101, 112, 101, 114} *CORRECT*\n2. []byte{112, 101, 101, 112, 114, 101}\n3. []byte{114, 101, 112, 101, 101, 112}\n4. []byte{112, 101, 101, 114, 107, 101}\n\n\n## What does this code print?\n```go\n// Code points:\n// g => 103\n// o => 111\nfmt.Println(string(103), string(111))\n```\n1. 103 111\n2. g o *CORRECT*\n3. n o\n4. \"103 111\"\n\n\n## What does this code print?\n```go\nconst word = \"gökyüzü\"\nbword := []byte(word)\n\n// ö => 2 bytes\n// ü => 2 bytes\nfmt.Println(utf8.RuneCount(bword), len(word), len(string(word[1])))\n```\n1. 7 10 2 *CORRECT*\n2. 10 7 1\n3. 10 7 2\n4. 7 7 1\n\n\n## Which one below is true?\n1. for range loops over the bytes of a string\n2. for range loops over the runes of a string *CORRECT*\n\n\n## For a utf-8 encoded string value, which one below is true?\n1. runes always start and end in the same indexes\n2. runes may start and end in different indexes *CORRECT*\n3. bytes may start and end in different indexes\n\n\n\n## Why can't you change the bytes of a string value?\n1. Strings values are immutable byte slices\n2. Strings are used a lot so they are being shared behind the scenes\n3. All of above *CORRECT*"
  },
  {
    "path": "20-project-spam-masker/01-step-1/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n/*\n✅ #1- Get and check the input\n✅ #2- Create a byte buffer and use it as the output\n✅ #3- Write input to the buffer as it is and print it\n✅ #4- Detect the link\n#5- Mask the link\n#6- Stop masking when whitespace is detected\n#7- Put a http:// prefix in front of the masked link\n*/\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"gimme somethin' to mask!\")\n\t\treturn\n\t}\n\n\tconst (\n\t\tlink  = \"http://\"\n\t\tnlink = len(link)\n\t)\n\n\tvar (\n\t\ttext = args[0]\n\t\tsize = len(text)\n\t\tbuf  = make([]byte, 0, size)\n\t)\n\n\tfor i := 0; i < size; i++ {\n\t\tbuf = append(buf, text[i])\n\n\t\t// slice the input and look for the link pattern\n\t\t// do not slice it when it goes beyond the input text's capacity\n\t\tif len(text[i:]) >= nlink && text[i:i+nlink] == link {\n\t\t}\n\t}\n\n\t// print out the buffer as text (string)\n\tfmt.Println(string(buf))\n}\n"
  },
  {
    "path": "20-project-spam-masker/01-step-1/spam.txt",
    "content": "Hi guys, \n\nHere is my new spammy webpage http://www.mysuperpage.com <-- This is my website!\n\nPlease click on the link now!!!\n\nWhen you click, I will be rich, thanks!"
  },
  {
    "path": "20-project-spam-masker/02-step-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n/*\n✅ #1- Get and check the input\n✅ #2- Create a byte buffer and use it as the output\n✅ #3- Write input to the buffer as it is and print it\n✅ #4- Detect the link\n✅ #5- Mask the link\n✅ #6- Stop masking when whitespace is detected\n✅ #7- Put a http:// prefix in front of the masked link\n*/\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nconst (\n\tlink  = \"http://\"\n\tnlink = len(link)\n\tmask  = '*'\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"gimme somethin' to mask!\")\n\t\treturn\n\t}\n\n\tvar (\n\t\ttext = args[0]\n\t\tsize = len(text)\n\t\tbuf  = make([]byte, 0, size)\n\n\t\tin bool\n\t)\n\n\tfor i := 0; i < size; i++ {\n\t\t// slice the input and look for the link pattern\n\t\t// do not slice it when it goes beyond the input text's capacity\n\t\tif len(text[i:]) >= nlink && text[i:i+nlink] == link {\n\t\t\t// set the flag: we're in a link! -> \"http://.....\"\n\t\t\tin = true\n\n\t\t\t// add the \"http://\" manually\n\t\t\tbuf = append(buf, link...)\n\n\t\t\t// jump to the next character after \"http://\"\n\t\t\ti += nlink\n\t\t}\n\n\t\t// get the current byte from the input\n\t\tc := text[i]\n\n\t\t// disable the link detection flag\n\t\t// this will prevent masking the rest of the bytes\n\t\tswitch c {\n\t\tcase ' ', '\\t', '\\n': // try -> unicode.IsSpace\n\t\t\tin = false\n\t\t}\n\n\t\t// if we're in the link detection mode (inside the link bytes)\n\t\t// then, mask the current character\n\t\tif in {\n\t\t\tc = mask\n\t\t}\n\t\tbuf = append(buf, c)\n\t}\n\n\t// print out the buffer as text (string)\n\tfmt.Println(string(buf))\n}\n"
  },
  {
    "path": "20-project-spam-masker/02-step-2/spam.txt",
    "content": "Hi guys, \n\nHere is my new spammy webpage http://www.mysuperpage.com <-- This is my website!\n\nPlease click on the link now!!!\n\nWhen you click, I will be rich, thanks!"
  },
  {
    "path": "20-project-spam-masker/03-step-2-no-append/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n/*\n✅ #1- Get and check the input\n✅ #2- Create a byte buffer and use it as the output\n✅ #3- Write input to the buffer as it is and print it\n✅ #4- Detect the link\n✅ #5- Mask the link\n✅ #6- Stop masking when whitespace is detected\n✅ #7- Put a http:// prefix in front of the masked link\n*/\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nconst (\n\tlink  = \"http://\"\n\tnlink = len(link)\n\tmask  = '*'\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"gimme somethin' to mask!\")\n\t\treturn\n\t}\n\n\tvar (\n\t\ttext = args[0]\n\t\tsize = len(text)\n\n\t\t// create a byte buffer directly from the string (text)\n\t\tbuf = []byte(text)\n\n\t\tin bool\n\t)\n\n\tfor i := 0; i < size; i++ {\n\t\t// no need to add an artificial http:// prefix\n\t\t// it's already there\n\t\tif len(text[i:]) >= nlink && text[i:i+nlink] == link {\n\t\t\tin = true\n\t\t\ti += nlink\n\t\t}\n\n\t\tswitch text[i] {\n\t\tcase ' ', '\\t', '\\n': // try -> unicode.IsSpace\n\t\t\tin = false\n\t\t}\n\n\t\t// when censoring mode: on\n\t\t// directly manipulate the bytes on the buffer\n\t\tif in {\n\t\t\tbuf[i] = mask\n\t\t}\n\t}\n\tfmt.Println(string(buf))\n}\n"
  },
  {
    "path": "20-project-spam-masker/03-step-2-no-append/spam.txt",
    "content": "Hi guys, \n\nHere is my new spammy webpage http://www.mysuperpage.com <-- This is my website!\n\nPlease click on the link now!!!\n\nWhen you click, I will be rich, thanks!"
  },
  {
    "path": "20-project-spam-masker/README.md",
    "content": "# Spam Masker Challenge Tips\n\n## Rules:\n\n* You shouldn't use a standard library function.\n\n* You should only solve the challenge by manipulating the bytes directly.\n\n* Manipulate the bytes of a string using indexing, slicing, appending etc.\n\n* Be efficient: Do not use string concat (+ operator).\n\t* Instead, create a new byte slice as a buffer from the given string argument.\n\t* Then, manipulate it during your program.\n\t* And, for once, print that buffer.\n\n* Mask only links starting with `http://`\n\n* Don't check for uppercase/lowercase letters\n\n\t* The goal is learning how to manipulate bytes in strings, it's not about creating the perfect masker.\n\n\t* For example: A spammer can prevent the masker like this (for now this is OK):\n\n\t  ```\n      \"Here's my spammy page: hTTp://youth-elixir.com\"\n                               ^^\n      ```\n\n* But, you should catch this:\n\n  ```\n  INPUT:\n  Here's my spammy page: http://hehefouls.netHAHAHA see you.\n\n  OUTPUT:\n  Here's my spammy page: http://******************* see you.\n  ```\n\n## Steps:\n\n1. Check whether there's a command line argument or not. If not, quit from the program with a message.\n\n2. Create a byte buffer as big as the argument.\n\n3. Loop and detect the `http://` patterns\n\n4. Copy the input character by character to the buffer\n\n5. If you detect `http://` pattern, copy the `http://` first, then copy the `*`s instead of the original link until you see whitespace character.\n\n    For example: \n    ```\n\tINPUT:\n    Here: http://www.mylink.com Click!\n\n    OUTPUT:\n\tHere: http://************** Click!\n    ```\n\n6. Print the buffer as a string"
  },
  {
    "path": "21-project-text-wrapper/README.md",
    "content": "# Text Wrapper Challenge Guideline\n\nIn this project your goal is to mimic the soft text wrapping feature of text editors. For example, when there are 100 characters on a line and if the soft-wrapping is set to 40, an editor may cut the line that goes beyond 40 characters and display the rest of the line in the next line instead.\n\n## EXAMPLE\n\nWrap the given text for 40 characters per line. For example, for the following input, the program should print the following output.\n\n**INPUT:**\n\n    Hello world, how is it going? It is ok.. The weather is beautiful.\n\n**OUTPUT:**\n\n    Hello world, how is it going? It is ok..\n    The weather is beautiful.\n\n## RULES\n\n* The program should work with Unicode text. You can find a unicode text in [story.txt](story.txt) file.\n\n* The program should not cut the words before they finish. Instead, it should put the whole word on the next line. \n\nFor example, this is not OK:\n \n    Hello world, how is it goi\n    ng? It is o\n    k. The weather is beautifu\n    l.\n\n## SOLUTION\n\n* [Get the solution source code here](main.go).\n"
  },
  {
    "path": "21-project-text-wrapper/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unicode\"\n)\n\nfunc main() {\n\tconst text = `Galaksinin Batı Sarmal Kolu'nun bir ucunda, haritası bile çıkarılmamış ücra bir köşede, gözlerden uzak, küçük ve sarı bir güneş vardır.\n\nBu güneşin yörüngesinde, kabaca yüz kırksekiz milyon kilometre uzağında, tamamıyla önemsiz ve mavi-yeşil renkli, küçük bir gezegen döner.\n\nGezegenin maymun soyundan gelen canlıları öyle ilkeldir ki dijital kol saatinin hâlâ çok etkileyici bir buluş olduğunu düşünürler.`\n\n\tconst maxWidth = 40\n\n\tvar lw int // line width\n\n\tfor _, r := range text {\n\t\tfmt.Printf(\"%c\", r)\n\n\t\tswitch lw++; {\n\t\tcase lw > maxWidth && r != '\\n' && unicode.IsSpace(r):\n\t\t\tfmt.Println()\n\t\t\tfallthrough\n\t\tcase r == '\\n':\n\t\t\tlw = 0\n\t\t}\n\t}\n\tfmt.Println()\n}\n"
  },
  {
    "path": "21-project-text-wrapper/story.txt",
    "content": "Galaksinin Batı Sarmal Kolu'nun bir ucunda, haritası bile çıkarılmamış ücra bir köşede, gözlerden uzak, küçük ve sarı bir güneş vardır.\n\nBu güneşin yörüngesinde, kabaca yüz kırksekiz milyon kilometre uzağında, tamamıyla önemsiz ve mavi-yeşil renkli, küçük bir gezegen döner.\n\nGezegenin maymun soyundan gelen canlıları öyle ilkeldir ki dijital kol saatinin hâlâ çok etkileyici bir buluş olduğunu düşünürler."
  },
  {
    "path": "22-maps/01-english-dict/01-as-a-slice/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"[english word] -> [turkish word]\")\n\t\treturn\n\t}\n\tquery := args[0]\n\n\tenglish := []string{\"good\", \"great\", \"perfect\"}\n\tturkish := []string{\"iyi\", \"harika\", \"mükemmel\"}\n\n\t// O(n) -> Inefficient: Depends on 'n'.\n\tfor i, w := range english {\n\t\tif query == w {\n\t\t\tfmt.Printf(\"%q means %q\\n\", w, turkish[i])\n\t\t\treturn\n\t\t}\n\t}\n\n\tfmt.Printf(\"%q not found\\n\", query)\n}\n"
  },
  {
    "path": "22-maps/01-english-dict/02-as-a-map/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// args := os.Args[1:]\n\t// if len(args) != 1 {\n\t// \tfmt.Println(\"[english word] -> [turkish word]\")\n\t// \treturn\n\t// }\n\t// query := args[0]\n\n\t// #1: Nil Map: Read-Only\n\tvar dict map[string]string\n\n\t// #5: You cannot assign to a nil map.\n\t// dict[\"up\"] = \"yukarı\"\n\t// dict[\"down\"] = \"aşağı\"\n\n\t// #2: Map retrieval is O(1) — on average.\n\tkey := \"good\"\n\n\tvalue := dict[key]\n\tfmt.Printf(\"%q means %#v\\n\", key, value)\n\n\t// #1B\n\tfmt.Printf(\"# of Keys: %d\\n\", len(dict))\n\n\t// fmt.Printf(\"Zero Value: %#v\\n\", dict)\n\n\t// #4: Nil map ready to use\n\t// if dict != nil {\n\t// \tvalue := dict[key]\n\t// \tfmt.Printf(\"%q means %#v\\n\", key, value)\n\t// }\n\n\t// #3: Cannot use non-comparable types as map key types\n\t// var broken map[[]int]int\n\t// var broken map[map[int]string]bool\n\t//\n\t// A map can only be compared to nil value\n\t// _ = dict == nil\n}\n"
  },
  {
    "path": "22-maps/02-english-dict-map-populate/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\t// #2A: Get the key from CLI\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"[english word] -> [turkish word]\")\n\t\treturn\n\t}\n\tquery := args[0]\n\n\t// #1: Empty Map Literal\n\t// dict := map[string]string{}\n\n\t// 3: Map Literal\n\tdict := map[string]string{\n\t\t\"good\":    \"kötü\",\n\t\t\"great\":   \"harika\",\n\t\t\"perfect\": \"mükemmel\",\n\t\t// #4\n\t\t// 42: \"forty two\",\n\t\t// \"forty two\": 42,\n\t}\n\n\tdict[\"up\"] = \"yukarı\"  // adds a new pair\n\tdict[\"down\"] = \"aşağı\" // adds a new pair\n\tdict[\"good\"] = \"iyi\"   // #5: overwrites the value at the key: \"good\"\n\tdict[\"mistake\"] = \"\"   // #8: a key with a zero-value\n\n\t// #10: comma ok in a short if\n\tif value, ok := dict[query]; ok {\n\t\tfmt.Printf(\"%q means %#v\\n\", query, value)\n\t\treturn\n\t}\n\tfmt.Printf(\"%q not found.\\n\", query)\n\n\t// fmt.Printf(\"Zero Value: %#v\\n\", dict)\n\tfmt.Printf(\"# of Keys : %d\\n\", len(dict))\n\n\t// #13: compare a map using its printed output\n\t// copied := map[string]string{\"up\": \"yukarı\", \"down\": \"aşağı\",\n\t// \t\"mistake\": \"\", \"good\": \"iyi\", \"great\": \"harika\",\n\t// \t\"perfect\": \"mükemmel\"}\n\n\t// first := fmt.Sprintf(\"%s\", dict)\n\t// second := fmt.Sprintf(\"%s\", copied)\n\n\t// if first == second {\n\t// \tfmt.Println(\"Maps are equal\")\n\t// }\n\n\t// #12: printing a map (ordered output since Go 1.12)\n\t// fmt.Printf(\"%#v\\n\", dict)\n\n\t// #11\n\t// for k, v := range dict {\n\t// \tfmt.Printf(\"%q means %#v\\n\", k, v)\n\t// }\n\n\t// #9: check for non-existing key: with comma, ok\n\t// value, ok := dict[query]\n\t// if !ok {\n\t// \tfmt.Printf(\"%q not found.\\n\", query)\n\t// }\n\n\t// #7: check for non-existing key using zero-value\n\t// if value == \"\" {\n\t// \tfmt.Printf(\"%q not found.\\n\", query)\n\t// }\n\n\t// #6: getting values from a map using keys directly\n\t// fmt.Println(\"good      -> \", dict[\"good\"])\n\t// fmt.Println(\"great     -> \", dict[\"great\"])\n\t// fmt.Println(\"perfect   -> \", dict[\"perfect\"])\n\n\t// #2B: retrieve values by key - O(1) efficiency\n\t// value := dict[query]\n\n}\n"
  },
  {
    "path": "22-maps/03-internals-cloning/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"[english word] -> [turkish word]\")\n\t\treturn\n\t}\n\tquery := args[0]\n\n\tdict := map[string]string{\n\t\t\"good\":    \"iyi\",\n\t\t\"great\":   \"harika\",\n\t\t\"perfect\": \"mükemmel\",\n\t\t\"awesome\": \"mükemmel\", // #5\n\t}\n\n\t// turkish := dict // #1\n\t// turkish[\"good\"] = \"güzel\"\n\t// dict[\"great\"] = \"kusursuz\"\n\n\tdelete(dict, \"awesome\") // #6\n\tdelete(dict, \"awesome\") // #7: no-op\n\tdelete(dict, \"notexisting\")\n\t\n\t// dict = nil // #8\n\tfor k := range dict { // #9\n\t\tdelete(dict, k)\n\t}\n\n\t// turkish := make(map[string]string) // #2\n\tturkish := make(map[string]string, len(dict)) // #3\n\tfor k, v := range dict {\n\t\tturkish[v] = k\n\t}\n\n\t// fmt.Printf(\"english: %q\\nturkish: %q\\n\", dict, turkish) // #4\n\tif value, ok := dict[query]; ok {\n\t\tfmt.Printf(\"%q means %#v\\n\", query, value)\n\t\treturn\n\t}\n\n\tif value, ok := turkish[query]; ok {\n\t\tfmt.Printf(\"%q means %#v\\n\", query, value)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%q not found.\\n\", query)\n}\n"
  },
  {
    "path": "22-maps/exercises/01-warm-up/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Warm-up\n//\n//  Create and print the following maps.\n//\n//  1. Phone numbers by last name\n//  2. Product availability by Product ID\n//  3. Multiple phone numbers by last name\n//  4. Shopping basket by Customer ID\n//\n//     Each item in the shopping basket has a Product ID and\n//     quantity. Through the map, you can tell:\n//     \"Mr. X has bought Y bananas\"\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// Hint: Store phone numbers as text\n\n\t// #1\n\t// Key        : Last name\n\t// Element    : Phone number\n\n\t// #2\n\t// Key        : Product ID\n\t// Element    : Available / Unavailable\n\n\t// #3\n\t// Key        : Last name\n\t// Element    : Phone numbers\n\n\t// #4\n\t// Key        : Customer ID\n\t// Element Key:\n\t//   Key: Product ID Element: Quantity\n}\n"
  },
  {
    "path": "22-maps/exercises/01-warm-up/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tphones map[string]string\n\t\t// Key        : Last name\n\t\t// Element    : Phone number\n\n\t\t// Key        : Product ID\n\t\t// Element    : Available / Unavailable\n\t\tproducts map[int]bool\n\n\t\tmultiPhones map[string][]string\n\t\t// Key        : Last name\n\t\t// Element    : Phone numbers\n\n\t\tbasket map[int]map[int]int\n\t\t// Key        : Customer ID\n\t\t// Element Key:\n\t\t//   Key: Product ID Element: Quantity\n\t)\n\n\tfmt.Printf(\"phones     : %#v\\n\", phones)\n\tfmt.Printf(\"products   : %#v\\n\", products)\n\tfmt.Printf(\"multiPhones: %#v\\n\", multiPhones)\n\tfmt.Printf(\"basket     : %#v\\n\", basket)\n}\n"
  },
  {
    "path": "22-maps/exercises/02-populate/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Populate and Lookup\n//\n//  Add elements to the maps that you've declared in the\n//  first exercise, and try them by looking up for the keys.\n//\n//  Either use the `make()` or `map literals`.\n//\n//  After completing the exercise, remove the data and check\n//  that your program still works.\n//\n//\n//  1. Phone numbers by last name\n//     --------------------------\n//     bowen  202-555-0179\n//     dulin  03.37.77.63.06\n//     greco  03489940240\n//\n//     Print the dulin's phone number.\n//\n//\n//  2. Product availability by Product ID\n//     ----------------\n//     617841573 true\n//     879401371 false\n//     576872813 true\n//\n//     Is Product ID 879401371 available?\n//\n//\n//  3. Multiple phone numbers by last name\n//     ------------------------------------------------------\n//     bowen  [202-555-0179]\n//     dulin  [03.37.77.63.06 03.37.70.50.05 02.20.40.10.04]\n//     greco  [03489940240 03489900120]\n//\n//     What is Greco's second phone number?\n//\n//\n//  4. Shopping basket by Customer ID\n//     -------------------------------\n//     100 [617841573:4 576872813:2]\n//     101 [576872813:5 657473833:20]\n//     102 []\n//\n//     How many of 576872813 the customer 101 is going to buy?\n//                (Product ID)  (Customer ID)\n//\n//\n// EXPECTED OUTPUT\n//\n//   1. Run the solution to see the output\n//   2. Here is the output with empty maps:\n//\n//      dulin's phone number: N/A\n//      Product ID #879401371 is not available\n//      greco's 2nd phone number: N/A\n//      Customer #101 is going to buy 5 from Product ID #576872813.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "22-maps/exercises/02-populate/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tphones := map[string]string{\n\t\t\"bowen\": \"202-555-0179\",\n\t\t\"dulin\": \"03.37.77.63.06\",\n\t\t\"greco\": \"03489940240\",\n\t}\n\n\tproducts := map[int]bool{\n\t\t617841573: true,\n\t\t879401371: false,\n\t\t576872813: true,\n\t}\n\n\tmultiPhones := map[string][]string{\n\t\t\"bowen\": {\"202-555-0179\"},\n\t\t\"dulin\": {\"03.37.77.63.06\", \"03.37.70.50.05\", \"02.20.40.10.04\"},\n\t\t\"greco\": {\"03489940240\", \"03489900120\"},\n\t}\n\n\tbasket := map[int]map[int]int{\n\t\t100: {617841573: 4, 576872813: 2},\n\t\t101: {576872813: 5, 657473833: 20},\n\t\t102: {},\n\t}\n\n\t// Print dulin's phone number.\n\twho, phone := \"dulin\", \"N/A\"\n\tif v, ok := phones[who]; ok {\n\t\tphone = v\n\t}\n\tfmt.Printf(\"%s's phone number: %s\\n\", who, phone)\n\n\t// Is Product ID 879401371 available?\n\tid, status := 879401371, \"available\"\n\tif !products[id] {\n\t\tstatus = \"not \" + status\n\t}\n\tfmt.Printf(\"Product ID #%d is %s\\n\", id, status)\n\n\t// What is Greco's second phone number?\n\twho, phone = \"greco\", \"N/A\"\n\tif phones := multiPhones[who]; len(phones) >= 2 {\n\t\tphone = phones[1]\n\t}\n\tfmt.Printf(\"%s's 2nd phone number: %s\\n\", who, phone)\n\n\t// How many of 576872813 the customer 101 is going to buy?\n\tcid, pid := 101, 576872813\n\tfmt.Printf(\"Customer #%d is going to buy %d from Product ID #%d.\\n\", cid, basket[cid][pid], pid)\n}\n"
  },
  {
    "path": "22-maps/exercises/03-students/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Students\n//\n//  Create a program that returns the students by the given\n//  Hogwarts house name (see the data below).\n//\n//  Print the students sorted by name.\n//\n//  \"bobo\" doesn't belong to Hogwarts, remove it by using\n//  the delete function.\n//\n//\n// RESTRICTIONS\n//\n//  + Add the following data to your map as is.\n//    Do not sort it manually and do not modify it.\n//\n//  + Slices in the map shouldn't be sorted (changed).\n//    HINT: Copy them.\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//\n//  Please type a Hogwarts house name.\n//\n//\n//  go run main.go bobo\n//\n//  Sorry. I don't know anything about \"bobo\".\n//\n//\n//  go run main.go hufflepuf\n//\n//  ~~~ hufflepuf students ~~~\n//\n//        + diggory\n//        + helga\n//        + scamander\n//        + wenlock\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// House        Student Name\n\t// ---------------------------\n\t// gryffindor   weasley\n\t// gryffindor   hagrid\n\t// gryffindor   dumbledore\n\t// gryffindor   lupin\n\t// hufflepuf    wenlock\n\t// hufflepuf    scamander\n\t// hufflepuf    helga\n\t// hufflepuf    diggory\n\t// ravenclaw    flitwick\n\t// ravenclaw    bagnold\n\t// ravenclaw    wildsmith\n\t// ravenclaw    montmorency\n\t// slytherin    horace\n\t// slytherin    nigellus\n\t// slytherin    higgs\n\t// slytherin    scorpius\n\t// bobo         wizardry\n\t// bobo         unwanted\n}\n"
  },
  {
    "path": "22-maps/exercises/03-students/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n)\n\nfunc main() {\n\thouses := map[string][]string{\n\t\t\"gryffindor\": {\"weasley\", \"hagrid\", \"dumbledore\", \"lupin\"},\n\t\t\"hufflepuf\":  {\"wenlock\", \"scamander\", \"helga\", \"diggory\", \"bobo\"},\n\t\t\"ravenclaw\":  {\"flitwick\", \"bagnold\", \"wildsmith\", \"montmorency\"},\n\t\t\"slytherin\":  {\"horace\", \"nigellus\", \"higgs\", \"bobo\", \"scorpius\"},\n\t\t\"bobo\":       {\"wizardry\", \"unwanted\"},\n\t}\n\n\t// remove the \"bobo\" house\n\tdelete(houses, \"bobo\")\n\n\targs := os.Args[1:]\n\tif len(args) < 1 {\n\t\tfmt.Println(\"Please type a Hogwarts house name.\")\n\t\treturn\n\t}\n\n\thouse, students := args[0], houses[args[0]]\n\tif students == nil {\n\t\tfmt.Printf(\"Sorry. I don't know anything about %q.\\n\", house)\n\t\treturn\n\t}\n\n\t// only sort the clone\n\tclone := append([]string(nil), students...)\n\tsort.Strings(clone)\n\n\tfmt.Printf(\"~~~ %s students ~~~\\n\\n\", house)\n\tfor _, student := range clone {\n\t\tfmt.Printf(\"\\t+ %s\\n\", student)\n\t}\n}\n"
  },
  {
    "path": "22-maps/exercises/README.md",
    "content": "# Header\n\nWhat you will learn?\n\n1. **[Warm Up](https://github.com/inancgumus/learngo/tree/master/22-maps/exercises/01-warm-up)**\n\n    Create and print the maps.\n\n2. **[Populate and Lookup](https://github.com/inancgumus/learngo/tree/master/22-maps/exercises/02-populate)**\n\n    Add elements to the maps that you've declared in the first exercise, and try them by looking up for the keys.\n\n3. **[Hogwarts Students](https://github.com/inancgumus/learngo/tree/master/22-maps/exercises/03-students)**\n\n    Create a program that returns the students by the given Hogwarts house name."
  },
  {
    "path": "22-maps/questions/README.md",
    "content": "## Why are maps used for?\nFor example, here is an inefficient program that uses a loop to find an element among millions of elements.\n```go\nmillions := []int{/* millions of elements */}\nfor _, v := range millions {\n    if v == userQuery {\n        // do something\n    }\n}\n```\n1. Maps allow fast-lookup for map keys in O(1) time *CORRECT*\n2. Maps allow fast-lookup for map keys in O(n) time\n3. Maps allow fast-traversal on map keys in O(1) time\n\n> **1:** That's right. Maps work in O(1) in average for fast-lookup.\n>\n> **2:** Map doesn't work in O(n) time for key lookup.\n>\n\n## When should you not use a map?\n1. To find an element through a key\n2. To loop over the map keys *CORRECT*\n3. To add structured data to your program\n\n> **1:** That is when you use a map.\n> \n> **2:** Right! Looping over map keys happen in O(n) time. So, maps are the worst data structures for key traversing.\n>\n> **3:** Maps don't allow you to add structured data to your program.\n\n\n## Which type below cannot be a map key?\n1. map[string]int\n2. []string\n3. []int\n4. []bool\n5. All of them *CORRECT*\n\n> **5:** Slices, maps, and function values are not comparable. So, they cannot be map keys.\n>\n\n## Which are the key and element types of the map below?\n```go\nmap[string]map[int]bool\n```\n1. Key: string Element: bool\n2. Key: string Element: int\n3. Key: string Element: map[int]\n4. Key: string Element: map[int]bool *CORRECT*\n\n> **4:** The map contains other maps. The element type of a map can be of any type.\n>\n\n## What is a map value behind the scenes?\n1. A map header\n2. A pointer to a map header *CORRECT*\n3. Tiny data structure with 3 fields: Pointer, Length and Capacity\n\n> **2**: That's right. Maps are complex data structures. However, each map value is only a pointer to a map header (which is a more complex data structure)."
  },
  {
    "path": "23-input-scanning/01-scanning/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\t// Simulate an error\n\t// os.Stdin.Close()\n\n\t// Create a new scanner that scans from the standard-input\n\tin := bufio.NewScanner(os.Stdin)\n\n\t// Stores the total number of lines in the input\n\tvar lines int\n\n\t// Scan the input line by line\n\tfor in.Scan() {\n\t\tlines++\n\n\t\t// Get the current line from the scanner's buffer\n\t\t// fmt.Println(\"Scanned Text :\", in.Text())\n\t\t// fmt.Println(\"Scanned Bytes:\", in.Bytes())\n\t\tin.Text()\n\t}\n\tfmt.Printf(\"There are %d line(s)\\n\", lines)\n\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"ERROR:\", err)\n\t}\n}\n"
  },
  {
    "path": "23-input-scanning/01-scanning/proverbs.txt",
    "content": "Go Proverbs\nMake the zero value useful\nClear is better than clever\nErrors are values"
  },
  {
    "path": "23-input-scanning/02-map-as-sets/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"regexp\"\n\t\"strings\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"Please type a search word.\")\n\t\treturn\n\t}\n\tquery := args[0]\n\n\trx := regexp.MustCompile(`[^a-z]+`)\n\n\tin := bufio.NewScanner(os.Stdin)\n\tin.Split(bufio.ScanWords)\n\n\twords := make(map[string]bool)\n\tfor in.Scan() {\n\t\tword := strings.ToLower(in.Text())\n\t\tword = rx.ReplaceAllString(word, \"\")\n\n\t\tif len(word) > 2 {\n\t\t\twords[word] = true\n\t\t}\n\t}\n\n\t// for word := range words {\n\t// \tfmt.Println(word)\n\t// }\n\n\tif words[query] {\n\t\tfmt.Printf(\"The input contains %q.\\n\", query)\n\t\treturn\n\t}\n\tfmt.Printf(\"Sorry. The input does not contain %q.\\n\", query)\n\n\t// query := \"sun\"\n\t// fmt.Println(\"sun:\", words[\"sun\"], \"tesla:\", words[\"tesla\"])\n\n\t// unnecessary\n\t// if _, ok := words[query]; ok {\n\t// \tfmt.Printf(\"The input contains %q.\\n\", query)\n\t// \treturn\n\t// }\n\t// fmt.Printf(\"Sorry. The input does not contain %q.\\n\", query)\n}\n"
  },
  {
    "path": "23-input-scanning/02-map-as-sets/shakespeare.txt",
    "content": "come night come romeo come thou day in night\nfor thou wilt lie upon the wings of night\nwhiter than new snow on a raven's back\ncome gentle night come loving black-browed night\ngive me my romeo and when he shall die\ntake him and cut him out in little stars\nand he will make the face of heaven so fine\nthat all the world will be in love with night\nand pay no worship to the garish sun\noh I have bought the mansion of love\nbut not possessed it and though I am sold\nnot yet enjoyed\n"
  },
  {
    "path": "23-input-scanning/03-project-log-parser/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/03-project-log-parser/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/03-project-log-parser/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/03-project-log-parser/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/03-project-log-parser/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tvar (\n\t\tsum     map[string]int // total visits per domain\n\t\tdomains []string       // unique domain names\n\t\ttotal   int            // total visits to all domains\n\t\tlines   int            // number of parsed lines (for the error messages)\n\t)\n\n\tsum = make(map[string]int)\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tlines++\n\n\t\t// Parse the fields\n\t\tfields := strings.Fields(in.Text())\n\t\tif len(fields) != 2 {\n\t\t\tfmt.Printf(\"wrong input: %v (line #%d)\\n\", fields, lines)\n\t\t\treturn\n\t\t}\n\n\t\tdomain := fields[0]\n\n\t\t// Sum the total visits per domain\n\t\tvisits, err := strconv.Atoi(fields[1])\n\t\tif visits < 0 || err != nil {\n\t\t\tfmt.Printf(\"wrong input: %q (line #%d)\\n\", fields[1], lines)\n\t\t\treturn\n\t\t}\n\n\t\t// Collect the unique domains\n\t\tif _, ok := sum[domain]; !ok {\n\t\t\tdomains = append(domains, domain)\n\t\t}\n\n\t\t// Keep track of total and per domain visits\n\t\ttotal += visits\n\t\tsum[domain] += visits\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range domains {\n\t\tvisits := sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/01-uppercaser/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Uppercaser\n//\n//  Use a scanner to convert the lines to uppercase, and\n//  print them.\n//\n//  1. Feed the shakespeare.txt to your program.\n//\n//  2. Scan the input using a new Scanner.\n//\n//  3. Print each line.\n//\n// EXPECTED OUTPUT\n//  Please run the solution to see the expected output.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/01-uppercaser/shakespeare.txt",
    "content": "come night come romeo come thou day in night\nfor thou wilt lie upon the wings of night\nwhiter than new snow on a raven's back\ncome gentle night come loving black-browed night\ngive me my romeo and when he shall die\ntake him and cut him out in little stars\nand he will make the face of heaven so fine\nthat all the world will be in love with night\nand pay no worship to the garish sun\noh I have bought the mansion of love\nbut not possessed it and though I am sold\nnot yet enjoyed\n"
  },
  {
    "path": "23-input-scanning/exercises/01-uppercaser/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\tin := bufio.NewScanner(os.Stdin)\n\n\tfor in.Scan() {\n\t\tfmt.Println(strings.ToUpper(in.Text()))\n\t}\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/01-uppercaser/solution/shakespeare.txt",
    "content": "come night come romeo come thou day in night\nfor thou wilt lie upon the wings of night\nwhiter than new snow on a raven's back\ncome gentle night come loving black-browed night\ngive me my romeo and when he shall die\ntake him and cut him out in little stars\nand he will make the face of heaven so fine\nthat all the world will be in love with night\nand pay no worship to the garish sun\noh I have bought the mansion of love\nbut not possessed it and though I am sold\nnot yet enjoyed\n"
  },
  {
    "path": "23-input-scanning/exercises/02-unique-words/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Unique Words\n//\n//  Create a program that prints the total and unique words\n//  from an input stream.\n//\n//  1. Feed the shakespeare.txt to your program.\n//\n//  2. Scan the input using a new Scanner.\n//\n//  3. Configure the scanner to scan for the words.\n//\n//  4. Count the unique words using a map.\n//\n//  5. Print the total and unique words.\n//\n//\n// EXPECTED OUTPUT\n//\n//  There are 99 words, 70 of them are unique.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/02-unique-words/shakespeare.txt",
    "content": "come night come romeo come thou day in night\nfor thou wilt lie upon the wings of night\nwhiter than new snow on a raven's back\ncome gentle night come loving black-browed night\ngive me my romeo and when he shall die\ntake him and cut him out in little stars\nand he will make the face of heaven so fine\nthat all the world will be in love with night\nand pay no worship to the garish sun\noh I have bought the mansion of love\nbut not possessed it and though I am sold\nnot yet enjoyed\n"
  },
  {
    "path": "23-input-scanning/exercises/02-unique-words/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tin := bufio.NewScanner(os.Stdin)\n\tin.Split(bufio.ScanWords)\n\n\ttotal, words := 0, make(map[string]int)\n\tfor in.Scan() {\n\t\ttotal++\n\t\twords[in.Text()]++\n\t}\n\tfmt.Printf(\"There are %d words, %d of them are unique.\\n\",\n\t\ttotal, len(words))\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/02-unique-words/solution/shakespeare.txt",
    "content": "come night come romeo come thou day in night\nfor thou wilt lie upon the wings of night\nwhiter than new snow on a raven's back\ncome gentle night come loving black-browed night\ngive me my romeo and when he shall die\ntake him and cut him out in little stars\nand he will make the face of heaven so fine\nthat all the world will be in love with night\nand pay no worship to the garish sun\noh I have bought the mansion of love\nbut not possessed it and though I am sold\nnot yet enjoyed\n"
  },
  {
    "path": "23-input-scanning/exercises/03-unique-words-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Unique Words 2\n//\n//  Use your solution from the previous \"Unique Words\"\n//  exercise.\n//\n//  Before adding the words to your map, remove the\n//  punctuation characters and numbers from them.\n//\n//\n// BE CAREFUL\n//\n//  Now the shakespeare.txt contains upper and lower\n//  case letters too.\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go < shakespeare.txt\n//\n//   There are 100 words, 69 of them are unique.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// This is the regular expression pattern you need to use:\n\t// [^A-Za-z]+\n\t//\n\t// Matches to any character but upper case and lower case letters\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/03-unique-words-2/shakespeare.txt",
    "content": "Come, night. Come, Romeo. Come, thou day in night,\nFor thou wilt lie upon the wings of night\nWhiter than new snow upon a raven’s back.\nCome, gentle night, come, loving, black-browed night,\nGive me my Romeo. And when I shall die,\nTake him and cut him out in little stars,\nAnd he will make the face of heaven so fine\nThat all the world will be in love with night\nAnd pay no worship to the garish sun.\nOh, I have bought the mansion of a love,\nBut not possessed it, and though I am sold,\nNot yet enjoyed."
  },
  {
    "path": "23-input-scanning/exercises/03-unique-words-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"regexp\"\n\t\"strings\"\n)\n\nfunc main() {\n\tin := bufio.NewScanner(os.Stdin)\n\tin.Split(bufio.ScanWords)\n\n\trx := regexp.MustCompile(`[^A-Za-z]+`)\n\n\ttotal, words := 0, make(map[string]int)\n\tfor in.Scan() {\n\t\ttotal++\n\n\t\tword := rx.ReplaceAllString(in.Text(), \"\")\n\t\tword = strings.ToLower(word)\n\t\twords[word]++\n\t}\n\n\tfmt.Printf(\"There are %d words, %d of them are unique.\\n\",\n\t\ttotal, len(words))\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/03-unique-words-2/solution/shakespeare.txt",
    "content": "Come, night. Come, Romeo. Come, thou day in night,\nFor thou wilt lie upon the wings of night\nWhiter than new snow upon a raven’s back.\nCome, gentle night, come, loving, black-browed night,\nGive me my Romeo. And when I shall die,\nTake him and cut him out in little stars,\nAnd he will make the face of heaven so fine\nThat all the world will be in love with night\nAnd pay no worship to the garish sun.\nOh, I have bought the mansion of a love,\nBut not possessed it, and though I am sold,\nNot yet enjoyed."
  },
  {
    "path": "23-input-scanning/exercises/04-grep/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Grep Clone\n//\n//  Create a grep clone. grep is a command-line utility for\n//  searching plain-text data for lines that match a specific\n//  pattern.\n//\n//  1. Feed the shakespeare.txt to your program.\n//\n//  2. Accept a command-line argument for the pattern\n//\n//  3. Only print the lines that contains that pattern\n//\n//  4. If no pattern is provided, print all the lines\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go come < shakespeare.txt\n//\n//    come night come romeo come thou day in night\n//    come gentle night come loving black-browed night\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/04-grep/shakespeare.txt",
    "content": "come night come romeo come thou day in night\nfor thou wilt lie upon the wings of night\nwhiter than new snow on a raven's back\ncome gentle night come loving black-browed night\ngive me my romeo and when he shall die\ntake him and cut him out in little stars\nand he will make the face of heaven so fine\nthat all the world will be in love with night\nand pay no worship to the garish sun\noh I have bought the mansion of love\nbut not possessed it and though I am sold\nnot yet enjoyed\n"
  },
  {
    "path": "23-input-scanning/exercises/04-grep/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\tin := bufio.NewScanner(os.Stdin)\n\n\tvar pattern string\n\tif args := os.Args[1:]; len(args) == 1 {\n\t\tpattern = args[0]\n\t}\n\n\tfor in.Scan() {\n\t\ts := in.Text()\n\t\tif strings.Contains(s, pattern) {\n\t\t\tfmt.Println(s)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/04-grep/solution/shakespeare.txt",
    "content": "come night come romeo come thou day in night\nfor thou wilt lie upon the wings of night\nwhiter than new snow on a raven's back\ncome gentle night come loving black-browed night\ngive me my romeo and when he shall die\ntake him and cut him out in little stars\nand he will make the face of heaven so fine\nthat all the world will be in love with night\nand pay no worship to the garish sun\noh I have bought the mansion of love\nbut not possessed it and though I am sold\nnot yet enjoyed\n"
  },
  {
    "path": "23-input-scanning/exercises/05-quit/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Quit\n//\n//  Create a program that quits when a user types the\n//  same word twice.\n//\n//\n// RESTRICTION\n//\n//  The program should work case insensitive.\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go\n//\n//   hey\n//   HEY\n//   TWICE!\n//\n//  go run main.go\n//\n//   hey\n//   hi\n//   HEY\n//   TWICE!\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/05-quit/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\tin := bufio.NewScanner(os.Stdin)\n\n\twords := make(map[string]bool)\n\tfor in.Scan() {\n\t\tw := strings.ToLower(in.Text())\n\n\t\tif words[w] {\n\t\t\tfmt.Println(\"TWICE!\")\n\t\t\treturn\n\t\t}\n\t\twords[in.Text()] = true\n\t}\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/06-log-parser/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/exercises/06-log-parser/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/exercises/06-log-parser/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/exercises/06-log-parser/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "23-input-scanning/exercises/06-log-parser/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Log Parser from Stratch\n//\n//  You've watched the lecture. Now, try to create the same\n//  log parser program on your own. Do not look at the lecture,\n//  and the existing source code.\n//\n//\n// EXPECTED OUTPUT\n//\n//  go run main.go < log.txt\n//\n//   DOMAIN                             VISITS\n//   ---------------------------------------------\n//   blog.golang.org                        30\n//   golang.org                             10\n//   learngoprogramming.com                 20\n//\n//   TOTAL                                  60\n//\n//\n//  go run main.go < log_err_missing.txt\n//\n//   wrong input: [golang.org] (line #3)\n//\n//\n//  go run main.go < log_err_negative.txt\n//\n//   wrong input: \"-100\" (line #3)\n//\n//\n//  go run main.go < log_err_str.txt\n//\n//   wrong input: \"FOUR\" (line #3)\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "23-input-scanning/exercises/README.md",
    "content": "# Exercises\n\nLet's exercise with the scanner and maps.\n\n1. **[Uppercaser](https://github.com/inancgumus/learngo/tree/master/23-input-scanning/exercises/01-uppercaser)**\n\n  Use a scanner to convert the lines to uppercase, and print them.\n   \n2. **[Unique Words](https://github.com/inancgumus/learngo/tree/master/23-input-scanning/exercises/02-unique-words)**\n\n  Create a program that counts the unique words from an input stream.\n\n3. **[Unique Words 2](https://github.com/inancgumus/learngo/tree/master/23-input-scanning/exercises/03-unique-words-2)**\n\n  Enhance the previous exercise: Before adding the words to your map, remove the punctuation characters and numbers from them.\n\n4. **[Grep Clone](https://github.com/inancgumus/learngo/tree/master/23-input-scanning/exercises/04-grep)**\n\n  Create a grep clone. grep is a command-line utility for searching plain-text data for lines that match a specific pattern.\n\n5. **[Quit](https://github.com/inancgumus/learngo/tree/master/23-input-scanning/exercises/05-quit)**\n\n  Create a program that quits when a user types the same word twice.\n\n6. **[Create the Log Parser program from scratch](https://github.com/inancgumus/learngo/tree/master/23-input-scanning/exercises/06-log-parser)**\n\n  You've watched the lecture. Now, try to create the same log parser program on your own. Do not look at the lecture, and the existing source code. The link contains the code where you need to start working on."
  },
  {
    "path": "23-input-scanning/questions/README.md",
    "content": "## What is an input stream?\n1. Any data source that generates contiguous data like Standard Input *CORRECT*\n2. An input from a user\n3. The contents of a file\n4. The contents of a website\n\n> **1:** That's right. The input stream can come from any data source. Standard Input is one of them, and you can redirect it to almost any data source like user input, files, website contents and so on.\n>\n> **2-4:** Yes, that may be an input stream, but it doesn't explain what an input stream is.\n>\n\n\n## What does the program print?\n```go\nin := bufio.Scanner(os.Stdin)\nin.Scan() // user enters: \"hi!\"\nin.Scan() // user enters: \"how are you?\"\nfmt.Println(in.Text())\n```\n1. \"hi\" and \"how are you?\"\n2. \"hi\"\n3. \"how are you?\" *CORRECT*\n4. Nothing\n\n> **3:** The Text() method only returns the last scanned token. A token can be a line or a word and so on.\n>\n\n\n## Using bufio.Scanner, how can you detect errors in the input stream?\n1. Using the Err() method *CORRECT*\n2. Using the Error() method\n3. By checking whether the Scanner is nil or not\n\n\n## How can you configure bufio.Scanner to only scan for the words?\n```go\nin := bufio.Scanner(os.Stdin)\n// ...\n```\n1. `in = bufio.NewScanner(in, bufio.ScanWords)`\n2. `in.Split(bufio.ScanWords)` *CORRECT*\n3. `in.ScanWords()`\n\n> **2:** That's right. bufio has a few splitters like ScanWords such as ScanLines (the default), ScanRunes, and so on.\n>\n\n\n## The function uses the \"Must\" prefix, why?\n```go\nregexp.MustCompile(\"...\")\n```\n1. It's only being used for readability purposes\n2. It's a guarantee that the function will work, no matter what\n3. The function may crash your program *CORRECT*\n\n> **3:** \"Must\" prefix is a convention. If a function or method may panic (= crash a program), then it's usually being prefixed with a \"must\" prefix.\n>"
  },
  {
    "path": "24-structs/01-intro/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ttype Movie struct {\n\t\tTitle  string\n\t\tGenre  string\n\t\tRating int\n\t}\n\n\ttype Rental struct {\n\t\tAddress string\n\t\tRooms   int\n\t\tSize    int\n\t\tPrice   int\n\t}\n\n\ttype Person struct {\n\t\tName     string\n\t\tLastname string\n\t\tAge      int\n\t}\n\n\tperson1 := Person{Name: \"Pablo\", Lastname: \"Picasso\", Age: 91}\n\tperson2 := Person{Name: \"Sigmund\", Lastname: \"Freud\", Age: 83}\n\n\tfmt.Printf(\"person1: %+v\\n\", person1)\n\tfmt.Printf(\"person2: %+v\\n\", person2)\n\n\ttype VideoGame struct {\n\t\tTitle     string\n\t\tGenre     string\n\t\tPublished bool\n\t}\n\n\tpacman := VideoGame{\n\t\tTitle:     \"Pac-Man\",\n\t\tGenre:     \"Arcade Game\",\n\t\tPublished: true,\n\t}\n\n\tfmt.Printf(\"pacman: %+v\\n\", pacman)\n}\n"
  },
  {
    "path": "24-structs/02-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t/*\n\t\tUSING VARIABLES\n\t*/\n\n\tvar (\n\t\tname, lastname string\n\t\tage            int\n\n\t\tname2, lastname2 string\n\t\tage2             int\n\t)\n\n\tname, lastname, age = \"Pablo\", \"Picasso\", 95\n\tname2, lastname2, age = \"Sigmund\", \"Freud\", 83\n\n\tfmt.Println(\"Picasso:\", name, lastname, age)\n\tfmt.Println(\"Freud  :\", name2, lastname2, age2)\n\n\t// var picasso struct {\n\t// \tname, lastname string\n\t// \tage            int\n\t// }\n\n\t// var freud struct {\n\t// \tname, lastname string\n\t// \tage            int\n\t// }\n\n\t// create a new struct type\n\ttype person struct {\n\t\tname, lastname string\n\t\tage            int\n\t}\n\n\t// picasso := person{name: \"Pablo\", lastname: \"Picasso\", age: 91}\n\tpicasso := person{\n\t\tname:     \"Pablo\",\n\t\tlastname: \"Picasso\",\n\t\tage:      91,\n\t}\n\n\tvar freud person\n\tfreud.name = \"Sigmund\"\n\tfreud.lastname = \"Freud\"\n\tfreud.age = 83\n\n\tfmt.Printf(\"\\n%s's age is %d\\n\", picasso.lastname, picasso.age)\n\n\tfmt.Printf(\"\\nPicasso: %#v\\n\", picasso)\n\tfmt.Printf(\"Freud  : %#v\\n\", freud)\n}\n"
  },
  {
    "path": "24-structs/03-compare-assign/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// #1b: create the song struct type\ntype song struct {\n\ttitle, artist string\n}\n\n// #5: structs can contain other structs\ntype playlist struct {\n\tgenre string\n\n\t// songTitles []string\n\t// songArtist []string\n\n\t// #6: include a slice of song structs\n\tsongs []song\n}\n\nfunc main() {\n\t// #1: create two struct values with the same type\n\tsong1 := song{title: \"wonderwall\", artist: \"oasis\"}\n\tsong2 := song{title: \"super sonic\", artist: \"oasis\"}\n\n\tfmt.Printf(\"song1: %+v\\nsong2: %+v\\n\", song1, song2)\n\n\t// #4: structs are copied\n\t// song1 = song2\n\n\t// #3: structs can be compared\n\tif song1 == song2 {\n\t\t// #2: struct comparison works like this\n\t\t// if song1.title == song2.title &&\n\t\t// \tsong1.artist == song2.artist {\n\t\tfmt.Println(\"songs are equal.\")\n\t} else {\n\t\tfmt.Println(\"songs are not equal.\")\n\t}\n\n\t// #8\n\tsongs := []song{\n\t\t// #7b: you don't have to type the element types\n\t\t{title: \"wonderwall\", artist: \"oasis\"},\n\t\t{title: \"supersonic\", artist: \"oasis\"},\n\t}\n\n\t// #7: a struct can include another struct\n\trock := playlist{\n\t\tgenre: \"indie rock\",\n\t\tsongs: songs,\n\t}\n\n\t// #9: you can't compare struct values that contains incomparable fields\n\t// you need to compare them manually\n\n\t// clone := rock\n\t// if rock.songs == clone {\n\t// }\n\t// if songs == songs {\n\n\t// #11: song is a clone, it cannot change the original struct value\n\tsong := rock.songs[0]\n\tsong.title = \"live forever\"\n\n\t// #11c: directly set the original one\n\trock.songs[0].title = \"live forever\"\n\n\t// #11b\n\tfmt.Printf(\"\\n%+v\\n%+v\\n\", song, rock.songs[0])\n\n\t// #10: printing\n\tfmt.Printf(\"\\n%-20s %20s\\n\", \"TITLE\", \"ARTIST\")\n\tfor _, s := range rock.songs {\n\t\t// s := rock.songs[i]\n\n\t\t// #12b: s is a copy inside because struct values are copied\n\t\ts.title = \"destroy\"\n\t\tfmt.Printf(\"%-20s %20s\\n\", s.title, s.artist)\n\t}\n\n\t// #12\n\tfmt.Printf(\"\\n%-20s %20s\\n\", \"TITLE\", \"ARTIST\")\n\tfor _, s := range rock.songs {\n\t\tfmt.Printf(\"%-20s %20s\\n\", s.title, s.artist)\n\t}\n}\n"
  },
  {
    "path": "24-structs/04-embedding/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// #1: declare the types\n\ttype text struct {\n\t\ttitle string\n\t\twords int\n\t}\n\n\ttype book struct {\n\t\t// title string\n\t\t// words int\n\n\t\t// #3: include the text as a field\n\t\t// text text\n\n\t\t// #4: embed the text\n\t\ttext\n\t\tisbn string\n\n\t\t// #5: add a conflicting field\n\t\ttitle string\n\t}\n\n\t// #2: print a book\n\t// moby := book{title: \"moby dick\", words: 206052, isbn: \"102030\"}\n\t// fmt.Printf(\"%s has %d words (isbn: %s)\\n\", moby.title, moby.words, moby.isbn)\n\n\t// #3b: type the text in its own field\n\tmoby := book{\n\t\t// #5c: type the field in a new field\n\t\t// title: \"conflict\",\n\t\ttext: text{title: \"moby dick\", words: 206052},\n\t\tisbn: \"102030\",\n\t}\n\n\tmoby.text.words = 1000\n\tmoby.words++\n\n\t// // #4b: print the book\n\tfmt.Printf(\"%s has %d words (isbn: %s)\\n\",\n\t\tmoby.title, // equals to: moby.text.title\n\t\tmoby.words, // equals to: moby.text.words\n\t\tmoby.isbn)\n\n\t// #3c: print the book\n\t// fmt.Printf(\"%s has %d words (isbn: %s)\\n\",\n\t// \tmoby.text.title, moby.text.words, moby.isbn)\n\n\t// #5b: print the conflict\n\tfmt.Printf(\"%#v\\n\", moby)\n\n\t// go get -u github.com/davecgh/go-spew/spew\n\t// spew.Dump(moby)\n}\n"
  },
  {
    "path": "24-structs/05-project-log-parser-structs/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "24-structs/05-project-log-parser-structs/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "24-structs/05-project-log-parser-structs/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "24-structs/05-project-log-parser-structs/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "24-structs/05-project-log-parser-structs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n}\n\nfunc main() {\n\tp := parser{sum: make(map[string]result)}\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.lines++\n\n\t\t// Parse the fields\n\t\tfields := strings.Fields(in.Text())\n\t\tif len(fields) != 2 {\n\t\t\tfmt.Printf(\"wrong input: %v (line #%d)\\n\", fields, p.lines)\n\t\t\treturn\n\t\t}\n\n\t\tdomain := fields[0]\n\n\t\t// Sum the total visits per domain\n\t\tvisits, err := strconv.Atoi(fields[1])\n\t\tif visits < 0 || err != nil {\n\t\t\tfmt.Printf(\"wrong input: %q (line #%d)\\n\", fields[1], p.lines)\n\t\t\treturn\n\t\t}\n\n\t\t// Collect the unique domains\n\t\tif _, ok := p.sum[domain]; !ok {\n\t\t\tp.domains = append(p.domains, domain)\n\t\t}\n\n\t\t// Keep track of total and per domain visits\n\t\tp.total += visits\n\n\t\t// You cannot assign to composite values\n\t\t// p.sum[domain].visits += visits\n\n\t\t// create and assign a new copy of `visit`\n\t\tp.sum[domain] = result{\n\t\t\tdomain: domain,\n\t\t\tvisits: visits + p.sum[domain].visits,\n\t\t}\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "24-structs/06-encoding/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\ntype permissions map[string]bool // #3\n\ntype user struct { // #1\n\tName        string      `json:\"username\"`\n\tPassword    string      `json:\"-\"`\n\tPermissions permissions `json:\"perms,omitempty\"` // #6\n\n\t// name        string // #1\n\t// password    string // #1\n\t// permissions // #3\n}\n\nfunc main() {\n\tusers := []user{ // #2\n\t\t{\"inanc\", \"1234\", nil},\n\t\t{\"god\", \"42\", permissions{\"admin\": true}},\n\t\t{\"devil\", \"66\", permissions{\"write\": true}},\n\t}\n\n\t// out, err := json.Marshal(users) // #4\n\tout, err := json.MarshalIndent(users, \"\", \"\\t\") // #5\n\tif err != nil {                                 // #4\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Println(string(out)) // #4\n}\n"
  },
  {
    "path": "24-structs/07-decoding/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n)\n\ntype user struct {\n\tName        string          `json:\"username\"`\n\tPermissions map[string]bool `json:\"perms\"`\n}\n\nfunc main() {\n\tvar input []byte\n\tfor in := bufio.NewScanner(os.Stdin); in.Scan(); {\n\t\tinput = append(input, in.Bytes()...)\n\t}\n\n\tvar users []user\n\tif err := json.Unmarshal(input, &users); err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfor _, user := range users {\n\t\tfmt.Print(\"+ \", user.Name)\n\n\t\tswitch p := user.Permissions; {\n\t\tcase p == nil:\n\t\t\tfmt.Print(\" has no power.\")\n\t\tcase p[\"admin\"]:\n\t\t\tfmt.Print(\" is an admin.\")\n\t\tcase p[\"write\"]:\n\t\t\tfmt.Print(\" can write.\")\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "24-structs/07-decoding/users.json",
    "content": "[\n\t{\n\t\t\"username\": \"inanc\"\n\t},\n\t{\n\t\t\"username\": \"god\",\n\t\t\"perms\": {\n\t\t\t\"admin\": true\n\t\t}\n\t},\n\t{\n\t\t\"username\": \"devil\",\n\t\t\"perms\": {\n\t\t\t\"write\": true\n\t\t}\n\t}\n]\n"
  },
  {
    "path": "24-structs/08-decoding-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n/* This lecture will be added later */\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n)\n\ntype user struct {\n\tName        string          `json:\"username\"`\n\tPermissions map[string]bool `json:\"perms\"`\n\n\tDevices []struct {\n\t\tName    string `json:\"name\"`\n\t\tBattery int    `json:\"battery\"`\n\t} `json:\"devices\"`\n}\n\n// type device struct {\n// \tName    string `json:\"name\"`\n// \tBattery int    `json:\"battery\"`\n// }\n\nfunc main() {\n\tvar input []byte\n\tfor in := bufio.NewScanner(os.Stdin); in.Scan(); {\n\t\tinput = append(input, in.Bytes()...)\n\t}\n\n\tvar users []user\n\tif err := json.Unmarshal(input, &users); err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfor _, user := range users {\n\t\tfmt.Print(\"+ \", user.Name)\n\n\t\tswitch p := user.Permissions; {\n\t\tcase p == nil:\n\t\t\tfmt.Print(\" has no power.\")\n\t\tcase p[\"admin\"]:\n\t\t\tfmt.Print(\" is an admin.\")\n\t\tcase p[\"write\"]:\n\t\t\tfmt.Print(\" can write.\")\n\t\t}\n\n\t\tfor _, device := range user.Devices {\n\t\t\tfmt.Printf(\"\\n\\t[ %-10s: %d%% ]\", device.Name, device.Battery)\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "24-structs/08-decoding-2/users.json",
    "content": "[\n\t{\n\t\t\"username\": \"inanc\",\n\t\t\"devices\": [\n\t\t\t{ \"name\": \"laptop\", \"battery\": 10 },\n\t\t\t{ \"name\": \"phone\", \"battery\": 30 }\n\t\t]\n\t},\n\t{\n\t\t\"username\": \"god\",\n\t\t\"perms\": {\n\t\t\t\"admin\": true\n\t\t},\n\t\t\"devices\": [\n\t\t\t{ \"name\": \"omniverse\", \"battery\": 95 }\n\t\t]\n\t},\n\t{\n\t\t\"username\": \"devil\",\n\t\t\"perms\": {\n\t\t\t\"write\": true\n\t\t}\n\t}\n]\n"
  },
  {
    "path": "24-structs/exercises/01-warmup/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Warm Up\n//\n//  Starting with this exercise, you'll build a command-line\n//  game store.\n//\n//  1. Declare the following structs:\n//\n//     + item: id (int), name (string), price (int)\n//\n//     + game: embed the item, genre (string)\n//\n//\n//  2. Create a game slice using the following data:\n//\n//     id  name          price    genre\n//\n//     1   god of war    50       action adventure\n//     2   x-com 2       30       strategy\n//     3   minecraft     20       sandbox\n//\n//\n//  3. Print all the games.\n//\n// EXPECTED OUTPUT\n//  Please run the solution to see the output.\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "24-structs/exercises/01-warmup/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ttype item struct {\n\t\tid    int\n\t\tname  string\n\t\tprice int\n\t}\n\n\ttype game struct {\n\t\titem\n\t\tgenre string\n\t}\n\n\tgames := []game{\n\t\t{\n\t\t\titem:  item{id: 1, name: \"god of war\", price: 50},\n\t\t\tgenre: \"action adventure\",\n\t\t},\n\t\t{item: item{id: 2, name: \"x-com 2\", price: 40}, genre: \"strategy\"},\n\t\t{item: item{id: 3, name: \"minecraft\", price: 20}, genre: \"sandbox\"},\n\t}\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\\n\", len(games))\n\n\tfor _, g := range games {\n\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t}\n}\n"
  },
  {
    "path": "24-structs/exercises/02-list/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: List\n//\n//  Now, it's time to add an interface to your program using\n//  the bufio.Scanner. So the users can list the games, or\n//  search for the games by id.\n//\n//  1. Scan for the input in a loop (use bufio.Scanner)\n//\n//  2. Print the available commands.\n//\n//  3. Implement the quit command: Quits from the loop.\n//\n//  4. Implement the list command: Lists all the games.\n//\n//\n// EXPECTED OUTPUT\n//  Please run the solution and try the program with list and\n//  quit commands.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// use your solution from the previous exercise\n}\n"
  },
  {
    "path": "24-structs/exercises/02-list/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\ttype item struct {\n\t\tid    int\n\t\tname  string\n\t\tprice int\n\t}\n\n\ttype game struct {\n\t\titem\n\t\tgenre string\n\t}\n\n\tgames := []game{\n\t\t{\n\t\t\titem:  item{id: 1, name: \"god of war\", price: 50},\n\t\t\tgenre: \"action adventure\",\n\t\t},\n\t\t{item: item{id: 2, name: \"x-com 2\", price: 40}, genre: \"strategy\"},\n\t\t{item: item{id: 3, name: \"minecraft\", price: 20}, genre: \"sandbox\"},\n\t}\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tswitch in.Text() {\n\t\tcase \"quit\":\n\t\t\tfmt.Println(\"bye!\")\n\t\t\treturn\n\n\t\tcase \"list\":\n\t\t\tfor _, g := range games {\n\t\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "24-structs/exercises/03-query-by-id/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Query By Id\n//\n//  Add a new command: \"id\". So the users can query the games\n//  by id.\n//\n//  1. Before the loop, index the games by id (use a map).\n//\n//  2. Add the \"id\" command.\n//     When a user types: id 2\n//     It should print only the game with id: 2.\n//\n//  3. Handle the errors:\n//\n//     id\n//     wrong id\n//\n//     id HEY\n//     wrong id\n//\n//     id 10\n//     sorry. I don't have the game\n//\n//     id 1\n//     #1: \"god of war\" (action adventure) $50\n//\n//     id 2\n//     #2: \"x-com 2\" (strategy) $40\n//\n//\n// EXPECTED OUTPUT\n//  Please also run the solution and try the program with\n//  list, quit, and id commands to see it in action.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// use your solution from the previous exercise\n}\n"
  },
  {
    "path": "24-structs/exercises/03-query-by-id/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\ttype item struct {\n\t\tid    int\n\t\tname  string\n\t\tprice int\n\t}\n\n\ttype game struct {\n\t\titem\n\t\tgenre string\n\t}\n\n\tgames := []game{\n\t\t{\n\t\t\titem:  item{id: 1, name: \"god of war\", price: 50},\n\t\t\tgenre: \"action adventure\",\n\t\t},\n\t\t{item: item{id: 2, name: \"x-com 2\", price: 40}, genre: \"strategy\"},\n\t\t{item: item{id: 3, name: \"minecraft\", price: 20}, genre: \"sandbox\"},\n\t}\n\n\t// index the games by id\n\tbyID := make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tcmd := strings.Fields(in.Text())\n\t\tif len(cmd) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch cmd[0] {\n\t\tcase \"quit\":\n\t\t\tfmt.Println(\"bye!\")\n\t\t\treturn\n\n\t\tcase \"list\":\n\t\t\tfor _, g := range games {\n\t\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t\t\t}\n\n\t\tcase \"id\":\n\t\t\tif len(cmd) != 2 {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tid, err := strconv.Atoi(cmd[1])\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tg, ok := byID[id]\n\t\t\tif !ok {\n\t\t\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "24-structs/exercises/04-encode/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Encode\n//\n//  Add a new command: \"save\". Encode the games to json, and\n//  print it, then terminate the loop.\n//\n//  1. Create a new struct type with exported fields: ID, Name, Genre and Price.\n//\n//  2. Create a new slice using the new struct type.\n//\n//  3. Save the games into the new slice.\n//\n//  4. Encode the new slice.\n//\n//\n// RESTRICTION\n//  Do not export the fields of the game struct.\n//\n//\n// EXPECTED OUTPUT\n//  Inanc's game store has 3 games.\n//\n//    > list   : lists all the games\n//    > id N   : queries a game by id\n//    > save   : exports the data to json and quits\n//    > quit   : quits\n//\n//  save\n//\n//  [\n//          {\n//                  \"id\": 1,\n//                  \"name\": \"god of war\",\n//                  \"genre\": \"action adventure\",\n//                  \"price\": 50\n//          },\n//          {\n//                  \"id\": 2,\n//                  \"name\": \"x-com 2\",\n//                  \"genre\": \"strategy\",\n//                  \"price\": 40\n//          },\n//          {\n//                  \"id\": 3,\n//                  \"name\": \"minecraft\",\n//                  \"genre\": \"sandbox\",\n//                  \"price\": 20\n//          }\n//  ]\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// use your solution from the previous exercise\n\n}\n"
  },
  {
    "path": "24-structs/exercises/04-encode/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\ttype item struct {\n\t\tid    int\n\t\tname  string\n\t\tprice int\n\t}\n\n\ttype game struct {\n\t\titem\n\t\tgenre string\n\t}\n\n\tgames := []game{\n\t\t{\n\t\t\titem:  item{id: 1, name: \"god of war\", price: 50},\n\t\t\tgenre: \"action adventure\",\n\t\t},\n\t\t{item: item{id: 2, name: \"x-com 2\", price: 40}, genre: \"strategy\"},\n\t\t{item: item{id: 3, name: \"minecraft\", price: 20}, genre: \"sandbox\"},\n\t}\n\n\t// index the games by id\n\tbyID := make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > save   : exports the data to json and quits\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tcmd := strings.Fields(in.Text())\n\t\tif len(cmd) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch cmd[0] {\n\t\tcase \"quit\":\n\t\t\tfmt.Println(\"bye!\")\n\t\t\treturn\n\n\t\tcase \"list\":\n\t\t\tfor _, g := range games {\n\t\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t\t\t}\n\n\t\tcase \"id\":\n\t\t\tif len(cmd) != 2 {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tid, err := strconv.Atoi(cmd[1])\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tg, ok := byID[id]\n\t\t\tif !ok {\n\t\t\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\n\t\tcase \"save\":\n\t\t\ttype jsonGame struct {\n\t\t\t\tID    int    `json:\"id\"`\n\t\t\t\tName  string `json:\"name\"`\n\t\t\t\tGenre string `json:\"genre\"`\n\t\t\t\tPrice int    `json:\"price\"`\n\t\t\t}\n\n\t\t\t// load the data into the encodable game values\n\t\t\tvar encodable []jsonGame\n\t\t\tfor _, g := range games {\n\t\t\t\tencodable = append(encodable,\n\t\t\t\t\tjsonGame{g.id, g.name, g.genre, g.price})\n\t\t\t}\n\n\t\t\tout, err := json.MarshalIndent(encodable, \"\", \"\\t\")\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"Sorry:\", err)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfmt.Println(string(out))\n\t\t\treturn\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "24-structs/exercises/05-decode/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: Decode\n//\n//  At the beginning of the file:\n//\n//  1. Load the initial data to the game store from json.\n//     (see the data constant below)\n//\n//  2. Load the decoded values into the usual `game` values (to the games slice as well).\n//\n//     So the rest of the program can work intact.\n//\n//\n// HINT\n//\n//  Move the jsonGame type to the top and reuse it both when\n//  loading the initial data, and in the \"save\" command.\n//\n//\n// EXPECTED OUTPUT\n//  Please run the solution to see the output.\n// ---------------------------------------------------------\n\nconst data = `\n[\n        {\n                \"id\": 1,\n                \"name\": \"god of war\",\n                \"genre\": \"action adventure\",\n                \"price\": 50\n        },\n        {\n                \"id\": 2,\n                \"name\": \"x-com 2\",\n                \"genre\": \"strategy\",\n                \"price\": 40\n        },\n        {\n                \"id\": 3,\n                \"name\": \"minecraft\",\n                \"genre\": \"sandbox\",\n                \"price\": 20\n        }\n]`\n\nfunc main() {\n\t// use your solution from the previous exercise\n}\n"
  },
  {
    "path": "24-structs/exercises/05-decode/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst data = `\n[\n        {\n                \"id\": 1,\n                \"name\": \"god of war\",\n                \"genre\": \"action adventure\",\n                \"price\": 50\n        },\n        {\n                \"id\": 2,\n                \"name\": \"x-com 2\",\n                \"genre\": \"strategy\",\n                \"price\": 40\n        },\n        {\n                \"id\": 3,\n                \"name\": \"minecraft\",\n                \"genre\": \"sandbox\",\n                \"price\": 20\n        }\n]`\n\nfunc main() {\n\ttype item struct {\n\t\tid    int\n\t\tname  string\n\t\tprice int\n\t}\n\n\ttype game struct {\n\t\titem\n\t\tgenre string\n\t}\n\n\t// ----------------------------------------------------------\n\t// DECODING SOLUTION:\n\n\t// encodable and decodable game type\n\ttype jsonGame struct {\n\t\tID    int    `json:\"id\"`\n\t\tName  string `json:\"name\"`\n\t\tGenre string `json:\"genre\"`\n\t\tPrice int    `json:\"price\"`\n\t}\n\n\t// load the initial data from json\n\tvar decoded []jsonGame\n\tif err := json.Unmarshal([]byte(data), &decoded); err != nil {\n\t\tfmt.Println(\"Sorry, there is a problem:\", err)\n\t\treturn\n\t}\n\n\t// load the data into usual game values\n\tvar games []game\n\tfor _, dg := range decoded {\n\t\tgames = append(games, game{item{dg.ID, dg.Name, dg.Price}, dg.Genre})\n\t}\n\t// ----------------------------------------------------------\n\n\t// index the games by id\n\tbyID := make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > save   : exports the data to json and quits\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tcmd := strings.Fields(in.Text())\n\t\tif len(cmd) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch cmd[0] {\n\t\tcase \"quit\":\n\t\t\tfmt.Println(\"bye!\")\n\t\t\treturn\n\n\t\tcase \"list\":\n\t\t\tfor _, g := range games {\n\t\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t\t\t}\n\n\t\tcase \"id\":\n\t\t\tif len(cmd) != 2 {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tid, err := strconv.Atoi(cmd[1])\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tg, ok := byID[id]\n\t\t\tif !ok {\n\t\t\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\n\t\tcase \"save\":\n\t\t\t// load the data into the encodable game values\n\t\t\tvar encodable []jsonGame\n\t\t\tfor _, g := range games {\n\t\t\t\tencodable = append(encodable,\n\t\t\t\t\tjsonGame{g.id, g.name, g.genre, g.price})\n\t\t\t}\n\n\t\t\tout, err := json.MarshalIndent(encodable, \"\", \"\\t\")\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"Sorry:\", err)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfmt.Println(string(out))\n\t\t\treturn\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "24-structs/exercises/README.md",
    "content": "# Struct Exercises\n\nYou'll build a queryable command-line game store.\n\n1. **[Warm Up](https://github.com/inancgumus/learngo/tree/master/24-structs/exercises/01-warmup)**\n\n    Load up the data into the game store.\n\n2. **[List](https://github.com/inancgumus/learngo/tree/master/24-structs/exercises/02-list)**\n\n    Now, it's time to add an interface to your program using the bufio.Scanner. So the users can list the games, or search for the games by id.\n\n3. **[Query By Id](https://github.com/inancgumus/learngo/tree/master/24-structs/exercises/03-query-by-id)**\n\n    Add a new command: \"id\". So the users can query the games by id.\n\n4. **[Encode](https://github.com/inancgumus/learngo/tree/master/24-structs/exercises/04-encode)**\n\n    Add a new command: \"save\". Encode the games to json, and print it, then terminate the loop.\n\n5. **[Decode](https://github.com/inancgumus/learngo/tree/master/24-structs/exercises/05-decode)**\n\n    Load the initial data to the game store from json."
  },
  {
    "path": "24-structs/questions/README.md",
    "content": "## When should you use a struct type?\n1. For storing the same type of values\n2. For adding an additional type of values in runtime\n3. For combining different types in a single type to represent a concept *CORRECT*\n\n> **1:** Arrays, slices, and maps are better candidates for that.\n>\n> **2:** Struct fields are fixed at compile-time, you cannot add additional fields in runtime, neither you can remove them.\n>\n> **3:** That's right. A struct type combines different types of fields in a single type. You can use a struct type to represent a concept.\n>\n\n\n## What are the properties of struct fields?\n1. They all should be of the same type\n2. Each one should have a name and possibly a different type *CORRECT*\n3. You can add additional fields in runtime\n4. You can remove the existing fields in runtime\n\n> **2:** Yes, each field should have a unique name. Also, each field should have a type, but every field can have a different type.\n>\n\n\n## What is wrong with the following code?\n```go\ntype weather struct {\n    temperature, humidity float64\n    windSpeed             float64\n    temperature           float64\n}\n```\n1. Nothing is wrong with it\n2. `temperature, humidity float64` field is a syntax error\n3. `temperature` field is not unique *CORRECT*\n\n> **2:** That's a parallel definition. It defines two float64 fields: temperature and humidity. It is correct.\n>\n> **3:** Right! Struct field names should be unique.\n>\n\n\n## What is the zero-value of the following struct value?\n```go\nvar movie struct {\n    title, genre string\n    rating       float64\n    released     bool\n}\n```\n1. `{}`\n2. `{title: \"\", genre: \"\", rating: 0, released: false}` *CORRECT*\n3. `{title: \"\", genre: \"\", rating: 0, released: true}`\n4. `{\"title, genre\": \"\", rating: 0, released: false}`\n\n> **1:** That's an empty struct value with no fields.\n>\n> **2:** Right! Go initializes a struct's fields to zero-values depending on their type.\n>\n\n\n\n## What is the type of the following struct?\n```go\navengers := struct {\n    title, genre string\n    rating       float64\n    released     bool\n}{\n    \"avengers: end game\", \"sci-fi\", 8.9, true,\n}\n\nfmt.Printf(\"%T\\n\", avengers)\n```\n1. `struct{}`\n2. `struct{ string; string; float64; bool }`\n3. `struct{ title string; genre string; rating float64; released bool }` *CORRECT*\n4. `{title: \"avengers: end game\"; genre: \"sci-fi\"; rating: 8.9; released: true}`\n\n> **1:** That's an empty struct type with no fields.\n>\n> **2:** Fields names is also a part of a struct's type.\n>\n> **3:** Right! Field names and types are part of a struct's type.\n>\n> **4:** Nope, that's a struct value.\n>\n\n\n## Are the following struct values equal?\n```go\ntype movie struct {\n    title, genre string\n    rating       float64\n    released     bool\n}\n\navengers := movie{\"avengers: end game\", \"sci-fi\", 8.9, true}\nclone    := movie{\n                title: \"avengers: end game\", genre: \"sci-fi\",\n                rating: 8.9, released: true,\n            }\n```\n1. There is a syntax error\n2. Yes *CORRECT*\n3. No\n\n> **2:** When creating a struct value, it doesn't matter whether you use the field names or not. So, they are equal.\n>\n\n\n\n## Are the following struct values equal? If not, why?\n```go\ntype movie struct {\n    title, genre string\n    rating       float64\n    released     bool\n}\n\navengers := movie{\n    title: \"avengers: end game\", genre: \"sci-fi\",\n    rating: 8.9, released: true,\n}\n\nclone := movie{title: \"avengers: end game\", genre: \"sci-fi\"}\n\nfmt.Println(avengers == clone)\n```\n1. Yes: They have the same set of fields\n2. No : They are not comparable\n3. No : Field values are different *CORRECT*\n\n> **1:** That's right, this means they are comparable, but that's not enough.\n>\n> **2:** Yes, they are. They use the same struct type.\n>\n> **3:** Yes, when you omit some of the fields, Go assigns zero values to them. Here, \"clone\" struct value's \"rating\" and \"released\" fields are: 0, and false, respectively.\n>\n\n\n## Do the movie and performance struct types have the same types?\n```go\ntype item        struct { title string }\ntype movie       struct { item }\ntype performance struct { item }\n```\n1. Yes: They have the same set of fields\n2. No : They have different type names *CORRECT*\n3. No : An embedded field cannot be compared\n\n> **2:** Right! Types with different names cannot be compared. However, you can convert one of them to the other because they have the same set of fields. movie{} == movie(performance{}) is ok, or vice versa.\n>\n\n\n## What does the program print?\n```go\ntype item struct{ title string }\n\ntype movie struct {\n    item\n    title string\n}\n\nm := movie{\n    title: \"avengers: end game\",\n    item:  item{\"midnight in paris\"},\n}\n\nfmt.Println(m.title, \"&\", m.item.title)\n```\n1. midnight in paris & midnight in paris\n2. avengers: end game & avengers: end game\n3. midnight in paris & avengers: end game\n4. avengers: end game & midnight in paris *CORRECT*\n\n> **4:** Right! `m.title` returns \"avengers: end game\" because the outer type always takes priority. However, `m.item.title` returns \"midnight in paris\" because you explicitly get it from the inner type: item.\n>\n\n\n## What is a field tag?\n1. It allows Go to index struct fields more efficiently\n2. You can use it for documenting your code\n3. It's like a comment\n4. Associates metadata about the field *CORRECT*\n\n> **4:** Correct. For example, the json package can read and encode/decode depending on the associated metadata.\n\n\n## Which one is correct about a field tag?\n1. It needs to be typed according to some rules\n2. You can change it to a different value in runtime\n3. It's just a string value, and it doesn't have a meaning on its own *CORRECT*\n\n> **1:** This is true to some extent but it can have any value.\n> \n> **2:** Fields tags are part of a struct type definition so you cannot change their value in runtime.\n> \n> **3:** Right! It's just a string value. It's only meaningful when other code reads it. For example, the json package can read it and encode/decode depending on the field tag's value.\n> \n\n\n## What is wrong with the following program?\n```go\ntype movie struct {\n    title string `json:\"title\"`\n}\n\nm := movie{\"black panthers\"}\nencoded, _ := json.Marshal(m)\n\nfmt.Println(string(encoded))\n```\n1. `movie` is unexported so you cannot encode\n2. `title` is unexported so you cannot encode *CORRECT*\n3. Error handling is missing so you cannot encode\n\n> **1:** The json package can encode a struct even though its type is unexported.\n> \n> **2:** Right! The json package can only encode exported fields.\n> \n> **3:** It's better to handle errors but it's not the main problem here.\n> \n\n\n## Why do you need to pass a pointer to the Unmarshal function?\n1. To make it work faster and efficient\n2. So it can update the value on memory *CORRECT*\n3. To prevent errors\n\n> **2:** Otherwise, it would not be able to update the given value. It's because, every value in Go is passed by value. So a function can only change the copy, not the original value. However, through a pointer, a function can change the original value."
  },
  {
    "path": "25-functions/01-basics/bad.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc showN() {\n\tif N == 0 {\n\t\treturn\n\t}\n\tfmt.Printf(\"showN       : N is %d\\n\", N)\n}\n\nfunc incrN() {\n\tN++\n}\n\n// you cannot declare a function within the same package with the same name\n// func incrN() {\n// }\n"
  },
  {
    "path": "25-functions/01-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n//\n// You need run this program like so:\n//   go run .\n//\n// This will magically pass all the go files in the current directory to the\n// Go compiler.\n//\n//\n// BUT NOT like so:\n//   go run main.go\n//\n// Because, the compiler needs to see bad.go too\n// It can't magically find bad.go — what you give is what you get.\n//\n\npackage main\n\n// N is a shared counter which is BAD\nvar N int\n\nfunc main() {\n\tshowN()\n\tincrN()\n\tincrN()\n\tshowN()\n}\n"
  },
  {
    "path": "25-functions/02-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tlocal := 10\n\tshow(local)\n\n\tincrWrong(local)\n\tfmt.Printf(\"local → %d\\n\", local)\n\n\t// incr(local)\n\tlocal = incr(local)\n\tshow(local)\n\n\tlocal = incrBy(local, 5)\n\tshow(local)\n\n\t_, err := incrByStr(local, \"TWO\")\n\tif err != nil {\n\t\tfmt.Printf(\"err   → %s\\n\", err)\n\t}\n\n\tlocal, _ = incrByStr(local, \"2\")\n\tshow(local)\n\n\t// CHAINING\n\n\t// can't save the number back into main's local\n\tshow(incrBy(local, 2))\n\tshow(local)\n\n\t// can't pass the results of the multiple-value returning func\n\t// show(incrByStr(local, \"3\"))\n\n\t// can call showErr directly because it accepts the same types\n\t// of parameters as with incrByStr's result values.\n\t// local = sanitize(incrByStr(local, \"NOPE\"))\n\t// show(local)\n\n\tlocal = sanitize(incrByStr(local, \"2\"))\n\tshow(local)\n\n\tlocal = limit(incrBy(local, 5), 2000)\n\tshow(local)\n}\n\nfunc show(n int) {\n\t// can't access main's local\n\t// fmt.Printf(\"show : n = %d\\n\", local)\n\tfmt.Printf(\"show  → n = %d\\n\", n)\n}\n\n// wrong: incr can't access to main's `local`\nfunc incrWrong(n int) {\n\t// n := local\n\tn++\n\t// can't return (there are no result values)\n\t// return n\n}\n\nfunc incr(n int) int {\n\tn++\n\treturn n\n}\n\nfunc incrBy(n, factor int) int {\n\treturn n * factor\n}\n\nfunc incrByStr(n int, factor string) (int, error) {\n\tm, err := strconv.Atoi(factor)\n\tn = incrBy(n, m)\n\treturn n, err\n}\n\nfunc sanitize(n int, err error) int {\n\tif err != nil {\n\t\treturn 0\n\t}\n\treturn n\n}\n\nfunc limit(n, lim int) (m int) {\n\t// var m int\n\tm = n\n\tif m >= lim {\n\t\tm = lim\n\t}\n\t// return m\n\treturn\n}\n"
  },
  {
    "path": "25-functions/03-refactor-to-funcs/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/03-refactor-to-funcs/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/03-refactor-to-funcs/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/03-refactor-to-funcs/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/03-refactor-to-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tp := newParser()\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.lines++\n\n\t\tparsed, err := parse(p, in.Text())\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t\treturn\n\t\t}\n\n\t\tdomain, visits := parsed.domain, parsed.visits\n\n\t\t// Collect the unique domains\n\t\tif _, ok := p.sum[domain]; !ok {\n\t\t\tp.domains = append(p.domains, domain)\n\t\t}\n\n\t\t// Keep track of total and per domain visits\n\t\tp.total += visits\n\n\t\t// create and assign a new copy of `visit`\n\t\tp.sum[domain] = result{\n\t\t\tdomain: domain,\n\t\t\tvisits: visits + p.sum[domain].visits,\n\t\t}\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "25-functions/03-refactor-to-funcs/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n}\n\n// newParser constructs, initializes and returns a new parser\nfunc newParser() parser {\n\treturn parser{sum: make(map[string]result)}\n}\n\n// parse parses a log line and returns the parsed result with an error\nfunc parse(p parser, line string) (parsed result, err error) {\n\tfields := strings.Fields(line)\n\tif len(fields) != 2 {\n\t\terr = fmt.Errorf(\"wrong input: %v (line #%d)\", fields, p.lines)\n\t\treturn\n\t}\n\n\tparsed.domain = fields[0]\n\n\tparsed.visits, err = strconv.Atoi(fields[1])\n\tif parsed.visits < 0 || err != nil {\n\t\terr = fmt.Errorf(\"wrong input: %q (line #%d)\", fields[1], p.lines)\n\t\treturn\n\t}\n\n\treturn\n}\n"
  },
  {
    "path": "25-functions/04-pass-by-value-semantics/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/04-pass-by-value-semantics/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/04-pass-by-value-semantics/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/04-pass-by-value-semantics/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/04-pass-by-value-semantics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tp := newParser()\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.lines++\n\n\t\tparsed, err := parse(p, in.Text())\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t\treturn\n\t\t}\n\n\t\tp = update(p, parsed)\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "25-functions/04-pass-by-value-semantics/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n}\n\n// newParser constructs, initializes and returns a new parser\nfunc newParser() parser {\n\treturn parser{sum: make(map[string]result)}\n}\n\n// parse parses a log line and returns the parsed result with an error\nfunc parse(p parser, line string) (parsed result, err error) {\n\tfields := strings.Fields(line)\n\tif len(fields) != 2 {\n\t\terr = fmt.Errorf(\"wrong input: %v (line #%d)\", fields, p.lines)\n\t\treturn\n\t}\n\n\tparsed.domain = fields[0]\n\n\tparsed.visits, err = strconv.Atoi(fields[1])\n\tif parsed.visits < 0 || err != nil {\n\t\terr = fmt.Errorf(\"wrong input: %q (line #%d)\", fields[1], p.lines)\n\t\treturn\n\t}\n\n\treturn\n}\n\n// update updates the parser for the given parsing result\nfunc update(p parser, parsed result) parser {\n\tdomain, visits := parsed.domain, parsed.visits\n\n\t// Collect the unique domains\n\tif _, ok := p.sum[domain]; !ok {\n\t\tp.domains = append(p.domains, domain)\n\t}\n\n\t// Keep track of total and per domain visits\n\tp.total += visits\n\n\t// create and assign a new copy of `visit`\n\tp.sum[domain] = result{\n\t\tdomain: domain,\n\t\tvisits: visits + p.sum[domain].visits,\n\t}\n\n\treturn p\n}\n"
  },
  {
    "path": "25-functions/exercises/README.md",
    "content": "# Function Exercises\n\n1. **[Refactor the Game Store to Funcs - Step #1](https://github.com/inancgumus/learngo/tree/master/25-functions/exercises/refactor-to-funcs-1)**\n\n    Remember the game store program from the structs exercises? Now, it's time to refactor it to funcs.\n\n2. **[Refactor the Game Store to Funcs - Step #2](https://github.com/inancgumus/learngo/tree/master/25-functions/exercises/refactor-to-funcs-2)**\n\n    Let's continue the refactoring from the previous exercise. This time, you're going to refactor the command handling logic.\n\n3. **[Refactor the Game Store to Funcs - Step #3](https://github.com/inancgumus/learngo/tree/master/25-functions/exercises/refactor-to-funcs-3)**\n\n    Let's continue from the previous exercise. This time, you're going to add json encoding and decoding using funcs.\n\n4. **[Rewrite the Log Parser program using funcs](https://github.com/inancgumus/learngo/tree/master/25-functions/exercises/rewrite-log-parser-using-funcs)**\n\n  You've watched the lecture. Now, try to rewrite the same log parser program using funcs on your own."
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-1/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor the game store to funcs - step #1\n//\n//  Remember the game store program from the structs exercises?\n//  Now, it's time to refactor it to funcs.\n//\n//  Create games.go file\n//\n//     1- Move the structs there\n//\n//     2- Add a func that creates and returns a game.\n//\n//        Name  : newGame\n//        Inputs: id, price, name and genre\n//        Output: game\n//\n//     3- Add a func that adds a `game` to `[]game` and returns `[]game`:\n//\n//        Name  : addGame\n//        Inputs: []game, game\n//        Output: []game\n//\n//     4- Add a func that uses newGame and addGame funcs to load up the game\n//        store:\n//\n//        Name  : load\n//        Inputs: none\n//        Output: []game\n//\n//     5- Add a func that indexes games by ID:\n//\n//        Name  : indexByID\n//        Inputs: []game\n//        Output: map[int]game\n//\n//     6- Add a func that prints the given game:\n//\n//        Name  : printGame\n//        Inputs: game\n//\n//\n//  Go back to main.go and change the existing code with\n//  the new funcs that you've created. There are hints\n//  inside the code.\n//\n// ---------------------------------------------------------\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\ttype item struct {\n\t\tid    int\n\t\tname  string\n\t\tprice int\n\t}\n\n\ttype game struct {\n\t\titem\n\t\tgenre string\n\t}\n\n\t// load()\n\tgames := []game{\n\t\t{\n\t\t\titem:  item{id: 1, name: \"god of war\", price: 50},\n\t\t\tgenre: \"action adventure\",\n\t\t},\n\t\t{item: item{id: 2, name: \"x-com 2\", price: 40}, genre: \"strategy\"},\n\t\t{item: item{id: 3, name: \"minecraft\", price: 20}, genre: \"sandbox\"},\n\t}\n\n\t// indexByID()\n\tbyID := make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tcmd := strings.Fields(in.Text())\n\t\tif len(cmd) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch cmd[0] {\n\t\tcase \"quit\":\n\t\t\tfmt.Println(\"bye!\")\n\t\t\treturn\n\n\t\tcase \"list\":\n\t\t\tfor _, g := range games {\n\t\t\t\t// printGame()\n\t\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t\t\t}\n\n\t\tcase \"id\":\n\t\t\tif len(cmd) != 2 {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tid, err := strconv.Atoi(cmd[1])\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tg, ok := byID[id]\n\t\t\tif !ok {\n\t\t\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// printGame()\n\t\t\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\t\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-1/solution/games.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype item struct {\n\tid    int\n\tname  string\n\tprice int\n}\n\ntype game struct {\n\titem\n\tgenre string\n}\n\nfunc load() (games []game) {\n\tgames = addGame(games, newGame(1, 50, \"god of war\", \"action adventure\"))\n\tgames = addGame(games, newGame(2, 40, \"x-com 2\", \"strategy\"))\n\tgames = addGame(games, newGame(3, 20, \"minecraft\", \"sandbox\"))\n\treturn\n}\n\nfunc addGame(games []game, g game) []game {\n\treturn append(games, g)\n}\n\nfunc newGame(id, price int, name, genre string) game {\n\treturn game{\n\t\titem:  item{id: id, name: name, price: price},\n\t\tgenre: genre,\n\t}\n}\n\nfunc indexByID(games []game) (byID map[int]game) {\n\tbyID = make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\treturn\n}\n\nfunc printGame(g game) {\n\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-1/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tgames := load()\n\tbyID := indexByID(games)\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tcmd := strings.Fields(in.Text())\n\t\tif len(cmd) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch cmd[0] {\n\t\tcase \"quit\":\n\t\t\tfmt.Println(\"bye!\")\n\t\t\treturn\n\n\t\tcase \"list\":\n\t\t\tfor _, g := range games {\n\t\t\t\tprintGame(g)\n\t\t\t}\n\n\t\tcase \"id\":\n\t\t\tif len(cmd) != 2 {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tid, err := strconv.Atoi(cmd[1])\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tg, ok := byID[id]\n\t\t\tif !ok {\n\t\t\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tprintGame(g)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-2/games.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype item struct {\n\tid    int\n\tname  string\n\tprice int\n}\n\ntype game struct {\n\titem\n\tgenre string\n}\n\nfunc load() (games []game) {\n\tgames = addGame(games, newGame(1, 50, \"god of war\", \"action adventure\"))\n\tgames = addGame(games, newGame(2, 40, \"x-com 2\", \"strategy\"))\n\tgames = addGame(games, newGame(3, 20, \"minecraft\", \"sandbox\"))\n\treturn\n}\n\nfunc addGame(games []game, g game) []game {\n\treturn append(games, g)\n}\n\nfunc newGame(id, price int, name, genre string) game {\n\treturn game{\n\t\titem:  item{id: id, name: name, price: price},\n\t\tgenre: genre,\n\t}\n}\n\nfunc indexByID(games []game) (byID map[int]game) {\n\tbyID = make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\treturn\n}\n\nfunc printGame(g game) {\n\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor the game store to funcs - step #2\n//\n//  Let's continue the refactoring from the previous\n//  exercise. This time, you're going to refactor the\n//  command handling logic.\n//\n//\n//  Create commands.go file\n//\n//     1- Add a func that runs the given command from the user:\n//\n//        Name  : runCmd\n//        Inputs: input string, []game, map[int]game\n//        Output: bool\n//\n//        This func returns true if it wants the program to\n//        continue. When it returns false, the program will\n//        terminate. So, all the commands that it calls need\n//        to return true or false as well depending on whether\n//        they want to cause the program to terminate or not.\n//\n//     2- Add a func that handles the quit command:\n//\n//        Name  : cmdQuit\n//        Input : none\n//        Output: bool\n//\n//     3- Add a func that handles the list command:\n//\n//        Name  : cmdList\n//        Inputs: []game\n//        Output: bool\n//\n//     4- Add a func that handles the id command:\n//\n//        Name  : cmdByID\n//        Inputs: cmd []string, []game, map[int]game\n//        Output: bool\n//\n//     5- Refactor the runCmd() with the cmdXXX funcs.\n//\n//  Go back to main.go and change the existing code with\n//  the new funcs that you've created. There are hints\n//  inside the code.\n//\n// ---------------------------------------------------------\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tgames := load()\n\tbyID := indexByID(games)\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\t// menu()\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\t// --- runCmd start ---\n\t\tfmt.Println()\n\n\t\tcmd := strings.Fields(in.Text())\n\t\tif len(cmd) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch cmd[0] {\n\t\tcase \"quit\":\n\t\t\t// cmdQuit()\n\t\t\tfmt.Println(\"bye!\")\n\t\t\treturn\n\n\t\tcase \"list\":\n\t\t\t// cmdList()\n\t\t\tfor _, g := range games {\n\t\t\t\tprintGame(g)\n\t\t\t}\n\n\t\tcase \"id\":\n\t\t\t// cmdByID\n\t\t\tif len(cmd) != 2 {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tid, err := strconv.Atoi(cmd[1])\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"wrong id\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tg, ok := byID[id]\n\t\t\tif !ok {\n\t\t\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tprintGame(g)\n\t\t}\n\t\t// --- runCmd end ---\n\t}\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-2/solution/commands.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc runCmd(input string, games []game, byID map[int]game) bool {\n\tfmt.Println()\n\n\tcmd := strings.Fields(input)\n\tif len(cmd) == 0 {\n\t\treturn true\n\t}\n\n\tswitch cmd[0] {\n\tcase \"quit\":\n\t\treturn cmdQuit()\n\n\tcase \"list\":\n\t\treturn cmdList(games)\n\n\tcase \"id\":\n\t\treturn cmdByID(cmd, games, byID)\n\t}\n\treturn true\n}\n\nfunc cmdQuit() bool {\n\tfmt.Println(\"bye!\")\n\treturn false\n}\n\nfunc cmdList(games []game) bool {\n\tfor _, g := range games {\n\t\tprintGame(g)\n\t}\n\treturn true\n}\n\nfunc cmdByID(cmd []string, games []game, byID map[int]game) bool {\n\tif len(cmd) != 2 {\n\t\tfmt.Println(\"wrong id\")\n\t\treturn true\n\t}\n\n\tid, err := strconv.Atoi(cmd[1])\n\tif err != nil {\n\t\tfmt.Println(\"wrong id\")\n\t\treturn true\n\t}\n\n\tg, ok := byID[id]\n\tif !ok {\n\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\treturn true\n\t}\n\n\tprintGame(g)\n\n\treturn true\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-2/solution/games.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype item struct {\n\tid    int\n\tname  string\n\tprice int\n}\n\ntype game struct {\n\titem\n\tgenre string\n}\n\nfunc load() (games []game) {\n\tgames = addGame(games, newGame(1, 50, \"god of war\", \"action adventure\"))\n\tgames = addGame(games, newGame(2, 40, \"x-com 2\", \"strategy\"))\n\tgames = addGame(games, newGame(3, 20, \"minecraft\", \"sandbox\"))\n\treturn\n}\n\nfunc addGame(games []game, g game) []game {\n\treturn append(games, g)\n}\n\nfunc newGame(id, price int, name, genre string) game {\n\treturn game{\n\t\titem:  item{id: id, name: name, price: price},\n\t\tgenre: genre,\n\t}\n}\n\nfunc indexByID(games []game) (byID map[int]game) {\n\tbyID = make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\treturn\n}\n\nfunc printGame(g game) {\n\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tgames := load()\n\tbyID := indexByID(games)\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() || !runCmd(in.Text(), games, byID) {\n\t\t\tbreak\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-3/commands.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc runCmd(input string, games []game, byID map[int]game) bool {\n\tfmt.Println()\n\n\tcmd := strings.Fields(input)\n\tif len(cmd) == 0 {\n\t\treturn true\n\t}\n\n\tswitch cmd[0] {\n\tcase \"quit\":\n\t\treturn cmdQuit()\n\n\tcase \"list\":\n\t\treturn cmdList(games)\n\n\tcase \"id\":\n\t\treturn cmdByID(cmd, games, byID)\n\t}\n\treturn true\n}\n\nfunc cmdQuit() bool {\n\tfmt.Println(\"bye!\")\n\treturn false\n}\n\nfunc cmdList(games []game) bool {\n\tfor _, g := range games {\n\t\tprintGame(g)\n\t}\n\treturn true\n}\n\nfunc cmdByID(cmd []string, games []game, byID map[int]game) bool {\n\tif len(cmd) != 2 {\n\t\tfmt.Println(\"wrong id\")\n\t\treturn true\n\t}\n\n\tid, err := strconv.Atoi(cmd[1])\n\tif err != nil {\n\t\tfmt.Println(\"wrong id\")\n\t\treturn true\n\t}\n\n\tg, ok := byID[id]\n\tif !ok {\n\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\treturn true\n\t}\n\n\tprintGame(g)\n\n\treturn true\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-3/games.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nconst data = `\n[\n        {\n                \"id\": 1,\n                \"name\": \"god of war\",\n                \"genre\": \"action adventure\",\n                \"price\": 50\n        },\n        {\n                \"id\": 2,\n                \"name\": \"x-com 2\",\n                \"genre\": \"strategy\",\n                \"price\": 40\n        },\n        {\n                \"id\": 3,\n                \"name\": \"minecraft\",\n                \"genre\": \"sandbox\",\n                \"price\": 20\n        }\n]`\n\ntype item struct {\n\tid    int\n\tname  string\n\tprice int\n}\n\ntype game struct {\n\titem\n\tgenre string\n}\n\nfunc load() (games []game) {\n\tgames = addGame(games, newGame(1, 50, \"god of war\", \"action adventure\"))\n\tgames = addGame(games, newGame(2, 40, \"x-com 2\", \"strategy\"))\n\tgames = addGame(games, newGame(3, 20, \"minecraft\", \"sandbox\"))\n\treturn\n}\n\nfunc addGame(games []game, g game) []game {\n\treturn append(games, g)\n}\n\nfunc newGame(id, price int, name, genre string) game {\n\treturn game{\n\t\titem:  item{id: id, name: name, price: price},\n\t\tgenre: genre,\n\t}\n}\n\nfunc indexByID(games []game) (byID map[int]game) {\n\tbyID = make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\treturn\n}\n\nfunc printGame(g game) {\n\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-3/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor the game store to funcs - step #3\n//\n//  Let's continue from the previous exercise. This time,\n//  you're going to add json encoding and decoding using\n//  funcs.\n//\n//  1- Create a new command in a func that encodes the\n//     game store data to json and terminates the program.\n//     Lastly, add it to runCmd func.\n//\n//     For more information, see: \"Encode\" exercise from\n//     the structs section.\n//\n//        Name  : cmdSave\n//        Inputs: []game\n//        Output: bool\n//\n//  2- Refactor the load() to load the games from the\n//     `data` constant (it's in the games.go as well).\n//\n//     For more information, see: \"Decode\" exercise from\n//     the structs section.\n//\n// ---------------------------------------------------------\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tgames := load()\n\tbyID := indexByID(games)\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() || !runCmd(in.Text(), games, byID) {\n\t\t\tbreak\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-3/solution/commands.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc runCmd(input string, games []game, byID map[int]game) bool {\n\tfmt.Println()\n\n\tcmd := strings.Fields(input)\n\tif len(cmd) == 0 {\n\t\treturn true\n\t}\n\n\tswitch cmd[0] {\n\tcase \"quit\":\n\t\treturn cmdQuit()\n\n\tcase \"list\":\n\t\treturn cmdList(games)\n\n\tcase \"id\":\n\t\treturn cmdByID(cmd, games, byID)\n\n\tcase \"save\":\n\t\treturn cmdSave(games)\n\t}\n\treturn true\n}\n\nfunc cmdQuit() bool {\n\tfmt.Println(\"bye!\")\n\treturn false\n}\n\nfunc cmdList(games []game) bool {\n\tfor _, g := range games {\n\t\tprintGame(g)\n\t}\n\treturn true\n}\n\nfunc cmdByID(cmd []string, games []game, byID map[int]game) bool {\n\tif len(cmd) != 2 {\n\t\tfmt.Println(\"wrong id\")\n\t\treturn true\n\t}\n\n\tid, err := strconv.Atoi(cmd[1])\n\tif err != nil {\n\t\tfmt.Println(\"wrong id\")\n\t\treturn true\n\t}\n\n\tg, ok := byID[id]\n\tif !ok {\n\t\tfmt.Println(\"sorry. I don't have the game\")\n\t\treturn true\n\t}\n\n\tprintGame(g)\n\n\treturn true\n}\n\nfunc cmdSave(games []game) bool {\n\t// load the data into encodable game values\n\tvar jg []jsonGame\n\tfor _, g := range games {\n\t\tjg = append(jg, jsonGame{g.id, g.name, g.genre, g.price})\n\t}\n\n\tout, err := json.MarshalIndent(jg, \"\", \"\\t\")\n\tif err != nil {\n\t\tfmt.Println(\"sorry, can't save:\", err)\n\t\treturn true\n\t}\n\n\tfmt.Println(string(out))\n\treturn false\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-3/solution/games.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\nconst data = `\n[\n        {\n                \"id\": 1,\n                \"name\": \"god of war\",\n                \"genre\": \"action adventure\",\n                \"price\": 50\n        },\n        {\n                \"id\": 2,\n                \"name\": \"x-com 2\",\n                \"genre\": \"strategy\",\n                \"price\": 40\n        },\n        {\n                \"id\": 3,\n                \"name\": \"minecraft\",\n                \"genre\": \"sandbox\",\n                \"price\": 20\n        }\n]`\n\ntype item struct {\n\tid    int\n\tname  string\n\tprice int\n}\n\ntype game struct {\n\titem\n\tgenre string\n}\n\n// encodable and decodable game type\ntype jsonGame struct {\n\tID    int    `json:\"id\"`\n\tName  string `json:\"name\"`\n\tGenre string `json:\"genre\"`\n\tPrice int    `json:\"price\"`\n}\n\nfunc load() (games []game) {\n\t// load the initial data from json\n\tvar decoded []jsonGame\n\tif err := json.Unmarshal([]byte(data), &decoded); err != nil {\n\t\tfmt.Println(\"Sorry, there is a problem:\", err)\n\t\treturn\n\t}\n\n\t// load the data into usual game values\n\tfor _, dg := range decoded {\n\t\tgames = addGame(games, newGame(dg.ID, dg.Price, dg.Name, dg.Genre))\n\t}\n\treturn games\n}\n\nfunc addGame(games []game, g game) []game {\n\treturn append(games, g)\n}\n\nfunc newGame(id, price int, name, genre string) game {\n\treturn game{\n\t\titem:  item{id: id, name: name, price: price},\n\t\tgenre: genre,\n\t}\n}\n\nfunc indexByID(games []game) (byID map[int]game) {\n\tbyID = make(map[int]game)\n\tfor _, g := range games {\n\t\tbyID[g.id] = g\n\t}\n\treturn\n}\n\nfunc printGame(g game) {\n\tfmt.Printf(\"#%d: %-15q %-20s $%d\\n\",\n\t\tg.id, g.name, \"(\"+g.genre+\")\", g.price)\n}\n"
  },
  {
    "path": "25-functions/exercises/refactor-to-funcs-3/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tgames := load()\n\tbyID := indexByID(games)\n\n\tfmt.Printf(\"Inanc's game store has %d games.\\n\", len(games))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\tfmt.Printf(`\n  > list   : lists all the games\n  > id N   : queries a game by id\n  > save   : exports the data to json and quits  \n  > quit   : quits\n\n`)\n\n\t\tif !in.Scan() || !runCmd(in.Text(), games, byID) {\n\t\t\tbreak\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "25-functions/exercises/rewrite-log-parser-using-funcs/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/exercises/rewrite-log-parser-using-funcs/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/exercises/rewrite-log-parser-using-funcs/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/exercises/rewrite-log-parser-using-funcs/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "25-functions/exercises/rewrite-log-parser-using-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n}\n\nfunc main() {\n\tp := parser{sum: make(map[string]result)}\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.lines++\n\n\t\t// Parse the fields\n\t\tfields := strings.Fields(in.Text())\n\t\tif len(fields) != 2 {\n\t\t\tfmt.Printf(\"wrong input: %v (line #%d)\\n\", fields, p.lines)\n\t\t\treturn\n\t\t}\n\n\t\tdomain := fields[0]\n\n\t\t// Sum the total visits per domain\n\t\tvisits, err := strconv.Atoi(fields[1])\n\t\tif visits < 0 || err != nil {\n\t\t\tfmt.Printf(\"wrong input: %q (line #%d)\\n\", fields[1], p.lines)\n\t\t\treturn\n\t\t}\n\n\t\t// Collect the unique domains\n\t\tif _, ok := p.sum[domain]; !ok {\n\t\t\tp.domains = append(p.domains, domain)\n\t\t}\n\n\t\t// Keep track of total and per domain visits\n\t\tp.total += visits\n\n\t\t// You cannot assign to composite values\n\t\t// p.sum[domain].visits += visits\n\n\t\t// create and assign a new copy of `visit`\n\t\tp.sum[domain] = result{\n\t\t\tdomain: domain,\n\t\t\tvisits: visits + p.sum[domain].visits,\n\t\t}\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "25-functions/questions/README.md",
    "content": "## Which one is a correct function declaration?\n1. add func(a, b int) {}\n2. function run(a int, b int) {}\n3. func run(int a, b) {}\n4. func run(a, b int) {} *CORRECT*\n\n\n## Which one is the input and result names of the following func?\n```go\nfunc run(p Process, id1, id2 int) (pid int, err error) {}\n```\n1. Inputs: p, id1, and id2. Results: pid, err. *CORRECT*\n2. Inputs: Process, int, int. Results: int, error.\n3. Inputs: run, p, id1, id2. Results: pid, err.\n4. The declaration syntax is wrong.\n\n\n## What is a return statement?\n1. Terminates a program.\n2. Terminates a func by returning zero or more values to a caller func. *CORRECT*\n3. Skips the next statement and runs the next.\n\n\n## What is wrong with the following code?\n```go\nfunc add(a, b int) {\n    return a + b\n    return\n}\n```\n1. The return statement should be called only once\n2. The last return statement is wrong\n3. It should declare an int result value and remove the last return statement *CORRECT*\n4. It should declare any numeric result value\n\n> **2:** Actually, it is correct because the func doesn't declare a result value.\n> \n> **3:** Correct. It should be: `func add(a, b int) int { return a + b }`\n\n\n## How to fix the following code?\n```go\nfunc incr(a int) {\n    a++\n    return\n}\n\nnum := 10\n\n// You want it to print 11 but it prints 10 instead.\nfmt.Println( incr(num) )\n```\n1. Change the func: `func incr(a int) int { a++; return a }` *CORRECT*\n2. Change the func: `func incr(a int, newA int) { a++; newA = a }`\n3. Change the func: `func incr(a int) int { return a++ }`\n\n> **1:** Go is a 100% pass-by-value language. So, the inputs to a func are local to that function: The changes are not visible outside of that func.\n\n\n## Why should you not use package level variables?\n1. Nothing is wrong with them\n2. Funcs cannot use package level variables\n3. They may increase code coupling and cause fragile code *CORRECT*\n\n> **3:** It's because: Anyone can access and change them.\n\n\n## Why should you return an error from the following func?\n```go\n// Why this?\nfunc incr(n string) (int, error) {\n\tm, err := strconv.Atoi(n)\n\treturn n + 1, err\n}\n\n// Instead of this?\nfunc incr(n string) int {\n\tm, _ := strconv.Atoi(n)\n\treturn m + 1\n}\n```\n1. You want to let the caller know when something goes wrong *CORRECT*\n2. When an error occurs, `Atoi` returns 0, so you don't need to return an error\n\n> **2:** Sometimes, this is partly true however it is better to let the caller know when something goes wrong.\n\n\n## How and why does the following return statement work?\n```go\nfunc spread(samples int, P int) (estimated float64) {\n\tfor i := 0; i < P; i++ {\n\t\testimated += estimate(i, P)\n\t}\n\treturn\n}\n```\n1. `estimated` is a named result value. So the naked return returns `estimated` automatically. *CORRECT*\n2. return statement is not necessary there. Go automatically returns `estimated`.\n3. Result values cannot have a name. This code is incorrect.\n\n\n## Does the following code work? If so, why?\nIT SHOULD PRINT: map[1:11 10:3]\n```go\nfunc main() {\n    stats := map[int]int{1: 10, 10: 2}\n    incrAll(stats)\n    fmt.Print(stats)\n}\n\nfunc incrAll(stats map[int]int) {\n    for k := range stats {\n        stats[k]++\n    }\n}\n```\n1. No, it doesn't work: Go is a pass by value language. `incrAll` cannot update the map value.\n2. Yes, it works: `incrAll` can update the map value. *CORRECT*\n\n> **2:** Map values are pointers. So, `incrAll` can update the map value.\n\n\n## Does the following code work? If so, why?\nIT SHOULD PRINT: [10 5 2]\n```go\nfunc main() {\n    stats := []int{10, 5}\n    add(stats, 2)\n    fmt.Print(stats)\n}\n\nfunc add(stats []int, n int) {\n    stats = append(stats, n)\n}\n```\n1. No, it doesn't work: `add()` cannot update the original slice header. *CORRECT*\n2. Yes, it works: `add()` can add new element to the original slice header.\n\n> **1:** Go is a pass-by-value programming language. add() creates a copy of the original slice header and adds the new element to the new slice header but it never returns the updated one. So, it cannot update the original slice header. It should have been returning the original slice header."
  },
  {
    "path": "26-pointers/01-pointers/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar counter byte = 100\n\tP := &counter\n\tV := *P\n\n\tfmt.Printf(\"counter : %-16d address: %-16p\\n\", counter, &counter)\n\tfmt.Printf(\"P       : %-16p address: %-16p *P: %-16d\\n\", P, &P, *P)\n\tfmt.Printf(\"V       : %-16d address: %-16p\\n\", V, &V)\n\n\tV = 200\n\tfmt.Println()\n\tfmt.Printf(\"counter : %-16d address: %-16p\\n\", counter, &counter)\n\tfmt.Printf(\"P       : %-16p address: %-16p *P: %-16d\\n\", P, &P, *P)\n\tfmt.Printf(\"V       : %-16d address: %-16p\\n\", V, &V)\n\n\tV = counter // reset the V to counter's initial value\n\tcounter++\n\tfmt.Println()\n\tfmt.Printf(\"counter : %-16d address: %-16p\\n\", counter, &counter)\n\tfmt.Printf(\"P       : %-16p address: %-16p *P: %-16d\\n\", P, &P, *P)\n\tfmt.Printf(\"V       : %-16d address: %-16p\\n\", V, &V)\n\n\t*P = 25\n\tfmt.Println()\n\tfmt.Printf(\"counter : %-16d address: %-16p\\n\", counter, &counter)\n\tfmt.Printf(\"P       : %-16p address: %-16p *P: %-16d\\n\", P, &P, *P)\n\tfmt.Printf(\"V       : %-16d address: %-16p\\n\", V, &V)\n}\n"
  },
  {
    "path": "26-pointers/02-pointers-basic-examples/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tcounter int\n\t\tV       int\n\t\tP       *int\n\t)\n\n\tcounter = 100 // counter is an int variable\n\tP = &counter  // P is a pointer int variable\n\tV = *P        // V is a int variable (a copy of counter)\n\n\tif P == nil {\n\t\tfmt.Printf(\"P is nil and its address is %p\\n\", P)\n\t}\n\n\tif P == &counter {\n\t\tfmt.Printf(\"P is equal to counter's address: %p == %p\\n\", \n\t\t\tP, &counter)\n\t}\n\n\tfmt.Printf(\"counter: %-13d addr: %-13p\\n\", counter, &counter)\n\tfmt.Printf(\"P      : %-13p addr: %-13p *P: %-13d\\n\", P, &P, *P)\n\tfmt.Printf(\"V      : %-13d addr: %-13p\\n\", V, &V)\n\n\tfmt.Println(\"\\n••••• change counter\")\n\tcounter = 10 // V doesn't change because it's a copy\n\tfmt.Printf(\"counter: %-13d addr: %-13p\\n\", counter, &counter)\n\tfmt.Printf(\"V      : %-13d addr: %-13p\\n\", V, &V)\n\n\tfmt.Println(\"\\n••••• change counter in passVal()\")\n\tcounter = passVal(counter)\n\tfmt.Printf(\"counter: %-13d addr: %-13p\\n\", counter, &counter)\n\n\tfmt.Println(\"\\n••••• change counter in passPtrVal()\")\n\tpassPtrVal(&counter) // same as passPtrVal(&counter) (no need to return)\n\tpassPtrVal(&counter) // same as passPtrVal(&counter) (no need to return)\n\tfmt.Printf(\"counter: %-13d addr: %-13p\\n\", counter, &counter)\n}\n\n// *pn is a int pointer variable (copy of P)\nfunc passPtrVal(pn *int) {\n\tfmt.Printf(\"pn     : %-13p addr: %-13p *pn: %d\\n\", pn, &pn, *pn)\n\n\t// pointers can breach function isolation borders\n\t*pn++ // counter changes because `pn` points to `counter` — (*pn)++\n\tfmt.Printf(\"pn     : %-13p addr: %-13p *pn: %d\\n\", pn, &pn, *pn)\n\n\t// setting it to nil doesn't effect the caller (the main function)\n\tpn = nil\n}\n\n// n is a int variable (copy of counter)\nfunc passVal(n int) int {\n\tn = 50 // counter doesn't change because `n` is a copy\n\tfmt.Printf(\"n      : %-13d addr: %-13p\\n\", n, &n)\n\treturn n\n}\n"
  },
  {
    "path": "26-pointers/03-pointers-composites/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(\"••••• ARRAYS\")\n\tarrays()\n\n\tfmt.Println(\"\\n••••• SLICES\")\n\tslices()\n\n\tfmt.Println(\"\\n••••• MAPS\")\n\tmaps()\n\n\tfmt.Println(\"\\n••••• STRUCTS\")\n\tstructs()\n}\n\n// ••••••••••••••••••••••••••••••••••••••••••••••••••\n\ntype house struct {\n\tname  string\n\trooms int\n}\n\nfunc structs() {\n\tmyHouse := house{name: \"My House\", rooms: 5}\n\n\taddRoom(myHouse)\n\n\t// fmt.Printf(\"%+v\\n\", myHouse)\n\tfmt.Printf(\"structs()     : %p %+v\\n\", &myHouse, myHouse)\n\n\taddRoomPtr(&myHouse)\n\tfmt.Printf(\"structs()     : %p %+v\\n\", &myHouse, myHouse)\n}\n\nfunc addRoomPtr(h *house) {\n\th.rooms++ // same: (*h).rooms++\n\tfmt.Printf(\"addRoomPtr()  : %p %+v\\n\", h, h)\n\tfmt.Printf(\"&h.name       : %p\\n\", &h.name)\n\tfmt.Printf(\"&h.rooms      : %p\\n\", &h.rooms)\n}\n\nfunc addRoom(h house) {\n\th.rooms++\n\tfmt.Printf(\"addRoom()     : %p %+v\\n\", &h, h)\n}\n\n// ••••••••••••••••••••••••••••••••••••••••••••••••••\n\nfunc maps() {\n\tconfused := map[string]int{\"one\": 2, \"two\": 1}\n\tfix(confused)\n\tfmt.Println(confused)\n\n\t// &confused[\"one\"]\n}\n\nfunc fix(m map[string]int) {\n\tm[\"one\"] = 1\n\tm[\"two\"] = 2\n\tm[\"three\"] = 3\n}\n\n// ••••••••••••••••••••••••••••••••••••••••••••••••••\n\nfunc slices() {\n\tdirs := []string{\"up\", \"down\", \"left\", \"right\"}\n\n\tup(dirs)\n\tfmt.Printf(\"slices list   : %p %q\\n\", &dirs, dirs)\n\n\tupPtr(&dirs)\n\tfmt.Printf(\"slices list   : %p %q\\n\", &dirs, dirs)\n}\n\nfunc upPtr(list *[]string) {\n\tlv := *list\n\n\tfor i := range lv {\n\t\tlv[i] = strings.ToUpper(lv[i])\n\t}\n\n\t*list = append(*list, \"HEISEN BUG\")\n\n\tfmt.Printf(\"upPtr list    : %p %q\\n\", list, list)\n}\n\nfunc up(list []string) {\n\tfor i := range list {\n\t\tlist[i] = strings.ToUpper(list[i])\n\t\tfmt.Printf(\"up.list[%d]    : %p\\n\", i, &list[i])\n\t}\n\n\tlist = append(list, \"HEISEN BUG\")\n\n\tfmt.Printf(\"up list       : %p %q\\n\", &list, list)\n}\n\n// ••••••••••••••••••••••••••••••••••••••••••••••••••\n\nfunc arrays() {\n\tnums := [...]int{1, 2, 3}\n\n\tincr(nums)\n\tfmt.Printf(\"arrays nums   : %p\\n\", &nums)\n\tfmt.Println(nums)\n\n\tincrByPtr(&nums)\n\tfmt.Println(nums)\n}\n\nfunc incr(nums [3]int) {\n\tfmt.Printf(\"incr nums     : %p\\n\", &nums)\n\tfor i := range nums {\n\t\tnums[i]++\n\t\tfmt.Printf(\"incr.nums[%d]  : %p\\n\", i, &nums[i])\n\t}\n}\n\nfunc incrByPtr(nums *[3]int) {\n\tfmt.Printf(\"incrByPtr nums: %p\\n\", &nums)\n\tfor i := range nums {\n\t\tnums[i]++ // same: (*nums)[i]++\n\t}\n}\n"
  },
  {
    "path": "26-pointers/04-log-parser-pointers/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/04-log-parser-pointers/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/04-log-parser-pointers/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/04-log-parser-pointers/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/04-log-parser-pointers/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tp := newParser()\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tparsed := parse(&p, in.Text())\n\t\tupdate(&p, parsed)\n\t}\n\n\tsummarize(p)\n\tdumpErrs([]error{in.Err(), p.lerr})\n}\n\n// summarize summarizes and prints the parsing result\nfunc summarize(p parser) {\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n}\n\n// dumpErrs simplifies handling multiple errors\nfunc dumpErrs(errs []error) {\n\tfor _, err := range errs {\n\t\tif err != nil {\n\t\t\tfmt.Println(\"> Err:\", err)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "26-pointers/04-log-parser-pointers/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n\tlerr    error             // the last error occurred\n}\n\n// newParser constructs, initializes and returns a new parser\nfunc newParser() parser {\n\treturn parser{sum: make(map[string]result)}\n}\n\n// parse parses a log line and returns the parsed result with an error\nfunc parse(p *parser, line string) (parsed result) {\n\tif p.lerr != nil {\n\t\treturn\n\t}\n\n\tp.lines++\n\n\tfields := strings.Fields(line)\n\tif len(fields) != 2 {\n\t\tp.lerr = fmt.Errorf(\"wrong input: %v (line #%d)\", fields, p.lines)\n\t\treturn\n\t}\n\n\tparsed.domain = fields[0]\n\n\tvar err error\n\n\tparsed.visits, err = strconv.Atoi(fields[1])\n\tif parsed.visits < 0 || err != nil {\n\t\tp.lerr = fmt.Errorf(\"wrong input: %q (line #%d)\", fields[1], p.lines)\n\t}\n\treturn\n}\n\n// update updates all the parsing results using the given parsing result\nfunc update(p *parser, parsed result) {\n\tif p.lerr != nil {\n\t\treturn\n\t}\n\n\tdomain, visits := parsed.domain, parsed.visits\n\n\t// Collect the unique domains\n\tif _, ok := p.sum[domain]; !ok {\n\t\tp.domains = append(p.domains, domain)\n\t}\n\n\t// Keep track of total and per domain visits\n\tp.total += visits\n\n\t// create and assign a new copy of `visit`\n\tp.sum[domain] = result{\n\t\tdomain: domain,\n\t\tvisits: visits + p.sum[domain].visits,\n\t}\n}\n"
  },
  {
    "path": "26-pointers/05-log-parser-pointers-vs-values/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/05-log-parser-pointers-vs-values/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/05-log-parser-pointers-vs-values/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/05-log-parser-pointers-vs-values/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/05-log-parser-pointers-vs-values/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tp := newParser()\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tparsed := parse(p, in.Text())\n\t\tupdate(p, parsed)\n\t}\n\n\tsummarize(p)\n\tdumpErrs([]error{in.Err(), err(p)})\n}\n\n// summarize summarizes and prints the parsing result\nfunc summarize(p *parser) {\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, p.sum[domain].visits)\n\t}\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n}\n\n// dumpErrs simplifies handling multiple errors\nfunc dumpErrs(errs []error) {\n\tfor _, err := range errs {\n\t\tif err != nil {\n\t\t\tfmt.Println(\"> Err:\", err)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "26-pointers/05-log-parser-pointers-vs-values/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n\tlerr    error             // the last error occurred\n}\n\n// newParser constructs, initializes and returns a new parser\nfunc newParser() *parser {\n\treturn &parser{sum: make(map[string]result)}\n}\n\n// parse parses a log line and returns the parsed result with an error\nfunc parse(p *parser, line string) (r result) {\n\tif p.lerr != nil {\n\t\treturn\n\t}\n\n\tp.lines++\n\n\tfields := strings.Fields(line)\n\tif len(fields) != 2 {\n\t\tp.lerr = fmt.Errorf(\"wrong input: %v (line #%d)\", fields, p.lines)\n\t\treturn\n\t}\n\n\tvar err error\n\n\tr.domain = fields[0]\n\tr.visits, err = strconv.Atoi(fields[1])\n\n\tif r.visits < 0 || err != nil {\n\t\tp.lerr = fmt.Errorf(\"wrong input: %q (line #%d)\", fields[1], p.lines)\n\t}\n\treturn\n}\n\n// update updates all the parsing results using the given parsing result\nfunc update(p *parser, r result) {\n\tif p.lerr != nil {\n\t\treturn\n\t}\n\n\t// Collect the unique domains\n\tif _, ok := p.sum[r.domain]; !ok {\n\t\tp.domains = append(p.domains, r.domain)\n\t}\n\n\t// Keep track of total and per domain visits\n\tp.total += r.visits\n\n\t// create and assign a new copy of `visit`\n\tp.sum[r.domain] = result{\n\t\tdomain: r.domain,\n\t\tvisits: r.visits + p.sum[r.domain].visits,\n\t}\n}\n\n// err returns the last error encountered\nfunc err(p *parser) error {\n\treturn p.lerr\n}\n"
  },
  {
    "path": "26-pointers/exercises/01-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Basics\n//\n//  Let's warm up with the pointer basics. Please follow the\n//  instructions inside the code. Run the solution to see\n//  its output if you need to.\n// ---------------------------------------------------------\n\npackage main\n\ntype computer struct {\n\tbrand string\n}\n\nfunc main() {\n\t// create a nil pointer with the type of pointer to a computer\n\n\t// compare the pointer variable to a nil value, and say it's nil\n\n\t// create an apple computer by putting its address to a pointer variable\n\n\t// put the apple into a new pointer variable\n\n\t// compare the apples: if they are equal say so and print their addresses\n\n\t// create a sony computer by putting its address to a new pointer variable\n\n\t// compare apple to sony, if they are not equal say so and print their\n\t// addresses\n\n\t// put apple's value into a new ordinary variable\n\n\t// print apple pointer variable's address, and the address it points to\n\t// and, print the new variable's addresses as well\n\n\t// compare the value that is pointed by the apple and the new variable\n\t// if they are equal say so\n\n\t// print the values:\n\t// the value that is pointed by the apple and the new variable\n\n\t// create a new function: change\n\t// the func can change the given computer's brand to another brand\n\n\t// change sony's brand to hp using the func — print sony's brand\n\n\t// write a func that returns the value that is pointed by the given *computer\n\t// print the returned value\n\n\t// write a new constructor func that returns a pointer to a computer\n\t// and call the func 3 times and print the returned values' addresses\n}\n"
  },
  {
    "path": "26-pointers/exercises/01-basics/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype computer struct {\n\tbrand string\n}\n\nfunc main() {\n\t// create a nil pointer with the type of pointer to a computer\n\tvar null *computer\n\n\t// compare the pointer variable to a nil value\n\tif null == nil {\n\t\t// , and say it's nil\n\t\tfmt.Println(\"null computer is nil\")\n\t}\n\n\t// create an apple computer by putting its address to a pointer variable\n\tapple := &computer{brand: \"apple\"}\n\n\t// put the apple into a new pointer variable\n\tnewApple := apple\n\n\t// compare the apples: if they are equal\n\tif apple == newApple {\n\t\t// say so and print their addresses\n\t\tfmt.Printf(\"apples are equal          : apple: %p newApple: %p\\n\",\n\t\t\tapple, newApple)\n\t}\n\n\t// create a sony computer by putting its address to a new pointer variable\n\tsony := &computer{brand: \"sony\"}\n\n\t// compare apple to sony, if they are not equal\n\tif apple != sony {\n\t\t// say so and print their addresses\n\t\tfmt.Printf(\"apple and sony are inequal: apple: %p sony: %p\\n\",\n\t\t\tapple, sony)\n\t}\n\n\t// put apple's value into a new ordinary variable\n\tappleVal := *apple\n\n\t// print apple pointer variable's address, and the address it points to\n\t// and, print the new variable's addresses as well\n\tfmt.Printf(\"apple                     : %p %p\\n\", &apple, apple)\n\tfmt.Printf(\"appleVal                  : %p\\n\", &appleVal)\n\n\t// compare the value that is pointed by the apple and the new variable\n\tif *apple == appleVal {\n\t\t// if they are equal say so\n\t\tfmt.Println(\"apple and appleVal are equal\")\n\n\t\t// print the values:\n\t\t// the value that is pointed by the apple and the new variable\n\t\tfmt.Printf(\"apple                     : %+v — appleVal: %+v\\n\",\n\t\t\t*apple, appleVal)\n\t}\n\n\t// change sony's brand to hp using the func\n\tchange(sony, \"hp\")\n\t// print sony's brand\n\tfmt.Printf(\"sony                      : %s\\n\", sony.brand)\n\n\t// print the returned value\n\tfmt.Printf(\"appleVal                  : %+v\\n\", valueOf(apple))\n\n\t// and call the func 3 times and print the returned values' addresses\n\tfmt.Printf(\"dell's address            : %p\\n\", newComputer(\"dell\"))\n\tfmt.Printf(\"lenovo's address          : %p\\n\", newComputer(\"lenovo\"))\n\tfmt.Printf(\"acer's address            : %p\\n\", newComputer(\"acer\"))\n}\n\n// create a new function: change\n// the func can change the given computer's brand to another brand\nfunc change(c *computer, brand string) {\n\tc.brand = brand\n}\n\n// write a func that returns the value that is pointed by the given *computer\nfunc valueOf(c *computer) computer {\n\treturn *c\n}\n\n// write a new constructor func that returns a pointer to a computer\nfunc newComputer(brand string) *computer {\n\treturn &computer{brand: brand}\n}\n"
  },
  {
    "path": "26-pointers/exercises/02-swap/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Swap\n//\n//  Using funcs, swap values through pointers, and swap\n//  the addresses of the pointers.\n//\n//\n//  1- Swap the values through a func\n//\n//     a- Declare two float variables\n//\n//     b- Declare a func that can swap the variables' values\n//        through their memory addresses\n//\n//     c- Pass the variables' addresses to the func\n//\n//     d- Print the variables\n//\n//\n//  2- Swap the addresses of the float pointers through a func\n//\n//     a- Declare two float pointer variables and,\n//        assign them the addresses of float variables\n//\n//     b- Declare a func that can swap the addresses\n//        of two float pointers\n//\n//     c- Pass the pointer variables to the func\n//\n//     d- Print the addresses, and values that are\n//        pointed by the pointer variables\n//\n// ---------------------------------------------------------\n\npackage main\n\nfunc main() {\n}\n"
  },
  {
    "path": "26-pointers/exercises/02-swap/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ta, b := 3.14, 6.28\n\tswap(&a, &b)\n\tfmt.Printf(\"a : %g — b : %g\\n\", a, b)\n\n\tpa, pb := &a, &b\n\tpa, pb = swapAddr(pa, pb)\n\tfmt.Printf(\"pa: %p — pb: %p\\n\", pa, pb)\n\tfmt.Printf(\"pa: %g — pb: %g\\n\", *pa, *pb)\n}\n\nfunc swap(a, b *float64) {\n\t*a, *b = *b, *a\n}\n\nfunc swapAddr(a, b *float64) (*float64, *float64) {\n\treturn b, a\n}\n"
  },
  {
    "path": "26-pointers/exercises/03-fix-the-crash/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Fix the crash\n//\n// EXPECTED OUTPUT\n//\n//   brand: apple\n// ---------------------------------------------------------\n\npackage main\n\nimport \"fmt\"\n\ntype computer struct {\n\tbrand *string\n}\n\nfunc main() {\n\tvar c *computer\n\tchange(c, \"apple\")\n\tfmt.Printf(\"brand: %s\\n\", c.brand)\n}\n\nfunc change(c *computer, brand string) {\n\t(*c.brand) = brand\n}\n"
  },
  {
    "path": "26-pointers/exercises/03-fix-the-crash/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype computer struct {\n\tbrand *string\n}\n\nfunc main() {\n\tc := &computer{} // init with a value (before: c was nil)\n\tchange(c, \"apple\")\n\tfmt.Printf(\"brand: %s\\n\", *c.brand) // print the pointed value\n}\n\nfunc change(c *computer, brand string) {\n\tc.brand = &brand // set the brand's address\n}\n"
  },
  {
    "path": "26-pointers/exercises/04-simplify/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// ---------------------------------------------------------\n// EXERCISE: Simplify the code\n// HINT    : Remove the unnecessary pointer usages\n// ---------------------------------------------------------\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar schools []map[int]string\n\n\tschools = append(schools, make(map[int]string))\n\tload(&schools[0], &([]string{\"batman\", \"superman\"}))\n\n\tschools = append(schools, make(map[int]string))\n\tload(&schools[1], &([]string{\"spiderman\", \"wonder woman\"}))\n\n\tfmt.Println(schools[0])\n\tfmt.Println(schools[1])\n}\n\nfunc load(m *map[int]string, students *[]string) {\n\tfor i, name := range *students {\n\t\t(*m)[i+1] = name\n\t}\n}\n"
  },
  {
    "path": "26-pointers/exercises/04-simplify/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tschools := make([]map[int]string, 2)\n\tfor i := range schools {\n\t\tschools[i] = make(map[int]string)\n\t}\n\n\tload(schools[0], []string{\"batman\", \"superman\"})\n\tload(schools[1], []string{\"spiderman\", \"wonder woman\"})\n\n\tfmt.Println(schools[0])\n\tfmt.Println(schools[1])\n}\n\nfunc load(m map[int]string, students []string) {\n\tfor i, name := range students {\n\t\tm[i+1] = name\n\t}\n}\n"
  },
  {
    "path": "26-pointers/exercises/05-log-parser/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/exercises/05-log-parser/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/exercises/05-log-parser/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/exercises/05-log-parser/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "26-pointers/exercises/05-log-parser/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tp := newParser()\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.lines++\n\n\t\tparsed, err := parse(p, in.Text())\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t\treturn\n\t\t}\n\n\t\tp = update(p, parsed)\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "26-pointers/exercises/05-log-parser/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n}\n\n// newParser constructs, initializes and returns a new parser\nfunc newParser() parser {\n\treturn parser{sum: make(map[string]result)}\n}\n\n// parse parses a log line and returns the parsed result with an error\nfunc parse(p parser, line string) (parsed result, err error) {\n\tfields := strings.Fields(line)\n\tif len(fields) != 2 {\n\t\terr = fmt.Errorf(\"wrong input: %v (line #%d)\", fields, p.lines)\n\t\treturn\n\t}\n\n\tparsed.domain = fields[0]\n\n\tparsed.visits, err = strconv.Atoi(fields[1])\n\tif parsed.visits < 0 || err != nil {\n\t\terr = fmt.Errorf(\"wrong input: %q (line #%d)\", fields[1], p.lines)\n\t\treturn\n\t}\n\n\treturn\n}\n\n// update updates the parser for the given parsing result\nfunc update(p parser, parsed result) parser {\n\tdomain, visits := parsed.domain, parsed.visits\n\n\t// Collect the unique domains\n\tif _, ok := p.sum[domain]; !ok {\n\t\tp.domains = append(p.domains, domain)\n\t}\n\n\t// Keep track of total and per domain visits\n\tp.total += visits\n\n\t// create and assign a new copy of `visit`\n\tp.sum[domain] = result{\n\t\tdomain: domain,\n\t\tvisits: visits + p.sum[domain].visits,\n\t}\n\n\treturn p\n}\n"
  },
  {
    "path": "26-pointers/exercises/README.md",
    "content": "# Pointer Exercises\n\n1. **[Basics](https://github.com/inancgumus/learngo/tree/master/26-pointers/exercises/01-basics)**\n\n    Warm-up and solidify your knowledge of pointers with the basic exercises. This exercise contains 10+ mini exercises in itself.\n\n2. **[Swap](https://github.com/inancgumus/learngo/tree/master/26-pointers/exercises/02-swap)**\n\n    Using funcs, swap the values through pointers, and swap the addresses of pointers. It may be tricky than it sounds.\n\n3. **[Fix the Crash](https://github.com/inancgumus/learngo/tree/master/26-pointers/exercises/03-fix-the-crash)**\n\n    Fix the crashing program. Another tricky exercise.\n\n4. **[Simplify](https://github.com/inancgumus/learngo/tree/master/26-pointers/exercises/04-simplify)**\n\n    Simplify the given code using your knowledge of map, slices, and pointers.\n\n5. **[Rewrite the Log Parser program using pointers](https://github.com/inancgumus/learngo/tree/master/26-pointers/exercises/05-log-parser)**\n\n    You've watched the lecture. Now, try to rewrite the same log parser program using pointers on your own."
  },
  {
    "path": "26-pointers/questions/README.md",
    "content": "## What is a pointer?\n1. A variable that contains an hexadecimal value\n2. A variable that contains a memory address\n3. A value that can contain a memory address of a value *CORRECT*\n4. A value that points to a function\n\n> **2:** Although a pointer can be put into a variable, it's not solely a variable. You're almost there! But this distinction is very important.\n> \n> **3:** A pointer is just another value that can contain a memory address of a value.\n\n\n## Which one is a pointer to a computer?\n```go\ntype computer struct {\n\tbrand string\n}\n```\n1. `*computer{}`\n2. `var c computer`\n3. `var *c computer`\n4. `var c *computer` *CORRECT*\n\n> **4:** * in front of a type denotes a pointer type.\n\n\n## Which one gets the pointed composite value by the following pointer?\n```go\ntype computer struct {\n\tbrand string\n}\n\nc := &computer{\"Apple\"}\n```\n1. `*c` *CORRECT*\n2. `&c`\n3. `c`\n4. `*computer`\n\n> **1:** * in front of a pointer value gets the value that is pointed by the pointer.\n> \n> **2:** & in front of a value gets the memory address of that value\n> \n> **4:** * in front of a type denotes a pointer type.\n\n\n## What is the result of the following code?\n```go\ntype computer struct {\n    brand string\n}\n\nvar a, b *computer\nfmt.Print(a == b)\n\na = &computer{\"Apple\"}\nb = &computer{\"Apple\"}\nfmt.Print(\" \", a == b, \" \", *a == *b)\n```\n1. false false false\n2. true true true\n3. true false true *CORRECT*\n4. false true true\n\n> **3:** a and b are nil at the beginning, so they are equal. However, after that, they get two different memory addresses from the composite literals, so their addresses are not equal but their values (that are pointed by the pointers) are equal.\n\n\n## How many variables are there in the following code?\n```go\ntype computer struct {\n    brand string\n}\n\nfunc main() {\n    a = &computer{\"Apple\"}\n    b := a\n    change(b)\n    change(b)\n}\n\nfunc change(c *computer) {\n    c.brand = \"Indie\"\n    c = nil\n}\n```\n1. 1\n2. 2\n3. 3\n4. 4 *CORRECT*\n\n> **4:** Every time a func runs, it creates new variables from its input params and named result values (if any). There two pointer variables: a and b. Then there are, two more pointer variables because: change is called two times.\n\n\n## Why you cannot take the address of a map's elements?\n1. It's an addressable value\n2. It's an unaddressable value *CORRECT*\n3. Doing so can crash your program\n\n> **2:** Map elements are not addressable, so you cannot take their addresses."
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) 2018 Inanc Gumus <m@inanc.io>\n\n=======================================================================\n\nAttribution-NonCommercial-ShareAlike 4.0 International\n\n=======================================================================\n\nCreative Commons Corporation (\"Creative Commons\") is not a law firm and\ndoes not provide legal services or legal advice. Distribution of\nCreative Commons public licenses does not create a lawyer-client or\nother relationship. Creative Commons makes its licenses and related\ninformation available on an \"as-is\" basis. Creative Commons gives no\nwarranties regarding its licenses, any material licensed under their\nterms and conditions, or any related information. Creative Commons\ndisclaims all liability for damages resulting from their use to the\nfullest extent possible.\n\nUsing Creative Commons Public Licenses\n\nCreative Commons public licenses provide a standard set of terms and\nconditions that creators and other rights holders may use to share\noriginal works of authorship and other material subject to copyright\nand certain other rights specified in the public license below. The\nfollowing considerations are for informational purposes only, are not\nexhaustive, and do not form part of our licenses.\n\n     Considerations for licensors: Our public licenses are\n     intended for use by those authorized to give the public\n     permission to use material in ways otherwise restricted by\n     copyright and certain other rights. Our licenses are\n     irrevocable. Licensors should read and understand the terms\n     and conditions of the license they choose before applying it.\n     Licensors should also secure all rights necessary before\n     applying our licenses so that the public can reuse the\n     material as expected. Licensors should clearly mark any\n     material not subject to the license. This includes other CC-\n     licensed material, or material used under an exception or\n     limitation to copyright. More considerations for licensors:\n\twiki.creativecommons.org/Considerations_for_licensors\n\n     Considerations for the public: By using one of our public\n     licenses, a licensor grants the public permission to use the\n     licensed material under specified terms and conditions. If\n     the licensor's permission is not necessary for any reason--for\n     example, because of any applicable exception or limitation to\n     copyright--then that use is not regulated by the license. Our\n     licenses grant only permissions under copyright and certain\n     other rights that a licensor has authority to grant. Use of\n     the licensed material may still be restricted for other\n     reasons, including because others have copyright or other\n     rights in the material. A licensor may make special requests,\n     such as asking that all changes be marked or described.\n     Although not required by our licenses, you are encouraged to\n     respect those requests where reasonable. More_considerations\n     for the public: \n\twiki.creativecommons.org/Considerations_for_licensees\n\n=======================================================================\n\nCreative Commons Attribution-NonCommercial-ShareAlike 4.0 International\nPublic License\n\nBy exercising the Licensed Rights (defined below), You accept and agree\nto be bound by the terms and conditions of this Creative Commons\nAttribution-NonCommercial-ShareAlike 4.0 International Public License\n(\"Public License\"). To the extent this Public License may be\ninterpreted as a contract, You are granted the Licensed Rights in\nconsideration of Your acceptance of these terms and conditions, and the\nLicensor grants You such rights in consideration of benefits the\nLicensor receives from making the Licensed Material available under\nthese terms and conditions.\n\n\nSection 1 -- Definitions.\n\n  a. Adapted Material means material subject to Copyright and Similar\n     Rights that is derived from or based upon the Licensed Material\n     and in which the Licensed Material is translated, altered,\n     arranged, transformed, or otherwise modified in a manner requiring\n     permission under the Copyright and Similar Rights held by the\n     Licensor. For purposes of this Public License, where the Licensed\n     Material is a musical work, performance, or sound recording,\n     Adapted Material is always produced where the Licensed Material is\n     synched in timed relation with a moving image.\n\n  b. Adapter's License means the license You apply to Your Copyright\n     and Similar Rights in Your contributions to Adapted Material in\n     accordance with the terms and conditions of this Public License.\n\n  c. BY-NC-SA Compatible License means a license listed at\n     creativecommons.org/compatiblelicenses, approved by Creative\n     Commons as essentially the equivalent of this Public License.\n\n  d. Copyright and Similar Rights means copyright and/or similar rights\n     closely related to copyright including, without limitation,\n     performance, broadcast, sound recording, and Sui Generis Database\n     Rights, without regard to how the rights are labeled or\n     categorized. For purposes of this Public License, the rights\n     specified in Section 2(b)(1)-(2) are not Copyright and Similar\n     Rights.\n\n  e. Effective Technological Measures means those measures that, in the\n     absence of proper authority, may not be circumvented under laws\n     fulfilling obligations under Article 11 of the WIPO Copyright\n     Treaty adopted on December 20, 1996, and/or similar international\n     agreements.\n\n  f. Exceptions and Limitations means fair use, fair dealing, and/or\n     any other exception or limitation to Copyright and Similar Rights\n     that applies to Your use of the Licensed Material.\n\n  g. License Elements means the license attributes listed in the name\n     of a Creative Commons Public License. The License Elements of this\n     Public License are Attribution, NonCommercial, and ShareAlike.\n\n  h. Licensed Material means the artistic or literary work, database,\n     or other material to which the Licensor applied this Public\n     License.\n\n  i. Licensed Rights means the rights granted to You subject to the\n     terms and conditions of this Public License, which are limited to\n     all Copyright and Similar Rights that apply to Your use of the\n     Licensed Material and that the Licensor has authority to license.\n\n  j. Licensor means the individual(s) or entity(ies) granting rights\n     under this Public License.\n\n  k. NonCommercial means not primarily intended for or directed towards\n     commercial advantage or monetary compensation. For purposes of\n     this Public License, the exchange of the Licensed Material for\n     other material subject to Copyright and Similar Rights by digital\n     file-sharing or similar means is NonCommercial provided there is\n     no payment of monetary compensation in connection with the\n     exchange.\n\n  l. Share means to provide material to the public by any means or\n     process that requires permission under the Licensed Rights, such\n     as reproduction, public display, public performance, distribution,\n     dissemination, communication, or importation, and to make material\n     available to the public including in ways that members of the\n     public may access the material from a place and at a time\n     individually chosen by them.\n\n  m. Sui Generis Database Rights means rights other than copyright\n     resulting from Directive 96/9/EC of the European Parliament and of\n     the Council of 11 March 1996 on the legal protection of databases,\n     as amended and/or succeeded, as well as other essentially\n     equivalent rights anywhere in the world.\n\n  n. You means the individual or entity exercising the Licensed Rights\n     under this Public License. Your has a corresponding meaning.\n\n\nSection 2 -- Scope.\n\n  a. License grant.\n\n       1. Subject to the terms and conditions of this Public License,\n          the Licensor hereby grants You a worldwide, royalty-free,\n          non-sublicensable, non-exclusive, irrevocable license to\n          exercise the Licensed Rights in the Licensed Material to:\n\n            a. reproduce and Share the Licensed Material, in whole or\n               in part, for NonCommercial purposes only; and\n\n            b. produce, reproduce, and Share Adapted Material for\n               NonCommercial purposes only.\n\n       2. Exceptions and Limitations. For the avoidance of doubt, where\n          Exceptions and Limitations apply to Your use, this Public\n          License does not apply, and You do not need to comply with\n          its terms and conditions.\n\n       3. Term. The term of this Public License is specified in Section\n          6(a).\n\n       4. Media and formats; technical modifications allowed. The\n          Licensor authorizes You to exercise the Licensed Rights in\n          all media and formats whether now known or hereafter created,\n          and to make technical modifications necessary to do so. The\n          Licensor waives and/or agrees not to assert any right or\n          authority to forbid You from making technical modifications\n          necessary to exercise the Licensed Rights, including\n          technical modifications necessary to circumvent Effective\n          Technological Measures. For purposes of this Public License,\n          simply making modifications authorized by this Section 2(a)\n          (4) never produces Adapted Material.\n\n       5. Downstream recipients.\n\n            a. Offer from the Licensor -- Licensed Material. Every\n               recipient of the Licensed Material automatically\n               receives an offer from the Licensor to exercise the\n               Licensed Rights under the terms and conditions of this\n               Public License.\n\n            b. Additional offer from the Licensor -- Adapted Material.\n               Every recipient of Adapted Material from You\n               automatically receives an offer from the Licensor to\n               exercise the Licensed Rights in the Adapted Material\n               under the conditions of the Adapter's License You apply.\n\n            c. No downstream restrictions. You may not offer or impose\n               any additional or different terms or conditions on, or\n               apply any Effective Technological Measures to, the\n               Licensed Material if doing so restricts exercise of the\n               Licensed Rights by any recipient of the Licensed\n               Material.\n\n       6. No endorsement. Nothing in this Public License constitutes or\n          may be construed as permission to assert or imply that You\n          are, or that Your use of the Licensed Material is, connected\n          with, or sponsored, endorsed, or granted official status by,\n          the Licensor or others designated to receive attribution as\n          provided in Section 3(a)(1)(A)(i).\n\n  b. Other rights.\n\n       1. Moral rights, such as the right of integrity, are not\n          licensed under this Public License, nor are publicity,\n          privacy, and/or other similar personality rights; however, to\n          the extent possible, the Licensor waives and/or agrees not to\n          assert any such rights held by the Licensor to the limited\n          extent necessary to allow You to exercise the Licensed\n          Rights, but not otherwise.\n\n       2. Patent and trademark rights are not licensed under this\n          Public License.\n\n       3. To the extent possible, the Licensor waives any right to\n          collect royalties from You for the exercise of the Licensed\n          Rights, whether directly or through a collecting society\n          under any voluntary or waivable statutory or compulsory\n          licensing scheme. In all other cases the Licensor expressly\n          reserves any right to collect such royalties, including when\n          the Licensed Material is used other than for NonCommercial\n          purposes.\n\n\nSection 3 -- License Conditions.\n\nYour exercise of the Licensed Rights is expressly made subject to the\nfollowing conditions.\n\n  a. Attribution.\n\n       1. If You Share the Licensed Material (including in modified\n          form), You must:\n\n            a. retain the following if it is supplied by the Licensor\n               with the Licensed Material:\n\n                 i. identification of the creator(s) of the Licensed\n                    Material and any others designated to receive\n                    attribution, in any reasonable manner requested by\n                    the Licensor (including by pseudonym if\n                    designated);\n\n                ii. a copyright notice;\n\n               iii. a notice that refers to this Public License;\n\n                iv. a notice that refers to the disclaimer of\n                    warranties;\n\n                 v. a URI or hyperlink to the Licensed Material to the\n                    extent reasonably practicable;\n\n            b. indicate if You modified the Licensed Material and\n               retain an indication of any previous modifications; and\n\n            c. indicate the Licensed Material is licensed under this\n               Public License, and include the text of, or the URI or\n               hyperlink to, this Public License.\n\n       2. You may satisfy the conditions in Section 3(a)(1) in any\n          reasonable manner based on the medium, means, and context in\n          which You Share the Licensed Material. For example, it may be\n          reasonable to satisfy the conditions by providing a URI or\n          hyperlink to a resource that includes the required\n          information.\n       3. If requested by the Licensor, You must remove any of the\n          information required by Section 3(a)(1)(A) to the extent\n          reasonably practicable.\n\n  b. ShareAlike.\n\n     In addition to the conditions in Section 3(a), if You Share\n     Adapted Material You produce, the following conditions also apply.\n\n       1. The Adapter's License You apply must be a Creative Commons\n          license with the same License Elements, this version or\n          later, or a BY-NC-SA Compatible License.\n\n       2. You must include the text of, or the URI or hyperlink to, the\n          Adapter's License You apply. You may satisfy this condition\n          in any reasonable manner based on the medium, means, and\n          context in which You Share Adapted Material.\n\n       3. You may not offer or impose any additional or different terms\n          or conditions on, or apply any Effective Technological\n          Measures to, Adapted Material that restrict exercise of the\n          rights granted under the Adapter's License You apply.\n\n\nSection 4 -- Sui Generis Database Rights.\n\nWhere the Licensed Rights include Sui Generis Database Rights that\napply to Your use of the Licensed Material:\n\n  a. for the avoidance of doubt, Section 2(a)(1) grants You the right\n     to extract, reuse, reproduce, and Share all or a substantial\n     portion of the contents of the database for NonCommercial purposes\n     only;\n\n  b. if You include all or a substantial portion of the database\n     contents in a database in which You have Sui Generis Database\n     Rights, then the database in which You have Sui Generis Database\n     Rights (but not its individual contents) is Adapted Material,\n     including for purposes of Section 3(b); and\n\n  c. You must comply with the conditions in Section 3(a) if You Share\n     all or a substantial portion of the contents of the database.\n\nFor the avoidance of doubt, this Section 4 supplements and does not\nreplace Your obligations under this Public License where the Licensed\nRights include other Copyright and Similar Rights.\n\n\nSection 5 -- Disclaimer of Warranties and Limitation of Liability.\n\n  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE\n     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS\n     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF\n     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,\n     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,\n     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR\n     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,\n     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT\n     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT\n     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.\n\n  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE\n     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,\n     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,\n     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,\n     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR\n     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN\n     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR\n     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR\n     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.\n\n  c. The disclaimer of warranties and limitation of liability provided\n     above shall be interpreted in a manner that, to the extent\n     possible, most closely approximates an absolute disclaimer and\n     waiver of all liability.\n\n\nSection 6 -- Term and Termination.\n\n  a. This Public License applies for the term of the Copyright and\n     Similar Rights licensed here. However, if You fail to comply with\n     this Public License, then Your rights under this Public License\n     terminate automatically.\n\n  b. Where Your right to use the Licensed Material has terminated under\n     Section 6(a), it reinstates:\n\n       1. automatically as of the date the violation is cured, provided\n          it is cured within 30 days of Your discovery of the\n          violation; or\n\n       2. upon express reinstatement by the Licensor.\n\n     For the avoidance of doubt, this Section 6(b) does not affect any\n     right the Licensor may have to seek remedies for Your violations\n     of this Public License.\n\n  c. For the avoidance of doubt, the Licensor may also offer the\n     Licensed Material under separate terms or conditions or stop\n     distributing the Licensed Material at any time; however, doing so\n     will not terminate this Public License.\n\n  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public\n     License.\n\n\nSection 7 -- Other Terms and Conditions.\n\n  a. The Licensor shall not be bound by any additional or different\n     terms or conditions communicated by You unless expressly agreed.\n\n  b. Any arrangements, understandings, or agreements regarding the\n     Licensed Material not stated herein are separate from and\n     independent of the terms and conditions of this Public License.\n\n\nSection 8 -- Interpretation.\n\n  a. For the avoidance of doubt, this Public License does not, and\n     shall not be interpreted to, reduce, limit, restrict, or impose\n     conditions on any use of the Licensed Material that could lawfully\n     be made without permission under this Public License.\n\n  b. To the extent possible, if any provision of this Public License is\n     deemed unenforceable, it shall be automatically reformed to the\n     minimum extent necessary to make it enforceable. If the provision\n     cannot be reformed, it shall be severed from this Public License\n     without affecting the enforceability of the remaining terms and\n     conditions.\n\n  c. No term or condition of this Public License will be waived and no\n     failure to comply consented to unless expressly agreed to by the\n     Licensor.\n\n  d. Nothing in this Public License constitutes or may be interpreted\n     as a limitation upon, or waiver of, any privileges and immunities\n     that apply to the Licensor or You, including from the legal\n     processes of any jurisdiction or authority.\n\n=======================================================================\n\nCreative Commons is not a party to its public\nlicenses. Notwithstanding, Creative Commons may elect to apply one of\nits public licenses to material it publishes and in those instances\nwill be considered the “Licensor.” The text of the Creative Commons\npublic licenses is dedicated to the public domain under the CC0 Public\nDomain Dedication. Except for the limited purpose of indicating that\nmaterial is shared under a Creative Commons public license or as\notherwise permitted by the Creative Commons policies published at\ncreativecommons.org/policies, Creative Commons does not authorize the\nuse of the trademark \"Creative Commons\" or any other trademark or logo\nof Creative Commons without its prior written consent including,\nwithout limitation, in connection with any unauthorized modifications\nto any of its public licenses or any other arrangements,\nunderstandings, or agreements concerning use of licensed material. For\nthe avoidance of doubt, this paragraph does not form part of the\npublic licenses.\n\nCreative Commons may be contacted at creativecommons.org.\n\nFor more information, see: https://creativecommons.org/licenses/by-nc-sa/4.0/\n\n=======================================================================\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\nWITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\nANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\nOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. "
  },
  {
    "path": "README.md",
    "content": "# Want to go beyond the basics? Get my book! ✨\n\nGo by Example: Programmer's guide to idiomatic and testable code.\n\n👉 https://github.com/inancgumus/gobyexample\n\n[![gobyexamplecover](https://github.com/inancgumus/learngo/assets/621232/14dd4bff-f6e1-489f-9aa5-1452b8219a11)](https://github.com/inancgumus/gobyexample)\n\n---\n\n# A Huge Number of Go Examples, Exercises, and Quizzes\n\nThe best way to learn is by doing. Inside this repository, you will find thousands of Go examples, exercises, and quizzes. I initially created this repository for my **[Go: Bootcamp Course](https://www.udemy.com/course/learn-go-the-complete-bootcamp-course-golang/?referralCode=5CE6EB34E2B1EF4A7D37)**. Later, I added a lot of exercises, and I wanted every programmer who is not yet enrolled in the course to learn for free as well. So here it is. Enjoy.\n\n**Available in the following languages:**\n* **[English](https://github.com/inancgumus/learngo)**\n* **[Spanish](translation/spanish)** _(WIP: Please Contribute)_\n* **[Chinese](translation/chinese)** _(WIP: Please Contribute)_\n\n## ❤️ Help other fellow developers\n\nSharing is free, but caring is priceless. [So, now please click here](https://twitter.com/intent/tweet?text=I%27m%20learning%20%23golang%20with%201000%2B%20hand-crafted%20examples%2C%20exercises%2C%20and%20quizzes.&url=https://github.com/inancgumus/learngo&via=inancgumus) and share this repository on Twitter.\n\n## Stay in touch\n\n* **[Follow me on Twitter](https://twitter.com/inancgumus)**\n\n  _I usually tweet Go tips and tricks._\n\n  [![@inancgumus](https://img.shields.io/twitter/follow/inancgumus.svg?style=social&label=@inancgumus)](https://twitter.com/inancgumus)\n\n* **[Subscribe to my newsletter](https://eepurl.com/c4DMNX)**\n\n  _Get updates from me._\n\n* **[Read my blog](https://blog.learngoprogramming.com)**\n\n  _Followed by 5K+ developers, and contains dozens of illustrated articles about Go._\n\n* **[Watch my Youtube channel](https://www.youtube.com/channel/UCYxepZhtnFIVRh8t5H_QAdg?view_as=subscriber)**\n\n---\n\n## License\nWhole materials are licensed under the <a rel=\"license\" href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.<br/>\n<a rel=\"license\" href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png\"/></a>\n"
  },
  {
    "path": "advfuncs/01-variadic-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tnums := []int{2, 3, 7}\n\tfmt.Printf(\"nums            : %d\\n\", nums)\n\n\tn := avgNoVariadic(nums)\n\tfmt.Printf(\"avgNoVariadic   : %d\\n\", n)\n\n\tn = avg(2, 3, 7)\n\tfmt.Printf(\"avg(2, 3, 7)    : %d\\n\", n)\n\n\tn = avg(2, 3, 7, 8)\n\tfmt.Printf(\"avg(2, 3, 7, 8) : %d\\n\", n)\n\n\t// use ... to pass a slice\n\tn = avg(nums...)\n\tfmt.Printf(\"avg(nums...)    : %d\\n\", n)\n\n\t// uses the existing slice\n\tdouble(nums...)\n\tfmt.Printf(\"double(nums...) : %d\\n\", nums)\n\n\t// creates a new slice\n\tdouble(4, 6, 14)\n\tfmt.Printf(\"double(4, 6, 14): %d\\n\", nums)\n\n\t// creates a nil slice\n\tfmt.Printf(\"\\nmain.nums       : %p\\n\", nums)\n\tinvestigate(\"passes main.nums\", nums...)\n\tinvestigate(\"passes main.nums\", nums...)\n\tinvestigate(\"passes args\", 4, 6, 14)\n\tinvestigate(\"passes args\", 4, 6, 14)\n\tinvestigate(\"no args\")\n}\n\nfunc investigate(msg string, nums ...int) {\n\tfmt.Printf(\"investigate.nums: %12p  ->  %s\\n\", nums, msg)\n\n\tif len(nums) > 0 {\n\t\tfmt.Printf(\"\\tfirst element: %d\\n\", nums[0])\n\t}\n}\n\nfunc double(nums ...int) {\n\tfor i := range nums {\n\t\tnums[i] *= 2\n\t}\n}\n\nfunc avg(nums ...int) int {\n\treturn sum(nums) / len(nums)\n}\n\nfunc avgNoVariadic(nums []int) int {\n\treturn sum(nums) / len(nums)\n}\n\nfunc sum(nums []int) (total int) {\n\tfor _, n := range nums {\n\t\ttotal += n\n\t}\n\treturn\n}\n"
  },
  {
    "path": "advfuncs/02-func-values/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype filterFunc func(int) bool\n\nfunc main() {\n\tsignatures()\n\tfuncValues()\n}\n\nfunc isEven(n int) bool {\n\treturn n%2 == 0\n}\n\nfunc isOdd(m int) bool {\n\treturn m%2 == 1\n}\n\nfunc signatures() {\n\tfmt.Println(\"••• FUNC SIGNATURES (TYPES) •••\")\n\tfmt.Printf(\"isEven     : %T\\n\", isEven)\n\tfmt.Printf(\"isOdd      : %T\\n\", isOdd)\n}\n\nfunc funcValues() {\n\tfmt.Println(\"\\n••• FUNC VALUES (VARS) •••\")\n\n\t// var value func(int) bool\n\tvar value filterFunc\n\tfmt.Printf(\"value nil? : %t\\n\", value == nil)\n\n\tvalue = isEven\n\tfmt.Printf(\"value(2)   : %t\\n\", value(2))\n\tfmt.Printf(\"isEven(2)  : %t\\n\", isEven(2))\n\n\tvalue = isOdd\n\tfmt.Printf(\"value(1)   : %t\\n\", value(1))\n\tfmt.Printf(\"isOdd(1)   : %t\\n\", isOdd(1))\n\n\tfmt.Printf(\"value nil? : %t\\n\", value == nil)\n\tfmt.Printf(\"value      : %p\\n\", value)\n\tfmt.Printf(\"isEven     : %p\\n\", isEven)\n\tfmt.Printf(\"isOdd      : %p\\n\", isOdd)\n}\n"
  },
  {
    "path": "advfuncs/03-func-to-func/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"unicode\"\n)\n\ntype filterFunc func(int) bool\n\nfunc main() {\n\tsignatures()\n\n\tfmt.Println(\"\\n••• WITHOUT FUNC VALUES •••\")\n\tnums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n\n\tfmt.Printf(\"evens      : %d\\n\", filterEvens(nums...))\n\tfmt.Printf(\"odds       : %d\\n\", filterOdds(nums...))\n\n\tfmt.Println(\"\\n••• FUNC VALUES •••\")\n\tfmt.Printf(\"evens      : %d\\n\", filter(isEven, nums...))\n\tfmt.Printf(\"odds       : %d\\n\", filter(isOdd, nums...))\n\n\tfmt.Println(\"\\n••• MAPPING •••\")\n\tfmt.Println(strings.Map(unpunct, \"hello!!! HOW ARE YOU???? :))\"))\n\tfmt.Println(strings.Map(unpunct, \"TIME IS UP!\"))\n}\n\nfunc unpunct(r rune) rune {\n\tif unicode.IsPunct(r) {\n\t\treturn -1\n\t}\n\treturn unicode.ToLower(r)\n}\n\nfunc filter(f filterFunc, nums ...int) (filtered []int) {\n\tfor _, n := range nums {\n\t\tif f(n) {\n\t\t\tfiltered = append(filtered, n)\n\t\t}\n\t}\n\treturn\n}\n\nfunc filterOdds(nums ...int) (filtered []int) {\n\tfor _, n := range nums {\n\t\tif isOdd(n) {\n\t\t\tfiltered = append(filtered, n)\n\t\t}\n\t}\n\treturn\n}\n\nfunc filterEvens(nums ...int) (filtered []int) {\n\tfor _, n := range nums {\n\t\tif isEven(n) {\n\t\t\tfiltered = append(filtered, n)\n\t\t}\n\t}\n\treturn\n}\n\nfunc isEven(n int) bool {\n\treturn n%2 == 0\n}\n\nfunc isOdd(m int) bool {\n\treturn m%2 == 1\n}\n\nfunc signatures() {\n\tfmt.Println(\"••• FUNC SIGNATURES (TYPES) •••\")\n\tfmt.Printf(\"isEven     : %T\\n\", isEven)\n\tfmt.Printf(\"isOdd      : %T\\n\", isOdd)\n}\n"
  },
  {
    "path": "advfuncs/04-closures/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype filterFunc func(int) bool\n\nfunc main() {\n\tnums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n\n\tfmt.Println(\"••• FUNC VALUES •••\")\n\tfmt.Printf(\"evens      : %d\\n\", filter(isEven, nums...))\n\tfmt.Printf(\"odds       : %d\\n\", filter(isOdd, nums...))\n\tfmt.Printf(\"> 3        : %d\\n\", filter(greaterThan3, nums...))\n\tfmt.Printf(\"> 6        : %d\\n\", filter(greaterThan6, nums...))\n\n\t// ========================================================================\n\n\tfmt.Println(\"\\n••• CLOSURES •••\")\n\n\tvar min int\n\tgreaterThan := func(n int) bool {\n\t\treturn n > min\n\t}\n\n\tmin = 3\n\tfmt.Printf(\"> 3        : %d\\n\", filter(greaterThan, nums...))\n\n\tmin = 6\n\tfmt.Printf(\"> 6        : %d\\n\", filter(greaterThan, nums...))\n\n\t// min = 1\n\t// fmt.Printf(\"> 1        : %d\\n\", filter(greaterThan, nums...))\n\t// min = 2\n\t// fmt.Printf(\"> 2        : %d\\n\", filter(greaterThan, nums...))\n\t// min = 3\n\t// fmt.Printf(\"> 3        : %d\\n\", filter(greaterThan, nums...))\n\n\tvar filterers []filterFunc\n\tfor i := 1; i <= 3; i++ {\n\t\tcurrent := i\n\n\t\tfilterers = append(filterers, func(n int) bool {\n\t\t\tmin = current\n\t\t\treturn greaterThan(n)\n\t\t})\n\t}\n\n\tprinter(filterers, nums...)\n}\n\nfunc printer(filterers []filterFunc, nums ...int) {\n\tfor i, filterer := range filterers {\n\t\tfmt.Printf(\"> %d        : %d\\n\", i+1, filter(filterer, nums...))\n\t}\n}\n\nfunc greaterThan6(n int) bool { return n > 6 }\nfunc greaterThan3(n int) bool { return n > 3 }\nfunc isEven(n int) bool       { return n%2 == 0 }\nfunc isOdd(m int) bool        { return m%2 == 1 }\n\nfunc filter(f filterFunc, nums ...int) (filtered []int) {\n\tfor _, n := range nums {\n\t\tif f(n) {\n\t\t\tfiltered = append(filtered, n)\n\t\t}\n\t}\n\treturn\n}\n"
  },
  {
    "path": "advfuncs/05-higher-order-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype filterFunc func(int) bool\n\nfunc main() {\n\tfmt.Println(\"••• HIGHER-ORDER FUNCS •••\")\n\n\tnums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n\n\todd := reverse(reverse(isEven))\n\tfmt.Printf(\"reversed   : %t\\n\", odd(8))\n\n\tfmt.Printf(\"> 3        : %d\\n\", filter(greater(3), nums...))\n\tfmt.Printf(\"> 6        : %d\\n\", filter(greater(6), nums...))\n\tfmt.Printf(\"<= 6       : %d\\n\", filter(lesseq(6), nums...))\n\tfmt.Printf(\"<= 6       : %d\\n\", filter(reverse(greater(6)), nums...))\n}\n\nfunc reverse(f filterFunc) filterFunc {\n\treturn func(n int) bool {\n\t\treturn !f(n)\n\t}\n}\n\nfunc greater(min int) filterFunc {\n\treturn func(n int) bool {\n\t\treturn n > min\n\t}\n}\n\nfunc lesseq(max int) filterFunc {\n\treturn func(n int) bool {\n\t\treturn n <= max\n\t}\n}\n\nfunc filter(f filterFunc, nums ...int) (filtered []int) {\n\tfor _, n := range nums {\n\t\tif f(n) {\n\t\t\tfiltered = append(filtered, n)\n\t\t}\n\t}\n\treturn\n}\n\nfunc isEven(n int) bool { return n%2 == 0 }\nfunc isOdd(m int) bool  { return m%2 == 1 }\n"
  },
  {
    "path": "advfuncs/06-functional-programming/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype filterFunc func(int) bool\n\nfunc main() {\n\tfmt.Println(\"••• HIGHER-ORDER FUNCS •••\")\n\n\tnums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n\n\todd := reverse(reverse(isEven))\n\tfmt.Printf(\"reversed   : %t\\n\", odd(8))\n\n\tfmt.Printf(\"> 3        : %d\\n\", filter(greater(3), nums...))\n\tfmt.Printf(\"> 6        : %d\\n\", filter(greater(6), nums...))\n\tfmt.Printf(\"<= 6       : %d\\n\", filter(lesseq(6), nums...))\n\tfmt.Printf(\"<= 6       : %d\\n\", filter(reverse(greater(6)), nums...))\n\n\tfmt.Println(\"\\n••• CLOSURES •••\")\n\tfmt.Printf(\"uniques    : %d\\n\", filter(uniques(), 1, 1, 2, 3, 3))\n\n\tdups := reverse(uniques())\n\tfmt.Printf(\"dups       : %v\\n\", filter(dups, 1, 1, 2, 3, 3))\n\n\tdups = reverse(uniques())\n\tfmt.Printf(\"dups dups  : %v\\n\", filter(dups, 1, 1, 2, 3, 3, 3, 3))\n\n\tdups = reverse(uniques())\n\tout := filter(dups, 1, 1, 2, 3, 3, 3, 3)\n\tfmt.Printf(\"dups uniqs : %v\\n\", filter(uniques(), out...))\n\n\tdups = reverse(uniques())\n\tchained := chain(reverse(greater(1)), dups, uniques())\n\tfmt.Printf(\"dups chain : %v\\n\", filter(chained, 1, 1, 2, 3, 3, 3, 3, 0, 0))\n}\n\nfunc chain(filters ...filterFunc) filterFunc {\n\treturn func(n int) bool {\n\t\tfor _, next := range filters {\n\t\t\tif !next(n) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n}\n\nfunc uniques() filterFunc {\n\tseen := make(map[int]bool)\n\n\treturn func(n int) (ok bool) {\n\t\tif !seen[n] {\n\t\t\tseen[n], ok = true, true\n\t\t}\n\t\treturn\n\t}\n}\n\nfunc reverse(f filterFunc) filterFunc {\n\treturn func(n int) bool {\n\t\treturn !f(n)\n\t}\n}\n\nfunc greater(min int) filterFunc {\n\treturn func(n int) bool {\n\t\treturn n > min\n\t}\n}\n\nfunc lesseq(max int) filterFunc {\n\treturn func(n int) bool {\n\t\treturn n <= max\n\t}\n}\n\nfunc filter(f filterFunc, nums ...int) (filtered []int) {\n\tfor _, n := range nums {\n\t\tif f(n) {\n\t\t\tfiltered = append(filtered, n)\n\t\t}\n\t}\n\treturn\n}\n\nfunc isEven(n int) bool { return n%2 == 0 }\nfunc isOdd(m int) bool  { return m%2 == 1 }\n"
  },
  {
    "path": "advfuncs/07-deferred-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\t// single()\n\t// stacked()\n\tfindTheMeaning()\n}\n\nfunc findTheMeaningNoDefer() {\n\tstart := time.Now()\n\tfmt.Printf(\"%s starts...\\n\", \"findTheMeaning\")\n\n\t// do some heavy calculation...\n\ttime.Sleep(time.Second * 2)\n\n\tfmt.Printf(\"%s took %v\\n\", \"findTheMeaning\", time.Since(start))\n}\n\nfunc findTheMeaning() {\n\tdefer measure(\"findTheMeaning\")()\n\n\t// do some heavy calculation\n\ttime.Sleep(time.Second * 2)\n}\n\nfunc measure(name string) func() {\n\tstart := time.Now()\n\tfmt.Printf(\"%s starts...\\n\", name)\n\n\treturn func() {\n\t\tfmt.Printf(\"%s took %v\\n\", name, time.Since(start))\n\t}\n}\n\nfunc stacked() {\n\tfor count := 1; count <= 5; count++ {\n\t\tdefer fmt.Println(count)\n\t}\n\n\tfmt.Println(\"the stacked func returns\")\n}\n\nfunc single() {\n\tvar count int\n\n\t// defer func() {\n\t// \tfmt.Println(count)\n\t// }()\n\tdefer fmt.Println(count)\n\n\tcount++\n\t// fmt.Println(count)\n\n\t// the defer runs here\n\t// fmt.Println(count)\n}\n"
  },
  {
    "path": "advfuncs/08-png-detector/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\nfunc main() {\n\tfiles := []string{\n\t\t\"pngs/cups-jpg.png\",\n\t\t\"pngs/forest-jpg.png\",\n\t\t\"pngs/golden.png\",\n\t\t\"pngs/work.png\",\n\t\t\"pngs/shakespeare-text.png\",\n\t\t\"pngs/empty.png\",\n\t}\n\n\tvalids := detect(files)\n\n\tfmt.Printf(\"Correct Files:\\n\")\n\tfor _, valid := range valids {\n\t\tfmt.Printf(\" + %s\\n\", valid)\n\t}\n}\n\nfunc detect(filenames []string) (pngs []string) {\n\tconst pngHeader = \"\\x89PNG\\r\\n\\x1a\\n\"\n\n\tbuf := make([]byte, len(pngHeader))\n\n\tfor _, filename := range filenames {\n\t\tif read(filename, buf) != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif bytes.Equal([]byte(pngHeader), buf) {\n\t\t\tpngs = append(pngs, filename)\n\t\t}\n\t}\n\treturn\n}\n\n// read reads len(buf) bytes to buf from a file\nfunc read(filename string, buf []byte) error {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\tfi, err := file.Stat()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif fi.Size() <= int64(len(buf)) {\n\t\treturn fmt.Errorf(\"file size < len(buf)\")\n\t}\n\n\t_, err = io.ReadFull(file, buf)\n\treturn err\n}\n\nfunc detectPNGUnsafeAndVerbose(filenames []string) (valids []string) {\n\tconst pngHeader = \"\\x89PNG\\r\\n\\x1a\\n\"\n\n\tbuf := make([]byte, len(pngHeader))\n\n\tfor _, filename := range filenames {\n\t\tfile, err := os.Open(filename)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tfi, err := file.Stat()\n\t\tif err != nil {\n\t\t\tfile.Close()\n\t\t\tcontinue\n\t\t}\n\n\t\tif fi.Size() <= int64(len(pngHeader)) {\n\t\t\tfile.Close()\n\t\t\tcontinue\n\t\t}\n\n\t\t_, err = io.ReadFull(file, buf)\n\t\tfile.Close()\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif bytes.Equal([]byte(pngHeader), buf) {\n\t\t\tvalids = append(valids, filename)\n\t\t}\n\t}\n\treturn\n}\n\n// defers don't run when the loop block ends\nfunc detectPNGWrong(filenames []string) (pngs []string) {\n\tconst pngHeader = \"\\x89PNG\\r\\n\\x1a\\n\"\n\n\tbuf := make([]byte, len(pngHeader))\n\n\tfor _, filename := range filenames {\n\t\tfmt.Printf(\"processing: %s\\n\", filename)\n\n\t\tfile, err := os.Open(filename)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tdefer func() {\n\t\t\tfmt.Printf(\"closes    : %s\\n\", filename)\n\t\t\tfile.Close()\n\t\t}()\n\n\t\tfi, err := file.Stat()\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif fi.Size() <= int64(len(pngHeader)) {\n\t\t\tcontinue\n\t\t}\n\n\t\t_, err = io.ReadFull(file, buf)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif bytes.Equal([]byte(pngHeader), buf) {\n\t\t\tpngs = append(pngs, filename)\n\t\t}\n\t}\n\treturn\n}\n"
  },
  {
    "path": "advfuncs/08-png-detector-with-panic/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\n/*\n\t// ~~~ THE CLASSIC WAY ~~~\n\ttry {\n\t\t// open a file\n\t\t// throws an exception\n\t} catch (ExceptionType name) {\n\t\t// handle the error\n\t} finally {\n\t\t// close the file\n\t}\n\n\t// ~~~ GO WAY ~~~\n\tfile, err := // open the file\n\tif err != nil {\n\t\t// handle the error\n\t}\n\t// close the file\n\n\t// really really exceptional problem occurs\n\t// mostly due to a programmer\n\n\t// panic(\"PANIC PANIC\")\n*/\n\nfunc main() {\n\tfiles := []string{\n\t\t\"pngs/cups-jpg.png\",\n\t\t\"pngs/forest-jpg.png\",\n\t\t\"pngs/golden.png\",\n\t\t\"pngs/work.png\",\n\t\t\"pngs/shakespeare-text.png\",\n\t\t\"pngs/empty.png\",\n\t}\n\n\tlist(\"png\", files)\n\n\t// fmt.Println(\"catch me if you can!\")\n}\n\nfunc list(format string, files []string) {\n\tvalids := detect(format, files)\n\n\tfmt.Printf(\"Correct Files:\\n\")\n\tfor _, valid := range valids {\n\t\tfmt.Printf(\" + %s\\n\", valid)\n\t}\n}\n\nfunc detect(format string, filenames []string) (valids []string) {\n\theader := headerOf(format)\n\n\tbuf := make([]byte, len(header))\n\n\tfor _, filename := range filenames {\n\t\tif read(filename, buf) != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif bytes.Equal([]byte(header), buf) {\n\t\t\tvalids = append(valids, filename)\n\t\t}\n\t}\n\treturn\n}\n\nfunc headerOf(format string) string {\n\tswitch format {\n\tcase \"png\":\n\t\treturn \"\\x89PNG\\r\\n\\x1a\\n\"\n\tcase \"jpg\":\n\t\treturn \"\\xff\\xd8\\xff\"\n\t}\n\tpanic(\"unknown format: \" + format)\n}\n\n// read reads len(buf) bytes to buf from a file\nfunc read(filename string, buf []byte) error {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\tfi, err := file.Stat()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif fi.Size() <= int64(len(buf)) {\n\t\treturn fmt.Errorf(\"file size < len(buf)\")\n\t}\n\n\t_, err = io.ReadFull(file, buf)\n\treturn err\n}\n"
  },
  {
    "path": "advfuncs/10-image-detector-recover/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\nfunc main() {\n\tdefer func() {\n\t\tif rerr := recover(); rerr != nil {\n\t\t\tfmt.Println(\"panicked:\", rerr)\n\t\t}\n\t}()\n\n\tfiles := []string{\n\t\t\"pngs/cups-jpg.png\",\n\t\t\"pngs/forest-jpg.png\",\n\t\t\"pngs/golden.png\",\n\t\t\"pngs/work.png\",\n\t\t\"pngs/shakespeare-text.png\",\n\t\t\"pngs/empty.png\",\n\t}\n\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"png or jpg?\")\n\t\treturn\n\t}\n\n\tlist(args[0], files)\n\n\t// fmt.Println(\"catch me if you can!\")\n}\n\nfunc list(format string, files []string) {\n\tvalids := detect(format, files)\n\n\tfmt.Printf(\"Correct Files:\\n\")\n\tfor _, valid := range valids {\n\t\tfmt.Printf(\" + %s\\n\", valid)\n\t}\n}\n\nfunc detect(format string, filenames []string) (pngs []string) {\n\theader := headerOf(format)\n\tbuf := make([]byte, len(header))\n\n\tfor _, filename := range filenames {\n\t\tif read(filename, buf) != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif bytes.Equal([]byte(header), buf) {\n\t\t\tpngs = append(pngs, filename)\n\t\t}\n\t}\n\treturn\n}\n\nfunc headerOf(format string) string {\n\tswitch format {\n\tcase \"png\":\n\t\treturn \"\\x89PNG\\r\\n\\x1a\\n\"\n\tcase \"jpg\":\n\t\treturn \"\\xff\\xd8\\xff\"\n\t}\n\t// this should never occur\n\tpanic(\"unknown format: \" + format)\n}\n\n// read reads len(buf) bytes to buf from a file\nfunc read(filename string, buf []byte) error {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\tfi, err := file.Stat()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif fi.Size() <= int64(len(buf)) {\n\t\treturn fmt.Errorf(\"file size < len(buf)\")\n\t}\n\n\t_, err = io.ReadFull(file, buf)\n\treturn err\n}\n"
  },
  {
    "path": "advfuncs/10b-named-params/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/inancgumus/learngo/magic\"\n\t//\n\t// Use the following one for the panicking library:\n\t// magic \"github.com/inancgumus/learngo/magicpanic\"\n\t//\n)\n\nfunc main() {\n\tfiles := []string{\n\t\t\"pngs/cups-jpg.png\",\n\t\t\"pngs/forest-jpg.png\",\n\t\t\"pngs/golden.png\",\n\t\t\"pngs/work.png\",\n\t\t\"pngs/shakespeare-text.png\",\n\t\t\"pngs/empty.png\",\n\t}\n\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Println(\"png or jpg?\")\n\t\treturn\n\t}\n\n\tlist(args[0], files)\n\n\t// fmt.Println(\"catch me if you can!\")\n}\n\nfunc list(format string, files []string) {\n\tvalids, err := magic.Detect(format, files)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"Correct Files:\\n\")\n\tfor _, valid := range valids {\n\t\tfmt.Printf(\" + %s\\n\", valid)\n\t}\n}\n"
  },
  {
    "path": "advfuncs/exercises/01-refactor/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// EXERCISE: Refactor\n//\n//   In the headerOf function, instead of using a switch,\n//   use a map. Declare it at the package-level.\n//\n// RESTRICTION\n//\n//   For panicking, use a deferred function and a named param.\n//\n// EXPECTED OUTPUT\n//\n//   Please run the solution.\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\tfmt.Println(headerOf(\"gif\"))\n}\n\nfunc headerOf(format string) string {\n\tswitch format {\n\tcase \"png\":\n\t\treturn \"\\x89PNG\\r\\n\\x1a\\n\"\n\tcase \"jpg\":\n\t\treturn \"\\xff\\xd8\\xff\"\n\t}\n\tpanic(\"unknown format: \" + format)\n}\n"
  },
  {
    "path": "advfuncs/exercises/01-refactor/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(headerOf(\"gif\"))\n}\n\nvar headers = map[string]string{\n\t\"png\": \"\\x89PNG\\r\\n\\x1a\\n\",\n\t\"jpg\": \"\\xff\\xd8\\xff\",\n}\n\nfunc headerOf(format string) (header string) {\n\tdefer func() {\n\t\tif header == \"\" {\n\t\t\tpanic(\"unknown format: \" + format)\n\t\t}\n\t}()\n\treturn headers[format]\n}\n"
  },
  {
    "path": "advfuncs/exercises/README.md",
    "content": "# Header\n\nWhat you will learn?\n\n1. **[Refactor](https://github.com/inancgumus/learngo/tree/master/28-error-handling/exercises/01-refactor)**\n\n    Refactor the headerOf function with a map + defer + and a named param.\n\n2. **[text](https://github.com/inancgumus/learngo/tree/master/)**\n\n    text"
  },
  {
    "path": "advfuncs/new/01-intro/funcval/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Printf(\"HasPrefix: %T\\n\", strings.HasPrefix)\n\tfmt.Printf(\"HasSuffix: %T\\n\", strings.HasSuffix)\n\tfmt.Println()\n\n\tvar fn func(string, string) bool\n\n\tfn = strings.HasPrefix\n\tfn = strings.HasSuffix\n\n\tok := fn(\"gopher\", \"go\")\n\n\tfmt.Printf(\"ok       : %t\\n\", ok)\n}\n"
  },
  {
    "path": "advfuncs/new/01-intro/passfunc/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"unicode\"\n)\n\nfunc main() {\n\ts := \"Func Values Are Awesome...\"\n\n\t// s = strings.Map(unicode.ToUpper, s)\n\t// s = strings.Map(unicode.ToLower, s)\n\t// s = strings.Map(excite, s)\n\t// s = strings.Map(calm, s)\n\n\t// fmt.Printf(\"%T\\n\", strings.Map)\n\ts = mapx(calm, s)\n\n\tfmt.Println(s)\n}\n\nfunc mapx(mapping func(rune) rune, s string) string {\n\tvar ns []rune\n\n\tfor _, r := range s {\n\t\tif r = mapping(r); r == -1 {\n\t\t\tcontinue\n\t\t}\n\t\tns = append(ns, r)\n\t}\n\treturn string(ns)\n}\n\nfunc calm(r rune) rune {\n\tif unicode.IsPunct(r) {\n\t\treturn -1\n\t}\n\treturn unicode.ToLower(r)\n}\n\nfunc excite(r rune) rune {\n\tif r == '.' {\n\t\treturn '!'\n\t}\n\treturn unicode.ToTitle(r)\n}\n"
  },
  {
    "path": "assets/database.json",
    "content": "[\n\t{\n\t\t\"Type\": \"book\",\n\t\t\"Item\": {\n\t\t\t\"Title\": \"moby dick\",\n\t\t\t\"Price\": 10,\n\t\t\t\"Published\": 118281600\n\t\t}\n\t},\n\t{\n\t\t\"Type\": \"book\",\n\t\t\"Item\": {\n\t\t\t\"Title\": \"odyssey\",\n\t\t\t\"Price\": 15,\n\t\t\t\"Published\": 733622400\n\t\t}\n\t},\n\t{\n\t\t\"Type\": \"book\",\n\t\t\"Item\": {\n\t\t\t\"Title\": \"hobbit\",\n\t\t\t\"Price\": 25,\n\t\t\t\"Published\": -62135596800\n\t\t}\n\t},\n\t{\n\t\t\"Type\": \"puzzle\",\n\t\t\"Item\": {\n\t\t\t\"Title\": \"rubik's cube\",\n\t\t\t\"Price\": 5\n\t\t}\n\t},\n\t{\n\t\t\"Type\": \"game\",\n\t\t\"Item\": {\n\t\t\t\"Title\": \"minecraft\",\n\t\t\t\"Price\": 20\n\t\t}\n\t},\n\t{\n\t\t\"Type\": \"game\",\n\t\t\"Item\": {\n\t\t\t\"Title\": \"tetris\",\n\t\t\t\"Price\": 5\n\t\t}\n\t},\n\t{\n\t\t\"Type\": \"toy\",\n\t\t\"Item\": {\n\t\t\t\"Title\": \"yoda\",\n\t\t\t\"Price\": 150\n\t\t}\n\t}\n]"
  },
  {
    "path": "concurrency/xxx-monte-carlo/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"math/rand\"\n\t\"os\"\n\t\"runtime\"\n\t\"strconv\"\n\t\"time\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\texit(\"Please provide the sample rate\")\n\t}\n\n\tsamples, err := strconv.Atoi(os.Args[1])\n\tif err != nil {\n\t\texit(\"Incorrect sample rate\")\n\t}\n\n\telapse := measure(time.Now())\n\tpi := spread(samples, runtime.NumCPU())\n\n\tfmt.Println(\"PI  : \", pi)\n\tfmt.Println(\"Time: \", elapse())\n}\n\nfunc exit(msg string) {\n\tfmt.Fprintln(os.Stderr, msg)\n\tos.Exit(1)\n}\n\nfunc measure(start time.Time) func() time.Duration {\n\treturn func() time.Duration {\n\t\treturn time.Since(start)\n\t}\n}\n\n// spread the work to P number of estimate go funcs.\n// returns the estimation.\nfunc spread(samples int, P int) (estimated float64) {\n\tcounts := make(chan float64)\n\n\tfor i := 0; i < P; i++ {\n\t\tgo func() { counts <- estimate(samples / P) }()\n\t}\n\n\tfor i := 0; i < P; i++ {\n\t\testimated += <-counts\n\t}\n\treturn estimated / float64(P)\n}\n\nfunc estimate(N int) float64 {\n\tconst radius = 1.0\n\n\tvar (\n\t\tseed   = rand.NewSource(time.Now().UnixNano())\n\t\trandom = rand.New(seed)\n\t\tinside int\n\t)\n\n\tfor i := 0; i < N; i++ {\n\t\tx, y := random.Float64(), random.Float64()\n\n\t\tif num := math.Sqrt(x*x + y*y); num < radius {\n\t\t\tinside++\n\t\t}\n\t}\n\treturn 4 * float64(inside) / float64(N)\n}\n"
  },
  {
    "path": "etc/FIX.md",
    "content": "# Things to fix\n\n- [ ] AliasedTypes: At 4:48, `runVal = rune(int32Val)` [Ref](https://www.udemy.com/learn-go-the-complete-bootcamp-course-golang/learn/v4/questions/5603536)\n\n- [ ] Underlying types demo gram/kilogram/ton confusion [Ref](https://www.udemy.com/learn-go-the-complete-bootcamp-course-golang/learn/v4/questions/5603348)\n\n- [ ] Multiplication table challenge exercises flyer [Ref](https://www.udemy.com/learn-go-the-complete-bootcamp-course-golang/learn/v4/questions/5600066)\n\n- [ ] Apply grammar mistakes to Udemy [Ref](https://github.com/inancgumus/learngo/commit/06891c57fc5299db5f5178bde4da7dd8e569c082)\n\n- [ ] Fix the printing lecture 78 exercise (numbers) [Ref](https://learngoprogramming.slack.com/archives/DC86N4QJK/p1542552870174800)\n\n- [ ] Fix the strings quiz [Ref](https://learngoprogramming.slack.com/archives/DC86N4QJK/p1542566248185500)\n\n- [ ] Type conversion lecture doesn't talk about literal conversion but it asks a question as if it's been explained [Ref](https://www.udemy.com/message/thread/120614366/)\n\n- [ ] Underlying types conversion possible misundertanding [Ref](https://twitter.com/in_aanand/status/1065136567629553664)\n\n- [ ] Comment: Gram vs Gram1 — He's asking Gram1 should have been clearer. Explain this in the video. If it was Gram1 then the example would be pointless."
  },
  {
    "path": "etc/stratch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// LearnGoProgramming.com ⭐️ @inancgumus\npackage main\n\nfunc main() {\n}\n"
  },
  {
    "path": "first/README.md",
    "content": "**The course videos follow this directory.**\n\nSo, you can find the lecture files in the same place as they are explained in the course videos. But then I've moved them into their own directories. This directory is here just for your convenience.\n\n---\n\n# ☢️ USE THE FOLLOWING DIRECTORIES INSTEAD! ☢️\n\n**For the first part of the course; only the following directories contains exercises and quizzes.**\n\n* [01-get-started/](https://github.com/inancgumus/learngo/tree/master/01-get-started)\n\n* [02-write-your-first-program/](https://github.com/inancgumus/learngo/tree/master/02-write-your-first-program)\n\n* [03-packages-and-scopes/](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes)\n\n* [04-statements-expressions-comments/](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments)\n\n* [05-write-your-first-library-package/](https://github.com/inancgumus/learngo/tree/master/05-write-your-first-library-package)\n"
  },
  {
    "path": "first/explain/comments/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// Package main makes this package an executable program\npackage main\n\nimport \"fmt\"\n\n/*\nmain function\nGo executes this program using this function.\nThere should be only one main file in the main package.\nExecutable programs are also called as \"commands\".\n*/\nfunc main() {\n\tfmt.Println(\"Hello Gopher!\")\n}\n"
  },
  {
    "path": "first/explain/expressions/01-operator/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello!\" + \"!\")\n}\n"
  },
  {
    "path": "first/explain/expressions/02-call-expression/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n)\n\nfunc main() {\n\t// runtime.NumCPU() is a call expression\n\tfmt.Println(runtime.NumCPU() + 1)\n}\n"
  },
  {
    "path": "first/explain/expressions/README",
    "content": "I've moved the main.go file for the expressions coding lecture into:\n\n02-call-expression/"
  },
  {
    "path": "first/explain/importing/01-file-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n}\n"
  },
  {
    "path": "first/explain/importing/02-renaming/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\nimport f \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\tf.Println(\"There!\")\n}\n"
  },
  {
    "path": "first/explain/packages/scopes/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "first/explain/packages/scopes/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "first/explain/packages/scopes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// two files belong to the same package\n\t// calling `bye()` of bye.go here\n\tbye()\n}\n\n// EXERCISE: Remove the comments from the below function\n//           And analyze the error message\n\n// func bye() {\n// \tfmt.Println(\"Bye!\")\n// }\n\n// ***** EXPLANATION *****\n//\n// ERROR: \"bye\" function \"redeclared\"\n//        in \"this block\"\n//\n// \"this block\" means = \"main package\"\n//\n// \"redeclared\" means = you're using the same name\n//   in the same scope again\n//\n// main package's scope is:\n// all source-code files which are in the same main package\n"
  },
  {
    "path": "first/explain/packages/what/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "first/explain/packages/what/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "first/explain/packages/what/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// You can access functions from other files\n\t// which are in the same package\n\n\t// Here, `main()` can access `bye()` and `hey()`\n\n\t// It's because bye.go, hey.go and main.go\n\t//   are in the main package.\n\n\tbye()\n\they()\n}\n"
  },
  {
    "path": "first/explain/scopes/01-scopes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// file scope\nimport \"fmt\"\n\n// package scope\nconst ok = true\n\n// package scope\nfunc main() { // block scope starts\n\n\tvar hello = \"Hello\"\n\n\t// hello and ok are visible here\n\tfmt.Println(hello, ok)\n\n} // block scope ends\n"
  },
  {
    "path": "first/explain/scopes/02-block-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc nope() { // block scope starts\n\n\t// hello and ok are only visible here\n\tconst ok = true\n\tvar hello = \"Hello\"\n\n\t_ = hello\n} // block scope ends\n\nfunc main() { // block scope starts\n\n\t// hello and ok are not visible here\n\n\t// ERROR:\n\t// fmt.Println(hello, ok)\n\n} // block scope ends\n"
  },
  {
    "path": "first/explain/scopes/03-nested-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// I didn't talk about this in a lecture\n// As a side-note, I wanted to put it here\n// Please review it.\n\nvar declareMeAgain = 10\n\nfunc nested() { // block scope starts\n\n\t// declares the same variable\n\t// they both can exist together\n\t// this one only belongs to this scope\n\t// package's variable is still intact\n\tvar declareMeAgain = 5\n\tfmt.Println(\"inside nope:\", declareMeAgain)\n\n} // block scope ends\n\nfunc main() { // block scope starts\n\n\tfmt.Println(\"inside main:\", declareMeAgain)\n\n\tnested()\n\n\t// package-level declareMeAgain isn't effected\n\t// from the change inside the nested func\n\tfmt.Println(\"inside main:\", declareMeAgain)\n\n} // block scope ends\n"
  },
  {
    "path": "first/explain/statements/01-execution-flow/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// Statements change the execution flow\n\t// Especially the control flow statements like `if`\n\tif 5 > 1 {\n\t\tfmt.Println(\"bigger\")\n\t}\n}\n"
  },
  {
    "path": "first/explain/statements/02-semicolons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello\"); fmt.Println(\"World!\")\n}\n"
  },
  {
    "path": "first/first/exercises/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE\n//  Print your name and your best friend's name using\n//  Println twice\n//\n// EXPECTED OUTPUT\n//  YourName\n//  YourBestFriendName\n//\n// BONUS\n//  Use `go run` first.\n//  And after that use `go build` and run your program.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n\t// ?\n}\n"
  },
  {
    "path": "first/first/exercises/01/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// go run main.go\n\n// go build\n// ./solution\n\nfunc main() {\n\tfmt.Println(\"Nikola\")\n\tfmt.Println(\"Thomas\")\n}\n"
  },
  {
    "path": "first/first/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// package main is a special package\n// it allows Go to create an executable file\npackage main\n\n/*\nThis is a multi-line comment.\n\nimport keyword makes another package available\n  for this .go \"file\".\n\nimport \"fmt\" lets you access fmt package's functionality\n  here in this file.\n*/\nimport \"fmt\"\n\n// \"func main\" is special.\n//\n// Go has to know where to start\n//\n// func main creates a starting point for Go\n//\n// After compiling the code,\n// Go runtime will first run this function\nfunc main() {\n\t// after: import \"fmt\"\n\t// Println function of \"fmt\" package becomes available\n\n\t// Look at what it looks like by typing in the console:\n\t//   go doc -src fmt Println\n\n\t// Println is just an exported function from\n\t//   \"fmt\" package\n\n\t// Exported = First Letter is uppercase\n\tfmt.Println(\"Hello Gopher!\")\n\n\t// Go cannot call Println function by itself.\n\t// That's why you need to call it here.\n\t// It only calls `func main` automatically.\n\n\t// -----\n\n\t// Go supports Unicode characters in string literals\n\t// And also in source-code: KÖSTEBEK!\n\n\t// EXERCISE: Remove the comments from below --> //\n\t// fmt.Println(\"Merhaba Köstebek!\")\n\n\t// Unnecessary note:\n\t// \"Merhaba Köstebek\" means \"Hello Gopher\"\n\t// in Turkish language\n}\n"
  },
  {
    "path": "first/first/questions/01-code-your-first-program-questions.md",
    "content": "## What does the package keyword do in the following program?\n```go\npackage main\n\nfunc main() {\n}\n```\n1. func\n2. package *CORRECT*\n3. fmt.Println\n4. import\n\n> **1:** This keyword is used to declare a new function.\n>\n>\n> **2:** That's right! package keyword allows you to define which package a Go file belongs to.\n>\n>\n> **3:** This is not a keyword. It's the Println function of the fmt package.\n>\n>\n> **4:** This keyword is used to import a package.\n>\n>\n\n\n## Which keyword is used to declare a new function?\n* func *CORRECT*\n* package\n* Println\n* import\n\n\n## What is a function?\n1. It's like a mini-program. It's a reusable and executable block of code. *CORRECT*\n2. It allows Go to execute a program.\n3. It allows Go to import a package called function.\n4. It prints a message to the console.\n\n> **2:** Go looks for package main and func main to do that. A function doesn't do that on its own.\n>\n>\n> **3:** `import` keyword does that.\n>\n>\n> **4:** For example: `fmt.Println` does that.\n>\n>\n\n\n## Do you have to call the main function yourself?\n1. Yes, so that, I can execute my program.\n2. No, Go calls the main function automatically. *CORRECT*\n\n> **1:** No, you don't need to call the main function. Go automatically executes it.\n>\n>\n\n\n## Do you have to call the other functions yourself?\n1. Yes, so that, I can execute that function. *CORRECT*\n2. Yes, so that, Go can execute my program.\n3. No, Go calls the functions automatically.\n\n> **1:** That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet).\n>\n>\n\n> **2:** That's only the job of the `func main`. There's only one `func main`.\n>\n>\n\n> **3:** Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself.\n>\n>\n\n\n## What does `package main` do?\n```go\npackage main\n\nfunc main() {\n}\n```\n* It controls everything\n* It allows you to properly exit from a program\n* It allows you to create an executable Go program *CORRECT*\n\n\n## What does `func main` do?\n```go\npackage main\n\nfunc main() {\n}\n```\n1. It contains a package called main\n2. Go starts executing your program by using the code inside func main *CORRECT*\n3. It prints a message to the console\n\n> **1:** main function doesn't contain a package.\n>\n>\n> **2:** That's right. Go automatically calls the main function to execute your program.\n>\n>\n> **3:** It doesn't print anything at least directly.\n>\n>\n\n\n## What does `import \"fmt\"` do?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi!\")\n}\n```\n1. It prints \"fmt\" to the console\n2. It defines a new package called \"fmt\"\n3. It imports the `fmt` package; so you can use its functionalities *CORRECT*\n\n> **1:** `fmt.Println` prints a message not the `import \"fmt\"`.\n>\n>\n> **2:** `package` keyword does that, not the `import` keyword.\n>\n>\n> **3:** Yes. For example, after you import the fmt package you can call its Println function to print a message to the console.\n>\n>\n\n\n## What this program does?\n```go\npackage main\n\nfunc main() {\n}\n```\n1. It prints a message to the console\n2. It's a correct program but it doesn't print anything *CORRECT*\n3. It's an incorrect program\n\n> **1:** It doesn't print a message. To do that you can use fmt.Println function.\n>\n>\n\n> **2:** Yes, it's a correct program but since it doesn't contain fmt.Println it doesn't print anything.\n>\n>\n\n> **3:** It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program.\n>\n>\n\n\n## What does this program print?\n```go\npackage main\n\nfunc main() {\n    fmt.Println(Hi! I want to be a Gopher!)\n}\n```\n* Hi! I want to be a Gopher!\n* It doesn't print anything\n* This program is incorrect *CORRECT*\n\n> **1:** It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println(\"Hi! I want to be a Gopher\")\n>\n>\n\n> **3:** It doesn't import \"fmt\" package. Also see #1.\n>\n>\n\n\n## What does this program print?\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi there!\")\n}\n```\n* Hi there! *CORRECT*\n* fmt\n* This program is incorrect; it imports the wrong package or there isn't a function called `Println`\n\n> **2:** import \"fmt\" imports the `fmt` package; so you can use its functionalities.\n>\n>\n> **3:** Actually, this program is correct.\n>\n>"
  },
  {
    "path": "first/first/questions/02-run-your-first-program-questions.md",
    "content": "## What's the difference between `go build` and `go run`?\n1. `go run` just compiles a program; whereas `go build` both compiles and runs it.\n2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT*\n\n> **1:** It's opposite actually.\n>\n>\n> **2:** `go run` compiles your program and puts it in a temporary directory. Then it runs the compiled program in there.\n>\n>\n\n## Which one below is true for runtime?\n1. It happens when your program starts running on a computer *CORRECT*\n2. It happens while your program is being compiled\n\n\n## Which one below is true for the compile-time?\n1. It happens when your program starts running in a computer\n2. It happens while your program is being compiled  *CORRECT*\n\n\n## In which stage your program can print a message to the console?\n1. While it's being compiled.\n2. While it runs (after compile-time). *CORRECT*\n3. While it runs (inside the compile-time).\n\n> **1:** In the compilation step your program cannot print a message. In that stage, it's literally dead.\n>\n>\n> **2:** That's right. That's the only time which your program can interact with a computer and instruct it to print a message to the console.\n>\n>\n> **3:** Running can only happen after the compile-time\n>\n>\n"
  },
  {
    "path": "first/printer/cmd/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Automatically imports!... AWESOME!\nimport \"github.com/inancgumus/learngo/first/printer\"\n\nfunc main() {\n\tprinter.Hello()\n}\n"
  },
  {
    "path": "first/printer/printer.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage printer\n\nimport \"fmt\"\n\n// Hello is an exported function\nfunc Hello() {\n\tfmt.Println(\"exported hello\")\n}\n"
  },
  {
    "path": "first/printer-exercise/solution/golang/cmd/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t// You should replace this with your username\n\t// If you remove this, vs code will do that for you\n\t\"github.com/inancgumus/learngo/first/printer-exercise/solution/golang\"\n)\n\nfunc main() {\n\tfmt.Println(golang.Version())\n}\n"
  },
  {
    "path": "first/printer-exercise/solution/golang/go.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage golang\n\nimport (\n\t\"runtime\"\n)\n\n// Version returns the current Go version\nfunc Version() string {\n\treturn runtime.Version()\n}\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/inancgumus/learngo\n\ngo 1.13\n\nrequire (\n\tgithub.com/fatih/color v1.10.0\n\tgithub.com/guineveresaenger/golang-rainbow v0.0.0-20171201190047-7b6c54e09b61\n\tgithub.com/inancgumus/prettyslice v0.0.0-20190305220808-d802ba58098f\n\tgithub.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3\n\tgithub.com/mattn/go-runewidth v0.0.9\n\tgolang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=\ngithub.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=\ngithub.com/guineveresaenger/golang-rainbow v0.0.0-20171201190047-7b6c54e09b61 h1:8wAz2sOxcUbqE1haQa0Bg/JoIxq6ihClZSWX2Sni/qc=\ngithub.com/guineveresaenger/golang-rainbow v0.0.0-20171201190047-7b6c54e09b61/go.mod h1:2Myrnv41e4+Cf+NKQs6i9vlZw3EwJd9o8wq1m+A0TaY=\ngithub.com/inancgumus/prettyslice v0.0.0-20190305220808-d802ba58098f h1:Nr2FPhL+zSJ1rer6AjTG4T2rkWIJukiLC9+/RVKVFJE=\ngithub.com/inancgumus/prettyslice v0.0.0-20190305220808-d802ba58098f/go.mod h1:lC0BwLhC6oUR2fTZj1R3+FB5o2lQ0RukM0fKsFhitjw=\ngithub.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3 h1:fO9A67/izFYFYky7l1pDP5Dr0BTCRkaQJUG6Jm5ehsk=\ngithub.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3/go.mod h1:Ey4uAp+LvIl+s5jRbOHLcZpUDnkjLBROl15fZLwPlTM=\ngithub.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=\ngithub.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=\ngithub.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=\ngithub.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=\ngithub.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=\ngithub.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=\ngolang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\ngolang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 h1:xYJJ3S178yv++9zXV/hnr29plCAGO9vAFG9dorqaFQc=\ngolang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=\ngolang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=\ngolang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=\ngolang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=\ngolang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\n"
  },
  {
    "path": "interfaces/01-methods/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype book struct {\n\ttitle string\n\tprice float64\n}\n\nfunc (b book) print() {\n\t// b is a copy of the original `book` value here.\n\tfmt.Printf(\"%-15s: $%.2f\\n\", b.title, b.price)\n}\n\n// ----------------------------------------------------------------------------\n// + you can use the same method names among different types.\n// + you don't need to type `printGame`, it's just: `print`.\n//\n// func (b book) printBook() {\n// \t// b is a copy of the original `book` value here.\n// \tfmt.Printf(\"%-15s: $%.2f\\n\", b.title, b.price)\n// }\n\n// ----------------------------------------------------------------------------\n// b is a copy of the original `book` value here.\n//\n// func printBook(b book) {\n// \tfmt.Printf(\"%-15s: $%.2f\\n\", b.title, b.price)\n// }\n"
  },
  {
    "path": "interfaces/01-methods/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype game struct {\n\ttitle string\n\tprice float64\n}\n\nfunc (g game) print() {\n\tfmt.Printf(\"%-15s: $%.2f\\n\", g.title, g.price)\n}\n\n// PREVIOUS CODE:\n\n// ----------------------------------------------------------------------------\n// you can use same method name among different types.\n// you don't need to type `printGame`, it's just: `print`.\n//\n// func (g game) printGame() {\n// \tfmt.Printf(\"%-15s: $%.2f\\n\", g.title, g.price)\n// }\n\n// ----------------------------------------------------------------------------\n// you cannot use the same function name within the same package.\n//\n// func printGame(g game) {\n// \tfmt.Printf(\"%-15s: $%.2f\\n\", g.title, g.price)\n// }\n"
  },
  {
    "path": "interfaces/01-methods/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tmobydick := book{\n\t\ttitle: \"moby dick\",\n\t\tprice: 10,\n\t}\n\n\tminecraft := game{\n\t\ttitle: \"minecraft\",\n\t\tprice: 20,\n\t}\n\n\ttetris := game{\n\t\ttitle: \"tetris\",\n\t\tprice: 5,\n\t}\n\n\t// #3\n\tmobydick.print()  // sends `mobydick` value to `book.print`\n\tminecraft.print() // sends `minecraft` value to `game.print`\n\ttetris.print()    // sends `tetris` value to `game.print`\n\n\t// #2\n\t// mobydick.printBook()\n\t// minecraft.printGame()\n\n\t// #1\n\t// printBook(mobydick)\n\t// printGame(minecraft)\n}\n"
  },
  {
    "path": "interfaces/02-receivers/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype book struct {\n\ttitle string\n\tprice float64\n}\n\nfunc (b book) print() {\n\tfmt.Printf(\"%-15s: $%.2f\\n\", b.title, b.price)\n}\n"
  },
  {
    "path": "interfaces/02-receivers/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype game struct {\n\ttitle string\n\tprice float64\n}\n\n// be consistent:\n// if another method in the same type has a pointer receiver,\n// use pointer receivers on the other methods as well.\nfunc (g *game) print() {\n\tfmt.Printf(\"%-15s: $%.2f\\n\", g.title, g.price)\n}\n\n// + discount gets a copy of `*game`.\n// + discount can update the original `game` through the game pointer.\n// + it's better to use the same receiver type: `*game` for all methods.\nfunc (g *game) discount(ratio float64) {\n\tg.price *= (1 - ratio)\n}\n\n// PREVIOUS CODE:\n\n// + `g` is a copy: `discount` cannot change the original `g`.\n// func (g *game) discount(ratio float64) {\n// \tg.price *= (1 - ratio)\n// }\n"
  },
  {
    "path": "interfaces/02-receivers/huge.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype huge struct {\n\t// about ~200mb\n\tgames [10_000_000]game\n\n\t// if this syntax doesn't work on your system, type it as:\n\t// games [10000000]game\n}\n\n// only copies a single pointer.\nfunc (h *huge) addr() {\n\tfmt.Printf(\"%p\\n\", h)\n}\n\n// each time it is called,\n// the original value will be copied.\n// calling addr() x 10 times = ~2 GB.\n// func (h huge) addr() {\n// \tfmt.Printf(\"%p\\n\", &h)\n// }\n"
  },
  {
    "path": "interfaces/02-receivers/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar (\n\t\tmobydick  = book{title: \"moby dick\", price: 10}\n\t\tminecraft = game{title: \"minecraft\", price: 20}\n\t\ttetris    = game{title: \"tetris\", price: 5}\n\t)\n\n\t// sends a pointer of minecraft to the discount method\n\t// same as: (&minecraft).discount(.1)\n\tminecraft.discount(.1)\n\n\tmobydick.print()\n\tminecraft.print()\n\ttetris.print()\n\n\t// creates a variable that occupies 200mb on memory\n\tvar h huge\n\tfor i := 0; i < 10; i++ {\n\t\th.addr()\n\t}\n}\n"
  },
  {
    "path": "interfaces/03-nonstructs/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype book struct {\n\ttitle string\n\tprice money\n}\n\nfunc (b book) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", b.title, b.price.string())\n}\n"
  },
  {
    "path": "interfaces/03-nonstructs/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype game struct {\n\ttitle string\n\tprice money\n}\n\nfunc (g *game) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", g.title, g.price.string())\n}\n\nfunc (g *game) discount(ratio float64) {\n\tg.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/03-nonstructs/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// + you can attach methods to non-struct types.\n// + rule: you need to declare a new type in the same package.\ntype list []*game\n\nfunc (l list) print() {\n\t// `list` acts like a `[]game`\n\tif len(l) == 0 {\n\t\tfmt.Println(\"Sorry. We're waiting for delivery 🚚.\")\n\t\treturn\n\t}\n\n\tfor _, it := range l {\n\t\tit.print()\n\t}\n}\n"
  },
  {
    "path": "interfaces/03-nonstructs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar (\n\t\t// mobydick  = book{title: \"moby dick\", price: 10}\n\t\tminecraft = game{title: \"minecraft\", price: 20}\n\t\ttetris    = game{title: \"tetris\", price: 5}\n\t)\n\n\tvar items []*game\n\titems = append(items, &minecraft, &tetris)\n\n\t// you can attach methods to a compatible type on the fly:\n\t// items -> []*game\n\t// list  -> []*game\n\tmy := list(items)\n\t// my = nil\n\n\t// you can call methods even on a nil value\n\tmy.print()\n}\n"
  },
  {
    "path": "interfaces/03-nonstructs/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) string() string {\n\t// $xx.yy\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype book struct {\n\ttitle string\n\tprice money\n}\n\nfunc (b book) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", b.title, b.price.string())\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype game struct {\n\ttitle string\n\tprice money\n}\n\nfunc (g *game) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", g.title, g.price.string())\n}\n\nfunc (g *game) discount(ratio float64) {\n\tg.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype printer interface {\n\tprint()\n}\n\ntype list []printer\n\nfunc (l list) print() {\n\tif len(l) == 0 {\n\t\tfmt.Println(\"Sorry. We're waiting for delivery 🚚.\")\n\t\treturn\n\t}\n\n\tfor _, it := range l {\n\t\t// fmt.Printf(\"(%-10T) --> \", it)\n\n\t\tit.print()\n\n\t\t// you cannot access to the discount method of the game type.\n\t\t// `it` is a printer not a game.\n\t\t// it.discount(.5)\n\t}\n}\n\n// PREVIOUS CODE:\n\n// type list []*game\n\n// func (l list) print() {\n// \tif len(l) == 0 {\n// \t\tfmt.Println(\"Sorry. Our store is closed. We're waiting for the delivery 🚚.\")\n// \t\treturn\n// \t}\n\n// \tfor _, it := range l {\n// \t\tit.print()\n// \t}\n// }\n"
  },
  {
    "path": "interfaces/04-interfaces/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tmobydick  = book{title: \"moby dick\", price: 10}\n\t\tminecraft = game{title: \"minecraft\", price: 20}\n\t\ttetris    = game{title: \"tetris\", price: 5}\n\t\trubik     = puzzle{title: \"rubik's cube\", price: 5}\n\t)\n\n\t// thanks to the printer interface we can add different types of values\n\t// to the list.\n\t//\n\t// only rule: they need to implement the `printer` interface.\n\t// to do that: each type needs to have a print method.\n\n\tvar store list\n\tstore = append(store, &minecraft, &tetris, mobydick, rubik)\n\tstore.print()\n\n\t// interface values are comparable\n\tfmt.Println(store[0] == &minecraft)\n\tfmt.Println(store[3] == rubik)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) string() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/power/blender.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// Blender can be powered\ntype Blender struct{}\n\n// Draw power to a Blender\nfunc (Blender) Draw(power int) {\n\tfmt.Printf(\"Blender is drawing %dkW of electrical power.\\n\", power)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/power/kettle.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// Kettle can be powered\ntype Kettle struct{}\n\n// Draw power to a Kettle\nfunc (Kettle) Draw(power int) {\n\tfmt.Printf(\"Kettle is drawing %dkW of electrical power.\\n\", power)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/power/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"time\"\n)\n\n// RUN IT WITH ALL THE FILES IN THE DIRECTORY LIKE SO:\n// go run .\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\tvar (\n\t\tblender Blender\n\t\tplayer  Player\n\t\tkettle  Kettle\n\t\tmixer   Mixer\n\t)\n\n\tsocket := &Socket{100}\n\n\tfmt.Printf(\"Socket's available power is %d kW.\\n\", socket.power)\n\n\tif err := socket.Plug(blender); err != nil {\n\t\tfmt.Println(\"Blender cannot be powered up:\", err)\n\t}\n\n\tif err := socket.Plug(player); err != nil {\n\t\tfmt.Println(\"Player cannot be powered up:\", err)\n\t}\n\n\tif err := socket.Plug(kettle); err != nil {\n\t\tfmt.Println(\"Kettle cannot be powered up:\", err)\n\t}\n\n\tif err := socket.Plug(mixer); err != nil {\n\t\tfmt.Println(\"Mixer cannot be powered up:\", err)\n\t}\n\n\tfmt.Printf(\"Socket's available power is %d kW.\\n\", socket.power)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/power/mixer.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// Mixer can be powered\ntype Mixer struct{}\n\n// Draw power to a Mixer\nfunc (Mixer) Draw(power int) {\n\tfmt.Printf(\"Mixer is drawing %dkW of electrical power.\\n\", power)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/power/player.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// Player can be powered\ntype Player struct{}\n\n// Draw power to a Player\nfunc (Player) Draw(power int) {\n\tfmt.Printf(\"Player is drawing %dkW of electrical power.\\n\", power)\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/power/socket.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n)\n\n// PowerDrawer represents an electrical device that can draw power.\n// The power source doesn't have to be a Socket.\ntype PowerDrawer interface {\n\tDraw(power int)\n}\n\n// Socket has the power!\ntype Socket struct {\n\tpower int\n}\n\n// Plug a device to draw power from the `Socket`\nfunc (s *Socket) Plug(device PowerDrawer) error {\n\tn := rand.Intn(50) + 1\n\n\tif s.power-n < 0 {\n\t\treturn fmt.Errorf(\"socket is out of power for %dkW\", n)\n\t}\n\n\ts.power -= n\n\tdevice.Draw(n)\n\n\treturn nil\n}\n"
  },
  {
    "path": "interfaces/04-interfaces/puzzle.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype puzzle struct {\n\ttitle string\n\tprice money\n}\n\n// if you remove this method,\n// you can no longer add it to the `store` in `main()`.\nfunc (p puzzle) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", p.title, p.price.string())\n}\n"
  },
  {
    "path": "interfaces/05-type-assertion/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype book struct {\n\ttitle string\n\tprice money\n}\n\nfunc (b book) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", b.title, b.price.string())\n}\n"
  },
  {
    "path": "interfaces/05-type-assertion/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype game struct {\n\ttitle string\n\tprice money\n}\n\nfunc (g *game) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", g.title, g.price.string())\n}\n\nfunc (g *game) discount(ratio float64) {\n\tg.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/05-type-assertion/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype printer interface {\n\tprint()\n\n\t// use type assertion when you cannot change the interface.\n\t// discount(ratio float64)\n}\n\ntype list []printer\n\nfunc (l list) print() {\n\tif len(l) == 0 {\n\t\tfmt.Println(\"Sorry. We're waiting for delivery 🚚.\")\n\t\treturn\n\t}\n\n\tfor _, it := range l {\n\t\tit.print()\n\t}\n}\n\n// type assertion can extract the wrapped value.\n// or: it can put the value into another interface.\nfunc (l list) discount(ratio float64) {\n\t// you can declare an interface in a function/method as well.\n\t// interface is just a type.\n\ttype discounter interface {\n\t\tdiscount(float64)\n\t}\n\n\tfor _, it := range l {\n\t\t// you can assert to an interface.\n\t\t// and extract another interface.\n\t\tif it, ok := it.(discounter); ok {\n\t\t\tit.discount(ratio)\n\t\t}\n\t}\n}\n\n// ----\n\n// func (l list) discount(ratio float64) {\n// \tfor _, it := range l {\n// \t\t// you can inline-assert interfaces\n// \t\t// interface is just a type.\n// \t\tg, ok := it.(interface{ discount(float64) })\n// \t\tif !ok {\n// \t\t\tcontinue\n// \t\t}\n\n// \t\tg.discount(ratio)\n// \t}\n// }\n\n// ----\n\n// // type assertion can pull out the real value behind an interface value.\n// // it can also check whether the value convertable to a given type.\n// func (l list) discount(ratio float64) {\n// \tfor _, it := range l {\n// \t\tg, ok := it.(*game)\n// \t\tif !ok {\n// \t\t\tcontinue\n// \t\t}\n\n// \t\tg.discount(ratio)\n// \t}\n// }\n"
  },
  {
    "path": "interfaces/05-type-assertion/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar (\n\t\tmobydick  = book{title: \"moby dick\", price: 10}\n\t\tminecraft = game{title: \"minecraft\", price: 20}\n\t\ttetris    = game{title: \"tetris\", price: 5}\n\t\trubik     = puzzle{title: \"rubik's cube\", price: 5}\n\t\tyoda      = toy{title: \"yoda\", price: 150}\n\t)\n\n\tvar store list\n\tstore = append(store, &minecraft, &tetris, mobydick, rubik, &yoda)\n\n\t// #2\n\tstore.discount(.5)\n\tstore.print()\n\n\t// #1\n\t// var p printer\n\t// p = &tetris\n\t// tetris.discount(.5)\n\t// p.print()\n}\n"
  },
  {
    "path": "interfaces/05-type-assertion/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) string() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/05-type-assertion/puzzle.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype puzzle struct {\n\ttitle string\n\tprice money\n}\n\nfunc (p puzzle) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", p.title, p.price.string())\n}\n"
  },
  {
    "path": "interfaces/05-type-assertion/toy.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype toy struct {\n\ttitle string\n\tprice money\n}\n\nfunc (t *toy) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", t.title, t.price.string())\n}\n\nfunc (t *toy) discount(ratio float64) {\n\tt.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"time\"\n)\n\ntype book struct {\n\ttitle     string\n\tprice     money\n\tpublished interface{}\n}\n\nfunc (b book) print() {\n\tp := format(b.published)\n\tfmt.Printf(\"%-15s: %s - (%v)\\n\", b.title, b.price.string(), p)\n}\n\nfunc format(v interface{}) string {\n\t// book{title: \"hobbit\", price: 25},\n\tif v == nil {\n\t\treturn \"unknown\"\n\t}\n\n\tvar t int\n\n\t// book{title: \"moby dick\", price: 10, published: 118281600},\n\tif v, ok := v.(int); ok {\n\t\tt = v\n\t}\n\n\t// book{title: \"odyssey\", price: 15, published: \"733622400\"},\n\tif v, ok := v.(string); ok {\n\t\tt, _ = strconv.Atoi(v)\n\t}\n\n\tu := time.Unix(int64(t), 0)\n\treturn u.String()\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/empty/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Let's create a variable using the empty interface type.\n\tvar any interface{}\n\n\t// The variable can accept any type of value.\n\tany = []int{1, 2, 3}\n\tany = map[int]bool{1: true, 2: false}\n\tany = \"hello\"\n\tany = 3\n\n\t// You can't multiply the last number.\n\t// Reason: `any` is an `interface{}`, it's not a number.\n\t// any = any * 2\n\t// any = int(any) * 2\n\n\tany = any.(int) * 2\n\tfmt.Println(any)\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/empty2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tnums := []int{1, 2, 3}\n\n\t// Store a slice in `any`\n\tvar any interface{}\n\tany = nums\n\n\t// `any` is an empty interface value, it's not a slice.\n\t// You cannot get its length. It has no length.\n\t// _ = len(any)\n\n\t// When you extract the slice from it, you can get the slice's length.\n\t_ = len(any.([]int))\n\n\t// You cannot assign an `[]T` slice to `[]interface{}` slice.\n\t// Where `T` can be of any type.\n\t// Reason: `[]interface{}` is a slice, it's not an `empty interface` value.\n\tvar many []interface{}\n\t// many = nums\n\n\t// The same reason that you can't assign an `[]int` to a `[]string`.\n\t// var words []string = nums\n\n\t// You need to copy the elements from `nums` to `many` manually.\n\tfor _, n := range nums {\n\t\tmany = append(many, n)\n\t}\n\tfmt.Println(many)\n\n\t// Each element of the `many` slice is an `empty interface` value.\n\t// el := many[0]\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype game struct {\n\ttitle string\n\tprice money\n}\n\nfunc (g *game) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", g.title, g.price.string())\n}\n\nfunc (g *game) discount(ratio float64) {\n\tg.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype printer interface {\n\tprint()\n}\n\ntype list []printer\n\nfunc (l list) print() {\n\tif len(l) == 0 {\n\t\tfmt.Println(\"Sorry. We're waiting for delivery 🚚.\")\n\t\treturn\n\t}\n\n\tfor _, it := range l {\n\t\tit.print()\n\t}\n}\n\nfunc (l list) discount(ratio float64) {\n\ttype discounter interface {\n\t\tdiscount(float64)\n\t}\n\n\tfor _, it := range l {\n\t\tif it, ok := it.(discounter); ok {\n\t\t\tit.discount(ratio)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tstore := list{\n\t\tbook{title: \"moby dick\", price: 10, published: 118281600},\n\t\tbook{title: \"odyssey\", price: 15, published: \"733622400\"},\n\t\tbook{title: \"hobbit\", price: 25},\n\t\tpuzzle{title: \"rubik's cube\", price: 5},\n\t\t&game{title: \"minecraft\", price: 20},\n\t\t&game{title: \"tetris\", price: 5},\n\t\t&toy{title: \"yoda\", price: 150},\n\t}\n\n\tstore.discount(.5)\n\tstore.print()\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) string() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/puzzle.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype puzzle struct {\n\ttitle string\n\tprice money\n}\n\nfunc (p puzzle) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", p.title, p.price.string())\n}\n"
  },
  {
    "path": "interfaces/06-empty-interface/toy.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype toy struct {\n\ttitle string\n\tprice money\n}\n\nfunc (t *toy) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", t.title, t.price.string())\n}\n\nfunc (t *toy) discount(ratio float64) {\n\tt.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/07-type-switch/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"time\"\n)\n\ntype book struct {\n\ttitle     string\n\tprice     money\n\tpublished interface{}\n}\n\nfunc (b book) print() {\n\tp := format(b.published)\n\tfmt.Printf(\"%-15s: %s - (%v)\\n\", b.title, b.price.string(), p)\n}\n\nfunc format(v interface{}) string {\n\tvar t int\n\n\tswitch v := v.(type) {\n\tcase int:\n\t\t// book{title: \"moby dick\", price: 10, published: 118281600},\n\t\tt = v\n\tcase string:\n\t\t// book{title: \"odyssey\", price: 15, published: \"733622400\"},\n\t\tt, _ = strconv.Atoi(v)\n\tdefault:\n\t\t// book{title: \"hobbit\", price: 25},\n\t\treturn \"unknown\"\n\t}\n\n\t// Mon Jan 2 15:04:05 -0700 MST 2006\n\tconst layout = \"2006/01\"\n\n\tu := time.Unix(int64(t), 0)\n\treturn u.Format(layout)\n}\n"
  },
  {
    "path": "interfaces/07-type-switch/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype game struct {\n\ttitle string\n\tprice money\n}\n\nfunc (g *game) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", g.title, g.price.string())\n}\n\nfunc (g *game) discount(ratio float64) {\n\tg.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/07-type-switch/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype printer interface {\n\tprint()\n}\n\ntype list []printer\n\nfunc (l list) print() {\n\tif len(l) == 0 {\n\t\tfmt.Println(\"Sorry. We're waiting for delivery 🚚.\")\n\t\treturn\n\t}\n\n\tfor _, it := range l {\n\t\tit.print()\n\t}\n}\n\nfunc (l list) discount(ratio float64) {\n\ttype discounter interface {\n\t\tdiscount(float64)\n\t}\n\n\tfor _, it := range l {\n\t\tif it, ok := it.(discounter); ok {\n\t\t\tit.discount(ratio)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "interfaces/07-type-switch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tstore := list{\n\t\tbook{title: \"moby dick\", price: 10, published: 118281600},\n\t\tbook{title: \"odyssey\", price: 15, published: \"733622400\"},\n\t\tbook{title: \"hobbit\", price: 25},\n\t\tpuzzle{title: \"rubik's cube\", price: 5},\n\t\t&game{title: \"minecraft\", price: 20},\n\t\t&game{title: \"tetris\", price: 5},\n\t\t&toy{title: \"yoda\", price: 150},\n\t}\n\n\tstore.discount(.5)\n\tstore.print()\n}\n"
  },
  {
    "path": "interfaces/07-type-switch/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) string() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/07-type-switch/puzzle.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype puzzle struct {\n\ttitle string\n\tprice money\n}\n\nfunc (p puzzle) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", p.title, p.price.string())\n}\n"
  },
  {
    "path": "interfaces/07-type-switch/toy.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype toy struct {\n\ttitle string\n\tprice money\n}\n\nfunc (t *toy) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", t.title, t.price.string())\n}\n\nfunc (t *toy) discount(ratio float64) {\n\tt.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/book.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"time\"\n)\n\ntype book struct {\n\t// embed the product type into the book type.\n\t// all the fields and methods of the product will be\n\t// available in this book type.\n\tproduct\n\tpublished interface{}\n}\n\n// book type's print method takes priority.\n//\n// + when you call it on a book value, the following method will\n//   be executed.\n//\n// + if it wasn't here, the product type's print method would\n//   have been executed.\nfunc (b *book) print() {\n\t// the book can also call the embedded product's print method\n\t// if it wants to, as in here:\n\tb.product.print()\n\n\tp := format(b.published)\n\tfmt.Printf(\"\\t - (%v)\\n\", p)\n}\n\nfunc format(v interface{}) string {\n\tvar t int\n\n\tswitch v := v.(type) {\n\tcase int:\n\t\t// book{title: \"moby dick\", price: 10, published: 118281600},\n\t\tt = v\n\tcase string:\n\t\t// book{title: \"odyssey\", price: 15, published: \"733622400\"},\n\t\tt, _ = strconv.Atoi(v)\n\tdefault:\n\t\t// book{title: \"hobbit\", price: 25},\n\t\treturn \"unknown\"\n\t}\n\n\t// Mon Jan 2 15:04:05 -0700 MST 2006\n\tconst layout = \"2006/01\"\n\n\tu := time.Unix(int64(t), 0)\n\treturn u.Format(layout)\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype game struct {\n\tproduct\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype item interface {\n\tprint()\n\tdiscount(ratio float64)\n}\n\ntype list []item\n\nfunc (l list) print() {\n\tif len(l) == 0 {\n\t\tfmt.Println(\"Sorry. We're waiting for delivery 🚚.\")\n\t\treturn\n\t}\n\n\tfor _, it := range l {\n\t\tit.print()\n\t}\n}\n\nfunc (l list) discount(ratio float64) {\n\tfor _, it := range l {\n\t\tit.discount(ratio)\n\t}\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tstore := list{\n\t\t&book{product{\"moby dick\", 10}, 118281600},\n\t\t&book{product{\"odyssey\", 15}, \"733622400\"},\n\t\t&book{product{\"hobbit\", 25}, nil},\n\t\t&puzzle{product{\"rubik's cube\", 5}},\n\t\t&game{product{\"minecraft\", 20}},\n\t\t&game{product{\"tetris\", 5}},\n\t\t&toy{product{\"yoda\", 150}},\n\t}\n\n\tstore.discount(.5)\n\tstore.print()\n\n\t// t := &toy{product{\"yoda\", 150}}\n\t// fmt.Printf(\"%#v\\n\", t)\n\n\t// b := &book{product{\"moby dick\", 10}, 118281600}\n\t// fmt.Printf(\"%#v\\n\", b)\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) string() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/product.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype product struct {\n\ttitle string\n\tprice money\n}\n\nfunc (p *product) print() {\n\tfmt.Printf(\"%-15s: %s\\n\", p.title, p.price.string())\n}\n\nfunc (p *product) discount(ratio float64) {\n\tp.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/puzzle.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype puzzle struct {\n\tproduct\n}\n"
  },
  {
    "path": "interfaces/08-promoted-methods/toy.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype toy struct {\n\tproduct\n}\n"
  },
  {
    "path": "interfaces/09-little-refactor/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype list []*product\n\nfunc (l list) print() {\n\tif len(l) == 0 {\n\t\tfmt.Println(\"Sorry. We're waiting for delivery 🚚.\")\n\t\treturn\n\t}\n\n\tfor _, p := range l {\n\t\tp.print()\n\t}\n}\n\nfunc (l list) discount(ratio float64) {\n\tfor _, p := range l {\n\t\tp.discount(ratio)\n\t}\n}\n"
  },
  {
    "path": "interfaces/09-little-refactor/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tl := list{\n\t\t{title: \"moby dick\", price: 10, released: toTimestamp(118281600)},\n\t\t{title: \"odyssey\", price: 15, released: toTimestamp(\"733622400\")},\n\t\t{title: \"hobbit\", price: 25},\n\t}\n\n\tl.discount(.5)\n\tl.print()\n}\n\n/*\nSummary:\n\n- Prefer to work directly with concrete types\n  - Leads to a simple and easy to understand code\n  - Abstractions (interfaces) can unnecessarily complicate your code\n\n- Separating responsibilities is critical\n  - Timestamp type can represent, store, and print a UNIX timestamp\n\n- When a type anonymously embeds a type, it can use the methods of the embedded type as its own.\n - Timestamp embeds a time.Time\n - So you can call the methods of the time.Time through a timestamp value\n*/\n"
  },
  {
    "path": "interfaces/09-little-refactor/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) string() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/09-little-refactor/product.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype product struct {\n\ttitle    string\n\tprice    money\n\treleased timestamp\n}\n\nfunc (p *product) print() {\n\tfmt.Printf(\"%s: %s (%s)\\n\", p.title, p.price.string(), p.released.string())\n}\n\nfunc (p *product) discount(ratio float64) {\n\tp.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/09-little-refactor/timestamp.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"strconv\"\n\t\"time\"\n)\n\n// timestamp stores, formats and automatically prints a timestamp.\ntype timestamp struct {\n\t// timestamp anonymously embeds a time.\n\t// no need to convert a time value to a timestamp value to use the methods of the time type.\n\ttime.Time\n}\n\nfunc (ts timestamp) string() string {\n\tif ts.IsZero() { // same as: ts.Time.IsZero()\n\t\treturn \"unknown\"\n\t}\n\n\t// Mon Jan 2 15:04:05 -0700 MST 2006\n\tconst layout = \"2006/01\"\n\treturn ts.Format(layout) // same as: ts.Time.Format(layout)\n}\n\n// toTimestamp returns a timestamp value depending on the type of `v`.\nfunc toTimestamp(v interface{}) (ts timestamp) {\n\tvar t int\n\n\tswitch v := v.(type) {\n\tcase int:\n\t\tt = v\n\tcase string:\n\t\tt, _ = strconv.Atoi(v)\n\t}\n\n\tts.Time = time.Unix(int64(t), 0)\n\treturn ts\n}\n"
  },
  {
    "path": "interfaces/10-stringer/_handlemethods.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// In the depths of the Go standard library's fmt package...\n// Printing functions use the handleMethods method.\n\n// Example:\n// var pocket money = 10\n// fmt.Println(pocket)\n\n//            the argument can be any type of value\n//      stores the pocket variable in the argument variable\n//                            ^\n//                            |\nfunc (p *pp) handleMethods(argument interface{}) (handled bool) {\n\t// ...\n\n\t// Checks whether a given argument is an error or an fmt.Stringer\n\tswitch v := argument.(type) {\n\t// ...\n\t// If the argument is a Stringer, calls its String() method\n\tcase Stringer:\n\t\t// ...\n\t\t//        pocket.String()\n\t\t//              ^\n\t\t//              |\n\t\tp.fmtString(v.String(), verb)\n\t\treturn\n\t}\n\n\t// ...\n}\n\n/*\nThe original `handleMethods` code is more involved:\n\nhttps://github.com/golang/go/blob/6f51082da77a1d4cafd5b7af0db69293943f4066/src/fmt/print.go#L574\n\n\t-> 574#handleMethods(..)\n\t-> 627#Stringer type check: If `v` is a Stringer, run:\n\t-> 630#v.String()\n*/"
  },
  {
    "path": "interfaces/10-stringer/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"strings\"\n)\n\ntype list []*product\n\nfunc (l list) String() string {\n\tif len(l) == 0 {\n\t\treturn \"Sorry. We're waiting for delivery 🚚.\\n\"\n\t}\n\n\tvar str strings.Builder\n\tfor _, p := range l {\n\t\t// fmt.Printf(\"* %s\\n\", p)\n\t\tstr.WriteString(\"* \")\n\t\tstr.WriteString(p.String())\n\t\tstr.WriteRune('\\n')\n\t}\n\treturn str.String()\n}\n\nfunc (l list) discount(ratio float64) {\n\tfor _, p := range l {\n\t\tp.discount(ratio)\n\t}\n}\n"
  },
  {
    "path": "interfaces/10-stringer/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tl := list{\n\t\t{title: \"moby dick\", price: 10, released: toTimestamp(118281600)},\n\t\t{title: \"odyssey\", price: 15, released: toTimestamp(\"733622400\")},\n\t\t{title: \"hobbit\", price: 25},\n\t}\n\n\tl.discount(.5)\n\n\t// The list is a stringer.\n\t// The `fmt.Print` function can print the `l`\n\t// by calling `l`'s `String()` method.\n\t//\n\t// Underneath, `fmt.Print` uses a type switch to\n\t// detect whether a type is a Stringer:\n\t// https://golang.org/src/fmt/print.go#L627\n\tfmt.Print(l)\n\n\t// The money type is a stringer.\n\t// You don't need to call the String method when printing a value of it.\n\t// var pocket money = 10\n\t// fmt.Println(\"I have\", pocket)\n}\n\n/*\nSummary:\n\n- fmt.Stringer has one method: String()\n  - That returns a string.\n  - It is better to be an fmt.Stringer instead of printing directly.\n\n- Implement the String() on a type and the type can represent itself as a string.\n  - Bonus: The functions in the fmt package can print your type.\n  - They use type assertion to detect if a type implements a String() method.\n\n- strings.Builder can efficiently combine multiple string values.\n*/\n"
  },
  {
    "path": "interfaces/10-stringer/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\n// String() returns a string representation of money.\n// money is an fmt.Stringer.\nfunc (m money) String() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/10-stringer/product.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype product struct {\n\ttitle    string\n\tprice    money\n\treleased timestamp\n}\n\nfunc (p *product) String() string {\n\treturn fmt.Sprintf(\"%s: %s (%s)\", p.title, p.price, p.released)\n}\n\nfunc (p *product) discount(ratio float64) {\n\tp.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/10-stringer/timestamp.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"strconv\"\n\t\"time\"\n)\n\n// timestamp stores, formats and automatically prints a timestamp.\ntype timestamp struct {\n\t// timestamp anonymously embeds a time.\n\t// no need to convert a time value to a timestamp value to use the methods of the time type.\n\ttime.Time\n}\n\n// String() returns a string representation of timestamp.\n// timestamp is an fmt.Stringer.\nfunc (ts timestamp) String() string {\n\tif ts.IsZero() { // same as: ts.Time.IsZero()\n\t\treturn \"unknown\"\n\t}\n\n\t// Mon Jan 2 15:04:05 -0700 MST 2006\n\tconst layout = \"2006/01\"\n\treturn ts.Format(layout) // same as: ts.Time.Format(layout)\n}\n\n// toTimestamp returns a timestamp value depending on the type of `v`.\nfunc toTimestamp(v interface{}) (ts timestamp) {\n\tvar t int\n\n\tswitch v := v.(type) {\n\tcase int:\n\t\tt = v\n\tcase string:\n\t\tt, _ = strconv.Atoi(v)\n\t}\n\n\tts.Time = time.Unix(int64(t), 0)\n\treturn ts\n}\n"
  },
  {
    "path": "interfaces/11-sort/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"sort\"\n\t\"strings\"\n)\n\n// product is now *product because sorting will unnecessarily copy the product values\n\ntype list []*product\n\nfunc (l list) String() string {\n\tif len(l) == 0 {\n\t\treturn \"Sorry. We're waiting for delivery 🚚.\\n\"\n\t}\n\n\tvar str strings.Builder\n\tfor _, p := range l {\n\t\t// fmt.Printf(\"* %s\\n\", p)\n\t\tstr.WriteString(\"* \")\n\t\tstr.WriteString(p.String())\n\t\tstr.WriteRune('\\n')\n\t}\n\treturn str.String()\n}\n\nfunc (l list) discount(ratio float64) {\n\tfor _, p := range l {\n\t\tp.discount(ratio)\n\t}\n}\n\n// implementation of the sort.Interface:\n\n// by default `list` sorts by `title`.\nfunc (l list) Len() int           { return len(l) }\nfunc (l list) Less(i, j int) bool { return l[i].title < l[j].title }\nfunc (l list) Swap(i, j int)      { l[i], l[j] = l[j], l[i] }\n\n// byRelease sorts by product release dates.\ntype byRelease struct {\n\t// byRelease embeds `list` and reuses list's Len and Swap methods.\n\tlist\n}\n\n// Less takes priority over the Less method of the `list`.\n// `sort.Sort` will first call this method instead of the `list`'s Less method.\nfunc (br byRelease) Less(i, j int) bool {\n\t// `Before()` accepts a `time.Time` but `released` is not `time.Time`.\n\treturn br.list[i].released.Before(br.list[j].released.Time)\n}\n\n/*\nAnonymous embedding means auto-forwarding method calls to the embedded value:\n\nfunc (br byRelease) Len() int      { return br.list.Len() }\nfunc (br byRelease) Swap(i, j int) { br.list.Swap(i, j)   }\n*/\n\nfunc byReleaseDate(l list) sort.Interface {\n\treturn &byRelease{l}\n}\n"
  },
  {
    "path": "interfaces/11-sort/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sort\"\n)\n\nfunc main() {\n\tl := list{\n\t\t{title: \"moby dick\", price: 10, released: toTimestamp(118281600)},\n\t\t{title: \"odyssey\", price: 15, released: toTimestamp(\"733622400\")},\n\t\t{title: \"hobbit\", price: 25},\n\t}\n\n\t// sort.Sort(l)\n\t// sort.Sort(sort.Reverse(l))\n\t// sort.Sort(byReleaseDate(l))\n\tsort.Sort(sort.Reverse(byReleaseDate(l)))\n\n\tfmt.Print(l)\n}\n\n/*\nSummary:\n\n- sort.Sort() can sort any type that implements the sort.Interface\n\n- sort.Interface has three methods: Len(), Less(), Swap()\n  - Len() returns the length of a collection.\n  - Less(i, j) should return true when an element comes before another one.\n  - Swap(i, j)s the elements when Less() returns true.\n\n- sort.Reverse() can reverse sort a type that satisfies the sort.Interface.\n\n- You can customize the sorting:\n  - Either by implementing the sort.Interface methods,\n  - or by anonymously embedding a type that already satisfies the sort.Interface\n  - and adding a Less() method.\n\n- Anonymous embedding means auto-forwarding method calls to an embedded value.\n*/\n"
  },
  {
    "path": "interfaces/11-sort/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) String() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/11-sort/product.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype product struct {\n\ttitle    string\n\tprice    money\n\treleased timestamp\n}\n\nfunc (p *product) String() string {\n\treturn fmt.Sprintf(\"%s: %s (%s)\", p.title, p.price, p.released)\n}\n\nfunc (p *product) discount(ratio float64) {\n\tp.price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/11-sort/timestamp.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"strconv\"\n\t\"time\"\n)\n\ntype timestamp struct {\n\ttime.Time\n}\n\nfunc (ts timestamp) String() string {\n\tif ts.IsZero() {\n\t\treturn \"unknown\"\n\t}\n\n\t// Mon Jan 2 15:04:05 -0700 MST 2006\n\tconst layout = \"2006/01\"\n\treturn ts.Format(layout)\n}\n\nfunc toTimestamp(v interface{}) (ts timestamp) {\n\tvar t int\n\n\tswitch v := v.(type) {\n\tcase int:\n\t\tt = v\n\tcase string:\n\t\tt, _ = strconv.Atoi(v)\n\t}\n\n\tts.Time = time.Unix(int64(t), 0)\n\treturn ts\n}\n"
  },
  {
    "path": "interfaces/12-marshaler/database.json",
    "content": "[\n {\n  \"title\": \"moby dick\",\n  \"price\": 10,\n  \"released\": 118281600\n },\n {\n  \"title\": \"odyssey\",\n  \"price\": 15,\n  \"released\": 733622400\n },\n {\n  \"title\": \"hobbit\",\n  \"price\": 25,\n  \"released\": -62135596800\n }\n]\n"
  },
  {
    "path": "interfaces/12-marshaler/list.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"sort\"\n\t\"strings\"\n)\n\ntype list []*product\n\nfunc (l list) String() string {\n\tif len(l) == 0 {\n\t\treturn \"Sorry. We're waiting for delivery 🚚.\\n\"\n\t}\n\n\tvar str strings.Builder\n\tfor _, p := range l {\n\t\t// fmt.Printf(\"* %s\\n\", p)\n\t\tstr.WriteString(\"* \")\n\t\tstr.WriteString(p.String())\n\t\tstr.WriteRune('\\n')\n\t}\n\treturn str.String()\n}\n\nfunc (l list) discount(ratio float64) {\n\tfor _, p := range l {\n\t\tp.discount(ratio)\n\t}\n}\n\n// implementation of the sort.Interface:\n\n// by default `list` sorts by `Title`.\nfunc (l list) Len() int           { return len(l) }\nfunc (l list) Less(i, j int) bool { return l[i].Title < l[j].Title }\nfunc (l list) Swap(i, j int)      { l[i], l[j] = l[j], l[i] }\n\n// byRelease sorts by product release dates.\ntype byRelease struct{ list }\n\nfunc (br byRelease) Less(i, j int) bool {\n\treturn br.list[i].Released.Before(br.list[j].Released.Time)\n}\n\nfunc byReleaseDate(l list) sort.Interface {\n\treturn &byRelease{l}\n}\n"
  },
  {
    "path": "interfaces/12-marshaler/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"log\"\n)\n\nconst data = `[\n {\n  \"title\": \"moby dick\",\n  \"price\": 10,\n  \"released\": 118281600\n },\n {\n  \"title\": \"odyssey\",\n  \"price\": 15,\n  \"released\": 733622400\n },\n {\n  \"title\": \"hobbit\",\n  \"price\": 25,\n  \"released\": -62135596800\n }\n]`\n\nfunc main() {\n\t/* encoding */\n\tl := list{\n\t\t{Title: \"moby dick\", Price: 10, Released: toTimestamp(118281600)},\n\t\t{Title: \"odyssey\", Price: 15, Released: toTimestamp(\"733622400\")},\n\t\t{Title: \"hobbit\", Price: 25},\n\t}\n\n\tdata, err := json.MarshalIndent(l, \"\", \" \")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Println(string(data))\n\n\t/* decoding */\n\t// var l list\n\t// if err := json.Unmarshal([]byte(data), &l); err != nil {\n\t// \tlog.Fatal(err)\n\t// }\n\t// fmt.Print(l)\n}\n\n/*\nSummary:\n\n- json.Marshal() and json.MarshalIndent() can only encode primitive types.\n  - Custom types can tell the encoder how to encode.\n  - To do that satisfy the json.Marshaler interface.\n\n- json.Unmarshal() can only decode primitive types.\n  - Custom types can tell the decoder how to decode.\n  - To do that satisfy the json.Unmarshaler interface.\n\n- strconv.AppendInt() can append an int value to a []byte.\n  - There are several other functions in the strconv package for other primitive types as well.\n  - Do not make unnecessary string <-> []byte conversions.\n\n- log.Fatal() can print the given error message and terminate the program.\n  - Use it only from the main(). Do not use it in other functions.\n  - main() is should be the main driver of a program.\n*/\n"
  },
  {
    "path": "interfaces/12-marshaler/money.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\ntype money float64\n\nfunc (m money) String() string {\n\treturn fmt.Sprintf(\"$%.2f\", m)\n}\n"
  },
  {
    "path": "interfaces/12-marshaler/product.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype product struct {\n\tTitle    string    `json:\"title\"`\n\tPrice    money     `json:\"price\"`\n\tReleased timestamp `json:\"released\"`\n}\n\nfunc (p *product) String() string {\n\treturn fmt.Sprintf(\"%s: %s (%s)\", p.Title, p.Price, p.Released)\n}\n\nfunc (p *product) discount(ratio float64) {\n\tp.Price *= money(1 - ratio)\n}\n"
  },
  {
    "path": "interfaces/12-marshaler/timestamp.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"strconv\"\n\t\"time\"\n)\n\ntype timestamp struct {\n\ttime.Time\n}\n\n// implementation of the fmt.Stringer interface:\n\nfunc (ts timestamp) String() string {\n\tif ts.IsZero() {\n\t\treturn \"unknown\"\n\t}\n\n\t// Mon Jan 2 15:04:05 -0700 MST 2006\n\tconst layout = \"2006/01\"\n\treturn ts.Format(layout)\n}\n\n// implementation of the json.Marshaler and json.Unmarshaler interfaces:\n\n// timestamp knows how to decode itself from json.\n// json.Unmarshal and json.Decode call this method.\nfunc (ts *timestamp) UnmarshalJSON(data []byte) error {\n\t*ts = toTimestamp(string(data))\n\treturn nil\n}\n\n// timestamp knows how to encode itself to json.\n// json.Marshal and json.Encode call this method.\nfunc (ts timestamp) MarshalJSON() (data []byte, _ error) {\n\treturn strconv.AppendInt(data, ts.Unix(), 10), nil\n}\n\nfunc toTimestamp(v interface{}) (ts timestamp) {\n\tvar t int\n\n\tswitch v := v.(type) {\n\tcase int:\n\t\tt = v\n\tcase string:\n\t\tt, _ = strconv.Atoi(v)\n\t}\n\n\tts.Time = time.Unix(int64(t), 0)\n\treturn ts\n}\n"
  },
  {
    "path": "interfaces/13-io/alice.txt",
    "content": "ALICE'S ADVENTURES IN WONDERLAND\nLewis Carroll\n\nCHAPTER I\nDown the Rabbit-Hole\n\nAlice was beginning to get very tired of sitting by her sister\non the bank, and of having nothing to do:  once or twice she had\npeeped into the book her sister was reading, but it had no\npictures or conversations in it, `and what is the use of a book,'\nthought Alice `without pictures or conversation?'\n\n  So she was considering in her own mind (as well as she could,\nfor the hot day made her feel very sleepy and stupid), whether\nthe pleasure of making a daisy-chain would be worth the trouble\nof getting up and picking the daisies, when suddenly a White\nRabbit with pink eyes ran close by her.\n\n  There was nothing so VERY remarkable in that; nor did Alice\nthink it so VERY much out of the way to hear the Rabbit say to\nitself, `Oh dear!  Oh dear!  I shall be late!'  (when she thought\nit over afterwards, it occurred to her that she ought to have\nwondered at this, but at the time it all seemed quite natural);\nbut when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-\nPOCKET, and looked at it, and then hurried on, Alice started to\nher feet, for it flashed across her mind that she had never\nbefore seen a rabbit with either a waistcoat-pocket, or a watch to\ntake out of it, and burning with curiosity, she ran across the\nfield after it, and fortunately was just in time to see it pop\ndown a large rabbit-hole under the hedge.\n\n  In another moment down went Alice after it, never once\nconsidering how in the world she was to get out again.\n\n  The rabbit-hole went straight on like a tunnel for some way,\nand then dipped suddenly down, so suddenly that Alice had not a\nmoment to think about stopping herself before she found herself\nfalling down a very deep well.\n\n  Either the well was very deep, or she fell very slowly, for she\nhad plenty of time as she went down to look about her and to\nwonder what was going to happen next.  First, she tried to look\ndown and make out what she was coming to, but it was too dark to\nsee anything; then she looked at the sides of the well, and\nnoticed that they were filled with cupboards and book-shelves;\nhere and there she saw maps and pictures hung upon pegs.  She\ntook down a jar from one of the shelves as she passed; it was\nlabelled `ORANGE MARMALADE', but to her great disappointment it\nwas empty:  she did not like to drop the jar for fear of killing\nsomebody, so managed to put it into one of the cupboards as she\nfell past it.\n\n  `Well!' thought Alice to herself, `after such a fall as this, I\nshall think nothing of tumbling down stairs!  How brave they'll\nall think me at home!  Why, I wouldn't say anything about it,\neven if I fell off the top of the house!' (Which was very likely\ntrue.)\n\n  Down, down, down.  Would the fall NEVER come to an end!  `I\nwonder how many miles I've fallen by this time?' she said aloud.\n`I must be getting somewhere near the centre of the earth.  Let\nme see:  that would be four thousand miles down, I think--' (for,\nyou see, Alice had learnt several things of this sort in her\nlessons in the schoolroom, and though this was not a VERY good\nopportunity for showing off her knowledge, as there was no one to\nlisten to her, still it was good practice to say it over) `--yes,\nthat's about the right distance--but then I wonder what Latitude\nor Longitude I've got to?'  (Alice had no idea what Latitude was,\nor Longitude either, but thought they were nice grand words to\nsay.)\n\n  Presently she began again.  `I wonder if I shall fall right\nTHROUGH the earth!  How funny it'll seem to come out among the\npeople that walk with their heads downward!  The Antipathies, I\nthink--' (she was rather glad there WAS no one listening, this\ntime, as it didn't sound at all the right word) `--but I shall\nhave to ask them what the name of the country is, you know.\nPlease, Ma'am, is this New Zealand or Australia?' (and she tried\nto curtsey as she spoke--fancy CURTSEYING as you're falling\nthrough the air!  Do you think you could manage it?)  `And what\nan ignorant little girl she'll think me for asking!  No, it'll\nnever do to ask:  perhaps I shall see it written up somewhere.'\n\n  Down, down, down.  There was nothing else to do, so Alice soon\nbegan talking again.  `Dinah'll miss me very much to-night, I\nshould think!'  (Dinah was the cat.)  `I hope they'll remember\nher saucer of milk at tea-time.  Dinah my dear!  I wish you were\ndown here with me!  There are no mice in the air, I'm afraid, but\nyou might catch a bat, and that's very like a mouse, you know.\nBut do cats eat bats, I wonder?'  And here Alice began to get\nrather sleepy, and went on saying to herself, in a dreamy sort of\nway, `Do cats eat bats?  Do cats eat bats?' and sometimes, `Do\nbats eat cats?' for, you see, as she couldn't answer either\nquestion, it didn't much matter which way she put it.  She felt\nthat she was dozing off, and had just begun to dream that she\nwas walking hand in hand with Dinah, and saying to her very\nearnestly, `Now, Dinah, tell me the truth:  did you ever eat a\nbat?' when suddenly, thump! thump! down she came upon a heap of\nsticks and dry leaves, and the fall was over.\n\n  Alice was not a bit hurt, and she jumped up on to her feet in a\nmoment:  she looked up, but it was all dark overhead; before her\nwas another long passage, and the White Rabbit was still in\nsight, hurrying down it.  There was not a moment to be lost:\naway went Alice like the wind, and was just in time to hear it\nsay, as it turned a corner, `Oh my ears and whiskers, how late\nit's getting!'  She was close behind it when she turned the\ncorner, but the Rabbit was no longer to be seen:  she found\nherself in a long, low hall, which was lit up by a row of lamps\nhanging from the roof.\n\n  There were doors all round the hall, but they were all locked;\nand when Alice had been all the way down one side and up the\nother, trying every door, she walked sadly down the middle,\nwondering how she was ever to get out again.\n\n  Suddenly she came upon a little three-legged table, all made of\nsolid glass; there was nothing on it except a tiny golden key,\nand Alice's first thought was that it might belong to one of the\ndoors of the hall; but, alas! either the locks were too large, or\nthe key was too small, but at any rate it would not open any of\nthem.  However, on the second time round, she came upon a low\ncurtain she had not noticed before, and behind it was a little\ndoor about fifteen inches high:  she tried the little golden key\nin the lock, and to her great delight it fitted!\n\n  Alice opened the door and found that it led into a small\npassage, not much larger than a rat-hole:  she knelt down and\nlooked along the passage into the loveliest garden you ever saw.\nHow she longed to get out of that dark hall, and wander about\namong those beds of bright flowers and those cool fountains, but\nshe could not even get her head though the doorway; `and even if\nmy head would go through,' thought poor Alice, `it would be of\nvery little use without my shoulders.  Oh, how I wish\nI could shut up like a telescope!  I think I could, if I only\nknow how to begin.'  For, you see, so many out-of-the-way things\nhad happened lately, that Alice had begun to think that very few\nthings indeed were really impossible.\n\n  There seemed to be no use in waiting by the little door, so she\nwent back to the table, half hoping she might find another key on\nit, or at any rate a book of rules for shutting people up like\ntelescopes:  this time she found a little bottle on it, (`which\ncertainly was not here before,' said Alice,) and round the neck\nof the bottle was a paper label, with the words `DRINK ME'\nbeautifully printed on it in large letters.\n\n  It was all very well to say `Drink me,' but the wise little\nAlice was not going to do THAT in a hurry.  `No, I'll look\nfirst,' she said, `and see whether it's marked \"poison\" or not';\nfor she had read several nice little histories about children who\nhad got burnt, and eaten up by wild beasts and other unpleasant\nthings, all because they WOULD not remember the simple rules\ntheir friends had taught them:  such as, that a red-hot poker\nwill burn you if you hold it too long; and that if you cut your\nfinger VERY deeply with a knife, it usually bleeds; and she had\nnever forgotten that, if you drink much from a bottle marked\n`poison,' it is almost certain to disagree with you, sooner or\nlater.\n\n  However, this bottle was NOT marked `poison,' so Alice ventured\nto taste it, and finding it very nice, (it had, in fact, a sort\nof mixed flavour of cherry-tart, custard, pine-apple, roast\nturkey, toffee, and hot buttered toast,) she very soon finished\nit off.\n\n     *       *       *       *       *       *       *\n\n         *       *       *       *       *       *\n\n     *       *       *       *       *       *       *\n\n  `What a curious feeling!' said Alice; `I must be shutting up\nlike a telescope.'\n\n  And so it was indeed:  she was now only ten inches high, and\nher face brightened up at the thought that she was now the right\nsize for going though the little door into that lovely garden.\nFirst, however, she waited for a few minutes to see if she was\ngoing to shrink any further:  she felt a little nervous about\nthis; `for it might end, you know,' said Alice to herself, `in my\ngoing out altogether, like a candle.  I wonder what I should be\nlike then?'  And she tried to fancy what the flame of a candle is\nlike after the candle is blown out, for she could not remember\never having seen such a thing.\n\n  After a while, finding that nothing more happened, she decided\non going into the garden at once; but, alas for poor Alice! when\nshe got to the door, she found he had forgotten the little golden\nkey, and when she went back to the table for it, she found she\ncould not possibly reach it:  she could see it quite plainly\nthrough the glass, and she tried her best to climb up one of the\nlegs of the table, but it was too slippery; and when she had\ntired herself out with trying, the poor little thing sat down and\ncried.\n\n  `Come, there's no use in crying like that!' said Alice to\nherself, rather sharply; `I advise you to leave off this minute!'\nShe generally gave herself very good advice, (though she very\nseldom followed it), and sometimes she scolded herself so\nseverely as to bring tears into her eyes; and once she remembered\ntrying to box her own ears for having cheated herself in a game\nof croquet she was playing against herself, for this curious\nchild was very fond of pretending to be two people.  `But it's no\nuse now,' thought poor Alice, `to pretend to be two people!  Why,\nthere's hardly enough of me left to make ONE respectable\nperson!'\n\n  Soon her eye fell on a little glass box that was lying under\nthe table:  she opened it, and found in it a very small cake, on\nwhich the words `EAT ME' were beautifully marked in currants.\n`Well, I'll eat it,' said Alice, `and if it makes me grow larger,\nI can reach the key; and if it makes me grow smaller, I can creep\nunder the door; so either way I'll get into the garden, and I\ndon't care which happens!'\n\n  She ate a little bit, and said anxiously to herself, `Which\nway?  Which way?', holding her hand on the top of her head to\nfeel which way it was growing, and she was quite surprised to\nfind that she remained the same size:  to be sure, this generally\nhappens when one eats cake, but Alice had got so much into the\nway of expecting nothing but out-of-the-way things to happen,\nthat it seemed quite dull and stupid for life to go on in the\ncommon way.\n\n  So she set to work, and very soon finished off the cake.\n\n                          CHAPTER II\n                        The Pool of Tears\n\n  `Curiouser and curiouser!' cried Alice (she was so much\nsurprised, that for the moment she quite forgot how to speak good\nEnglish); `now I'm opening out like the largest telescope that\never was!  Good-bye, feet!' (for when she looked down at her\nfeet, they seemed to be almost out of sight, they were getting so\nfar off).  `Oh, my poor little feet, I wonder who will put on\nyour shoes and stockings for you now, dears?  I'm sure _I_ shan't\nbe able!  I shall be a great deal too far off to trouble myself\nabout you:  you must manage the best way you can; --but I must be\nkind to them,' thought Alice, `or perhaps they won't walk the\nway I want to go!  Let me see:  I'll give them a new pair of\nboots every Christmas.'\n\n  And she went on planning to herself how she would manage it.\n`They must go by the carrier,' she thought; `and how funny it'll\nseem, sending presents to one's own feet!  And how odd the\ndirections will look!\n\n            ALICE'S RIGHT FOOT, ESQ.\n                HEARTHRUG,\n                    NEAR THE FENDER,\n                        (WITH ALICE'S LOVE).\n\nOh dear, what nonsense I'm talking!'\n\n  Just then her head struck against the roof of the hall:  in\nfact she was now more than nine feet high, and she at once took\nup the little golden key and hurried off to the garden door.\n\n  Poor Alice!  It was as much as she could do, lying down on one\nside, to look through into the garden with one eye; but to get\nthrough was more hopeless than ever:  she sat down and began to\ncry again.\n\n  `You ought to be ashamed of yourself,' said Alice, `a great\ngirl like you,' (she might well say this), `to go on crying in\nthis way!  Stop this moment, I tell you!'  But she went on all\nthe same, shedding gallons of tears, until there was a large pool\nall round her, about four inches deep and reaching half down the\nhall.\n\n  After a time she heard a little pattering of feet in the\ndistance, and she hastily dried her eyes to see what was coming.\nIt was the White Rabbit returning, splendidly dressed, with a\npair of white kid gloves in one hand and a large fan in the\nother:  he came trotting along in a great hurry, muttering to\nhimself as he came, `Oh! the Duchess, the Duchess! Oh! won't she\nbe savage if I've kept her waiting!'  Alice felt so desperate\nthat she was ready to ask help of any one; so, when the Rabbit\ncame near her, she began, in a low, timid voice, `If you please,\nsir--'  The Rabbit started violently, dropped the white kid\ngloves and the fan, and skurried away into the darkness as hard\nas he could go.\n\n  Alice took up the fan and gloves, and, as the hall was very\nhot, she kept fanning herself all the time she went on talking:\n`Dear, dear!  How queer everything is to-day!  And yesterday\nthings went on just as usual.  I wonder if I've been changed in\nthe night?  Let me think:  was I the same when I got up this\nmorning?  I almost think I can remember feeling a little\ndifferent.  But if I'm not the same, the next question is, Who in\nthe world am I?  Ah, THAT'S the great puzzle!'  And she began\nthinking over all the children she knew that were of the same age\nas herself, to see if she could have been changed for any of\nthem.\n\n  `I'm sure I'm not Ada,' she said, `for her hair goes in such\nlong ringlets, and mine doesn't go in ringlets at all; and I'm\nsure I can't be Mabel, for I know all sorts of things, and she,\noh! she knows such a very little!  Besides, SHE'S she, and I'm I,\nand--oh dear, how puzzling it all is!  I'll try if I know all the\nthings I used to know.  Let me see:  four times five is twelve,\nand four times six is thirteen, and four times seven is--oh dear!\nI shall never get to twenty at that rate!  However, the\nMultiplication Table doesn't signify:  let's try Geography.\nLondon is the capital of Paris, and Paris is the capital of Rome,\nand Rome--no, THAT'S all wrong, I'm certain!  I must have been\nchanged for Mabel!  I'll try and say \"How doth the little--\"'\nand she crossed her hands on her lap as if she were saying lessons,\nand began to repeat it, but her voice sounded hoarse and\nstrange, and the words did not come the same as they used to do:--\n\n            `How doth the little crocodile\n              Improve his shining tail,\n            And pour the waters of the Nile\n              On every golden scale!\n\n            `How cheerfully he seems to grin,\n              How neatly spread his claws,\n            And welcome little fishes in\n              With gently smiling jaws!'\n\n  `I'm sure those are not the right words,' said poor Alice, and\nher eyes filled with tears again as she went on, `I must be Mabel\nafter all, and I shall have to go and live in that poky little\nhouse, and have next to no toys to play with, and oh! ever so\nmany lessons to learn!  No, I've made up my mind about it; if I'm\nMabel, I'll stay down here!  It'll be no use their putting their\nheads down and saying \"Come up again, dear!\"  I shall only look\nup and say \"Who am I then?  Tell me that first, and then, if I\nlike being that person, I'll come up:  if not, I'll stay down\nhere till I'm somebody else\"--but, oh dear!' cried Alice, with a\nsudden burst of tears, `I do wish they WOULD put their heads\ndown!  I am so VERY tired of being all alone here!'\n\n  As she said this she looked down at her hands, and was\nsurprised to see that she had put on one of the Rabbit's little\nwhite kid gloves while she was talking.  `How CAN I have done\nthat?' she thought.  `I must be growing small again.'  She got up\nand went to the table to measure herself by it, and found that,\nas nearly as she could guess, she was now about two feet high,\nand was going on shrinking rapidly:  she soon found out that the\ncause of this was the fan she was holding, and she dropped it\nhastily, just in time to avoid shrinking away altogether.\n\n`That WAS a narrow escape!' said Alice, a good deal frightened at\nthe sudden change, but very glad to find herself still in\nexistence; `and now for the garden!' and she ran with all speed\nback to the little door:  but, alas! the little door was shut\nagain, and the little golden key was lying on the glass table as\nbefore, `and things are worse than ever,' thought the poor child,\n`for I never was so small as this before, never!  And I declare\nit's too bad, that it is!'\n\n  As she said these words her foot slipped, and in another\nmoment, splash! she was up to her chin in salt water.  He first\nidea was that she had somehow fallen into the sea, `and in that\ncase I can go back by railway,' she said to herself.  (Alice had\nbeen to the seaside once in her life, and had come to the general\nconclusion, that wherever you go to on the English coast you find\na number of bathing machines in the sea, some children digging in\nthe sand with wooden spades, then a row of lodging houses, and\nbehind them a railway station.)  However, she soon made out that\nshe was in the pool of tears which she had wept when she was nine\nfeet high.\n\n  `I wish I hadn't cried so much!' said Alice, as she swam about,\ntrying to find her way out.  `I shall be punished for it now, I\nsuppose, by being drowned in my own tears!  That WILL be a queer\nthing, to be sure!  However, everything is queer to-day.'\n\n  Just then she heard something splashing about in the pool a\nlittle way off, and she swam nearer to make out what it was:  at\nfirst she thought it must be a walrus or hippopotamus, but then\nshe remembered how small she was now, and she soon made out that\nit was only a mouse that had slipped in like herself.\n\n  `Would it be of any use, now,' thought Alice, `to speak to this\nmouse?  Everything is so out-of-the-way down here, that I should\nthink very likely it can talk:  at any rate, there's no harm in\ntrying.'  So she began:  `O Mouse, do you know the way out of\nthis pool?  I am very tired of swimming about here, O Mouse!'\n(Alice thought this must be the right way of speaking to a mouse:\nshe had never done such a thing before, but she remembered having\nseen in her brother's Latin Grammar, `A mouse--of a mouse--to a\nmouse--a mouse--O mouse!'  The Mouse looked at her rather\ninquisitively, and seemed to her to wink with one of its little\neyes, but it said nothing.\n\n  `Perhaps it doesn't understand English,' thought Alice; `I\ndaresay it's a French mouse, come over with William the\nConqueror.'  (For, with all her knowledge of history, Alice had\nno very clear notion how long ago anything had happened.)  So she\nbegan again:  `Ou est ma chatte?' which was the first sentence in\nher French lesson-book.  The Mouse gave a sudden leap out of the\nwater, and seemed to quiver all over with fright.  `Oh, I beg\nyour pardon!' cried Alice hastily, afraid that she had hurt the\npoor animal's feelings.  `I quite forgot you didn't like cats.'\n\n  `Not like cats!' cried the Mouse, in a shrill, passionate\nvoice.  `Would YOU like cats if you were me?'\n\n  `Well, perhaps not,' said Alice in a soothing tone:  `don't be\nangry about it.  And yet I wish I could show you our cat Dinah:\nI think you'd take a fancy to cats if you could only see her.\nShe is such a dear quiet thing,' Alice went on, half to herself,\nas she swam lazily about in the pool, `and she sits purring so\nnicely by the fire, licking her paws and washing her face--and\nshe is such a nice soft thing to nurse--and she's such a capital\none for catching mice--oh, I beg your pardon!' cried Alice again,\nfor this time the Mouse was bristling all over, and she felt\ncertain it must be really offended.  `We won't talk about her any\nmore if you'd rather not.'\n\n  `We indeed!' cried the Mouse, who was trembling down to the end\nof his tail.  `As if I would talk on such a subject!  Our family\nalways HATED cats:  nasty, low, vulgar things!  Don't let me hear\nthe name again!'\n\n  `I won't indeed!' said Alice, in a great hurry to change the\nsubject of conversation.  `Are you--are you fond--of--of dogs?'\nThe Mouse did not answer, so Alice went on eagerly:  `There is\nsuch a nice little dog near our house I should like to show you!\nA little bright-eyed terrier, you know, with oh, such long curly\nbrown hair!  And it'll fetch things when you throw them, and\nit'll sit up and beg for its dinner, and all sorts of things--I\ncan't remember half of them--and it belongs to a farmer, you\nknow, and he says it's so useful, it's worth a hundred pounds!\nHe says it kills all the rats and--oh dear!' cried Alice in a\nsorrowful tone, `I'm afraid I've offended it again!'  For the\nMouse was swimming away from her as hard as it could go, and\nmaking quite a commotion in the pool as it went.\n\n  So she called softly after it, `Mouse dear!  Do come back\nagain, and we won't talk about cats or dogs either, if you don't\nlike them!'  When the Mouse heard this, it turned round and swam\nslowly back to her:  its face was quite pale (with passion, Alice\nthought), and it said in a low trembling voice, `Let us get to\nthe shore, and then I'll tell you my history, and you'll\nunderstand why it is I hate cats and dogs.'\n\n  It was high time to go, for the pool was getting quite crowded\nwith the birds and animals that had fallen into it:  there were a\nDuck and a Dodo, a Lory and an Eaglet, and several other curious\ncreatures.  Alice led the way, and the whole party swam to the\nshore.\n\n\n\n                           CHAPTER III\n\n                  A Caucus-Race and a Long Tale\n\n\n  They were indeed a queer-looking party that assembled on the\nbank--the birds with draggled feathers, the animals with their\nfur clinging close to them, and all dripping wet, cross, and\nuncomfortable.\n\n  The first question of course was, how to get dry again:  they\nhad a consultation about this, and after a few minutes it seemed\nquite natural to Alice to find herself talking familiarly with\nthem, as if she had known them all her life.  Indeed, she had\nquite a long argument with the Lory, who at last turned sulky,\nand would only say, `I am older than you, and must know better';\nand this Alice would not allow without knowing how old it was,\nand, as the Lory positively refused to tell its age, there was no\nmore to be said.\n\n  At last the Mouse, who seemed to be a person of authority among\nthem, called out, `Sit down, all of you, and listen to me!  I'LL\nsoon make you dry enough!'  They all sat down at once, in a large\nring, with the Mouse in the middle.  Alice kept her eyes\nanxiously fixed on it, for she felt sure she would catch a bad\ncold if she did not get dry very soon.\n\n  `Ahem!' said the Mouse with an important air, `are you all ready?\nThis is the driest thing I know.  Silence all round, if you please!\n\"William the Conqueror, whose cause was favoured by the pope, was\nsoon submitted to by the English, who wanted leaders, and had been\nof late much accustomed to usurpation and conquest.  Edwin and\nMorcar, the earls of Mercia and Northumbria--\"'\n\n  `Ugh!' said the Lory, with a shiver.\n\n  `I beg your pardon!' said the Mouse, frowning, but very\npolitely:  `Did you speak?'\n\n  `Not I!' said the Lory hastily.\n\n  `I thought you did,' said the Mouse.  `--I proceed.  \"Edwin and\nMorcar, the earls of Mercia and Northumbria, declared for him:\nand even Stigand, the patriotic archbishop of Canterbury, found\nit advisable--\"'\n\n  `Found WHAT?' said the Duck.\n\n  `Found IT,' the Mouse replied rather crossly:  `of course you\nknow what \"it\" means.'\n\n  `I know what \"it\" means well enough, when I find a thing,' said\nthe Duck:  `it's generally a frog or a worm.  The question is,\nwhat did the archbishop find?'\n\n  The Mouse did not notice this question, but hurriedly went on,\n`\"--found it advisable to go with Edgar Atheling to meet William\nand offer him the crown.  William's conduct at first was\nmoderate.  But the insolence of his Normans--\"  How are you\ngetting on now, my dear?' it continued, turning to Alice as it\nspoke.\n\n  `As wet as ever,' said Alice in a melancholy tone:  `it doesn't\nseem to dry me at all.'\n\n  `In that case,' said the Dodo solemnly, rising to its feet, `I\nmove that the meeting adjourn, for the immediate adoption of more\nenergetic remedies--'\n\n  `Speak English!' said the Eaglet.  `I don't know the meaning of\nhalf those long words, and, what's more, I don't believe you do\neither!'  And the Eaglet bent down its head to hide a smile:\nsome of the other birds tittered audibly.\n\n  `What I was going to say,' said the Dodo in an offended tone,\n`was, that the best thing to get us dry would be a Caucus-race.'\n\n  `What IS a Caucus-race?' said Alice; not that she wanted much\nto know, but the Dodo had paused as if it thought that SOMEBODY\nought to speak, and no one else seemed inclined to say anything.\n\n  `Why,' said the Dodo, `the best way to explain it is to do it.'\n(And, as you might like to try the thing yourself, some winter\nday, I will tell you how the Dodo managed it.)\n\n  First it marked out a race-course, in a sort of circle, (`the\nexact shape doesn't matter,' it said,) and then all the party\nwere placed along the course, here and there.  There was no `One,\ntwo, three, and away,' but they began running when they liked,\nand left off when they liked, so that it was not easy to know\nwhen the race was over.  However, when they had been running half\nan hour or so, and were quite dry again, the Dodo suddenly called\nout `The race is over!' and they all crowded round it, panting,\nand asking, `But who has won?'\n\n  This question the Dodo could not answer without a great deal of\nthought, and it sat for a long time with one finger pressed upon\nits forehead (the position in which you usually see Shakespeare,\nin the pictures of him), while the rest waited in silence.  At\nlast the Dodo said, `EVERYBODY has won, and all must have\nprizes.'\n\n  `But who is to give the prizes?' quite a chorus of voices\nasked.\n\n  `Why, SHE, of course,' said the Dodo, pointing to Alice with\none finger; and the whole party at once crowded round her,\ncalling out in a confused way, `Prizes! Prizes!'\n\n  Alice had no idea what to do, and in despair she put her hand\nin her pocket, and pulled out a box of comfits, (luckily the salt\nwater had not got into it), and handed them round as prizes.\nThere was exactly one a-piece all round.\n\n  `But she must have a prize herself, you know,' said the Mouse.\n\n  `Of course,' the Dodo replied very gravely.  `What else have\nyou got in your pocket?' he went on, turning to Alice.\n\n  `Only a thimble,' said Alice sadly.\n\n  `Hand it over here,' said the Dodo.\n\n  Then they all crowded round her once more, while the Dodo\nsolemnly presented the thimble, saying `We beg your acceptance of\nthis elegant thimble'; and, when it had finished this short\nspeech, they all cheered.\n\n  Alice thought the whole thing very absurd, but they all looked\nso grave that she did not dare to laugh; and, as she could not\nthink of anything to say, she simply bowed, and took the thimble,\nlooking as solemn as she could.\n\n  The next thing was to eat the comfits:  this caused some noise\nand confusion, as the large birds complained that they could not\ntaste theirs, and the small ones choked and had to be patted on\nthe back.  However, it was over at last, and they sat down again\nin a ring, and begged the Mouse to tell them something more.\n\n  `You promised to tell me your history, you know,' said Alice,\n`and why it is you hate--C and D,' she added in a whisper, half\nafraid that it would be offended again.\n\n  `Mine is a long and a sad tale!' said the Mouse, turning to\nAlice, and sighing.\n\n  `It IS a long tail, certainly,' said Alice, looking down with\nwonder at the Mouse's tail; `but why do you call it sad?'  And\nshe kept on puzzling about it while the Mouse was speaking, so\nthat her idea of the tale was something like this:--\n\n                    `Fury said to a\n                   mouse, That he\n                 met in the\n               house,\n            \"Let us\n              both go to\n                law:  I will\n                  prosecute\n                    YOU.  --Come,\n                       I'll take no\n                        denial; We\n                     must have a\n                 trial:  For\n              really this\n           morning I've\n          nothing\n         to do.\"\n           Said the\n             mouse to the\n               cur, \"Such\n                 a trial,\n                   dear Sir,\n                         With\n                     no jury\n                  or judge,\n                would be\n              wasting\n             our\n              breath.\"\n               \"I'll be\n                 judge, I'll\n                   be jury,\"\n                         Said\n                    cunning\n                      old Fury:\n                     \"I'll\n                      try the\n                         whole\n                          cause,\n                             and\n                        condemn\n                       you\n                      to\n                       death.\"'\n\n\n  `You are not attending!' said the Mouse to Alice severely.\n`What are you thinking of?'\n\n  `I beg your pardon,' said Alice very humbly:  `you had got to\nthe fifth bend, I think?'\n\n  `I had NOT!' cried the Mouse, sharply and very angrily.\n\n  `A knot!' said Alice, always ready to make herself useful, and\nlooking anxiously about her.  `Oh, do let me help to undo it!'\n\n  `I shall do nothing of the sort,' said the Mouse, getting up\nand walking away.  `You insult me by talking such nonsense!'\n\n  `I didn't mean it!' pleaded poor Alice.  `But you're so easily\noffended, you know!'\n\n  The Mouse only growled in reply.\n\n  `Please come back and finish your story!' Alice called after\nit; and the others all joined in chorus, `Yes, please do!' but\nthe Mouse only shook its head impatiently, and walked a little\nquicker.\n\n  `What a pity it wouldn't stay!' sighed the Lory, as soon as it\nwas quite out of sight; and an old Crab took the opportunity of\nsaying to her daughter `Ah, my dear!  Let this be a lesson to you\nnever to lose YOUR temper!'  `Hold your tongue, Ma!' said the\nyoung Crab, a little snappishly.  `You're enough to try the\npatience of an oyster!'\n\n  `I wish I had our Dinah here, I know I do!' said Alice aloud,\naddressing nobody in particular.  `She'd soon fetch it back!'\n\n  `And who is Dinah, if I might venture to ask the question?'\nsaid the Lory.\n\n  Alice replied eagerly, for she was always ready to talk about\nher pet:  `Dinah's our cat.  And she's such a capital one for\ncatching mice you can't think!  And oh, I wish you could see her\nafter the birds!  Why, she'll eat a little bird as soon as look\nat it!'\n\n  This speech caused a remarkable sensation among the party.\nSome of the birds hurried off at once:  one the old Magpie began\nwrapping itself up very carefully, remarking, `I really must be\ngetting home; the night-air doesn't suit my throat!' and a Canary\ncalled out in a trembling voice to its children, `Come away, my\ndears!  It's high time you were all in bed!'  On various pretexts\nthey all moved off, and Alice was soon left alone.\n\n  `I wish I hadn't mentioned Dinah!' she said to herself in a\nmelancholy tone.  `Nobody seems to like her, down here, and I'm\nsure she's the best cat in the world!  Oh, my dear Dinah!  I\nwonder if I shall ever see you any more!'  And here poor Alice\nbegan to cry again, for she felt very lonely and low-spirited.\nIn a little while, however, she again heard a little pattering of\nfootsteps in the distance, and she looked up eagerly, half hoping\nthat the Mouse had changed his mind, and was coming back to\nfinish his story.\n\n\n\n                           CHAPTER IV\n\n                The Rabbit Sends in a Little Bill\n\n\n  It was the White Rabbit, trotting slowly back again, and\nlooking anxiously about as it went, as if it had lost something;\nand she heard it muttering to itself `The Duchess!  The Duchess!\nOh my dear paws!  Oh my fur and whiskers!  She'll get me\nexecuted, as sure as ferrets are ferrets!  Where CAN I have\ndropped them, I wonder?'  Alice guessed in a moment that it was\nlooking for the fan and the pair of white kid gloves, and she\nvery good-naturedly began hunting about for them, but they were\nnowhere to be seen--everything seemed to have changed since her\nswim in the pool, and the great hall, with the glass table and\nthe little door, had vanished completely.\n\n  Very soon the Rabbit noticed Alice, as she went hunting about,\nand called out to her in an angry tone, `Why, Mary Ann, what ARE\nyou doing out here?  Run home this moment, and fetch me a pair of\ngloves and a fan!  Quick, now!'  And Alice was so much frightened\nthat she ran off at once in the direction it pointed to, without\ntrying to explain the mistake it had made.\n\n  `He took me for his housemaid,' she said to herself as she ran.\n`How surprised he'll be when he finds out who I am!  But I'd\nbetter take him his fan and gloves--that is, if I can find them.'\nAs she said this, she came upon a neat little house, on the door\nof which was a bright brass plate with the name `W. RABBIT'\nengraved upon it.  She went in without knocking, and hurried\nupstairs, in great fear lest she should meet the real Mary Ann,\nand be turned out of the house before she had found the fan and\ngloves.\n\n  `How queer it seems,' Alice said to herself, `to be going\nmessages for a rabbit!  I suppose Dinah'll be sending me on\nmessages next!'  And she began fancying the sort of thing that\nwould happen:  `\"Miss Alice!  Come here directly, and get ready\nfor your walk!\" \"Coming in a minute, nurse!  But I've got to see\nthat the mouse doesn't get out.\"  Only I don't think,' Alice went\non, `that they'd let Dinah stop in the house if it began ordering\npeople about like that!'\n\n  By this time she had found her way into a tidy little room with\na table in the window, and on it (as she had hoped) a fan and two\nor three pairs of tiny white kid gloves:  she took up the fan and\na pair of the gloves, and was just going to leave the room, when\nher eye fell upon a little bottle that stood near the looking-\nglass.  There was no label this time with the words `DRINK ME,'\nbut nevertheless she uncorked it and put it to her lips.  `I know\nSOMETHING interesting is sure to happen,' she said to herself,\n`whenever I eat or drink anything; so I'll just see what this\nbottle does.  I do hope it'll make me grow large again, for\nreally I'm quite tired of being such a tiny little thing!'\n\n  It did so indeed, and much sooner than she had expected:\nbefore she had drunk half the bottle, she found her head pressing\nagainst the ceiling, and had to stoop to save her neck from being\nbroken.  She hastily put down the bottle, saying to herself\n`That's quite enough--I hope I shan't grow any more--As it is, I\ncan't get out at the door--I do wish I hadn't drunk quite so\nmuch!'\n\n  Alas! it was too late to wish that!  She went on growing, and\ngrowing, and very soon had to kneel down on the floor:  in\nanother minute there was not even room for this, and she tried\nthe effect of lying down with one elbow against the door, and the\nother arm curled round her head.  Still she went on growing, and,\nas a last resource, she put one arm out of the window, and one\nfoot up the chimney, and said to herself `Now I can do no more,\nwhatever happens.  What WILL become of me?'\n\n  Luckily for Alice, the little magic bottle had now had its full\neffect, and she grew no larger:  still it was very uncomfortable,\nand, as there seemed to be no sort of chance of her ever getting\nout of the room again, no wonder she felt unhappy.\n\n  `It was much pleasanter at home,' thought poor Alice, `when one\nwasn't always growing larger and smaller, and being ordered about\nby mice and rabbits.  I almost wish I hadn't gone down that\nrabbit-hole--and yet--and yet--it's rather curious, you know,\nthis sort of life!  I do wonder what CAN have happened to me!\nWhen I used to read fairy-tales, I fancied that kind of thing\nnever happened, and now here I am in the middle of one!  There\nought to be a book written about me, that there ought!  And when\nI grow up, I'll write one--but I'm grown up now,' she added in a\nsorrowful tone; `at least there's no room to grow up any more\nHERE.'\n\n  `But then,' thought Alice, `shall I NEVER get any older than I\nam now?  That'll be a comfort, one way--never to be an old woman-\n-but then--always to have lessons to learn!  Oh, I shouldn't like\nTHAT!'\n\n  `Oh, you foolish Alice!' she answered herself.  `How can you\nlearn lessons in here?  Why, there's hardly room for YOU, and no\nroom at all for any lesson-books!'\n\n  And so she went on, taking first one side and then the other,\nand making quite a conversation of it altogether; but after a few\nminutes she heard a voice outside, and stopped to listen.\n\n  `Mary Ann!  Mary Ann!' said the voice.  `Fetch me my gloves\nthis moment!'  Then came a little pattering of feet on the\nstairs.  Alice knew it was the Rabbit coming to look for her, and\nshe trembled till she shook the house, quite forgetting that she\nwas now about a thousand times as large as the Rabbit, and had no\nreason to be afraid of it.\n\n  Presently the Rabbit came up to the door, and tried to open it;\nbut, as the door opened inwards, and Alice's elbow was pressed\nhard against it, that attempt proved a failure.  Alice heard it\nsay to itself `Then I'll go round and get in at the window.'\n\n  `THAT you won't' thought Alice, and, after waiting till she\nfancied she heard the Rabbit just under the window, she suddenly\nspread out her hand, and made a snatch in the air.  She did not\nget hold of anything, but she heard a little shriek and a fall,\nand a crash of broken glass, from which she concluded that it was\njust possible it had fallen into a cucumber-frame, or something\nof the sort.\n\n  Next came an angry voice--the Rabbit's--`Pat! Pat!  Where are\nyou?'  And then a voice she had never heard before, `Sure then\nI'm here!  Digging for apples, yer honour!'\n\n  `Digging for apples, indeed!' said the Rabbit angrily.  `Here!\nCome and help me out of THIS!'  (Sounds of more broken glass.)\n\n  `Now tell me, Pat, what's that in the window?'\n\n  `Sure, it's an arm, yer honour!'  (He pronounced it `arrum.')\n\n  `An arm, you goose!   Who ever saw one that size?  Why, it\nfills the whole window!'\n\n  `Sure, it does, yer honour:  but it's an arm for all that.'\n\n  `Well, it's got no business there, at any rate:  go and take it\naway!'\n\n  There was a long silence after this, and Alice could only hear\nwhispers now and then; such as, `Sure, I don't like it, yer\nhonour, at all, at all!'  `Do as I tell you, you coward!' and at\nlast she spread out her hand again, and made another snatch in\nthe air.  This time there were TWO little shrieks, and more\nsounds of broken glass.  `What a number of cucumber-frames there\nmust be!' thought Alice.  `I wonder what they'll do next!  As for\npulling me out of the window, I only wish they COULD!  I'm sure I\ndon't want to stay in here any longer!'\n\n  She waited for some time without hearing anything more:  at\nlast came a rumbling of little cartwheels, and the sound of a\ngood many voice all talking together:  she made out the words:\n`Where's the other ladder?--Why, I hadn't to bring but one;\nBill's got the other--Bill! fetch it here, lad!--Here, put 'em up\nat this corner--No, tie 'em together first--they don't reach half\nhigh enough yet--Oh! they'll do well enough; don't be particular-\n-Here, Bill! catch hold of this rope--Will the roof bear?--Mind\nthat loose slate--Oh, it's coming down!  Heads below!' (a loud\ncrash)--`Now, who did that?--It was Bill, I fancy--Who's to go\ndown the chimney?--Nay, I shan't! YOU do it!--That I won't,\nthen!--Bill's to go down--Here, Bill! the master says you're to\ngo down the chimney!'\n\n  `Oh! So Bill's got to come down the chimney, has he?' said\nAlice to herself.  `Shy, they seem to put everything upon Bill!\nI wouldn't be in Bill's place for a good deal:  this fireplace is\nnarrow, to be sure; but I THINK I can kick a little!'\n\n  She drew her foot as far down the chimney as she could, and\nwaited till she heard a little animal (she couldn't guess of what\nsort it was) scratching and scrambling about in the chimney close\nabove her:  then, saying to herself `This is Bill,' she gave one\nsharp kick, and waited to see what would happen next.\n\n  The first thing she heard was a general chorus of `There goes\nBill!' then the Rabbit's voice along--`Catch him, you by the\nhedge!' then silence, and then another confusion of voices--`Hold\nup his head--Brandy now--Don't choke him--How was it, old fellow?\nWhat happened to you?  Tell us all about it!'\n\n  Last came a little feeble, squeaking voice, (`That's Bill,'\nthought Alice,) `Well, I hardly know--No more, thank ye; I'm\nbetter now--but I'm a deal too flustered to tell you--all I know\nis, something comes at me like a Jack-in-the-box, and up I goes\nlike a sky-rocket!'\n\n  `So you did, old fellow!' said the others.\n\n  `We must burn the house down!' said the Rabbit's voice; and\nAlice called out as loud as she could, `If you do.  I'll set\nDinah at you!'\n\n  There was a dead silence instantly, and Alice thought to\nherself, `I wonder what they WILL do next!  If they had any\nsense, they'd take the roof off.'  After a minute or two, they\nbegan moving about again, and Alice heard the Rabbit say, `A\nbarrowful will do, to begin with.'\n\n  `A barrowful of WHAT?' thought Alice; but she had not long to\ndoubt, for the next moment a shower of little pebbles came\nrattling in at the window, and some of them hit her in the face.\n`I'll put a stop to this,' she said to herself, and shouted out,\n`You'd better not do that again!' which produced another dead\nsilence.\n\n  Alice noticed with some surprise that the pebbles were all\nturning into little cakes as they lay on the floor, and a bright\nidea came into her head.  `If I eat one of these cakes,' she\nthought, `it's sure to make SOME change in my size; and as it\ncan't possibly make me larger, it must make me smaller, I\nsuppose.'\n\n  So she swallowed one of the cakes, and was delighted to find\nthat she began shrinking directly.  As soon as she was small\nenough to get through the door, she ran out of the house, and\nfound quite a crowd of little animals and birds waiting outside.\nThe poor little Lizard, Bill, was in the middle, being held up by\ntwo guinea-pigs, who were giving it something out of a bottle.\nThey all made a rush at Alice the moment she appeared; but she\nran off as hard as she could, and soon found herself safe in a\nthick wood.\n\n  `The first thing I've got to do,' said Alice to herself, as she\nwandered about in the wood, `is to grow to my right size again;\nand the second thing is to find my way into that lovely garden.\nI think that will be the best plan.'\n\n  It sounded an excellent plan, no doubt, and very neatly and\nsimply arranged; the only difficulty was, that she had not the\nsmallest idea how to set about it; and while she was peering\nabout anxiously among the trees, a little sharp bark just over\nher head made her look up in a great hurry.\n\n  An enormous puppy was looking down at her with large round\neyes, and feebly stretching out one paw, trying to touch her.\n`Poor little thing!' said Alice, in a coaxing tone, and she tried\nhard to whistle to it; but she was terribly frightened all the\ntime at the thought that it might be hungry, in which case it\nwould be very likely to eat her up in spite of all her coaxing.\n\n  Hardly knowing what she did, she picked up a little bit of\nstick, and held it out to the puppy; whereupon the puppy jumped\ninto the air off all its feet at once, with a yelp of delight,\nand rushed at the stick, and made believe to worry it; then Alice\ndodged behind a great thistle, to keep herself from being run\nover; and the moment she appeared on the other side, the puppy\nmade another rush at the stick, and tumbled head over heels in\nits hurry to get hold of it; then Alice, thinking it was very\nlike having a game of play with a cart-horse, and expecting every\nmoment to be trampled under its feet, ran round the thistle\nagain; then the puppy began a series of short charges at the\nstick, running a very little way forwards each time and a long\nway back, and barking hoarsely all the while, till at last it sat\ndown a good way off, panting, with its tongue hanging out of its\nmouth, and its great eyes half shut.\n\n  This seemed to Alice a good opportunity for making her escape;\nso she set off at once, and ran till she was quite tired and out\nof breath, and till the puppy's bark sounded quite faint in the\ndistance.\n\n  `And yet what a dear little puppy it was!' said Alice, as she\nleant against a buttercup to rest herself, and fanned herself\nwith one of the leaves:  `I should have liked teaching it tricks\nvery much, if--if I'd only been the right size to do it!  Oh\ndear!  I'd nearly forgotten that I've got to grow up again!  Let\nme see--how IS it to be managed?  I suppose I ought to eat or\ndrink something or other; but the great question is, what?'\n\n  The great question certainly was, what?  Alice looked all round\nher at the flowers and the blades of grass, but she did not see\nanything that looked like the right thing to eat or drink under\nthe circumstances.  There was a large mushroom growing near her,\nabout the same height as herself; and when she had looked under\nit, and on both sides of it, and behind it, it occurred to her\nthat she might as well look and see what was on the top of it.\n\n  She stretched herself up on tiptoe, and peeped over the edge of\nthe mushroom, and her eyes immediately met those of a large\ncaterpillar, that was sitting on the top with its arms folded,\nquietly smoking a long hookah, and taking not the smallest notice\nof her or of anything else.\n\n\n\n                            CHAPTER V\n\n                    Advice from a Caterpillar\n\n\n  The Caterpillar and Alice looked at each other for some time in\nsilence:  at last the Caterpillar took the hookah out of its\nmouth, and addressed her in a languid, sleepy voice.\n\n  `Who are YOU?' said the Caterpillar.\n\n  This was not an encouraging opening for a conversation.  Alice\nreplied, rather shyly, `I--I hardly know, sir, just at present--\nat least I know who I WAS when I got up this morning, but I think\nI must have been changed several times since then.'\n\n  `What do you mean by that?' said the Caterpillar sternly.\n`Explain yourself!'\n\n  `I can't explain MYSELF, I'm afraid, sir' said Alice, `because\nI'm not myself, you see.'\n\n  `I don't see,' said the Caterpillar.\n\n  `I'm afraid I can't put it more clearly,' Alice replied very\npolitely, `for I can't understand it myself to begin with; and\nbeing so many different sizes in a day is very confusing.'\n\n  `It isn't,' said the Caterpillar.\n\n  `Well, perhaps you haven't found it so yet,' said Alice; `but\nwhen you have to turn into a chrysalis--you will some day, you\nknow--and then after that into a butterfly, I should think you'll\nfeel it a little queer, won't you?'\n\n  `Not a bit,' said the Caterpillar.\n\n  `Well, perhaps your feelings may be different,' said Alice;\n`all I know is, it would feel very queer to ME.'\n\n  `You!' said the Caterpillar contemptuously.  `Who are YOU?'\n\n  Which brought them back again to the beginning of the\nconversation.  Alice felt a little irritated at the Caterpillar's\nmaking such VERY short remarks, and she drew herself up and said,\nvery gravely, `I think, you ought to tell me who YOU are, first.'\n\n  `Why?' said the Caterpillar.\n\n  Here was another puzzling question; and as Alice could not\nthink of any good reason, and as the Caterpillar seemed to be in\na VERY unpleasant state of mind, she turned away.\n\n  `Come back!' the Caterpillar called after her.  `I've something\nimportant to say!'\n\n  This sounded promising, certainly:  Alice turned and came back\nagain.\n\n  `Keep your temper,' said the Caterpillar.\n\n  `Is that all?' said Alice, swallowing down her anger as well as\nshe could.\n\n  `No,' said the Caterpillar.\n\n  Alice thought she might as well wait, as she had nothing else\nto do, and perhaps after all it might tell her something worth\nhearing.  For some minutes it puffed away without speaking, but\nat last it unfolded its arms, took the hookah out of its mouth\nagain, and said, `So you think you're changed, do you?'\n\n  `I'm afraid I am, sir,' said Alice; `I can't remember things as\nI used--and I don't keep the same size for ten minutes together!'\n\n  `Can't remember WHAT things?' said the Caterpillar.\n\n  `Well, I've tried to say \"HOW DOTH THE LITTLE BUSY BEE,\" but it\nall came different!' Alice replied in a very melancholy voice.\n\n  `Repeat, \"YOU ARE OLD, FATHER WILLIAM,\"' said the Caterpillar.\n\n  Alice folded her hands, and began:--\n\n    `You are old, Father William,' the young man said,\n      `And your hair has become very white;\n    And yet you incessantly stand on your head--\n      Do you think, at your age, it is right?'\n\n    `In my youth,' Father William replied to his son,\n      `I feared it might injure the brain;\n    But, now that I'm perfectly sure I have none,\n      Why, I do it again and again.'\n\n    `You are old,' said the youth, `as I mentioned before,\n      And have grown most uncommonly fat;\n    Yet you turned a back-somersault in at the door--\n      Pray, what is the reason of that?'\n\n    `In my youth,' said the sage, as he shook his grey locks,\n      `I kept all my limbs very supple\n    By the use of this ointment--one shilling the box--\n      Allow me to sell you a couple?'\n\n    `You are old,' said the youth, `and your jaws are too weak\n      For anything tougher than suet;\n    Yet you finished the goose, with the bones and the beak--\n      Pray how did you manage to do it?'\n\n    `In my youth,' said his father, `I took to the law,\n      And argued each case with my wife;\n    And the muscular strength, which it gave to my jaw,\n      Has lasted the rest of my life.'\n\n    `You are old,' said the youth, `one would hardly suppose\n      That your eye was as steady as ever;\n    Yet you balanced an eel on the end of your nose--\n      What made you so awfully clever?'\n\n    `I have answered three questions, and that is enough,'\n      Said his father; `don't give yourself airs!\n    Do you think I can listen all day to such stuff?\n      Be off, or I'll kick you down stairs!'\n\n\n  `That is not said right,' said the Caterpillar.\n\n  `Not QUITE right, I'm afraid,' said Alice, timidly; `some of the\nwords have got altered.'\n\n  `It is wrong from beginning to end,' said the Caterpillar\ndecidedly, and there was silence for some minutes.\n\n  The Caterpillar was the first to speak.\n\n  `What size do you want to be?' it asked.\n\n  `Oh, I'm not particular as to size,' Alice hastily replied;\n`only one doesn't like changing so often, you know.'\n\n  `I DON'T know,' said the Caterpillar.\n\n  Alice said nothing:  she had never been so much contradicted in\nher life before, and she felt that she was losing her temper.\n\n  `Are you content now?' said the Caterpillar.\n\n  `Well, I should like to be a LITTLE larger, sir, if you\nwouldn't mind,' said Alice:  `three inches is such a wretched\nheight to be.'\n\n  `It is a very good height indeed!' said the Caterpillar\nangrily, rearing itself upright as it spoke (it was exactly three\ninches high).\n\n  `But I'm not used to it!' pleaded poor Alice in a piteous tone.\nAnd she thought of herself, `I wish the creatures wouldn't be so\neasily offended!'\n\n  `You'll get used to it in time,' said the Caterpillar; and it\nput the hookah into its mouth and began smoking again.\n\n  This time Alice waited patiently until it chose to speak again.\nIn a minute or two the Caterpillar took the hookah out of its\nmouth and yawned once or twice, and shook itself.  Then it got\ndown off the mushroom, and crawled away in the grass, merely\nremarking as it went, `One side will make you grow taller, and\nthe other side will make you grow shorter.'\n\n  `One side of WHAT?  The other side of WHAT?' thought Alice to\nherself.\n\n  `Of the mushroom,' said the Caterpillar, just as if she had\nasked it aloud; and in another moment it was out of sight.\n\n  Alice remained looking thoughtfully at the mushroom for a\nminute, trying to make out which were the two sides of it; and as\nit was perfectly round, she found this a very difficult question.\nHowever, at last she stretched her arms round it as far as they\nwould go, and broke off a bit of the edge with each hand.\n\n  `And now which is which?' she said to herself, and nibbled a\nlittle of the right-hand bit to try the effect:  the next moment\nshe felt a violent blow underneath her chin:  it had struck her\nfoot!\n\n  She was a good deal frightened by this very sudden change, but\nshe felt that there was no time to be lost, as she was shrinking\nrapidly; so she set to work at once to eat some of the other bit.\nHer chin was pressed so closely against her foot, that there was\nhardly room to open her mouth; but she did it at last, and\nmanaged to swallow a morsel of the lefthand bit.\n\n\n     *       *       *       *       *       *       *\n\n         *       *       *       *       *       *\n\n     *       *       *       *       *       *       *\n\n  `Come, my head's free at last!' said Alice in a tone of\ndelight, which changed into alarm in another moment, when she\nfound that her shoulders were nowhere to be found:  all she could\nsee, when she looked down, was an immense length of neck, which\nseemed to rise like a stalk out of a sea of green leaves that lay\nfar below her.\n\n  `What CAN all that green stuff be?' said Alice.  `And where\nHAVE my shoulders got to?  And oh, my poor hands, how is it I\ncan't see you?'  She was moving them about as she spoke, but no\nresult seemed to follow, except a little shaking among the\ndistant green leaves.\n\n  As there seemed to be no chance of getting her hands up to her\nhead, she tried to get her head down to them, and was delighted\nto find that her neck would bend about easily in any direction,\nlike a serpent.  She had just succeeded in curving it down into a\ngraceful zigzag, and was going to dive in among the leaves, which\nshe found to be nothing but the tops of the trees under which she\nhad been wandering, when a sharp hiss made her draw back in a\nhurry:  a large pigeon had flown into her face, and was beating\nher violently with its wings.\n\n  `Serpent!' screamed the Pigeon.\n\n  `I'm NOT a serpent!' said Alice indignantly.  `Let me alone!'\n\n  `Serpent, I say again!' repeated the Pigeon, but in a more\nsubdued tone, and added with a kind of sob, `I've tried every\nway, and nothing seems to suit them!'\n\n  `I haven't the least idea what you're talking about,' said\nAlice.\n\n  `I've tried the roots of trees, and I've tried banks, and I've\ntried hedges,' the Pigeon went on, without attending to her; `but\nthose serpents!  There's no pleasing them!'\n\n  Alice was more and more puzzled, but she thought there was no\nuse in saying anything more till the Pigeon had finished.\n\n  `As if it wasn't trouble enough hatching the eggs,' said the\nPigeon; `but I must be on the look-out for serpents night and\nday!  Why, I haven't had a wink of sleep these three weeks!'\n\n  `I'm very sorry you've been annoyed,' said Alice, who was\nbeginning to see its meaning.\n\n  `And just as I'd taken the highest tree in the wood,' continued\nthe Pigeon, raising its voice to a shriek, `and just as I was\nthinking I should be free of them at last, they must needs come\nwriggling down from the sky!  Ugh, Serpent!'\n\n  `But I'm NOT a serpent, I tell you!' said Alice.  `I'm a--I'm\na--'\n\n  `Well!  WHAT are you?' said the Pigeon.  `I can see you're\ntrying to invent something!'\n\n  `I--I'm a little girl,' said Alice, rather doubtfully, as she\nremembered the number of changes she had gone through that day.\n\n  `A likely story indeed!' said the Pigeon in a tone of the\ndeepest contempt.  `I've seen a good many little girls in my\ntime, but never ONE with such a neck as that!  No, no!  You're a\nserpent; and there's no use denying it.  I suppose you'll be\ntelling me next that you never tasted an egg!'\n\n  `I HAVE tasted eggs, certainly,' said Alice, who was a very\ntruthful child; `but little girls eat eggs quite as much as\nserpents do, you know.'\n\n  `I don't believe it,' said the Pigeon; `but if they do, why\nthen they're a kind of serpent, that's all I can say.'\n\n  This was such a new idea to Alice, that she was quite silent\nfor a minute or two, which gave the Pigeon the opportunity of\nadding, `You're looking for eggs, I know THAT well enough; and\nwhat does it matter to me whether you're a little girl or a\nserpent?'\n\n  `It matters a good deal to ME,' said Alice hastily; `but I'm\nnot looking for eggs, as it happens; and if I was, I shouldn't\nwant YOURS:  I don't like them raw.'\n\n  `Well, be off, then!' said the Pigeon in a sulky tone, as it\nsettled down again into its nest.  Alice crouched down among the\ntrees as well as she could, for her neck kept getting entangled\namong the branches, and every now and then she had to stop and\nuntwist it.  After a while she remembered that she still held the\npieces of mushroom in her hands, and she set to work very\ncarefully, nibbling first at one and then at the other, and\ngrowing sometimes taller and sometimes shorter, until she had\nsucceeded in bringing herself down to her usual height.\n\n  It was so long since she had been anything near the right size,\nthat it felt quite strange at first; but she got used to it in a\nfew minutes, and began talking to herself, as usual.  `Come,\nthere's half my plan done now!  How puzzling all these changes\nare!  I'm never sure what I'm going to be, from one minute to\nanother!  However, I've got back to my right size:  the next\nthing is, to get into that beautiful garden--how IS that to be\ndone, I wonder?'  As she said this, she came suddenly upon an\nopen place, with a little house in it about four feet high.\n`Whoever lives there,' thought Alice, `it'll never do to come\nupon them THIS size:  why, I should frighten them out of their\nwits!'  So she began nibbling at the righthand bit again, and did\nnot venture to go near the house till she had brought herself\ndown to nine inches high.\n\n\n\n                           CHAPTER VI\n\n                         Pig and Pepper\n\n\n  For a minute or two she stood looking at the house, and\nwondering what to do next, when suddenly a footman in livery came\nrunning out of the wood--(she considered him to be a footman\nbecause he was in livery:  otherwise, judging by his face only,\nshe would have called him a fish)--and rapped loudly at the door\nwith his knuckles.  It was opened by another footman in livery,\nwith a round face, and large eyes like a frog; and both footmen,\nAlice noticed, had powdered hair that curled all over their\nheads.  She felt very curious to know what it was all about, and\ncrept a little way out of the wood to listen.\n\n  The Fish-Footman began by producing from under his arm a great\nletter, nearly as large as himself, and this he handed over to\nthe other, saying, in a solemn tone, `For the Duchess.  An\ninvitation from the Queen to play croquet.'  The Frog-Footman\nrepeated, in the same solemn tone, only changing the order of the\nwords a little, `From the Queen.  An invitation for the Duchess\nto play croquet.'\n\n  Then they both bowed low, and their curls got entangled\ntogether.\n\n  Alice laughed so much at this, that she had to run back into\nthe wood for fear of their hearing her; and when she next peeped\nout the Fish-Footman was gone, and the other was sitting on the\nground near the door, staring stupidly up into the sky.\n\n  Alice went timidly up to the door, and knocked.\n\n  `There's no sort of use in knocking,' said the Footman, `and\nthat for two reasons.  First, because I'm on the same side of the\ndoor as you are; secondly, because they're making such a noise\ninside, no one could possibly hear you.'  And certainly there was\na most extraordinary noise going on within--a constant howling\nand sneezing, and every now and then a great crash, as if a dish\nor kettle had been broken to pieces.\n\n  `Please, then,' said Alice, `how am I to get in?'\n\n  `There might be some sense in your knocking,' the Footman went\non without attending to her, `if we had the door between us.  For\ninstance, if you were INSIDE, you might knock, and I could let\nyou out, you know.'  He was looking up into the sky all the time\nhe was speaking, and this Alice thought decidedly uncivil.  `But\nperhaps he can't help it,' she said to herself; `his eyes are so\nVERY nearly at the top of his head.  But at any rate he might\nanswer questions.--How am I to get in?' she repeated, aloud.\n\n  `I shall sit here,' the Footman remarked, `till tomorrow--'\n\n  At this moment the door of the house opened, and a large plate\ncame skimming out, straight at the Footman's head:  it just\ngrazed his nose, and broke to pieces against one of the trees\nbehind him.\n\n  `--or next day, maybe,' the Footman continued in the same tone,\nexactly as if nothing had happened.\n\n  `How am I to get in?' asked Alice again, in a louder tone.\n\n  `ARE you to get in at all?' said the Footman.  `That's the\nfirst question, you know.'\n\n  It was, no doubt:  only Alice did not like to be told so.\n`It's really dreadful,' she muttered to herself, `the way all the\ncreatures argue.  It's enough to drive one crazy!'\n\n  The Footman seemed to think this a good opportunity for\nrepeating his remark, with variations.  `I shall sit here,' he\nsaid, `on and off, for days and days.'\n\n  `But what am I to do?' said Alice.\n\n  `Anything you like,' said the Footman, and began whistling.\n\n  `Oh, there's no use in talking to him,' said Alice desperately:\n`he's perfectly idiotic!'  And she opened the door and went in.\n\n  The door led right into a large kitchen, which was full of\nsmoke from one end to the other:  the Duchess was sitting on a\nthree-legged stool in the middle, nursing a baby; the cook was\nleaning over the fire, stirring a large cauldron which seemed to\nbe full of soup.\n\n  `There's certainly too much pepper in that soup!' Alice said to\nherself, as well as she could for sneezing.\n\n  There was certainly too much of it in the air.  Even the\nDuchess sneezed occasionally; and as for the baby, it was\nsneezing and howling alternately without a moment's pause.  The\nonly things in the kitchen that did not sneeze, were the cook,\nand a large cat which was sitting on the hearth and grinning from\near to ear.\n\n  `Please would you tell me,' said Alice, a little timidly, for\nshe was not quite sure whether it was good manners for her to\nspeak first, `why your cat grins like that?'\n\n  `It's a Cheshire cat,' said the Duchess, `and that's why.\nPig!'\n\n  She said the last word with such sudden violence that Alice\nquite jumped; but she saw in another moment that it was addressed\nto the baby, and not to her, so she took courage, and went on\nagain:--\n\n  `I didn't know that Cheshire cats always grinned; in fact, I\ndidn't know that cats COULD grin.'\n\n  `They all can,' said the Duchess; `and most of 'em do.'\n\n  `I don't know of any that do,' Alice said very politely,\nfeeling quite pleased to have got into a conversation.\n\n  `You don't know much,' said the Duchess; `and that's a fact.'\n\n  Alice did not at all like the tone of this remark, and thought\nit would be as well to introduce some other subject of\nconversation.  While she was trying to fix on one, the cook took\nthe cauldron of soup off the fire, and at once set to work\nthrowing everything within her reach at the Duchess and the baby\n--the fire-irons came first; then followed a shower of saucepans,\nplates, and dishes.  The Duchess took no notice of them even when\nthey hit her; and the baby was howling so much already, that it\nwas quite impossible to say whether the blows hurt it or not.\n\n  `Oh, PLEASE mind what you're doing!' cried Alice, jumping up\nand down in an agony of terror.  `Oh, there goes his PRECIOUS\nnose'; as an unusually large saucepan flew close by it, and very\nnearly carried it off.\n\n  `If everybody minded their own business,' the Duchess said in a\nhoarse growl, `the world would go round a deal faster than it\ndoes.'\n\n  `Which would NOT be an advantage,' said Alice, who felt very\nglad to get an opportunity of showing off a little of her\nknowledge.  `Just think of what work it would make with the day\nand night!  You see the earth takes twenty-four hours to turn\nround on its axis--'\n\n  `Talking of axes,' said the Duchess, `chop off her head!'\n\n  Alice glanced rather anxiously at the cook, to see if she meant\nto take the hint; but the cook was busily stirring the soup, and\nseemed not to be listening, so she went on again:  `Twenty-four\nhours, I THINK; or is it twelve?  I--'\n\n  `Oh, don't bother ME,' said the Duchess; `I never could abide\nfigures!'  And with that she began nursing her child again,\nsinging a sort of lullaby to it as she did so, and giving it a\nviolent shake at the end of every line:\n\n        `Speak roughly to your little boy,\n          And beat him when he sneezes:\n        He only does it to annoy,\n          Because he knows it teases.'\n\n                    CHORUS.\n\n    (In which the cook and the baby joined):--\n\n                `Wow! wow! wow!'\n\n  While the Duchess sang the second verse of the song, she kept\ntossing the baby violently up and down, and the poor little thing\nhowled so, that Alice could hardly hear the words:--\n\n        `I speak severely to my boy,\n          I beat him when he sneezes;\n        For he can thoroughly enjoy\n          The pepper when he pleases!'\n\n                    CHORUS.\n\n                `Wow! wow! wow!'\n\n  `Here! you may nurse it a bit, if you like!' the Duchess said\nto Alice, flinging the baby at her as she spoke.  `I must go and\nget ready to play croquet with the Queen,' and she hurried out of\nthe room.  The cook threw a frying-pan after her as she went out,\nbut it just missed her.\n\n  Alice caught the baby with some difficulty, as it was a queer-\nshaped little creature, and held out its arms and legs in all\ndirections, `just like a star-fish,' thought Alice.  The poor\nlittle thing was snorting like a steam-engine when she caught it,\nand kept doubling itself up and straightening itself out again,\nso that altogether, for the first minute or two, it was as much\nas she could do to hold it.\n\n  As soon as she had made out the proper way of nursing it,\n(which was to twist it up into a sort of knot, and then keep\ntight hold of its right ear and left foot, so as to prevent its\nundoing itself,) she carried it out into the open air.  `IF I\ndon't take this child away with me,' thought Alice, `they're sure\nto kill it in a day or two:  wouldn't it be murder to leave it\nbehind?'  She said the last words out loud, and the little thing\ngrunted in reply (it had left off sneezing by this time).  `Don't\ngrunt,' said Alice; `that's not at all a proper way of expressing\nyourself.'\n\n  The baby grunted again, and Alice looked very anxiously into\nits face to see what was the matter with it.  There could be no\ndoubt that it had a VERY turn-up nose, much more like a snout\nthan a real nose; also its eyes were getting extremely small for\na baby:  altogether Alice did not like the look of the thing at\nall.  `But perhaps it was only sobbing,' she thought, and looked\ninto its eyes again, to see if there were any tears.\n\n  No, there were no tears.  `If you're going to turn into a pig,\nmy dear,' said Alice, seriously, `I'll have nothing more to do\nwith you.  Mind now!'  The poor little thing sobbed again (or\ngrunted, it was impossible to say which), and they went on for\nsome while in silence.\n\n  Alice was just beginning to think to herself, `Now, what am I\nto do with this creature when I get it home?' when it grunted\nagain, so violently, that she looked down into its face in some\nalarm.  This time there could be NO mistake about it:  it was\nneither more nor less than a pig, and she felt that it would be\nquite absurd for her to carry it further.\n\n  So she set the little creature down, and felt quite relieved to\nsee it trot away quietly into the wood.  `If it had grown up,'\nshe said to herself, `it would have made a dreadfully ugly child:\nbut it makes rather a handsome pig, I think.'  And she began\nthinking over other children she knew, who might do very well as\npigs, and was just saying to herself, `if one only knew the right\nway to change them--' when she was a little startled by seeing\nthe Cheshire Cat sitting on a bough of a tree a few yards off.\n\n  The Cat only grinned when it saw Alice.  It looked good-\nnatured, she thought:  still it had VERY long claws and a great\nmany teeth, so she felt that it ought to be treated with respect.\n\n  `Cheshire Puss,' she began, rather timidly, as she did not at\nall know whether it would like the name:  however, it only\ngrinned a little wider.  `Come, it's pleased so far,' thought\nAlice, and she went on.  `Would you tell me, please, which way I\nought to go from here?'\n\n  `That depends a good deal on where you want to get to,' said\nthe Cat.\n\n  `I don't much care where--' said Alice.\n\n  `Then it doesn't matter which way you go,' said the Cat.\n\n  `--so long as I get SOMEWHERE,' Alice added as an explanation.\n\n  `Oh, you're sure to do that,' said the Cat, `if you only walk\nlong enough.'\n\n  Alice felt that this could not be denied, so she tried another\nquestion.  `What sort of people live about here?'\n\n  `In THAT direction,' the Cat said, waving its right paw round,\n`lives a Hatter:  and in THAT direction,' waving the other paw,\n`lives a March Hare.  Visit either you like:  they're both mad.'\n\n  `But I don't want to go among mad people,' Alice remarked.\n\n  `Oh, you can't help that,' said the Cat:  `we're all mad here.\nI'm mad.  You're mad.'\n\n  `How do you know I'm mad?' said Alice.\n\n  `You must be,' said the Cat, `or you wouldn't have come here.'\n\n  Alice didn't think that proved it at all; however, she went on\n`And how do you know that you're mad?'\n\n  `To begin with,' said the Cat, `a dog's not mad.  You grant\nthat?'\n\n  `I suppose so,' said Alice.\n\n  `Well, then,' the Cat went on, `you see, a dog growls when it's\nangry, and wags its tail when it's pleased.  Now I growl when I'm\npleased, and wag my tail when I'm angry.  Therefore I'm mad.'\n\n  `I call it purring, not growling,' said Alice.\n\n  `Call it what you like,' said the Cat.  `Do you play croquet\nwith the Queen to-day?'\n\n  `I should like it very much,' said Alice, `but I haven't been\ninvited yet.'\n\n  `You'll see me there,' said the Cat, and vanished.\n\n  Alice was not much surprised at this, she was getting so used\nto queer things happening.  While she was looking at the place\nwhere it had been, it suddenly appeared again.\n\n  `By-the-bye, what became of the baby?' said the Cat.  `I'd\nnearly forgotten to ask.'\n\n  `It turned into a pig,' Alice quietly said, just as if it had\ncome back in a natural way.\n\n  `I thought it would,' said the Cat, and vanished again.\n\n  Alice waited a little, half expecting to see it again, but it\ndid not appear, and after a minute or two she walked on in the\ndirection in which the March Hare was said to live.  `I've seen\nhatters before,' she said to herself; `the March Hare will be\nmuch the most interesting, and perhaps as this is May it won't be\nraving mad--at least not so mad as it was in March.'  As she said\nthis, she looked up, and there was the Cat again, sitting on a\nbranch of a tree.\n\n  `Did you say pig, or fig?' said the Cat.\n\n  `I said pig,' replied Alice; `and I wish you wouldn't keep\nappearing and vanishing so suddenly:  you make one quite giddy.'\n\n  `All right,' said the Cat; and this time it vanished quite\nslowly, beginning with the end of the tail, and ending with the\ngrin, which remained some time after the rest of it had gone.\n\n  `Well!  I've often seen a cat without a grin,' thought Alice;\n`but a grin without a cat!  It's the most curious thing I ever\nsay in my life!'\n\n  She had not gone much farther before she came in sight of the\nhouse of the March Hare:  she thought it must be the right house,\nbecause the chimneys were shaped like ears and the roof was\nthatched with fur.  It was so large a house, that she did not\nlike to go nearer till she had nibbled some more of the lefthand\nbit of mushroom, and raised herself to about two feet high:  even\nthen she walked up towards it rather timidly, saying to herself\n`Suppose it should be raving mad after all!  I almost wish I'd\ngone to see the Hatter instead!'\n\n\n\n                           CHAPTER VII\n\n                         A Mad Tea-Party\n\n\n  There was a table set out under a tree in front of the house,\nand the March Hare and the Hatter were having tea at it:  a\nDormouse was sitting between them, fast asleep, and the other two\nwere using it as a cushion, resting their elbows on it, and the\ntalking over its head.  `Very uncomfortable for the Dormouse,'\nthought Alice; `only, as it's asleep, I suppose it doesn't mind.'\n\n  The table was a large one, but the three were all crowded\ntogether at one corner of it:  `No room!  No room!' they cried\nout when they saw Alice coming.  `There's PLENTY of room!' said\nAlice indignantly, and she sat down in a large arm-chair at one\nend of the table.\n\n  `Have some wine,' the March Hare said in an encouraging tone.\n\n  Alice looked all round the table, but there was nothing on it\nbut tea.  `I don't see any wine,' she remarked.\n\n  `There isn't any,' said the March Hare.\n\n  `Then it wasn't very civil of you to offer it,' said Alice\nangrily.\n\n  `It wasn't very civil of you to sit down without being\ninvited,' said the March Hare.\n\n  `I didn't know it was YOUR table,' said Alice; `it's laid for a\ngreat many more than three.'\n\n  `Your hair wants cutting,' said the Hatter.  He had been\nlooking at Alice for some time with great curiosity, and this was\nhis first speech.\n\n  `You should learn not to make personal remarks,' Alice said\nwith some severity; `it's very rude.'\n\n  The Hatter opened his eyes very wide on hearing this; but all\nhe SAID was, `Why is a raven like a writing-desk?'\n\n  `Come, we shall have some fun now!' thought Alice.  `I'm glad\nthey've begun asking riddles.--I believe I can guess that,' she\nadded aloud.\n\n  `Do you mean that you think you can find out the answer to it?'\nsaid the March Hare.\n\n  `Exactly so,' said Alice.\n\n  `Then you should say what you mean,' the March Hare went on.\n\n  `I do,' Alice hastily replied; `at least--at least I mean what\nI say--that's the same thing, you know.'\n\n  `Not the same thing a bit!' said the Hatter.  `You might just\nas well say that \"I see what I eat\" is the same thing as \"I eat\nwhat I see\"!'\n\n  `You might just as well say,' added the March Hare, `that \"I\nlike what I get\" is the same thing as \"I get what I like\"!'\n\n  `You might just as well say,' added the Dormouse, who seemed to\nbe talking in his sleep, `that \"I breathe when I sleep\" is the\nsame thing as \"I sleep when I breathe\"!'\n\n  `It IS the same thing with you,' said the Hatter, and here the\nconversation dropped, and the party sat silent for a minute,\nwhile Alice thought over all she could remember about ravens and\nwriting-desks, which wasn't much.\n\n  The Hatter was the first to break the silence.  `What day of\nthe month is it?' he said, turning to Alice:  he had taken his\nwatch out of his pocket, and was looking at it uneasily, shaking\nit every now and then, and holding it to his ear.\n\n  Alice considered a little, and then said `The fourth.'\n\n  `Two days wrong!' sighed the Hatter.  `I told you butter\nwouldn't suit the works!' he added looking angrily at the March\nHare.\n\n  `It was the BEST butter,' the March Hare meekly replied.\n\n  `Yes, but some crumbs must have got in as well,' the Hatter\ngrumbled:  `you shouldn't have put it in with the bread-knife.'\n\n  The March Hare took the watch and looked at it gloomily:  then\nhe dipped it into his cup of tea, and looked at it again:  but he\ncould think of nothing better to say than his first remark, `It\nwas the BEST butter, you know.'\n\n  Alice had been looking over his shoulder with some curiosity.\n`What a funny watch!' she remarked.  `It tells the day of the\nmonth, and doesn't tell what o'clock it is!'\n\n  `Why should it?' muttered the Hatter.  `Does YOUR watch tell\nyou what year it is?'\n\n  `Of course not,' Alice replied very readily:  `but that's\nbecause it stays the same year for such a long time together.'\n\n  `Which is just the case with MINE,' said the Hatter.\n\n  Alice felt dreadfully puzzled.  The Hatter's remark seemed to\nhave no sort of meaning in it, and yet it was certainly English.\n`I don't quite understand you,' she said, as politely as she\ncould.\n\n  `The Dormouse is asleep again,' said the Hatter, and he poured\na little hot tea upon its nose.\n\n  The Dormouse shook its head impatiently, and said, without\nopening its eyes, `Of course, of course; just what I was going to\nremark myself.'\n\n  `Have you guessed the riddle yet?' the Hatter said, turning to\nAlice again.\n\n  `No, I give it up,' Alice replied:  `what's the answer?'\n\n  `I haven't the slightest idea,' said the Hatter.\n\n  `Nor I,' said the March Hare.\n\n  Alice sighed wearily.  `I think you might do something better\nwith the time,' she said, `than waste it in asking riddles that\nhave no answers.'\n\n  `If you knew Time as well as I do,' said the Hatter, `you\nwouldn't talk about wasting IT.  It's HIM.'\n\n  `I don't know what you mean,' said Alice.\n\n  `Of course you don't!' the Hatter said, tossing his head\ncontemptuously.  `I dare say you never even spoke to Time!'\n\n  `Perhaps not,' Alice cautiously replied:  `but I know I have to\nbeat time when I learn music.'\n\n  `Ah! that accounts for it,' said the Hatter.  `He won't stand\nbeating.  Now, if you only kept on good terms with him, he'd do\nalmost anything you liked with the clock.  For instance, suppose\nit were nine o'clock in the morning, just time to begin lessons:\nyou'd only have to whisper a hint to Time, and round goes the\nclock in a twinkling!  Half-past one, time for dinner!'\n\n  (`I only wish it was,' the March Hare said to itself in a\nwhisper.)\n\n  `That would be grand, certainly,' said Alice thoughtfully:\n`but then--I shouldn't be hungry for it, you know.'\n\n  `Not at first, perhaps,' said the Hatter:  `but you could keep\nit to half-past one as long as you liked.'\n\n  `Is that the way YOU manage?' Alice asked.\n\n  The Hatter shook his head mournfully.  `Not I!' he replied.\n`We quarrelled last March--just before HE went mad, you know--'\n(pointing with his tea spoon at the March Hare,) `--it was at the\ngreat concert given by the Queen of Hearts, and I had to sing\n\n            \"Twinkle, twinkle, little bat!\n            How I wonder what you're at!\"\n\nYou know the song, perhaps?'\n\n  `I've heard something like it,' said Alice.\n\n  `It goes on, you know,' the Hatter continued, `in this way:--\n\n            \"Up above the world you fly,\n            Like a tea-tray in the sky.\n                    Twinkle, twinkle--\"'\n\nHere the Dormouse shook itself, and began singing in its sleep\n`Twinkle, twinkle, twinkle, twinkle--' and went on so long that\nthey had to pinch it to make it stop.\n\n  `Well, I'd hardly finished the first verse,' said the Hatter,\n`when the Queen jumped up and bawled out, \"He's murdering the\ntime!  Off with his head!\"'\n\n  `How dreadfully savage!' exclaimed Alice.\n\n  `And ever since that,' the Hatter went on in a mournful tone,\n`he won't do a thing I ask!  It's always six o'clock now.'\n\n  A bright idea came into Alice's head.  `Is that the reason so\nmany tea-things are put out here?' she asked.\n\n  `Yes, that's it,' said the Hatter with a sigh:  `it's always\ntea-time, and we've no time to wash the things between whiles.'\n\n  `Then you keep moving round, I suppose?' said Alice.\n\n  `Exactly so,' said the Hatter:  `as the things get used up.'\n\n  `But what happens when you come to the beginning again?' Alice\nventured to ask.\n\n  `Suppose we change the subject,' the March Hare interrupted,\nyawning.  `I'm getting tired of this.  I vote the young lady\ntells us a story.'\n\n  `I'm afraid I don't know one,' said Alice, rather alarmed at\nthe proposal.\n\n  `Then the Dormouse shall!' they both cried.  `Wake up,\nDormouse!'  And they pinched it on both sides at once.\n\n  The Dormouse slowly opened his eyes.  `I wasn't asleep,' he\nsaid in a hoarse, feeble voice:  `I heard every word you fellows\nwere saying.'\n\n  `Tell us a story!' said the March Hare.\n\n  `Yes, please do!' pleaded Alice.\n\n  `And be quick about it,' added the Hatter, `or you'll be asleep\nagain before it's done.'\n\n  `Once upon a time there were three little sisters,' the\nDormouse began in a great hurry; `and their names were Elsie,\nLacie, and Tillie; and they lived at the bottom of a well--'\n\n  `What did they live on?' said Alice, who always took a great\ninterest in questions of eating and drinking.\n\n  `They lived on treacle,' said the Dormouse, after thinking a\nminute or two.\n\n  `They couldn't have done that, you know,' Alice gently\nremarked; `they'd have been ill.'\n\n  `So they were,' said the Dormouse; `VERY ill.'\n\n  Alice tried to fancy to herself what such an extraordinary ways\nof living would be like, but it puzzled her too much, so she went\non:  `But why did they live at the bottom of a well?'\n\n  `Take some more tea,' the March Hare said to Alice, very\nearnestly.\n\n  `I've had nothing yet,' Alice replied in an offended tone, `so\nI can't take more.'\n\n  `You mean you can't take LESS,' said the Hatter:  `it's very\neasy to take MORE than nothing.'\n\n  `Nobody asked YOUR opinion,' said Alice.\n\n  `Who's making personal remarks now?' the Hatter asked\ntriumphantly.\n\n  Alice did not quite know what to say to this:  so she helped\nherself to some tea and bread-and-butter, and then turned to the\nDormouse, and repeated her question.  `Why did they live at the\nbottom of a well?'\n\n  The Dormouse again took a minute or two to think about it, and\nthen said, `It was a treacle-well.'\n\n  `There's no such thing!'  Alice was beginning very angrily, but\nthe Hatter and the March Hare went `Sh! sh!' and the Dormouse\nsulkily remarked, `If you can't be civil, you'd better finish the\nstory for yourself.'\n\n  `No, please go on!' Alice said very humbly; `I won't interrupt\nagain.  I dare say there may be ONE.'\n\n  `One, indeed!' said the Dormouse indignantly.  However, he\nconsented to go on.  `And so these three little sisters--they\nwere learning to draw, you know--'\n\n  `What did they draw?' said Alice, quite forgetting her promise.\n\n  `Treacle,' said the Dormouse, without considering at all this\ntime.\n\n  `I want a clean cup,' interrupted the Hatter:  `let's all move\none place on.'\n\n  He moved on as he spoke, and the Dormouse followed him:  the\nMarch Hare moved into the Dormouse's place, and Alice rather\nunwillingly took the place of the March Hare.  The Hatter was the\nonly one who got any advantage from the change:  and Alice was a\ngood deal worse off than before, as the March Hare had just upset\nthe milk-jug into his plate.\n\n  Alice did not wish to offend the Dormouse again, so she began\nvery cautiously:  `But I don't understand.  Where did they draw\nthe treacle from?'\n\n  `You can draw water out of a water-well,' said the Hatter; `so\nI should think you could draw treacle out of a treacle-well--eh,\nstupid?'\n\n  `But they were IN the well,' Alice said to the Dormouse, not\nchoosing to notice this last remark.\n\n  `Of course they were', said the Dormouse; `--well in.'\n\n  This answer so confused poor Alice, that she let the Dormouse\ngo on for some time without interrupting it.\n\n  `They were learning to draw,' the Dormouse went on, yawning and\nrubbing its eyes, for it was getting very sleepy; `and they drew\nall manner of things--everything that begins with an M--'\n\n  `Why with an M?' said Alice.\n\n  `Why not?' said the March Hare.\n\n  Alice was silent.\n\n  The Dormouse had closed its eyes by this time, and was going\noff into a doze; but, on being pinched by the Hatter, it woke up\nagain with a little shriek, and went on:  `--that begins with an\nM, such as mouse-traps, and the moon, and memory, and muchness--\nyou know you say things are \"much of a muchness\"--did you ever\nsee such a thing as a drawing of a muchness?'\n\n  `Really, now you ask me,' said Alice, very much confused, `I\ndon't think--'\n\n  `Then you shouldn't talk,' said the Hatter.\n\n  This piece of rudeness was more than Alice could bear:  she got\nup in great disgust, and walked off; the Dormouse fell asleep\ninstantly, and neither of the others took the least notice of her\ngoing, though she looked back once or twice, half hoping that\nthey would call after her:  the last time she saw them, they were\ntrying to put the Dormouse into the teapot.\n\n  `At any rate I'll never go THERE again!' said Alice as she\npicked her way through the wood.  `It's the stupidest tea-party I\never was at in all my life!'\n\n  Just as she said this, she noticed that one of the trees had a\ndoor leading right into it.  `That's very curious!' she thought.\n`But everything's curious today.  I think I may as well go in at\nonce.'  And in she went.\n\n  Once more she found herself in the long hall, and close to the\nlittle glass table.  `Now, I'll manage better this time,' she\nsaid to herself, and began by taking the little golden key, and\nunlocking the door that led into the garden.  Then she went to\nwork nibbling at the mushroom (she had kept a piece of it in her\npocked) till she was about a foot high:  then she walked down the\nlittle passage:  and THEN--she found herself at last in the\nbeautiful garden, among the bright flower-beds and the cool\nfountains.\n\n\n\n                          CHAPTER VIII\n\n                   The Queen's Croquet-Ground\n\n\n  A large rose-tree stood near the entrance of the garden:  the\nroses growing on it were white, but there were three gardeners at\nit, busily painting them red.  Alice thought this a very curious\nthing, and she went nearer to watch them, and just as she came up\nto them she heard one of them say, `Look out now, Five!  Don't go\nsplashing paint over me like that!'\n\n  `I couldn't help it,' said Five, in a sulky tone; `Seven jogged\nmy elbow.'\n\n  On which Seven looked up and said, `That's right, Five!  Always\nlay the blame on others!'\n\n  `YOU'D better not talk!' said Five.  `I heard the Queen say only\nyesterday you deserved to be beheaded!'\n\n  `What for?' said the one who had spoken first.\n\n  `That's none of YOUR business, Two!' said Seven.\n\n  `Yes, it IS his business!' said Five, `and I'll tell him--it\nwas for bringing the cook tulip-roots instead of onions.'\n\n  Seven flung down his brush, and had just begun `Well, of all\nthe unjust things--' when his eye chanced to fall upon Alice, as\nshe stood watching them, and he checked himself suddenly:  the\nothers looked round also, and all of them bowed low.\n\n  `Would you tell me,' said Alice, a little timidly, `why you are\npainting those roses?'\n\n  Five and Seven said nothing, but looked at Two.  Two began in a\nlow voice, `Why the fact is, you see, Miss, this here ought to\nhave been a RED rose-tree, and we put a white one in by mistake;\nand if the Queen was to find it out, we should all have our heads\ncut off, you know.  So you see, Miss, we're doing our best, afore\nshe comes, to--'  At this moment Five, who had been anxiously\nlooking across the garden, called out `The Queen!  The Queen!'\nand the three gardeners instantly threw themselves flat upon\ntheir faces.  There was a sound of many footsteps, and Alice\nlooked round, eager to see the Queen.\n\n  First came ten soldiers carrying clubs; these were all shaped\nlike the three gardeners, oblong and flat, with their hands and\nfeet at the corners:  next the ten courtiers; these were\nornamented all over with diamonds, and walked two and two, as the\nsoldiers did.  After these came the royal children; there were\nten of them, and the little dears came jumping merrily along hand\nin hand, in couples:  they were all ornamented with hearts.  Next\ncame the guests, mostly Kings and Queens, and among them Alice\nrecognised the White Rabbit:  it was talking in a hurried nervous\nmanner, smiling at everything that was said, and went by without\nnoticing her.  Then followed the Knave of Hearts, carrying the\nKing's crown on a crimson velvet cushion; and, last of all this\ngrand procession, came THE KING AND QUEEN OF HEARTS.\n\n  Alice was rather doubtful whether she ought not to lie down on\nher face like the three gardeners, but she could not remember\nevery having heard of such a rule at processions; `and besides,\nwhat would be the use of a procession,' thought she, `if people\nhad all to lie down upon their faces, so that they couldn't see\nit?'  So she stood still where she was, and waited.\n\n  When the procession came opposite to Alice, they all stopped\nand looked at her, and the Queen said severely `Who is this?'\nShe said it to the Knave of Hearts, who only bowed and smiled in\nreply.\n\n  `Idiot!' said the Queen, tossing her head impatiently; and,\nturning to Alice, she went on, `What's your name, child?'\n\n  `My name is Alice, so please your Majesty,' said Alice very\npolitely; but she added, to herself, `Why, they're only a pack of\ncards, after all.  I needn't be afraid of them!'\n\n  `And who are THESE?' said the Queen, pointing to the three\ngardeners who were lying round the rosetree; for, you see, as\nthey were lying on their faces, and the pattern on their backs\nwas the same as the rest of the pack, she could not tell whether\nthey were gardeners, or soldiers, or courtiers, or three of her\nown children.\n\n  `How should I know?' said Alice, surprised at her own courage.\n`It's no business of MINE.'\n\n  The Queen turned crimson with fury, and, after glaring at her\nfor a moment like a wild beast, screamed `Off with her head!\nOff--'\n\n  `Nonsense!' said Alice, very loudly and decidedly, and the\nQueen was silent.\n\n  The King laid his hand upon her arm, and timidly said\n`Consider, my dear:  she is only a child!'\n\n  The Queen turned angrily away from him, and said to the Knave\n`Turn them over!'\n\n  The Knave did so, very carefully, with one foot.\n\n  `Get up!' said the Queen, in a shrill, loud voice, and the\nthree gardeners instantly jumped up, and began bowing to the\nKing, the Queen, the royal children, and everybody else.\n\n  `Leave off that!' screamed the Queen.  `You make me giddy.'\nAnd then, turning to the rose-tree, she went on, `What HAVE you\nbeen doing here?'\n\n  `May it please your Majesty,' said Two, in a very humble tone,\ngoing down on one knee as he spoke, `we were trying--'\n\n  `I see!' said the Queen, who had meanwhile been examining the\nroses.  `Off with their heads!' and the procession moved on,\nthree of the soldiers remaining behind to execute the unfortunate\ngardeners, who ran to Alice for protection.\n\n  `You shan't be beheaded!' said Alice, and she put them into a\nlarge flower-pot that stood near.  The three soldiers wandered\nabout for a minute or two, looking for them, and then quietly\nmarched off after the others.\n\n  `Are their heads off?' shouted the Queen.\n\n  `Their heads are gone, if it please your Majesty!' the soldiers\nshouted in reply.\n\n  `That's right!' shouted the Queen.  `Can you play croquet?'\n\n  The soldiers were silent, and looked at Alice, as the question\nwas evidently meant for her.\n\n  `Yes!' shouted Alice.\n\n  `Come on, then!' roared the Queen, and Alice joined the\nprocession, wondering very much what would happen next.\n\n  `It's--it's a very fine day!' said a timid voice at her side.\nShe was walking by the White Rabbit, who was peeping anxiously\ninto her face.\n\n  `Very,' said Alice:  `--where's the Duchess?'\n\n  `Hush!  Hush!' said the Rabbit in a low, hurried tone.  He\nlooked anxiously over his shoulder as he spoke, and then raised\nhimself upon tiptoe, put his mouth close to her ear, and\nwhispered `She's under sentence of execution.'\n\n  `What for?' said Alice.\n\n  `Did you say \"What a pity!\"?' the Rabbit asked.\n\n  `No, I didn't,' said Alice:  `I don't think it's at all a pity.\nI said \"What for?\"'\n\n  `She boxed the Queen's ears--' the Rabbit began.  Alice gave a\nlittle scream of laughter.  `Oh, hush!' the Rabbit whispered in a\nfrightened tone.  `The Queen will hear you!  You see, she came\nrather late, and the Queen said--'\n\n  `Get to your places!' shouted the Queen in a voice of thunder,\nand people began running about in all directions, tumbling up\nagainst each other; however, they got settled down in a minute or\ntwo, and the game began.  Alice thought she had never seen such a\ncurious croquet-ground in her life; it was all ridges and\nfurrows; the balls were live hedgehogs, the mallets live\nflamingoes, and the soldiers had to double themselves up and to\nstand on their hands and feet, to make the arches.\n\n  The chief difficulty Alice found at first was in managing her\nflamingo:  she succeeded in getting its body tucked away,\ncomfortably enough, under her arm, with its legs hanging down,\nbut generally, just as she had got its neck nicely straightened\nout, and was going to give the hedgehog a blow with its head, it\nWOULD twist itself round and look up in her face, with such a\npuzzled expression that she could not help bursting out laughing:\nand when she had got its head down, and was going to begin again,\nit was very provoking to find that the hedgehog had unrolled\nitself, and was in the act of crawling away:  besides all this,\nthere was generally a ridge or furrow in the way wherever she\nwanted to send the hedgehog to, and, as the doubled-up soldiers\nwere always getting up and walking off to other parts of the\nground, Alice soon came to the conclusion that it was a very\ndifficult game indeed.\n\n  The players all played at once without waiting for turns,\nquarrelling all the while, and fighting for the hedgehogs; and in\na very short time the Queen was in a furious passion, and went\nstamping about, and shouting `Off with his head!' or `Off with\nher head!' about once in a minute.\n\n  Alice began to feel very uneasy:  to be sure, she had not as\nyet had any dispute with the Queen, but she knew that it might\nhappen any minute, `and then,' thought she, `what would become of\nme?  They're dreadfully fond of beheading people here; the great\nwonder is, that there's any one left alive!'\n\n  She was looking about for some way of escape, and wondering\nwhether she could get away without being seen, when she noticed a\ncurious appearance in the air:  it puzzled her very much at\nfirst, but, after watching it a minute or two, she made it out to\nbe a grin, and she said to herself `It's the Cheshire Cat:  now I\nshall have somebody to talk to.'\n\n  `How are you getting on?' said the Cat, as soon as there was\nmouth enough for it to speak with.\n\n  Alice waited till the eyes appeared, and then nodded.  `It's no\nuse speaking to it,' she thought, `till its ears have come, or at\nleast one of them.'  In another minute the whole head appeared,\nand then Alice put down her flamingo, and began an account of the\ngame, feeling very glad she had someone to listen to her.  The\nCat seemed to think that there was enough of it now in sight, and\nno more of it appeared.\n\n  `I don't think they play at all fairly,' Alice began, in rather\na complaining tone, `and they all quarrel so dreadfully one can't\nhear oneself speak--and they don't seem to have any rules in\nparticular; at least, if there are, nobody attends to them--and\nyou've no idea how confusing it is all the things being alive;\nfor instance, there's the arch I've got to go through next\nwalking about at the other end of the ground--and I should have\ncroqueted the Queen's hedgehog just now, only it ran away when it\nsaw mine coming!'\n\n  `How do you like the Queen?' said the Cat in a low voice.\n\n  `Not at all,' said Alice:  `she's so extremely--'  Just then\nshe noticed that the Queen was close behind her, listening:  so\nshe went on, `--likely to win, that it's hardly worth while\nfinishing the game.'\n\n  The Queen smiled and passed on.\n\n  `Who ARE you talking to?' said the King, going up to Alice, and\nlooking at the Cat's head with great curiosity.\n\n  `It's a friend of mine--a Cheshire Cat,' said Alice:  `allow me\nto introduce it.'\n\n  `I don't like the look of it at all,' said the King:  `however,\nit may kiss my hand if it likes.'\n\n  `I'd rather not,' the Cat remarked.\n\n  `Don't be impertinent,' said the King, `and don't look at me\nlike that!'  He got behind Alice as he spoke.\n\n  `A cat may look at a king,' said Alice.  `I've read that in\nsome book, but I don't remember where.'\n\n  `Well, it must be removed,' said the King very decidedly, and\nhe called the Queen, who was passing at the moment, `My dear!  I\nwish you would have this cat removed!'\n\n  The Queen had only one way of settling all difficulties, great\nor small.  `Off with his head!' she said, without even looking\nround.\n\n  `I'll fetch the executioner myself,' said the King eagerly, and\nhe hurried off.\n\n  Alice thought she might as well go back, and see how the game\nwas going on, as she heard the Queen's voice in the distance,\nscreaming with passion.  She had already heard her sentence three\nof the players to be executed for having missed their turns, and\nshe did not like the look of things at all, as the game was in\nsuch confusion that she never knew whether it was her turn or\nnot.  So she went in search of her hedgehog.\n\n  The hedgehog was engaged in a fight with another hedgehog,\nwhich seemed to Alice an excellent opportunity for croqueting one\nof them with the other:  the only difficulty was, that her\nflamingo was gone across to the other side of the garden, where\nAlice could see it trying in a helpless sort of way to fly up\ninto a tree.\n\n  By the time she had caught the flamingo and brought it back,\nthe fight was over, and both the hedgehogs were out of sight:\n`but it doesn't matter much,' thought Alice, `as all the arches\nare gone from this side of the ground.'  So she tucked it away\nunder her arm, that it might not escape again, and went back for\na little more conversation with her friend.\n\n  When she got back to the Cheshire Cat, she was surprised to\nfind quite a large crowd collected round it:  there was a dispute\ngoing on between the executioner, the King, and the Queen, who\nwere all talking at once, while all the rest were quite silent,\nand looked very uncomfortable.\n\n  The moment Alice appeared, she was appealed to by all three to\nsettle the question, and they repeated their arguments to her,\nthough, as they all spoke at once, she found it very hard indeed\nto make out exactly what they said.\n\n  The executioner's argument was, that you couldn't cut off a\nhead unless there was a body to cut it off from:  that he had\nnever had to do such a thing before, and he wasn't going to begin\nat HIS time of life.\n\n  The King's argument was, that anything that had a head could be\nbeheaded, and that you weren't to talk nonsense.\n\n  The Queen's argument was, that if something wasn't done about\nit in less than no time she'd have everybody executed, all round.\n(It was this last remark that had made the whole party look so\ngrave and anxious.)\n\n  Alice could think of nothing else to say but `It belongs to the\nDuchess:  you'd better ask HER about it.'\n\n  `She's in prison,' the Queen said to the executioner:  `fetch\nher here.'  And the executioner went off like an arrow.\n\n   The Cat's head began fading away the moment he was gone, and,\nby the time he had come back with the Dutchess, it had entirely\ndisappeared; so the King and the executioner ran wildly up and\ndown looking for it, while the rest of the party went back to the game.\n\n\n\n                           CHAPTER IX\n\n                     The Mock Turtle's Story\n\n\n  `You can't think how glad I am to see you again, you dear old\nthing!' said the Duchess, as she tucked her arm affectionately\ninto Alice's, and they walked off together.\n\n  Alice was very glad to find her in such a pleasant temper, and\nthought to herself that perhaps it was only the pepper that had\nmade her so savage when they met in the kitchen.\n\n  `When I'M a Duchess,' she said to herself, (not in a very\nhopeful tone though), `I won't have any pepper in my kitchen AT\nALL.  Soup does very well without--Maybe it's always pepper that\nmakes people hot-tempered,' she went on, very much pleased at\nhaving found out a new kind of rule, `and vinegar that makes them\nsour--and camomile that makes them bitter--and--and barley-sugar\nand such things that make children sweet-tempered.  I only wish\npeople knew that:  then they wouldn't be so stingy about it, you\nknow--'\n\n  She had quite forgotten the Duchess by this time, and was a\nlittle startled when she heard her voice close to her ear.\n`You're thinking about something, my dear, and that makes you\nforget to talk.  I can't tell you just now what the moral of that\nis, but I shall remember it in a bit.'\n\n  `Perhaps it hasn't one,' Alice ventured to remark.\n\n  `Tut, tut, child!' said the Duchess.  `Everything's got a\nmoral, if only you can find it.'  And she squeezed herself up\ncloser to Alice's side as she spoke.\n\n  Alice did not much like keeping so close to her:  first,\nbecause the Duchess was VERY ugly; and secondly, because she was\nexactly the right height to rest her chin upon Alice's shoulder,\nand it was an uncomfortably sharp chin.  However, she did not\nlike to be rude, so she bore it as well as she could.\n\n  `The game's going on rather better now,' she said, by way of\nkeeping up the conversation a little.\n\n  `'Tis so,' said the Duchess:  `and the moral of that is--\"Oh,\n'tis love, 'tis love, that makes the world go round!\"'\n\n  `Somebody said,' Alice whispered, `that it's done by everybody\nminding their own business!'\n\n  `Ah, well!  It means much the same thing,' said the Duchess,\ndigging her sharp little chin into Alice's shoulder as she added,\n`and the moral of THAT is--\"Take care of the sense, and the\nsounds will take care of themselves.\"'\n\n  `How fond she is of finding morals in things!' Alice thought to\nherself.\n\n  `I dare say you're wondering why I don't put my arm round your\nwaist,' the Duchess said after a pause:  `the reason is, that I'm\ndoubtful about the temper of your flamingo.  Shall I try the\nexperiment?'\n\n  `HE might bite,' Alice cautiously replied, not feeling at all\nanxious to have the experiment tried.\n\n  `Very true,' said the Duchess:  `flamingoes and mustard both\nbite.  And the moral of that is--\"Birds of a feather flock\ntogether.\"'\n\n  `Only mustard isn't a bird,' Alice remarked.\n\n  `Right, as usual,' said the Duchess:  `what a clear way you\nhave of putting things!'\n\n  `It's a mineral, I THINK,' said Alice.\n\n  `Of course it is,' said the Duchess, who seemed ready to agree\nto everything that Alice said; `there's a large mustard-mine near\nhere.  And the moral of that is--\"The more there is of mine, the\nless there is of yours.\"'\n\n  `Oh, I know!' exclaimed Alice, who had not attended to this\nlast remark, `it's a vegetable.  It doesn't look like one, but it\nis.'\n\n  `I quite agree with you,' said the Duchess; `and the moral of\nthat is--\"Be what you would seem to be\"--or if you'd like it put\nmore simply--\"Never imagine yourself not to be otherwise than\nwhat it might appear to others that what you were or might have\nbeen was not otherwise than what you had been would have appeared\nto them to be otherwise.\"'\n\n  `I think I should understand that better,' Alice said very\npolitely, `if I had it written down:  but I can't quite follow it\nas you say it.'\n\n  `That's nothing to what I could say if I chose,' the Duchess\nreplied, in a pleased tone.\n\n  `Pray don't trouble yourself to say it any longer than that,'\nsaid Alice.\n\n  `Oh, don't talk about trouble!' said the Duchess.  `I make you\na present of everything I've said as yet.'\n\n  `A cheap sort of present!' thought Alice.  `I'm glad they don't\ngive birthday presents like that!'  But she did not venture to\nsay it out loud.\n\n  `Thinking again?' the Duchess asked, with another dig of her\nsharp little chin.\n\n  `I've a right to think,' said Alice sharply, for she was\nbeginning to feel a little worried.\n\n  `Just about as much right,' said the Duchess, `as pigs have to\nfly; and the m--'\n\n  But here, to Alice's great surprise, the Duchess's voice died\naway, even in the middle of her favourite word `moral,' and the\narm that was linked into hers began to tremble.  Alice looked up,\nand there stood the Queen in front of them, with her arms folded,\nfrowning like a thunderstorm.\n\n  `A fine day, your Majesty!' the Duchess began in a low, weak\nvoice.\n\n  `Now, I give you fair warning,' shouted the Queen, stamping on\nthe ground as she spoke; `either you or your head must be off,\nand that in about half no time!  Take your choice!'\n\n  The Duchess took her choice, and was gone in a moment.\n\n  `Let's go on with the game,' the Queen said to Alice; and Alice\nwas too much frightened to say a word, but slowly followed her\nback to the croquet-ground.\n\n  The other guests had taken advantage of the Queen's absence,\nand were resting in the shade:  however, the moment they saw her,\nthey hurried back to the game, the Queen merely remarking that a\nmoment's delay would cost them their lives.\n\n  All the time they were playing the Queen never left off\nquarrelling with the other players, and shouting `Off with his\nhead!' or `Off with her head!'  Those whom she sentenced were\ntaken into custody by the soldiers, who of course had to leave\noff being arches to do this, so that by the end of half an hour\nor so there were no arches left, and all the players, except the\nKing, the Queen, and Alice, were in custody and under sentence of\nexecution.\n\n  Then the Queen left off, quite out of breath, and said to\nAlice, `Have you seen the Mock Turtle yet?'\n\n  `No,' said Alice.  `I don't even know what a Mock Turtle is.'\n\n  `It's the thing Mock Turtle Soup is made from,' said the Queen.\n\n  `I never saw one, or heard of one,' said Alice.\n\n  `Come on, then,' said the Queen, `and he shall tell you his\nhistory,'\n\n  As they walked off together, Alice heard the King say in a low\nvoice, to the company generally, `You are all pardoned.'  `Come,\nTHAT'S a good thing!' she said to herself, for she had felt quite\nunhappy at the number of executions the Queen had ordered.\n\n  They very soon came upon a Gryphon, lying fast asleep in the\nsun.  (IF you don't know what a Gryphon is, look at the picture.)\n`Up, lazy thing!' said the Queen, `and take this young lady to\nsee the Mock Turtle, and to hear his history.  I must go back and\nsee after some executions I have ordered'; and she walked off,\nleaving Alice alone with the Gryphon.  Alice did not quite like\nthe look of the creature, but on the whole she thought it would\nbe quite as safe to stay with it as to go after that savage\nQueen:  so she waited.\n\n  The Gryphon sat up and rubbed its eyes:  then it watched the\nQueen till she was out of sight:  then it chuckled.  `What fun!'\nsaid the Gryphon, half to itself, half to Alice.\n\n  `What IS the fun?' said Alice.\n\n  `Why, SHE,' said the Gryphon.  `It's all her fancy, that:  they\nnever executes nobody, you know.  Come on!'\n\n  `Everybody says \"come on!\" here,' thought Alice, as she went\nslowly after it:  `I never was so ordered about in all my life,\nnever!'\n\n  They had not gone far before they saw the Mock Turtle in the\ndistance, sitting sad and lonely on a little ledge of rock, and,\nas they came nearer, Alice could hear him sighing as if his heart\nwould break.  She pitied him deeply.  `What is his sorrow?' she\nasked the Gryphon, and the Gryphon answered, very nearly in the\nsame words as before, `It's all his fancy, that:  he hasn't got\nno sorrow, you know.  Come on!'\n\n  So they went up to the Mock Turtle, who looked at them with\nlarge eyes full of tears, but said nothing.\n\n  `This here young lady,' said the Gryphon, `she wants for to\nknow your history, she do.'\n\n  `I'll tell it her,' said the Mock Turtle in a deep, hollow\ntone:  `sit down, both of you, and don't speak a word till I've\nfinished.'\n\n  So they sat down, and nobody spoke for some minutes.  Alice\nthought to herself, `I don't see how he can EVEN finish, if he\ndoesn't begin.'  But she waited patiently.\n\n  `Once,' said the Mock Turtle at last, with a deep sigh, `I was\na real Turtle.'\n\n  These words were followed by a very long silence, broken only\nby an occasional exclamation of `Hjckrrh!' from the Gryphon, and\nthe constant heavy sobbing of the Mock Turtle.  Alice was very\nnearly getting up and saying, `Thank you, sir, for your\ninteresting story,' but she could not help thinking there MUST be\nmore to come, so she sat still and said nothing.\n\n  `When we were little,' the Mock Turtle went on at last, more\ncalmly, though still sobbing a little now and then, `we went to\nschool in the sea.  The master was an old Turtle--we used to call\nhim Tortoise--'\n\n  `Why did you call him Tortoise, if he wasn't one?' Alice asked.\n\n  `We called him Tortoise because he taught us,' said the Mock\nTurtle angrily:  `really you are very dull!'\n\n  `You ought to be ashamed of yourself for asking such a simple\nquestion,' added the Gryphon; and then they both sat silent and\nlooked at poor Alice, who felt ready to sink into the earth.  At\nlast the Gryphon said to the Mock Turtle, `Drive on, old fellow!\nDon't be all day about it!' and he went on in these words:\n\n  `Yes, we went to school in the sea, though you mayn't believe\nit--'\n\n  `I never said I didn't!' interrupted Alice.\n\n  `You did,' said the Mock Turtle.\n\n  `Hold your tongue!' added the Gryphon, before Alice could speak\nagain.  The Mock Turtle went on.\n\n  `We had the best of educations--in fact, we went to school\nevery day--'\n\n  `I'VE been to a day-school, too,' said Alice; `you needn't be\nso proud as all that.'\n\n  `With extras?' asked the Mock Turtle a little anxiously.\n\n  `Yes,' said Alice, `we learned French and music.'\n\n  `And washing?' said the Mock Turtle.\n\n  `Certainly not!' said Alice indignantly.\n\n  `Ah! then yours wasn't a really good school,' said the Mock\nTurtle in a tone of great relief.  `Now at OURS they had at the\nend of the bill, \"French, music, AND WASHING--extra.\"'\n\n  `You couldn't have wanted it much,' said Alice; `living at the\nbottom of the sea.'\n\n  `I couldn't afford to learn it.' said the Mock Turtle with a\nsigh.  `I only took the regular course.'\n\n  `What was that?' inquired Alice.\n\n  `Reeling and Writhing, of course, to begin with,' the Mock\nTurtle replied; `and then the different branches of Arithmetic--\nAmbition, Distraction, Uglification, and Derision.'\n\n  `I never heard of \"Uglification,\"' Alice ventured to say.  `What\nis it?'\n\n  The Gryphon lifted up both its paws in surprise.  `What!  Never\nheard of uglifying!' it exclaimed.  `You know what to beautify\nis, I suppose?'\n\n  `Yes,' said Alice doubtfully:  `it means--to--make--anything--\nprettier.'\n\n  `Well, then,' the Gryphon went on, `if you don't know what to\nuglify is, you ARE a simpleton.'\n\n  Alice did not feel encouraged to ask any more questions about\nit, so she turned to the Mock Turtle, and said `What else had you\nto learn?'\n\n  `Well, there was Mystery,' the Mock Turtle replied, counting\noff the subjects on his flappers, `--Mystery, ancient and modern,\nwith Seaography:  then Drawling--the Drawling-master was an old\nconger-eel, that used to come once a week:  HE taught us\nDrawling, Stretching, and Fainting in Coils.'\n\n  `What was THAT like?' said Alice.\n\n  `Well, I can't show it you myself,' the Mock Turtle said:  `I'm\ntoo stiff.  And the Gryphon never learnt it.'\n\n  `Hadn't time,' said the Gryphon:  `I went to the Classics\nmaster, though.  He was an old crab, HE was.'\n\n  `I never went to him,' the Mock Turtle said with a sigh:  `he\ntaught Laughing and Grief, they used to say.'\n\n  `So he did, so he did,' said the Gryphon, sighing in his turn;\nand both creatures hid their faces in their paws.\n\n  `And how many hours a day did you do lessons?' said Alice, in a\nhurry to change the subject.\n\n  `Ten hours the first day,' said the Mock Turtle: `nine the\nnext, and so on.'\n\n  `What a curious plan!' exclaimed Alice.\n\n  `That's the reason they're called lessons,' the Gryphon\nremarked:  `because they lessen from day to day.'\n\n  This was quite a new idea to Alice, and she thought it over a\nlittle before she made her next remark.  `Then the eleventh day\nmust have been a holiday?'\n\n  `Of course it was,' said the Mock Turtle.\n\n  `And how did you manage on the twelfth?' Alice went on eagerly.\n\n  `That's enough about lessons,' the Gryphon interrupted in a\nvery decided tone:  `tell her something about the games now.'\n\n\n\n                            CHAPTER X\n\n                      The Lobster Quadrille\n\n\n  The Mock Turtle sighed deeply, and drew the back of one flapper\nacross his eyes.  He looked at Alice, and tried to speak, but for\na minute or two sobs choked his voice.  `Same as if he had a bone\nin his throat,' said the Gryphon:  and it set to work shaking him\nand punching him in the back.  At last the Mock Turtle recovered\nhis voice, and, with tears running down his cheeks, he went on\nagain:--\n\n  `You may not have lived much under the sea--' (`I haven't,'\nsaid Alice)--`and perhaps you were never even introduced to a lobster--'\n(Alice began to say `I once tasted--' but checked herself hastily,\nand said `No, never') `--so you can have no idea what a delightful\nthing a Lobster Quadrille is!'\n\n  `No, indeed,' said Alice.  `What sort of a dance is it?'\n\n  `Why,' said the Gryphon, `you first form into a line along the\nsea-shore--'\n\n  `Two lines!' cried the Mock Turtle.  `Seals, turtles, salmon,\nand so on; then, when you've cleared all the jelly-fish out of\nthe way--'\n\n  `THAT generally takes some time,' interrupted the Gryphon.\n\n  `--you advance twice--'\n\n  `Each with a lobster as a partner!' cried the Gryphon.\n\n  `Of course,' the Mock Turtle said:  `advance twice, set to\npartners--'\n\n  `--change lobsters, and retire in same order,' continued the\nGryphon.\n\n  `Then, you know,' the Mock Turtle went on, `you throw the--'\n\n  `The lobsters!' shouted the Gryphon, with a bound into the air.\n\n  `--as far out to sea as you can--'\n\n  `Swim after them!' screamed the Gryphon.\n\n  `Turn a somersault in the sea!' cried the Mock Turtle,\ncapering wildly about.\n\n  `Back to land again, and that's all the first figure,' said the\nMock Turtle, suddenly dropping his voice; and the two creatures,\nwho had been jumping about like mad things all this time, sat\ndown again very sadly and quietly, and looked at Alice.\n\n  `It must be a very pretty dance,' said Alice timidly.\n\n  `Would you like to see a little of it?' said the Mock Turtle.\n\n  `Very much indeed,' said Alice.\n\n  `Come, let's try the first figure!' said the Mock Turtle to the\nGryphon.  `We can do without lobsters, you know.  Which shall\nsing?'\n\n  `Oh, YOU sing,' said the Gryphon.  `I've forgotten the words.'\n\n  So they began solemnly dancing round and round Alice, every now\nand then treading on her toes when they passed too close, and\nwaving their forepaws to mark the time, while the Mock Turtle\nsang this, very slowly and sadly:--\n\n\n`\"Will you walk a little faster?\" said a whiting to a snail.\n\"There's a porpoise close behind us, and he's treading on my\n tail.\nSee how eagerly the lobsters and the turtles all advance!\nThey are waiting on the shingle--will you come and join the\ndance?\n\nWill you, won't you, will you, won't you, will you join the\ndance?\nWill you, won't you, will you, won't you, won't you join the\ndance?\n\n\n\"You can really have no notion how delightful it will be\nWhen they take us up and throw us, with the lobsters, out to\n                                                      sea!\"\nBut the snail replied \"Too far, too far!\" and gave a look\n                                                       askance--\nSaid he thanked the whiting kindly, but he would not join the\n   dance.\n    Would not, could not, would not, could not, would not join\n        the dance.\n    Would not, could not, would not, could not, could not join\n        the dance.\n\n`\"What matters it how far we go?\" his scaly friend replied.\n\"There is another shore, you know, upon the other side.\nThe further off from England the nearer is to France--\nThen turn not pale, beloved snail, but come and join the dance.\n\n    Will you, won't you, will you, won't you, will you join the\n         dance?\n    Will you, won't you, will you, won't you, won't you join the\n         dance?\"'\n\n\n\n  `Thank you, it's a very interesting dance to watch,' said\nAlice, feeling very glad that it was over at last:  `and I do so\nlike that curious song about the whiting!'\n\n  `Oh, as to the whiting,' said the Mock Turtle, `they--you've\nseen them, of course?'\n\n  `Yes,' said Alice, `I've often seen them at dinn--' she\nchecked herself hastily.\n\n  `I don't know where Dinn may be,' said the Mock Turtle, `but\nif you've seen them so often, of course you know what they're\nlike.'\n\n  `I believe so,' Alice replied thoughtfully.  `They have their\ntails in their mouths--and they're all over crumbs.'\n\n  `You're wrong about the crumbs,' said the Mock Turtle:\n`crumbs would all wash off in the sea.  But they HAVE their tails\nin their mouths; and the reason is--' here the Mock Turtle\nyawned and shut his eyes.--`Tell her about the reason and all\nthat,' he said to the Gryphon.\n\n  `The reason is,' said the Gryphon, `that they WOULD go with\nthe lobsters to the dance.  So they got thrown out to sea.  So\nthey had to fall a long way.  So they got their tails fast in\ntheir mouths.  So they couldn't get them out again.  That's all.'\n\n  `Thank you,' said Alice, `it's very interesting.  I never knew\nso much about a whiting before.'\n\n  `I can tell you more than that, if you like,' said the\nGryphon.  `Do you know why it's called a whiting?'\n\n  `I never thought about it,' said Alice.  `Why?'\n\n  `IT DOES THE BOOTS AND SHOES.' the Gryphon replied very\nsolemnly.\n\n  Alice was thoroughly puzzled.  `Does the boots and shoes!' she\nrepeated in a wondering tone.\n\n  `Why, what are YOUR shoes done with?' said the Gryphon.  `I\nmean, what makes them so shiny?'\n\n  Alice looked down at them, and considered a little before she\ngave her answer.  `They're done with blacking, I believe.'\n\n  `Boots and shoes under the sea,' the Gryphon went on in a deep\nvoice, `are done with a whiting.  Now you know.'\n\n  `And what are they made of?' Alice asked in a tone of great\ncuriosity.\n\n  `Soles and eels, of course,' the Gryphon replied rather\nimpatiently:  `any shrimp could have told you that.'\n\n  `If I'd been the whiting,' said Alice, whose thoughts were\nstill running on the song, `I'd have said to the porpoise, \"Keep\nback, please:  we don't want YOU with us!\"'\n\n  `They were obliged to have him with them,' the Mock Turtle\nsaid:  `no wise fish would go anywhere without a porpoise.'\n\n  `Wouldn't it really?' said Alice in a tone of great surprise.\n\n  `Of course not,' said the Mock Turtle:  `why, if a fish came\nto ME, and told me he was going a journey, I should say \"With\nwhat porpoise?\"'\n\n  `Don't you mean \"purpose\"?' said Alice.\n\n  `I mean what I say,' the Mock Turtle replied in an offended\ntone.  And the Gryphon added `Come, let's hear some of YOUR\nadventures.'\n\n  `I could tell you my adventures--beginning from this morning,'\nsaid Alice a little timidly:  `but it's no use going back to\nyesterday, because I was a different person then.'\n\n  `Explain all that,' said the Mock Turtle.\n\n  `No, no!  The adventures first,' said the Gryphon in an\nimpatient tone:  `explanations take such a dreadful time.'\n\n  So Alice began telling them her adventures from the time when\nshe first saw the White Rabbit.  She was a little nervous about\nit just at first, the two creatures got so close to her, one on\neach side, and opened their eyes and mouths so VERY wide, but she\ngained courage as she went on.  Her listeners were perfectly\nquiet till she got to the part about her repeating `YOU ARE OLD,\nFATHER WILLIAM,' to the Caterpillar, and the words all coming\ndifferent, and then the Mock Turtle drew a long breath, and said\n`That's very curious.'\n\n  `It's all about as curious as it can be,' said the Gryphon.\n\n  `It all came different!' the Mock Turtle repeated\nthoughtfully.  `I should like to hear her try and repeat\nsomething now.  Tell her to begin.'  He looked at the Gryphon as\nif he thought it had some kind of authority over Alice.\n\n  `Stand up and repeat \"'TIS THE VOICE OF THE SLUGGARD,\"' said\nthe Gryphon.\n\n  `How the creatures order one about, and make one repeat\nlessons!' thought Alice; `I might as well be at school at once.'\nHowever, she got up, and began to repeat it, but her head was so\nfull of the Lobster Quadrille, that she hardly knew what she was\nsaying, and the words came very queer indeed:--\n\n    `'Tis the voice of the Lobster; I heard him declare,\n    \"You have baked me too brown, I must sugar my hair.\"\n    As a duck with its eyelids, so he with his nose\n    Trims his belt and his buttons, and turns out his toes.'\n\n              [later editions continued as follows\n    When the sands are all dry, he is gay as a lark,\n    And will talk in contemptuous tones of the Shark,\n    But, when the tide rises and sharks are around,\n    His voice has a timid and tremulous sound.]\n\n  `That's different from what I used to say when I was a child,'\nsaid the Gryphon.\n\n  `Well, I never heard it before,' said the Mock Turtle; `but it\nsounds uncommon nonsense.'\n\n  Alice said nothing; she had sat down with her face in her\nhands, wondering if anything would EVER happen in a natural way\nagain.\n\n  `I should like to have it explained,' said the Mock Turtle.\n\n  `She can't explain it,' said the Gryphon hastily.  `Go on with\nthe next verse.'\n\n  `But about his toes?' the Mock Turtle persisted.  `How COULD\nhe turn them out with his nose, you know?'\n\n  `It's the first position in dancing.' Alice said; but was\ndreadfully puzzled by the whole thing, and longed to change the\nsubject.\n\n  `Go on with the next verse,' the Gryphon repeated impatiently:\n`it begins \"I passed by his garden.\"'\n\n  Alice did not dare to disobey, though she felt sure it would\nall come wrong, and she went on in a trembling voice:--\n\n    `I passed by his garden, and marked, with one eye,\n    How the Owl and the Panther were sharing a pie--'\n\n        [later editions continued as follows\n    The Panther took pie-crust, and gravy, and meat,\n    While the Owl had the dish as its share of the treat.\n    When the pie was all finished, the Owl, as a boon,\n    Was kindly permitted to pocket the spoon:\n    While the Panther received knife and fork with a growl,\n    And concluded the banquet--]\n\n  `What IS the use of repeating all that stuff,' the Mock Turtle\ninterrupted, `if you don't explain it as you go on?  It's by far\nthe most confusing thing I ever heard!'\n\n  `Yes, I think you'd better leave off,' said the Gryphon:  and\nAlice was only too glad to do so.\n\n  `Shall we try another figure of the Lobster Quadrille?' the\nGryphon went on.  `Or would you like the Mock Turtle to sing you\na song?'\n\n  `Oh, a song, please, if the Mock Turtle would be so kind,'\nAlice replied, so eagerly that the Gryphon said, in a rather\noffended tone, `Hm! No accounting for tastes!  Sing her \"Turtle\nSoup,\" will you, old fellow?'\n\n  The Mock Turtle sighed deeply, and began, in a voice sometimes\nchoked with sobs, to sing this:--\n\n\n    `Beautiful Soup, so rich and green,\n    Waiting in a hot tureen!\n    Who for such dainties would not stoop?\n    Soup of the evening, beautiful Soup!\n    Soup of the evening, beautiful Soup!\n        Beau--ootiful Soo--oop!\n        Beau--ootiful Soo--oop!\n    Soo--oop of the e--e--evening,\n        Beautiful, beautiful Soup!\n\n    `Beautiful Soup!  Who cares for fish,\n    Game, or any other dish?\n    Who would not give all else for two p\n    ennyworth only of beautiful Soup?\n    Pennyworth only of beautiful Soup?\n        Beau--ootiful Soo--oop!\n        Beau--ootiful Soo--oop!\n    Soo--oop of the e--e--evening,\n        Beautiful, beauti--FUL SOUP!'\n\n  `Chorus again!' cried the Gryphon, and the Mock Turtle had\njust begun to repeat it, when a cry of `The trial's beginning!'\nwas heard in the distance.\n\n  `Come on!' cried the Gryphon, and, taking Alice by the hand,\nit hurried off, without waiting for the end of the song.\n\n  `What trial is it?' Alice panted as she ran; but the Gryphon\nonly answered `Come on!' and ran the faster, while more and more\nfaintly came, carried on the breeze that followed them, the\nmelancholy words:--\n\n    `Soo--oop of the e--e--evening,\n        Beautiful, beautiful Soup!'\n\n\n\n                           CHAPTER XI\n\n                      Who Stole the Tarts?\n\n\n  The King and Queen of Hearts were seated on their throne when\nthey arrived, with a great crowd assembled about them--all sorts\nof little birds and beasts, as well as the whole pack of cards:\nthe Knave was standing before them, in chains, with a soldier on\neach side to guard him; and near the King was the White Rabbit,\nwith a trumpet in one hand, and a scroll of parchment in the\nother.  In the very middle of the court was a table, with a large\ndish of tarts upon it:  they looked so good, that it made Alice\nquite hungry to look at them--`I wish they'd get the trial done,'\nshe thought, `and hand round the refreshments!'  But there seemed\nto be no chance of this, so she began looking at everything about\nher, to pass away the time.\n\n  Alice had never been in a court of justice before, but she had\nread about them in books, and she was quite pleased to find that\nshe knew the name of nearly everything there.  `That's the\njudge,' she said to herself, `because of his great wig.'\n\n  The judge, by the way, was the King; and as he wore his crown\nover the wig, (look at the frontispiece if you want to see how he\ndid it,) he did not look at all comfortable, and it was certainly\nnot becoming.\n\n  `And that's the jury-box,' thought Alice, `and those twelve\ncreatures,' (she was obliged to say `creatures,' you see, because\nsome of them were animals, and some were birds,) `I suppose they\nare the jurors.'  She said this last word two or three times over\nto herself, being rather proud of it:  for she thought, and\nrightly too, that very few little girls of her age knew the\nmeaning of it at all.  However, `jury-men' would have done just\nas well.\n\n  The twelve jurors were all writing very busily on slates.\n`What are they doing?'  Alice whispered to the Gryphon.  `They\ncan't have anything to put down yet, before the trial's begun.'\n\n  `They're putting down their names,' the Gryphon whispered in\nreply, `for fear they should forget them before the end of the\ntrial.'\n\n  `Stupid things!' Alice began in a loud, indignant voice, but\nshe stopped hastily, for the White Rabbit cried out, `Silence in\nthe court!' and the King put on his spectacles and looked\nanxiously round, to make out who was talking.\n\n  Alice could see, as well as if she were looking over their\nshoulders, that all the jurors were writing down `stupid things!'\non their slates, and she could even make out that one of them\ndidn't know how to spell `stupid,' and that he had to ask his\nneighbour to tell him.  `A nice muddle their slates'll be in\nbefore the trial's over!' thought Alice.\n\n  One of the jurors had a pencil that squeaked.  This of course,\nAlice could not stand, and she went round the court and got\nbehind him, and very soon found an opportunity of taking it\naway.  She did it so quickly that the poor little juror (it was\nBill, the Lizard) could not make out at all what had become of\nit; so, after hunting all about for it, he was obliged to write\nwith one finger for the rest of the day; and this was of very\nlittle use, as it left no mark on the slate.\n\n  `Herald, read the accusation!' said the King.\n\n  On this the White Rabbit blew three blasts on the trumpet, and\nthen unrolled the parchment scroll, and read as follows:--\n\n    `The Queen of Hearts, she made some tarts,\n          All on a summer day:\n      The Knave of Hearts, he stole those tarts,\n          And took them quite away!'\n\n  `Consider your verdict,' the King said to the jury.\n\n  `Not yet, not yet!' the Rabbit hastily interrupted.  `There's\na great deal to come before that!'\n\n  `Call the first witness,' said the King; and the White Rabbit\nblew three blasts on the trumpet, and called out, `First\nwitness!'\n\n  The first witness was the Hatter.  He came in with a teacup in\none hand and a piece of bread-and-butter in the other.  `I beg\npardon, your Majesty,' he began, `for bringing these in:  but I\nhadn't quite finished my tea when I was sent for.'\n\n  `You ought to have finished,' said the King.  `When did you\nbegin?'\n\n  The Hatter looked at the March Hare, who had followed him into\nthe court, arm-in-arm with the Dormouse.  `Fourteenth of March, I\nthink it was,' he said.\n\n  `Fifteenth,' said the March Hare.\n\n  `Sixteenth,' added the Dormouse.\n\n  `Write that down,' the King said to the jury, and the jury\neagerly wrote down all three dates on their slates, and then\nadded them up, and reduced the answer to shillings and pence.\n\n  `Take off your hat,' the King said to the Hatter.\n\n  `It isn't mine,' said the Hatter.\n\n  `Stolen!' the King exclaimed, turning to the jury, who\ninstantly made a memorandum of the fact.\n\n  `I keep them to sell,' the Hatter added as an explanation;\n`I've none of my own.  I'm a hatter.'\n\n  Here the Queen put on her spectacles, and began staring at the\nHatter, who turned pale and fidgeted.\n\n  `Give your evidence,' said the King; `and don't be nervous, or\nI'll have you executed on the spot.'\n\n  This did not seem to encourage the witness at all:  he kept\nshifting from one foot to the other, looking uneasily at the\nQueen, and in his confusion he bit a large piece out of his\nteacup instead of the bread-and-butter.\n\n  Just at this moment Alice felt a very curious sensation, which\npuzzled her a good deal until she made out what it was:  she was\nbeginning to grow larger again, and she thought at first she\nwould get up and leave the court; but on second thoughts she\ndecided to remain where she was as long as there was room for\nher.\n\n  `I wish you wouldn't squeeze so.' said the Dormouse, who was\nsitting next to her.  `I can hardly breathe.'\n\n  `I can't help it,' said Alice very meekly:  `I'm growing.'\n\n  `You've no right to grow here,' said the Dormouse.\n\n  `Don't talk nonsense,' said Alice more boldly:  `you know\nyou're growing too.'\n\n  `Yes, but I grow at a reasonable pace,' said the Dormouse:\n`not in that ridiculous fashion.'  And he got up very sulkily\nand crossed over to the other side of the court.\n\n  All this time the Queen had never left off staring at the\nHatter, and, just as the Dormouse crossed the court, she said to\none of the officers of the court, `Bring me the list of the\nsingers in the last concert!' on which the wretched Hatter\ntrembled so, that he shook both his shoes off.\n\n  `Give your evidence,' the King repeated angrily, `or I'll have\nyou executed, whether you're nervous or not.'\n\n  `I'm a poor man, your Majesty,' the Hatter began, in a\ntrembling voice, `--and I hadn't begun my tea--not above a week\nor so--and what with the bread-and-butter getting so thin--and\nthe twinkling of the tea--'\n\n  `The twinkling of the what?' said the King.\n\n  `It began with the tea,' the Hatter replied.\n\n  `Of course twinkling begins with a T!' said the King sharply.\n`Do you take me for a dunce?  Go on!'\n\n  `I'm a poor man,' the Hatter went on, `and most things\ntwinkled after that--only the March Hare said--'\n\n  `I didn't!' the March Hare interrupted in a great hurry.\n\n  `You did!' said the Hatter.\n\n  `I deny it!' said the March Hare.\n\n  `He denies it,' said the King:  `leave out that part.'\n\n  `Well, at any rate, the Dormouse said--' the Hatter went on,\nlooking anxiously round to see if he would deny it too:  but the\nDormouse denied nothing, being fast asleep.\n\n  `After that,' continued the Hatter, `I cut some more bread-\nand-butter--'\n\n  `But what did the Dormouse say?' one of the jury asked.\n\n  `That I can't remember,' said the Hatter.\n\n  `You MUST remember,' remarked the King, `or I'll have you\nexecuted.'\n\n  The miserable Hatter dropped his teacup and bread-and-butter,\nand went down on one knee.  `I'm a poor man, your Majesty,' he\nbegan.\n\n  `You're a very poor speaker,' said the King.\n\n  Here one of the guinea-pigs cheered, and was immediately\nsuppressed by the officers of the court.  (As that is rather a\nhard word, I will just explain to you how it was done.  They had\na large canvas bag, which tied up at the mouth with strings:\ninto this they slipped the guinea-pig, head first, and then sat\nupon it.)\n\n  `I'm glad I've seen that done,' thought Alice.  `I've so often\nread in the newspapers, at the end of trials, \"There was some\nattempts at applause, which was immediately suppressed by the\nofficers of the court,\" and I never understood what it meant\ntill now.'\n\n  `If that's all you know about it, you may stand down,'\ncontinued the King.\n\n  `I can't go no lower,' said the Hatter:  `I'm on the floor, as\nit is.'\n\n  `Then you may SIT down,' the King replied.\n\n  Here the other guinea-pig cheered, and was suppressed.\n\n  `Come, that finished the guinea-pigs!' thought Alice.  `Now we\nshall get on better.'\n\n  `I'd rather finish my tea,' said the Hatter, with an anxious\nlook at the Queen, who was reading the list of singers.\n\n  `You may go,' said the King, and the Hatter hurriedly left the\ncourt, without even waiting to put his shoes on.\n\n  `--and just take his head off outside,' the Queen added to one\nof the officers:  but the Hatter was out of sight before the\nofficer could get to the door.\n\n  `Call the next witness!' said the King.\n\n  The next witness was the Duchess's cook.  She carried the\npepper-box in her hand, and Alice guessed who it was, even before\nshe got into the court, by the way the people near the door began\nsneezing all at once.\n\n  `Give your evidence,' said the King.\n\n  `Shan't,' said the cook.\n\n  The King looked anxiously at the White Rabbit, who said in a\nlow voice, `Your Majesty must cross-examine THIS witness.'\n\n  `Well, if I must, I must,' the King said, with a melancholy\nair, and, after folding his arms and frowning at the cook till\nhis eyes were nearly out of sight, he said in a deep voice, `What\nare tarts made of?'\n\n  `Pepper, mostly,' said the cook.\n\n  `Treacle,' said a sleepy voice behind her.\n\n  `Collar that Dormouse,' the Queen shrieked out.  `Behead that\nDormouse!  Turn that Dormouse out of court!  Suppress him!  Pinch\nhim!  Off with his whiskers!'\n\n  For some minutes the whole court was in confusion, getting the\nDormouse turned out, and, by the time they had settled down\nagain, the cook had disappeared.\n\n  `Never mind!' said the King, with an air of great relief.\n`Call the next witness.'  And he added in an undertone to the\nQueen, `Really, my dear, YOU must cross-examine the next witness.\nIt quite makes my forehead ache!'\n\n  Alice watched the White Rabbit as he fumbled over the list,\nfeeling very curious to see what the next witness would be like,\n`--for they haven't got much evidence YET,' she said to herself.\nImagine her surprise, when the White Rabbit read out, at the top\nof his shrill little voice, the name `Alice!'\n\n\n\n                           CHAPTER XII\n\n                        Alice's Evidence\n\n\n  `Here!' cried Alice, quite forgetting in the flurry of the\nmoment how large she had grown in the last few minutes, and she\njumped up in such a hurry that she tipped over the jury-box with\nthe edge of her skirt, upsetting all the jurymen on to the heads\nof the crowd below, and there they lay sprawling about, reminding\nher very much of a globe of goldfish she had accidentally upset\nthe week before.\n\n  `Oh, I BEG your pardon!' she exclaimed in a tone of great\ndismay, and began picking them up again as quickly as she could,\nfor the accident of the goldfish kept running in her head, and\nshe had a vague sort of idea that they must be collected at once\nand put back into the jury-box, or they would die.\n\n  `The trial cannot proceed,' said the King in a very grave\nvoice, `until all the jurymen are back in their proper places--\nALL,' he repeated with great emphasis, looking hard at Alice as\nhe said do.\n\n  Alice looked at the jury-box, and saw that, in her haste, she\nhad put the Lizard in head downwards, and the poor little thing\nwas waving its tail about in a melancholy way, being quite unable\nto move.  She soon got it out again, and put it right; `not that\nit signifies much,' she said to herself; `I should think it\nwould be QUITE as much use in the trial one way up as the other.'\n\n  As soon as the jury had a little recovered from the shock of\nbeing upset, and their slates and pencils had been found and\nhanded back to them, they set to work very diligently to write\nout a history of the accident, all except the Lizard, who seemed\ntoo much overcome to do anything but sit with its mouth open,\ngazing up into the roof of the court.\n\n  `What do you know about this business?' the King said to\nAlice.\n\n  `Nothing,' said Alice.\n\n  `Nothing WHATEVER?' persisted the King.\n\n  `Nothing whatever,' said Alice.\n\n  `That's very important,' the King said, turning to the jury.\nThey were just beginning to write this down on their slates, when\nthe White Rabbit interrupted:  `UNimportant, your Majesty means,\nof course,' he said in a very respectful tone, but frowning and\nmaking faces at him as he spoke.\n\n  `UNimportant, of course, I meant,' the King hastily said, and\nwent on to himself in an undertone, `important--unimportant--\nunimportant--important--' as if he were trying which word\nsounded best.\n\n  Some of the jury wrote it down `important,' and some\n`unimportant.'  Alice could see this, as she was near enough to\nlook over their slates; `but it doesn't matter a bit,' she\nthought to herself.\n\n  At this moment the King, who had been for some time busily\nwriting in his note-book, cackled out `Silence!' and read out\nfrom his book, `Rule Forty-two.  ALL PERSONS MORE THAN A MILE\nHIGH TO LEAVE THE COURT.'\n\n  Everybody looked at Alice.\n\n  `I'M not a mile high,' said Alice.\n\n  `You are,' said the King.\n\n  `Nearly two miles high,' added the Queen.\n\n  `Well, I shan't go, at any rate,' said Alice:  `besides,\nthat's not a regular rule:  you invented it just now.'\n\n  `It's the oldest rule in the book,' said the King.\n\n  `Then it ought to be Number One,' said Alice.\n\n  The King turned pale, and shut his note-book hastily.\n`Consider your verdict,' he said to the jury, in a low, trembling\nvoice.\n\n  `There's more evidence to come yet, please your Majesty,' said\nthe White Rabbit, jumping up in a great hurry; `this paper has\njust been picked up.'\n\n  `What's in it?' said the Queen.\n\n  `I haven't opened it yet,' said the White Rabbit, `but it seems\nto be a letter, written by the prisoner to--to somebody.'\n\n  `It must have been that,' said the King, `unless it was\nwritten to nobody, which isn't usual, you know.'\n\n  `Who is it directed to?' said one of the jurymen.\n\n  `It isn't directed at all,' said the White Rabbit; `in fact,\nthere's nothing written on the OUTSIDE.'  He unfolded the paper\nas he spoke, and added `It isn't a letter, after all:  it's a set\nof verses.'\n\n  `Are they in the prisoner's handwriting?' asked another of\nthey jurymen.\n\n  `No, they're not,' said the White Rabbit, `and that's the\nqueerest thing about it.'  (The jury all looked puzzled.)\n\n  `He must have imitated somebody else's hand,' said the King.\n(The jury all brightened up again.)\n\n  `Please your Majesty,' said the Knave, `I didn't write it, and\nthey can't prove I did:  there's no name signed at the end.'\n\n  `If you didn't sign it,' said the King, `that only makes the\nmatter worse.  You MUST have meant some mischief, or else you'd\nhave signed your name like an honest man.'\n\n  There was a general clapping of hands at this:  it was the\nfirst really clever thing the King had said that day.\n\n  `That PROVES his guilt,' said the Queen.\n\n  `It proves nothing of the sort!' said Alice.  `Why, you don't\neven know what they're about!'\n\n  `Read them,' said the King.\n\n  The White Rabbit put on his spectacles.  `Where shall I begin,\nplease your Majesty?' he asked.\n\n  `Begin at the beginning,' the King said gravely, `and go on\ntill you come to the end:  then stop.'\n\n  These were the verses the White Rabbit read:--\n\n        `They told me you had been to her,\n          And mentioned me to him:\n        She gave me a good character,\n          But said I could not swim.\n\n        He sent them word I had not gone\n          (We know it to be true):\n        If she should push the matter on,\n          What would become of you?\n\n        I gave her one, they gave him two,\n          You gave us three or more;\n        They all returned from him to you,\n          Though they were mine before.\n\n        If I or she should chance to be\n          Involved in this affair,\n        He trusts to you to set them free,\n          Exactly as we were.\n\n        My notion was that you had been\n          (Before she had this fit)\n        An obstacle that came between\n          Him, and ourselves, and it.\n\n        Don't let him know she liked them best,\n          For this must ever be\n        A secret, kept from all the rest,\n          Between yourself and me.'\n\n  `That's the most important piece of evidence we've heard yet,'\nsaid the King, rubbing his hands; `so now let the jury--'\n\n  `If any one of them can explain it,' said Alice, (she had\ngrown so large in the last few minutes that she wasn't a bit\nafraid of interrupting him,) `I'll give him sixpence.  _I_ don't\nbelieve there's an atom of meaning in it.'\n\n  The jury all wrote down on their slates, `SHE doesn't believe\nthere's an atom of meaning in it,' but none of them attempted to\nexplain the paper.\n\n  `If there's no meaning in it,' said the King, `that saves a\nworld of trouble, you know, as we needn't try to find any.  And\nyet I don't know,' he went on, spreading out the verses on his\nknee, and looking at them with one eye; `I seem to see some\nmeaning in them, after all.  \"--SAID I COULD NOT SWIM--\" you\ncan't swim, can you?' he added, turning to the Knave.\n\n  The Knave shook his head sadly.  `Do I look like it?' he said.\n(Which he certainly did NOT, being made entirely of cardboard.)\n\n  `All right, so far,' said the King, and he went on muttering\nover the verses to himself:  `\"WE KNOW IT TO BE TRUE--\" that's\nthe jury, of course-- \"I GAVE HER ONE, THEY GAVE HIM TWO--\" why,\nthat must be what he did with the tarts, you know--'\n\n  `But, it goes on \"THEY ALL RETURNED FROM HIM TO YOU,\"' said\nAlice.\n\n  `Why, there they are!' said the King triumphantly, pointing to\nthe tarts on the table.  `Nothing can be clearer than THAT.\nThen again--\"BEFORE SHE HAD THIS FIT--\"  you never had fits, my\ndear, I think?' he said to the Queen.\n\n  `Never!' said the Queen furiously, throwing an inkstand at the\nLizard as she spoke.  (The unfortunate little Bill had left off\nwriting on his slate with one finger, as he found it made no\nmark; but he now hastily began again, using the ink, that was\ntrickling down his face, as long as it lasted.)\n\n  `Then the words don't FIT you,' said the King, looking round\nthe court with a smile.  There was a dead silence.\n\n  `It's a pun!' the King added in an offended tone, and\neverybody laughed, `Let the jury consider their verdict,' the\nKing said, for about the twentieth time that day.\n\n  `No, no!' said the Queen.  `Sentence first--verdict afterwards.'\n\n  `Stuff and nonsense!' said Alice loudly.  `The idea of having\nthe sentence first!'\n\n  `Hold your tongue!' said the Queen, turning purple.\n\n  `I won't!' said Alice.\n\n  `Off with her head!' the Queen shouted at the top of her voice.\nNobody moved.\n\n  `Who cares for you?' said Alice, (she had grown to her full\nsize by this time.)  `You're nothing but a pack of cards!'\n\n  At this the whole pack rose up into the air, and came flying\ndown upon her:  she gave a little scream, half of fright and half\nof anger, and tried to beat them off, and found herself lying on\nthe bank, with her head in the lap of her sister, who was gently\nbrushing away some dead leaves that had fluttered down from the\ntrees upon her face.\n\n  `Wake up, Alice dear!' said her sister; `Why, what a long\nsleep you've had!'\n\n  `Oh, I've had such a curious dream!' said Alice, and she told\nher sister, as well as she could remember them, all these strange\nAdventures of hers that you have just been reading about; and\nwhen she had finished, her sister kissed her, and said, `It WAS a\ncurious dream, dear, certainly:  but now run in to your tea; it's\ngetting late.'  So Alice got up and ran off, thinking while she\nran, as well she might, what a wonderful dream it had been.\n\n  But her sister sat still just as she left her, leaning her\nhead on her hand, watching the setting sun, and thinking of\nlittle Alice and all her wonderful Adventures, till she too began\ndreaming after a fashion, and this was her dream:--\n\n  First, she dreamed of little Alice herself, and once again the\ntiny hands were clasped upon her knee, and the bright eager eyes\nwere looking up into hers--she could hear the very tones of her\nvoice, and see that queer little toss of her head to keep back\nthe wandering hair that WOULD always get into her eyes--and\nstill as she listened, or seemed to listen, the whole place\naround her became alive the strange creatures of her little\nsister's dream.\n\n  The long grass rustled at her feet as the White Rabbit hurried\nby--the frightened Mouse splashed his way through the\nneighbouring pool--she could hear the rattle of the teacups as\nthe March Hare and his friends shared their never-ending meal,\nand the shrill voice of the Queen ordering off her unfortunate\nguests to execution--once more the pig-baby was sneezing on the\nDuchess's knee, while plates and dishes crashed around it--once\nmore the shriek of the Gryphon, the squeaking of the Lizard's\nslate-pencil, and the choking of the suppressed guinea-pigs,\nfilled the air, mixed up with the distant sobs of the miserable\nMock Turtle.\n\n  So she sat on, with closed eyes, and half believed herself in\nWonderland, though she knew she had but to open them again, and\nall would change to dull reality--the grass would be only\nrustling in the wind, and the pool rippling to the waving of the\nreeds--the rattling teacups would change to tinkling sheep-\nbells, and the Queen's shrill cries to the voice of the shepherd\nboy--and the sneeze of the baby, the shriek of the Gryphon, and\nall thy other queer noises, would change (she knew) to the\nconfused clamour of the busy farm-yard--while the lowing of the\ncattle in the distance would take the place of the Mock Turtle's\nheavy sobs.\n\n  Lastly, she pictured to herself how this same little sister of\nhers would, in the after-time, be herself a grown woman; and how\nshe would keep, through all her riper years, the simple and\nloving heart of her childhood:  and how she would gather about\nher other little children, and make THEIR eyes bright and eager\nwith many a strange tale, perhaps even with the dream of\nWonderland of long ago:  and how she would feel with all their\nsimple sorrows, and find a pleasure in all their simple joys,\nremembering her own child-life, and the happy summer days.\n\n                             THE END\n\u001a\n"
  },
  {
    "path": "interfaces/13-io/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\nfunc main() {\n\t// Stdin, Stdout, and Stderr are *os.File.\n\n\t// #1: reads from the standard input\n\t// ------------------------------------------------\n\t// if err := read(os.Stdin); err != nil {\n\t// \tfmt.Fprintln(os.Stderr, err)\n\t// \treturn\n\t// }\n\n\t// #2: writes to the standard output\n\t// ------------------------------------------------\n\t// buf := []byte(\"hi!\\n\")\n\t// if err := write(os.Stdout, buf); err != nil {\n\t// \tfmt.Fprintln(os.Stderr, err)\n\t// \treturn\n\t// }\n\n\t// #2b: reads the entire file content into memory.\n\t// ------------------------------------------------\n\t// buf, err := ioutil.ReadFile(\"alice.txt\")\n\t// if err != nil {\n\t// \tfmt.Fprintln(os.Stderr, err)\n\t// \treturn\n\t// }\n\t// if err := write(os.Stdout, buf); err != nil {\n\t// \tfmt.Fprintln(os.Stderr, err)\n\t// \treturn\n\t// }\n\n\t// #3: reads and writes with 32KB of memory\n\t//     no matter how large the source data is.\n\t// ------------------------------------------------\n\tif err := ioCopy(os.Stdout, os.Stdin); err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n}\n\n// ioCopy streams from a file to another file.\n// we use it to stream from the standard input to ouput.\nfunc ioCopy(dst, src *os.File) error {\n\t// Use a fixed-length buffer to efficiently read from src stream in chunks.\n\tbuf := make([]byte, 32768)\n\n\t// read over and over again to read all the data.\n\tfor {\n\t\t// read can read only up to the buffer length.\n\t\tnr, er := src.Read(buf)\n\t\t// only write data if there is something to write.\n\t\tif nr > 0 {\n\t\t\t_, ew := dst.Write(buf[:nr])\n\t\t\tif ew != nil {\n\t\t\t\treturn ew\n\t\t\t}\n\t\t}\n\t\t// io.EOF = there is nothing left to read—close the loop.\n\t\tif er == io.EOF {\n\t\t\treturn nil\n\t\t}\n\t\t// Only return an error if the reading really fails.\n\t\tif er != nil {\n\t\t\treturn er\n\t\t}\n\t}\n\treturn nil\n}\n\n// write example.\nfunc write(dst *os.File, buf []byte) error {\n\tnw, ew := dst.Write(buf)\n\n\tfmt.Printf(\"wrote    : %d bytes\\n\", nw)\n\tfmt.Printf(\"write err: %v\\n\", ew)\n\n\treturn ew\n}\n\n// read example.\nfunc read(src *os.File) error {\n\tbuf := make([]byte, 1024*32) // in the middle.\n\t// buf := make([]byte, 148157) // defies the purpose of streaming.\n\t// buf := make([]byte, 8) // too many chunking.\n\n\tfor {\n\t\tnr, er := src.Read(buf)\n\t\t// fmt.Printf(\"buf      : %q\\n\", buf[0:nr])\n\t\tfmt.Printf(\"read     : %d bytes\\n\", nr)\n\t\tfmt.Printf(\"read err : %v\\n\", er)\n\n\t\tif er == io.EOF {\n\t\t\treturn nil\n\t\t}\n\t\tif er != nil {\n\t\t\treturn er\n\t\t}\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "interfaces/14-io-reusable/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\nfunc main() {\n\tn, err := transfer()\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%d bytes transferred.\\n\", n)\n}\n\nfunc transfer() (n int64, err error) {\n\t// stream from the standard input to the in-memory buffer in 32KB data chunks.\n\t// os.Stdin.Read(...) -> os.Stdout.Write(...)\n\tif n, err = io.Copy(os.Stdout, os.Stdin); err != nil {\n\t\treturn n, err\n\t}\n\treturn n, err\n}\n\n// ioCopy streams from a file to another file.\n// we use it to stream from the standard input to ouput.\nfunc ioCopy(dst, src *os.File) error {\n\t// Use a fixed-length buffer to efficiently read from src stream in chunks.\n\tbuf := make([]byte, 32768)\n\n\t// read over and over again to read all the data.\n\tfor {\n\t\t// read can read only up to the buffer length.\n\t\tnr, er := src.Read(buf)\n\t\t// only write data if there is something to write.\n\t\tif nr > 0 {\n\t\t\t_, ew := dst.Write(buf[:nr])\n\t\t\tif ew != nil {\n\t\t\t\treturn ew\n\t\t\t}\n\t\t}\n\t\t// io.EOF = there is nothing left to read—close the loop.\n\t\tif er == io.EOF {\n\t\t\treturn nil\n\t\t}\n\t\t// Only return an error if the reading really fails.\n\t\tif er != nil {\n\t\t\treturn er\n\t\t}\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "interfaces/15-png-detector/.gitignore",
    "content": "rosie.unknown"
  },
  {
    "path": "interfaces/15-png-detector/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\t// initiate the transmission channel (http connection) to the webserver.\n\tresp, err := http.Get(\"https://inancgumus.github.com/x/rosie.unknown\")\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\t// close it so the http package can reuse the connection.\n\tdefer resp.Body.Close()\n\n\t// resp.Body here is an io.ReadCloser: Read() + Close() methods.\n\t// but in the transfer function it's an io.Reader: Only the Read() method.\n\tn, err := transfer(resp.Body)\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%d bytes transferred.\\n\", n)\n\n\t// resp.Body.Close() runs here (because of the defer above)\n}\n\nfunc transfer(r io.Reader) (n int64, err error) {\n\tconst pngSign = \"\\x89PNG\\r\\n\\x1a\\n\"\n\tconst pngSignLen = 8\n\n\t// create an in-memory buffer (bytes.Buffer is an io.Reader and an io.Writer).\n\tvar memory bytes.Buffer\n\n\t// stream from the standard input to the in-memory buffer in 32KB data chunks.\n\t// r.Read(...) -> memory.Write(...)\n\tif n, err = io.Copy(&memory, r); err != nil {\n\t\treturn n, err\n\t}\n\n\t// check the png signature.\n\tbuf := memory.Bytes()\n\tfmt.Printf(\"% x\\n\", buf[:pngSignLen])\n\tfmt.Printf(\"% x\\n\", pngSign)\n\n\treturn n, err\n}\n"
  },
  {
    "path": "interfaces/16-io-compose/.gitignore",
    "content": "rosie.unknown\nrosie.png\n_other.go\ntoc"
  },
  {
    "path": "interfaces/16-io-compose/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\tresp, err := http.Get(\"https://inancgumus.github.com/x/rosie.unknown\")\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tdefer resp.Body.Close()\n\n\t// creates a file (or truncates if the file exists)\n\tfile, err := os.Create(\"rosie.png\")\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tdefer file.Close()\n\n\tn, err := transfer(resp.Body, file)\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%d bytes transferred.\\n\", n)\n\n\t// main() runs the deferred funcs in reverse order:\n\t// file.Close()\n\t// resp.Body.Close()\n}\n\n// transfer streams data from a reader to a writer.\n// if the reader doesn't contain a PNG signature, transfer returns errNotPNG.\n// otherwise, it transfers the data to the writer.\nfunc transfer(r io.Reader, w io.Writer) (n int64, err error) {\n\tconst pngSign = \"\\x89PNG\\r\\n\\x1a\\n\"\n\tconst pngSignLen = 8\n\n\tvar memory bytes.Buffer\n\n\t// limit what copy() reads.\n\t// lr := io.LimitReader(r, pngSignLen)\n\t// if n, err = io.Copy(&memory, lr); err != nil {\n\t// return n, err\n\t// }\n\n\t// same as above. behind the scenes CopyN() calls LimitReader.\n\tif n, err = io.CopyN(&memory, r, pngSignLen); err != nil {\n\t\treturn n, err\n\t}\n\n\t// check the png signature.\n\tif !bytes.HasPrefix(memory.Bytes(), []byte(pngSign)) {\n\t\treturn n, errors.New(\"not png\")\n\t}\n\n\t// stitch the PNG signature (memory) and the response body reader together.\n\t// then copy them successively to the writer (*os.File).\n\treturn io.Copy(w, io.MultiReader(&memory, r))\n}\n"
  },
  {
    "path": "interfaces/17-write-an-io-reader/.gitignore",
    "content": "rosie.unknown\nrosie.png\n_other.go\ntoc"
  },
  {
    "path": "interfaces/17-write-an-io-reader/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\t// resp, err := http.Get(\"https://inancgumus.github.com/x/rosie.jpg\")\n\tresp, err := http.Get(\"https://inancgumus.github.com/x/rosie.unknown\")\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tdefer resp.Body.Close()\n\n\tfile, err := os.Create(\"rosie.png\")\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tdefer file.Close()\n\n\tn, err := io.Copy(file, pngReader(resp.Body))\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%d bytes transferred.\\n\", n)\n}\n"
  },
  {
    "path": "interfaces/17-write-an-io-reader/reader.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n)\n\n// reader reads from `r` if the stream starts with a given signature.\n// otherwise it stops and returns with an error.\ntype signatureReader struct {\n\tr         io.Reader // reads from the response.Body (or from any reader)\n\tsignature []byte    // stream should start with this initial signature\n}\n\n// Read implements the io.Reader interface.\nfunc (sr *signatureReader) Read(b []byte) (n int, err error) {\n\tn, err = sr.r.Read(b)\n\n\tl := len(sr.signature)\n\tif l == 0 {\n\t\t// simply return if the signature has already been detected.\n\t\treturn\n\t}\n\t// 1) buffer   : **** -> b[:3]            -> ***\n\t//    signature: ***  -> sr.signature[:3] -> ***\n\t// 2) buffer   : **   -> b[:2]            -> **\n\t//    signature: **** -> sr.signature[:2] -> **\n\tif lb := len(b); lb < l {\n\t\tl = lb\n\t}\n\tif got, want := b[:l], sr.signature[:l]; !bytes.Equal(got, want) {\n\t\terr = fmt.Errorf(\"signature doesn't match, got: % x, want: % x\", got, want)\n\t}\n\t// Assuming the `len(b)` is 4.\n\t// 1st Read(): pr.signature[0:4] -> first part\n\t// 2nd Read(): pr.signature[0:4] -> second part\n\tsr.signature = sr.signature[l:]\n\treturn n, err\n}\n\n// create a reader for detecting only the png signatures.\nfunc pngReader(r io.Reader) io.Reader {\n\treturn &signatureReader{\n\t\tr:         r,\n\t\tsignature: []byte(\"\\x89PNG\\r\\n\\x1a\\n\"),\n\t}\n}\n"
  },
  {
    "path": "interfaces/18-testing/.gitignore",
    "content": "rosie.unknown\nrosie.png\n_other.go\ntoc"
  },
  {
    "path": "interfaces/18-testing/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\t// resp, err := http.Get(\"https://inancgumus.github.com/x/rosie.jpg\")\n\tresp, err := http.Get(\"https://inancgumus.github.com/x/rosie.unknown\")\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tdefer resp.Body.Close()\n\n\tfile, err := os.Create(\"rosie.png\")\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tdefer file.Close()\n\n\tn, err := io.Copy(file, pngReader(resp.Body))\n\tif err != nil {\n\t\tfmt.Fprintln(os.Stderr, err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%d bytes transferred.\\n\", n)\n}\n"
  },
  {
    "path": "interfaces/18-testing/reader.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n)\n\n// reader reads from `r` if the stream starts with a given signature.\n// otherwise it stops and returns with an error.\ntype signatureReader struct {\n\tr         io.Reader // reads from the response.Body (or from any reader)\n\tsignature []byte    // stream should start with this initial signature\n}\n\n// Read implements the io.Reader interface.\nfunc (sr *signatureReader) Read(b []byte) (n int, err error) {\n\tn, err = sr.r.Read(b)\n\n\tl := len(sr.signature)\n\tif l == 0 {\n\t\treturn\n\t}\n\tif lb := len(b); lb < l {\n\t\tl = lb\n\t}\n\tif got, want := b[:l], sr.signature[:l]; !bytes.Equal(got, want) {\n\t\terr = fmt.Errorf(\"signature doesn't match, got: % x, want: % x\", got, want)\n\t}\n\tsr.signature = sr.signature[l:]\n\treturn n, err\n}\n\n// create a reader for detecting only the png signatures.\nfunc pngReader(r io.Reader) io.Reader {\n\treturn &signatureReader{\n\t\tr:         r,\n\t\tsignature: []byte(\"\\x89PNG\\r\\n\\x1a\\n\"),\n\t}\n}\n"
  },
  {
    "path": "interfaces/18-testing/reader_test.go",
    "content": "package main\n\nimport (\n\t\"io/ioutil\"\n\t\"strings\"\n\t\"testing\"\n)\n\nfunc TestCorrectSignature(t *testing.T) {\n\tconst signature = \"\\x89PNG\\r\\n\\x1a\\n\"\n\tconst input = signature + \"REST OF THE DATA\"\n\n\tpr := pngReader(strings.NewReader(input))\n\n\tout, err := ioutil.ReadAll(pr)\n\tif err != nil {\n\t\tt.Fatalf(\"got: %q; want: nil err\", err)\n\t}\n\tif string(out) != input {\n\t\tt.Fatalf(\"got: % x; want: % x\", out, input)\n\t}\n}\n\nfunc TestIncorrectSignature(t *testing.T) {\n\tconst input = \"WITHOUT PNG SIGNATURE\"\n\n\t// strings.Reader is a read-only, in-memory stream reader.\n\t// It's an io.Reader implementation.\n\tpr := pngReader(strings.NewReader(input))\n\n\t// `ioutil.ReadAll` is a dangerous but useful utility function\n\t// that can read all the data from a reader into memory.\n\t// Don't use it for large (?) data.\n\t_, err := ioutil.ReadAll(pr)\n\tif err == nil {\n\t\tt.Fatalf(\"got: %v; want: !nil err\", err)\n\t}\n}\n\nfunc TestSummation(t *testing.T) {\n\tt.Skip() // skip this test\n\n\tresult := 1 + 2\n\tif result != 5 { // it'll always fail\n\t\t// t.Fatal(\"want: 5\") // not a good error message\n\t\tt.Fatalf(\"got: %d; want: 5\", result) // explanatory error message: good.\n\t}\n}\n"
  },
  {
    "path": "logparser/functional/Makefile",
    "content": "SHELL := /bin/bash\n\nr: \n\tgo run . < ../logs/log.txt\n\nt: \n\ttime go run . < ../logs/log.txt"
  },
  {
    "path": "logparser/functional/chartwriter.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// func chartWriter(w io.Writer) outputFn {\n// \treturn func(res []result) error {\n// \t\treturn chartWrite(w, res)\n// \t}\n// }\n\n// func chartWrite(w io.Writer, res []result) error {\n// \tsort.Slice(res, func(i, j int) bool {\n// \t\treturn res[i].domain > res[j].domain\n// \t})\n\n// \tdonut := chart.DonutChart{\n// \t\tTitle: \"Total Visits Per Domain\",\n// \t\tTitleStyle: chart.Style{\n// \t\t\tFontSize:  35,\n// \t\t\tShow:      true,\n// \t\t\tFontColor: chart.ColorAlternateGreen,\n// \t\t},\n// \t\tWidth:  1920,\n// \t\tHeight: 800,\n// \t}\n\n// \tfor _, r := range res {\n// \t\tv := chart.Value{\n// \t\t\tLabel: r.domain + r.page + \": \" + strconv.Itoa(r.visits),\n// \t\t\tValue: float64(r.visits),\n// \t\t\tStyle: chart.Style{\n// \t\t\t\tFontSize: 14,\n// \t\t\t},\n// \t\t}\n\n// \t\tdonut.Values = append(donut.Values, v)\n// \t}\n\n// \treturn donut.Render(chart.SVG, w)\n// }\n"
  },
  {
    "path": "logparser/functional/field.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strconv\"\n)\n\n// field helps for field parsing\ntype field struct{ err error }\n\n// uatoi parses an unsigned integer string and saves the error.\n// it assumes that the val is unsigned.\n// for ease of usability: it returns an int instead of uint.\nfunc (f *field) uatoi(name, val string) int {\n\tn, err := strconv.Atoi(val)\n\tif err != nil || n < 0 {\n\t\tf.err = fmt.Errorf(\"incorrect field -> %q = %q\", name, val)\n\t}\n\treturn n\n}\n\nfunc atoi(input []byte) (int, error) {\n\tval := 0\n\tfor i := 0; i < len(input); i++ {\n\t\tchar := input[i]\n\t\tif char < '0' || char > '9' {\n\t\t\treturn 0, errors.New(\"invalid number\")\n\t\t}\n\t\tval = val*10 + int(char) - '0'\n\t}\n\treturn val, nil\n}\n"
  },
  {
    "path": "logparser/functional/filters.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"strings\"\n\nfunc noopFilter(r result) bool {\n\treturn true\n}\n\nfunc notUsing(filter filterFn) filterFn {\n\treturn func(r result) bool {\n\t\treturn !filter(r)\n\t}\n}\n\nfunc domainExtFilter(domains ...string) filterFn {\n\treturn func(r result) bool {\n\t\tfor _, domain := range domains {\n\t\t\tif strings.HasSuffix(r.domain, \".\"+domain) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n}\n\nfunc domainFilter(domain string) filterFn {\n\treturn func(r result) bool {\n\t\treturn strings.Contains(r.domain, domain)\n\t}\n}\n\nfunc orgDomainsFilter(r result) bool {\n\treturn strings.HasSuffix(r.domain, \".org\")\n}\n"
  },
  {
    "path": "logparser/functional/groupers.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// domainGrouper groups by domain.\n// but it keeps the other fields.\n// for example: it returns pages as well, but you shouldn't use them.\n// exercise: write a function that erases superfluous data.\nfunc domainGrouper(r result) string {\n\treturn r.domain\n}\n\nfunc pageGrouper(r result) string {\n\treturn r.domain + r.page\n}\n\n// groupBy allocates map unnecessarily\nfunc noopGrouper(r result) string {\n\t// with something like:\n\t// return randomStrings()\n\treturn \"\"\n}\n"
  },
  {
    "path": "logparser/functional/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tp := pipeline{\n\t\tread:   textReader(os.Stdin),\n\t\twrite:  textWriter(os.Stdout),\n\t\tfilter: notUsing(domainExtFilter(\"io\", \"com\")),\n\t\tgroup:  domainGrouper,\n\t}\n\n\t// var p pipeline\n\t// p.\n\t// \tfilterBy(notUsing(domainExtFilter(\"io\", \"com\"))).\n\t// \tgroupBy(domainGrouper)\n\n\tif err := p.start(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n\n// []outputter{textFile(\"results.txt\"), chartFile(\"graph.png\")}\n\n// func outputs(w io.Writer) outputFn {\n// \ttw := textWriter(w)\n// \tcw := chartWriter(w)\n\n// \treturn func(rs []result) error {\n// \t\terr := tw(rs)\n// \t\terr = cw(rs)\n// \t\treturn err\n// \t}\n// }\n"
  },
  {
    "path": "logparser/functional/pipeline.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"os\"\n\ntype (\n\tprocessFn func(r result)\n\tinputFn   func(processFn) error\n\toutputFn  func([]result) error\n\tfilterFn  func(result) (include bool)\n\tgroupFn   func(result) (key string)\n)\n\ntype pipeline struct {\n\tread   inputFn\n\twrite  outputFn\n\tfilter filterFn\n\tgroup  groupFn\n}\n\nfunc (p *pipeline) filterBy(f filterFn) *pipeline { p.filter = f; return p }\nfunc (p *pipeline) groupBy(f groupFn) *pipeline   { p.group = f; return p }\nfunc (p *pipeline) from(f inputFn) *pipeline      { p.read = f; return p }\nfunc (p *pipeline) to(f outputFn) *pipeline       { p.write = f; return p }\n\nfunc (p *pipeline) defaults() {\n\tif p.filter == nil {\n\t\tp.filter = noopFilter\n\t}\n\n\tif p.group == nil {\n\t\tp.group = domainGrouper\n\t}\n\n\tif p.read == nil {\n\t\tp.read = textReader(os.Stdin)\n\t}\n\n\tif p.write == nil {\n\t\tp.write = textWriter(os.Stdout)\n\t}\n}\n\nfunc (p *pipeline) start() error {\n\tp.defaults()\n\n\t// retrieve and process the lines\n\tsum := make(map[string]result)\n\n\tprocess := func(r result) {\n\t\tif !p.filter(r) {\n\t\t\treturn\n\t\t}\n\n\t\tk := p.group(r)\n\t\tsum[k] = r.add(sum[k])\n\t}\n\n\t// return err from input reader\n\tif err := p.read(process); err != nil {\n\t\treturn err\n\t}\n\n\t// prepare the results for outputting\n\tvar out []result\n\tfor _, res := range sum {\n\t\tout = append(out, res)\n\t}\n\n\t// return err from output reader\n\treturn p.write(out)\n}\n"
  },
  {
    "path": "logparser/functional/result.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nconst fieldsLength = 4\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain  string\n\tpage    string\n\tvisits  int\n\tuniques int\n}\n\n// add adds the metrics of another result\nfunc (r result) add(other result) result {\n\tr.visits += other.visits\n\tr.uniques += other.uniques\n\treturn r\n}\n\n// parseFields parses and returns the parsing result\nfunc parseFields(line string) (r result, err error) {\n\tfields := strings.Fields(line)\n\n\tif len(fields) != fieldsLength {\n\t\treturn r, fmt.Errorf(\"wrong number of fields %q\", fields)\n\t}\n\n\tr.domain = fields[0]\n\tr.page = fields[1]\n\n\tf := new(field)\n\tr.visits = f.uatoi(\"visits\", fields[2])\n\tr.uniques = f.uatoi(\"uniques\", fields[3])\n\n\treturn r, f.err\n}\n\nfunc fastParseFields(data []byte) (res result, err error) {\n\tconst separator = ' '\n\n\tvar findex int\n\n\tfor i, j := 0, 0; i < len(data); i++ {\n\t\tc := data[i]\n\t\tlast := len(data) == i+1\n\n\t\tif c != separator && !last {\n\t\t\tcontinue\n\t\t}\n\n\t\tif last {\n\t\t\ti = len(data)\n\t\t}\n\n\t\tswitch fval := data[j:i]; findex {\n\t\tcase 0:\n\t\t\tres.domain = string(fval)\n\t\tcase 1:\n\t\t\tres.page = string(fval)\n\t\tcase 2:\n\t\t\tres.visits, err = atoi(fval)\n\t\tcase 3:\n\t\t\tres.uniques, err = atoi(fval)\n\t\t}\n\n\t\tif err != nil {\n\t\t\treturn res, err\n\t\t}\n\n\t\tj = i + 1\n\t\tfindex++\n\t}\n\n\tif findex != fieldsLength {\n\t\terr = fmt.Errorf(\"wrong number of fields %q\", data)\n\t}\n\treturn res, err\n}\n"
  },
  {
    "path": "logparser/functional/textreader.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"io\"\n)\n\nfunc textReader(r io.Reader) inputFn {\n\treturn func(process processFn) error {\n\t\tvar (\n\t\t\tl  = 1\n\t\t\tin = bufio.NewScanner(r)\n\t\t)\n\n\t\tfor in.Scan() {\n\t\t\tr, err := fastParseFields(in.Bytes())\n\t\t\t// r, err := parseFields(in.Text())\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"line %d: %v\", l, err)\n\t\t\t}\n\n\t\t\tprocess(r)\n\t\t\tl++\n\t\t}\n\n\t\tif c, ok := r.(io.Closer); ok {\n\t\t\tc.Close()\n\t\t}\n\t\treturn in.Err()\n\t}\n}\n"
  },
  {
    "path": "logparser/functional/textwriter.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"sort\"\n\t\"strings\"\n)\n\n// TODO: sort by result key interfaces section\n\nconst (\n\n\t//          DOMAINS PAGES VISITS UNIQUES\n\t//             ^      ^     ^    ^\n\t//             |      |     |    |\n\theader     = \"%-25s %-10s %10s %10s\\n\"\n\tline       = \"%-25s %-10s %10d %10d\\n\"\n\tfooter     = \"\\n%-36s %10d %10d\\n\" // -> \"\" VISITS UNIQUES\n\tdash       = \"-\"\n\tdashLength = 58\n)\n\nfunc textWriter(w io.Writer) outputFn {\n\treturn func(res []result) error {\n\t\tsort.Slice(res, func(i, j int) bool {\n\t\t\treturn res[i].domain > res[j].domain\n\t\t})\n\n\t\tvar total result\n\n\t\tfmt.Fprintf(w, header, \"DOMAINS\", \"PAGES\", \"VISITS\", \"UNIQUES\")\n\t\tfmt.Fprintf(w, strings.Repeat(dash, dashLength)+\"\\n\")\n\n\t\tfor _, r := range res {\n\t\t\ttotal = total.add(r)\n\t\t\tfmt.Fprintf(w, line, r.domain, r.page, r.visits, r.uniques)\n\t\t}\n\n\t\tfmt.Fprintf(w, footer, \"\", total.visits, total.uniques)\n\n\t\treturn nil\n\t}\n}\n\nfunc noWhere() outputFn {\n\treturn func(res []result) error {\n\t\treturn nil\n\t}\n}\n"
  },
  {
    "path": "logparser/logs/Makefile",
    "content": "SHELL := /bin/bash\nLINES = $$(wc -l log.txt | cut -f1 -d' ')\nECHO_LINES = echo -e \">> log.txt has $(LINES) lines\"\n\nn ?= 18\nload: restore\n\t@echo \"enlarging the file with itself, please wait...\"\t\n\n\t@for i in {1..$(n)}; do \\\n\t\tawk 1 log.txt log.txt > log_.txt; \\\n\t\tmv log_.txt log.txt; \\\n\t\trm -f log_.txt; \\\n\tdone\n\t\n\t@$(ECHO_LINES)\n\nrestore:\n\t@echo \"restoring the file...\"\n\t@git checkout log.txt\n\t@$(ECHO_LINES)\n\nmultiply: remove\n\t@echo \"creating 20 log files...\"\n\t@for i in {1..20}; do \\\n\t\techo log$${i}.txt; \\\n\t\tcp log.txt log$${i}.txt; \\\n\tdone\n\nremove:\n\trm -f log{1..20}.txt\n\nlines:\n\t@$(ECHO_LINES)"
  },
  {
    "path": "logparser/logs/log.jsonl",
    "content": "{\"domain\": \"learngoprogramming.com\", \"page\": \"/\", \"visits\": 10, \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/courses\", \"visits\": 15, \"uniques\": 10}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/courses\", \"visits\": 10, \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 20, \"uniques\": 15}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 5, \"uniques\": 2}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 40, \"uniques\": 20}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 45, \"uniques\": 25}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 60, \"uniques\": 30}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 30, \"uniques\": 20}\n{\"domain\": \"blog.golang.org\", \"page\": \"/updates\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 65, \"uniques\": 35}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"inanc.io\", \"page\": \"/about\", \"visits\": 30, \"uniques\": 15}\n{\"domain\": \"inanc.io\", \"page\": \"/about\",\"visits\": 70, \"uniques\": 35}"
  },
  {
    "path": "logparser/logs/log.txt",
    "content": "learngoprogramming.com / 10 5\nlearngoprogramming.com /courses 15 10\nlearngoprogramming.com /courses 10 5\nlearngoprogramming.com /articles 20 15\nlearngoprogramming.com /articles 5 2\ngolang.org / 40 20\ngolang.org / 20 10\ngolang.org /blog 45 25\ngolang.org /blog 15 5\nblog.golang.org /courses 60 30\nblog.golang.org /courses 30 20\nblog.golang.org /updates 20 10\nblog.golang.org /reference 65 35\nblog.golang.org /reference 15 5\ninanc.io /about 30 15\ninanc.io /about 70 35"
  },
  {
    "path": "logparser/logs/log_err_missing.jsonl",
    "content": "{\"domain\": \"learngoprogramming.com\", \"page\": \"/\", \"visits\": 10, \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"visits\": 15, \"uniques\": 10}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/courses\", \"visits\": 10, \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 20, \"uniques\": 15}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 5, \"uniques\": 2}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 40, \"uniques\": 20}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 45, \"uniques\": 25}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 60, \"uniques\": 30}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 30, \"uniques\": 20}\n{\"domain\": \"blog.golang.org\", \"page\": \"/updates\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 65, \"uniques\": 35}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"inanc.io\", \"page\": \"/about\", \"visits\": 30, \"uniques\": 15}\n{\"domain\": \"inanc.io\", \"page\": \"/about\",\"visits\": 70, \"uniques\": 35}"
  },
  {
    "path": "logparser/logs/log_err_missing.txt",
    "content": "learngoprogramming.com / 10 5\nlearngoprogramming.com /courses 15 10\nlearngoprogramming.com /courses 10 5\nlearngoprogramming.com /articles 20 15\nlearngoprogramming.com /articles 5 2\ngolang.org / 40 20\ngolang.org / 20 10\ngolang.org /blog 45 25\ngolang.org /blog 15 5\nblog.golang.org /updates\nblog.golang.org /updates 30 20\nblog.golang.org /updates 20 10\nblog.golang.org /reference 65 35\nblog.golang.org /reference 15 5\ninanc.io /about 30 15\ninanc.io /about 70 35\n"
  },
  {
    "path": "logparser/logs/log_err_negative.jsonl",
    "content": "{\"domain\": \"learngoprogramming.com\", \"page\": \"/\", \"visits\": 10, \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/courses\", \"visits\": 15, \"uniques\": 10}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/courses\", \"visits\": 10, \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 20, \"uniques\": -15}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 5, \"uniques\": 2}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 40, \"uniques\": 20}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 45, \"uniques\": 25}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 60, \"uniques\": 30}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 30, \"uniques\": 20}\n{\"domain\": \"blog.golang.org\", \"page\": \"/updates\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 65, \"uniques\": 35}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"inanc.io\", \"page\": \"/about\", \"visits\": 30, \"uniques\": 15}\n{\"domain\": \"inanc.io\", \"page\": \"/about\",\"visits\": 70, \"uniques\": 35}"
  },
  {
    "path": "logparser/logs/log_err_negative.txt",
    "content": "learngoprogramming.com / 10 5\nlearngoprogramming.com /courses 15 10\nlearngoprogramming.com /courses 10 5\nlearngoprogramming.com /articles 20 15\nlearngoprogramming.com /articles 5 2\ngolang.org / 40 20\ngolang.org / 20 10\ngolang.org /blog 45 -250\ngolang.org /blog 15 5\nblog.golang.org /updates 60 30\nblog.golang.org /updates 30 20\nblog.golang.org /updates 20 10\nblog.golang.org /reference 65 35\nblog.golang.org /reference 15 5\ninanc.io /about 30 15\ninanc.io /about 70 35\n"
  },
  {
    "path": "logparser/logs/log_err_str.jsonl",
    "content": "{\"domain\": \"learngoprogramming.com\", \"page\": \"/\", \"visits\": 10, \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/courses\", \"visits\": 15, \"uniques\": 10}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/courses\", \"visits\": \"TEN\", \"uniques\": 5}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 20, \"uniques\": 15}\n{\"domain\": \"learngoprogramming.com\", \"page\": \"/articles\", \"visits\": 5, \"uniques\": 2}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 40, \"uniques\": 20}\n{\"domain\": \"golang.org\", \"page\": \"/\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 45, \"uniques\": 25}\n{\"domain\": \"golang.org\", \"page\": \"/blog\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 60, \"uniques\": 30}\n{\"domain\": \"blog.golang.org\", \"page\": \"/courses\", \"visits\": 30, \"uniques\": 20}\n{\"domain\": \"blog.golang.org\", \"page\": \"/updates\", \"visits\": 20, \"uniques\": 10}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 65, \"uniques\": 35}\n{\"domain\": \"blog.golang.org\", \"page\": \"/reference\", \"visits\": 15, \"uniques\": 5}\n{\"domain\": \"inanc.io\", \"page\": \"/about\", \"visits\": 30, \"uniques\": 15}\n{\"domain\": \"inanc.io\", \"page\": \"/about\",\"visits\": 70, \"uniques\": 35}"
  },
  {
    "path": "logparser/logs/log_err_str.txt",
    "content": "learngoprogramming.com / 10 5\nlearngoprogramming.com /courses 15 10\nlearngoprogramming.com /courses 10 5\nlearngoprogramming.com /articles 20 15\nlearngoprogramming.com /articles 5 2\ngolang.org / 40 TWENTY\ngolang.org / 20 10\ngolang.org /blog 45 25\ngolang.org /blog 15 5\nblog.golang.org /updates 60 30\nblog.golang.org /updates 30 20\nblog.golang.org /updates 20 10\nblog.golang.org /reference 65 35\nblog.golang.org /reference 15 5\ninanc.io /about 30 15\ninanc.io /about 70 35"
  },
  {
    "path": "logparser/testing/log.txt",
    "content": "learngoprogramming.com 10 200\nlearngoprogramming.com 10 300\ngolang.org 4 50\ngolang.org 6 100\nblog.golang.org 20 25\nblog.golang.org 10 1"
  },
  {
    "path": "logparser/testing/log_err_missing.txt",
    "content": "learngoprogramming.com 10 200\nlearngoprogramming.com 10\ngolang.org 4 50\ngolang.org 6 100\nblog.golang.org 20 25\nblog.golang.org 10 1"
  },
  {
    "path": "logparser/testing/log_err_negative.txt",
    "content": "learngoprogramming.com 10 200\nlearngoprogramming.com 10 300\ngolang.org -100 50\ngolang.org 6 100\nblog.golang.org 20 25\nblog.golang.org 10 1"
  },
  {
    "path": "logparser/testing/log_err_str.txt",
    "content": "learngoprogramming.com 10 200\nlearngoprogramming.com 10 THREE-HUNDRED\ngolang.org FOUR 50\ngolang.org 6 100\nblog.golang.org 20 25\nblog.golang.org 10 1"
  },
  {
    "path": "logparser/testing/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"os\"\n\n\t\"github.com/inancgumus/learngo/logparser/testing/report\"\n)\n\nfunc main() {\n\tp := report.New()\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.Parse(in.Text())\n\t}\n\n\tsummarize(p.Summarize(), p.Err(), in.Err())\n}\n"
  },
  {
    "path": "logparser/testing/main_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// +build integration\n\n// go test -tags=integration\n\npackage main_test\n\nimport (\n\t\"bytes\"\n\t\"os/exec\"\n\t\"strings\"\n\t\"testing\"\n)\n\nconst (\n\tokIn = `\na.com 1 2\nb.com 3 4\na.com 4 5\nb.com 6 7`\n\n\tokOut = `\nDOMAIN                             VISITS           TIME SPENT\n-----------------------------------------------------------------\na.com                                   5                    7\nb.com                                   9                   11\n\nTOTAL                                  14                   18`\n)\n\nfunc TestSummary(t *testing.T) {\n\ttests := []struct {\n\t\tname, in, out string\n\t}{\n\t\t{\"valid input\", okIn, okOut},\n\t\t{\"missing fields\", \"a.com 1 2\\nb.com 3\", \"> Err: line #2: missing fields: [b.com 3]\"},\n\t\t{\"incorrect visits\", \"a.com 1 2\\nb.com -1 1\", `> Err: line #2: incorrect visits: \"-1\"`},\n\t\t{\"incorrect time spent\", \"a.com 1 2\\nb.com 3 -1\", `> Err: line #2: incorrect time spent: \"-1\"`},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\trun(t, strings.TrimSpace(tt.in), strings.TrimSpace(tt.out))\n\t\t})\n\t}\n}\n\nfunc run(t *testing.T, in, out string) {\n\tcmd := exec.Command(\"go\", \"run\", \".\")\n\tcmd.Stdin = strings.NewReader(in)\n\n\tgot, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\tif !bytes.Equal(got, []byte(out+\"\\n\")) {\n\t\tt.Fatalf(\"\\nwant:\\n%s\\n\\ngot:\\n%s\", out, got)\n\t}\n}\n"
  },
  {
    "path": "logparser/testing/report/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage report\n\nimport (\n\t\"fmt\"\n)\n\n// Parser parses the log file and generates a summary report.\ntype Parser struct {\n\tsummary *Summary // summarizes the parsing results\n\tlines   int      // number of parsed lines (for the error messages)\n\tlerr    error    // the last error occurred\n}\n\n// New returns a new parsing state.\nfunc New() *Parser {\n\treturn &Parser{summary: newSummary()}\n}\n\n// Parse parses a log line and adds it to the summary.\nfunc (p *Parser) Parse(line string) {\n\t// if there was an error do not continue\n\tif p.lerr != nil {\n\t\treturn\n\t}\n\n\t// chain the parser's error to the result's\n\tres, err := parse(line)\n\tif p.lines++; err != nil {\n\t\tp.lerr = fmt.Errorf(\"line #%d: %s\", p.lines, err)\n\t\treturn\n\t}\n\n\tp.summary.update(res)\n}\n\n// Summarize summarizes the parsing results.\n// Only use it after the parsing is done.\nfunc (p *Parser) Summarize() *Summary {\n\treturn p.summary\n}\n\n// Err returns the last error encountered\nfunc (p *Parser) Err() error {\n\treturn p.lerr\n}\n"
  },
  {
    "path": "logparser/testing/report/parser_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage report_test\n\nimport (\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/inancgumus/learngo/logparser/testing/report\"\n)\n\nfunc newParser(lines string) *report.Parser {\n\tp := report.New()\n\tp.Parse(lines)\n\treturn p\n}\n\nfunc TestParserLineErrs(t *testing.T) {\n\tp := newParser(\"a.com 1 2\")\n\tp.Parse(\"b.com -1 -1\")\n\n\twant := \"#2\"\n\terr := p.Err().Error()\n\n\tif !strings.Contains(err, want) {\n\t\tt.Errorf(\"want: %q; got: %q\", want, err)\n\t}\n}\n\nfunc TestParserStopsOnErr(t *testing.T) {\n\tp := newParser(\"a.com 10 20\")\n\tp.Parse(\"b.com -1 -1\")\n\tp.Parse(\"neverparses.com 30 40\")\n\n\ts := p.Summarize()\n\tif want, got := 10, s.Total().Visits; want != got {\n\t\tt.Errorf(\"want: %d; got: %d\", want, got)\n\t}\n}\n\nfunc TestParserIncorrectFields(t *testing.T) {\n\ttests := []struct {\n\t\tin, name string\n\t}{\n\t\t{\"a.com\", \"missing fields\"},\n\t\t{\"a.com -1 2\", \"incorrect visits\"},\n\t\t{\"a.com 1 -1\", \"incorrect time spent\"},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tif p := newParser(tt.in); p.Err() == nil {\n\t\t\t\tt.Errorf(\"in: %q; got: nil err\", tt.in)\n\t\t\t}\n\t\t})\n\t}\n}\n"
  },
  {
    "path": "logparser/testing/report/result.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage report\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// always put all the related things together as in here\n\n// Result stores metrics for a domain\n// it uses the value mechanics,\n// because it doesn't have to update anything\ntype Result struct {\n\tDomain    string `json:\"domain\"`\n\tVisits    int    `json:\"visits\"`\n\tTimeSpent int    `json:\"time_spent\"`\n\t// add more metrics if needed\n}\n\n// add adds the metrics of another Result to itself and returns a new Result\nfunc (r Result) add(other Result) Result {\n\treturn Result{\n\t\tDomain:    r.Domain,\n\t\tVisits:    r.Visits + other.Visits,\n\t\tTimeSpent: r.TimeSpent + other.TimeSpent,\n\t}\n}\n\n// parse parses a single log line\nfunc parse(line string) (r Result, err error) {\n\tfields := strings.Fields(line)\n\tif len(fields) != 3 {\n\t\treturn r, fmt.Errorf(\"missing fields: %v\", fields)\n\t}\n\n\tf := new(field)\n\tr.Domain = fields[0]\n\tr.Visits = f.atoi(\"visits\", fields[1])\n\tr.TimeSpent = f.atoi(\"time spent\", fields[2])\n\treturn r, f.err\n}\n\n// field helps for field parsing\ntype field struct{ err error }\n\nfunc (f *field) atoi(name, val string) int {\n\tn, err := strconv.Atoi(val)\n\tif n < 0 || err != nil {\n\t\tf.err = fmt.Errorf(\"incorrect %s: %q\", name, val)\n\t}\n\treturn n\n}\n"
  },
  {
    "path": "logparser/testing/report/summary.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage report\n\nimport (\n\t\"sort\"\n)\n\n// Summary aggregates the parsing results\ntype Summary struct {\n\tsum     map[string]Result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   Result            // total visits for all domains\n}\n\n// newSummary constructs and initializes a new summary\n// You can't use its methods without pointer mechanics\nfunc newSummary() *Summary {\n\treturn &Summary{sum: make(map[string]Result)}\n}\n\n// Update updates the report for the given parsing result\nfunc (s *Summary) update(r Result) {\n\tdomain := r.Domain\n\tif _, ok := s.sum[domain]; !ok {\n\t\ts.domains = append(s.domains, domain)\n\t}\n\n\t// let the result handle the addition\n\t// this allows us to manage the result in once place\n\t// and this way it becomes easily extendable\n\ts.total = s.total.add(r)\n\ts.sum[domain] = r.add(s.sum[domain])\n}\n\n// Iterator returns `next()` to detect when the iteration ends,\n// and a `cur()` to return the current result.\n// iterator iterates sorted by domains.\nfunc (s *Summary) Iterator() (next func() bool, cur func() Result) {\n\tsort.Strings(s.domains)\n\n\t// remember the last iterated result\n\tvar last int\n\n\tnext = func() bool {\n\t\tdefer func() { last++ }()\n\t\treturn len(s.domains) > last\n\t}\n\n\tcur = func() Result {\n\t\t// returns a copy so the caller cannot change it\n\t\tname := s.domains[last-1]\n\t\treturn s.sum[name]\n\t}\n\n\treturn\n}\n\n// Total returns the total metrics\nfunc (s *Summary) Total() Result {\n\treturn s.total\n}\n\n// For the interfaces section\n//\n// MarshalJSON marshals a report to JSON\n// Alternative: unexported embedding\n// func (s *Summary) MarshalJSON() ([]byte, error) {\n// \ttype total struct {\n// \t\t*Result\n// \t\tIgnoreDomain *string `json:\"domain,omitempty\"`\n// \t}\n\n// \treturn json.Marshal(struct {\n// \t\tSum     map[string]Result `json:\"summary\"`\n// \t\tDomains []string          `json:\"domains\"`\n// \t\tTotal   total             `json:\"total\"`\n// \t}{\n// \t\tSum: s.sum, Domains: s.domains, Total: total{Result: &s.total},\n// \t})\n// }\n"
  },
  {
    "path": "logparser/testing/report/summary_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage report_test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/inancgumus/learngo/logparser/testing/report\"\n)\n\nfunc TestSummaryTotal(t *testing.T) {\n\tp := newParser(\"a.com 1 2\")\n\tp.Parse(\"b.com 3 4\")\n\n\ts := p.Summarize()\n\n\twant := report.Result{Domain: \"\", Visits: 4, TimeSpent: 6}\n\tif got := s.Total(); want != got {\n\t\tt.Errorf(\"want: %+v; got: %+v\", want, got)\n\t}\n}\n\nfunc TestSummaryIterator(t *testing.T) {\n\tp := newParser(\"a.com 1 2\")\n\tp.Parse(\"a.com 3 4\")\n\tp.Parse(\"b.com 5 6\")\n\n\ts := p.Summarize()\n\tnext, cur := s.Iterator()\n\n\twants := []report.Result{\n\t\t{Domain: \"a.com\", Visits: 4, TimeSpent: 6},\n\t\t{Domain: \"b.com\", Visits: 5, TimeSpent: 6},\n\t}\n\n\tfor _, want := range wants {\n\t\tt.Run(want.Domain, func(t *testing.T) {\n\t\t\tif got := next(); !got {\n\t\t\t\tt.Errorf(\"next(): want: %t; got: %t\", true, got)\n\t\t\t}\n\t\t\tif got := cur(); want != got {\n\t\t\t\tt.Errorf(\"cur(): want: %+v; got: %+v\", want, got)\n\t\t\t}\n\t\t})\n\t}\n}\n"
  },
  {
    "path": "logparser/testing/summarize.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\n\t\"github.com/inancgumus/learngo/logparser/testing/report\"\n)\n\n// summarize prints the parsing results.\n//\n// it prints the errors and returns if there are any.\n//\n// --json flag encodes to json and prints.\nfunc summarize(sum *report.Summary, errors ...error) {\n\tif errs(errors...) {\n\t\treturn\n\t}\n\n\tif args := os.Args[1:]; len(args) == 1 && args[0] == \"--json\" {\n\t\tencode(sum)\n\t\treturn\n\t}\n\tstdout(sum)\n}\n\n// encodes the summary to json\nfunc encode(sum *report.Summary) {\n\tout, err := json.MarshalIndent(sum, \"\", \"\\t\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tos.Stdout.Write(out)\n}\n\n// prints the summary to standard out\nfunc stdout(sum *report.Summary) {\n\tconst (\n\t\thead = \"%-30s %10s %20s\\n\"\n\t\tval  = \"%-30s %10d %20d\\n\"\n\t)\n\n\tfmt.Printf(head, \"DOMAIN\", \"VISITS\", \"TIME SPENT\")\n\tfmt.Println(strings.Repeat(\"-\", 65))\n\n\tfor next, cur := sum.Iterator(); next(); {\n\t\tr := cur()\n\t\tfmt.Printf(val, r.Domain, r.Visits, r.TimeSpent)\n\t}\n\n\tt := sum.Total()\n\tfmt.Printf(\"\\n\"+val, \"TOTAL\", t.Visits, t.TimeSpent)\n}\n\n// this variadic func simplifies the multiple error handling\nfunc errs(errs ...error) (wasErr bool) {\n\tfor _, err := range errs {\n\t\tif err != nil {\n\t\t\tfmt.Printf(\"> Err: %s\\n\", err)\n\t\t\twasErr = true\n\t\t}\n\t}\n\treturn\n}\n"
  },
  {
    "path": "logparser/v1/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v1/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v1/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v1/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v1/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tvar (\n\t\tsum     map[string]int // total visits per domain\n\t\tdomains []string       // unique domain names\n\t\ttotal   int            // total visits to all domains\n\t\tlines   int            // number of parsed lines (for the error messages)\n\t)\n\n\tsum = make(map[string]int)\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tlines++\n\n\t\t// Parse the fields\n\t\tfields := strings.Fields(in.Text())\n\t\tif len(fields) != 2 {\n\t\t\tfmt.Printf(\"wrong input: %v (line #%d)\\n\", fields, lines)\n\t\t\treturn\n\t\t}\n\n\t\tdomain := fields[0]\n\n\t\t// Sum the total visits per domain\n\t\tvisits, err := strconv.Atoi(fields[1])\n\t\tif visits < 0 || err != nil {\n\t\t\tfmt.Printf(\"wrong input: %q (line #%d)\\n\", fields[1], lines)\n\t\t\treturn\n\t\t}\n\n\t\t// Collect the unique domains\n\t\tif _, ok := sum[domain]; !ok {\n\t\t\tdomains = append(domains, domain)\n\t\t}\n\n\t\t// Keep track of total and per domain visits\n\t\ttotal += visits\n\t\tsum[domain] += visits\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range domains {\n\t\tvisits := sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "logparser/v2/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v2/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v2/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v2/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n}\n\nfunc main() {\n\tp := parser{sum: make(map[string]result)}\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.lines++\n\n\t\t// Parse the fields\n\t\tfields := strings.Fields(in.Text())\n\t\tif len(fields) != 2 {\n\t\t\tfmt.Printf(\"wrong input: %v (line #%d)\\n\", fields, p.lines)\n\t\t\treturn\n\t\t}\n\n\t\tdomain := fields[0]\n\n\t\t// Sum the total visits per domain\n\t\tvisits, err := strconv.Atoi(fields[1])\n\t\tif visits < 0 || err != nil {\n\t\t\tfmt.Printf(\"wrong input: %q (line #%d)\\n\", fields[1], p.lines)\n\t\t\treturn\n\t\t}\n\n\t\t// Collect the unique domains\n\t\tif _, ok := p.sum[domain]; !ok {\n\t\t\tp.domains = append(p.domains, domain)\n\t\t}\n\n\t\t// Keep track of total and per domain visits\n\t\tp.total += visits\n\n\t\t// You cannot assign to composite values\n\t\t// p.sum[domain].visits += visits\n\n\t\t// create and assign a new copy of `visit`\n\t\tp.sum[domain] = result{\n\t\t\tdomain: domain,\n\t\t\tvisits: visits + p.sum[domain].visits,\n\t\t}\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "logparser/v3/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v3/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v3/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v3/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v3/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tp := newParser()\n\n\t// Scan the standard-in line by line\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tp.lines++\n\n\t\tparsed, err := parse(p, in.Text())\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t\treturn\n\t\t}\n\n\t\tp = update(p, parsed)\n\t}\n\n\t// Print the visits per domain\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tparsed := p.sum[domain]\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, parsed.visits)\n\t}\n\n\t// Print the total visits for all domains\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n\n\t// Let's handle the error\n\tif err := in.Err(); err != nil {\n\t\tfmt.Println(\"> Err:\", err)\n\t}\n}\n"
  },
  {
    "path": "logparser/v3/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n}\n\n// newParser constructs, initializes and returns a new parser\nfunc newParser() parser {\n\treturn parser{sum: make(map[string]result)}\n}\n\n// parse parses a log line and returns the parsed result with an error\nfunc parse(p parser, line string) (parsed result, err error) {\n\tfields := strings.Fields(line)\n\tif len(fields) != 2 {\n\t\terr = fmt.Errorf(\"wrong input: %v (line #%d)\", fields, p.lines)\n\t\treturn\n\t}\n\n\tparsed.domain = fields[0]\n\n\tparsed.visits, err = strconv.Atoi(fields[1])\n\tif parsed.visits < 0 || err != nil {\n\t\terr = fmt.Errorf(\"wrong input: %q (line #%d)\", fields[1], p.lines)\n\t\treturn\n\t}\n\n\treturn\n}\n\n// update updates the parser for the given parsing result\nfunc update(p parser, parsed result) parser {\n\tdomain, visits := parsed.domain, parsed.visits\n\n\t// Collect the unique domains\n\tif _, ok := p.sum[domain]; !ok {\n\t\tp.domains = append(p.domains, domain)\n\t}\n\n\t// Keep track of total and per domain visits\n\tp.total += visits\n\n\t// create and assign a new copy of `visit`\n\tp.sum[domain] = result{\n\t\tdomain: domain,\n\t\tvisits: visits + p.sum[domain].visits,\n\t}\n\n\treturn p\n}\n"
  },
  {
    "path": "logparser/v4/log.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org 4\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v4/log_err_missing.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v4/log_err_negative.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org -100\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v4/log_err_str.txt",
    "content": "learngoprogramming.com 10\nlearngoprogramming.com 10\ngolang.org FOUR\ngolang.org 6\nblog.golang.org 20\nblog.golang.org 10"
  },
  {
    "path": "logparser/v4/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"sort\"\n\t\"strings\"\n)\n\nfunc main() {\n\tp := newParser()\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor in.Scan() {\n\t\tparsed := parse(p, in.Text())\n\t\tupdate(p, parsed)\n\t}\n\n\tsummarize(p)\n\tdumpErrs([]error{in.Err(), err(p)})\n}\n\n// summarize summarizes and prints the parsing result\nfunc summarize(p *parser) {\n\tsort.Strings(p.domains)\n\n\tfmt.Printf(\"%-30s %10s\\n\", \"DOMAIN\", \"VISITS\")\n\tfmt.Println(strings.Repeat(\"-\", 45))\n\n\tfor _, domain := range p.domains {\n\t\tfmt.Printf(\"%-30s %10d\\n\", domain, p.sum[domain].visits)\n\t}\n\tfmt.Printf(\"\\n%-30s %10d\\n\", \"TOTAL\", p.total)\n}\n\n// dumpErrs simplifies handling multiple errors\nfunc dumpErrs(errs []error) {\n\tfor _, err := range errs {\n\t\tif err != nil {\n\t\t\tfmt.Println(\"> Err:\", err)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "logparser/v4/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// result stores the parsed result for a domain\ntype result struct {\n\tdomain string\n\tvisits int\n\t// add more metrics if needed\n}\n\n// parser keep tracks of the parsing\ntype parser struct {\n\tsum     map[string]result // metrics per domain\n\tdomains []string          // unique domain names\n\ttotal   int               // total visits for all domains\n\tlines   int               // number of parsed lines (for the error messages)\n\tlerr    error             // the last error occurred\n}\n\n// newParser constructs, initializes and returns a new parser\nfunc newParser() *parser {\n\treturn &parser{sum: make(map[string]result)}\n}\n\n// parse parses a log line and returns the parsed result with an error\nfunc parse(p *parser, line string) (r result) {\n\tif p.lerr != nil {\n\t\treturn\n\t}\n\n\tp.lines++\n\n\tfields := strings.Fields(line)\n\tif len(fields) != 2 {\n\t\tp.lerr = fmt.Errorf(\"wrong input: %v (line #%d)\", fields, p.lines)\n\t\treturn\n\t}\n\n\tvar err error\n\n\tr.domain = fields[0]\n\tr.visits, err = strconv.Atoi(fields[1])\n\n\tif r.visits < 0 || err != nil {\n\t\tp.lerr = fmt.Errorf(\"wrong input: %q (line #%d)\", fields[1], p.lines)\n\t}\n\treturn\n}\n\n// update updates all the parsing results using the given parsing result\nfunc update(p *parser, r result) {\n\tif p.lerr != nil {\n\t\treturn\n\t}\n\n\t// Collect the unique domains\n\tif _, ok := p.sum[r.domain]; !ok {\n\t\tp.domains = append(p.domains, r.domain)\n\t}\n\n\t// Keep track of total and per domain visits\n\tp.total += r.visits\n\n\t// create and assign a new copy of `visit`\n\tp.sum[r.domain] = result{\n\t\tdomain: r.domain,\n\t\tvisits: r.visits + p.sum[r.domain].visits,\n\t}\n}\n\n// err returns the last error encountered\nfunc err(p *parser) error {\n\treturn p.lerr\n}\n"
  },
  {
    "path": "logparser/v5/Makefile",
    "content": "r: \n\tgo run . < ../../logs/log.txt\n\nt: \n\ttime go run . < ../../logs/log.txt"
  },
  {
    "path": "logparser/v5/filepipe.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"os\"\n\t\"strings\"\n\n\t\"github.com/inancgumus/learngo/logparser/v5/pipe\"\n)\n\n// fromFile generates a default pipeline.\n// Detects the correct parser by the file extension.\n// Uses a TextReport and groups by domain.\nfunc fromFile(path string) (*pipe.Pipeline, error) {\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar src pipe.Iterator\n\tswitch {\n\tcase strings.HasSuffix(path, \".txt\"):\n\t\tsrc = pipe.NewTextLog(f)\n\tcase strings.HasSuffix(path, \".jsonl\"):\n\t\tsrc = pipe.NewJSONLog(f)\n\t}\n\n\treturn pipe.New(\n\t\tsrc,\n\t\tpipe.NewTextReport(os.Stdout),\n\t\tpipe.GroupBy(pipe.DomainGrouper),\n\t), nil\n}\n"
  },
  {
    "path": "logparser/v5/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n)\n\nfunc main() {\n\t// p := pipe.Default(\n\t// \tos.Stdin, os.Stdout,\n\t// \tpipe.FilterBy(pipe.DomainExtFilter(\"com\", \"io\")),\n\t// \tpipe.GroupBy(pipe.DomainGrouper),\n\t// )\n\n\tp, err := fromFile(os.Args[1])\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tif err := p.Run(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n"
  },
  {
    "path": "logparser/v5/passthrough.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"github.com/inancgumus/learngo/logparser/v5/pipe\"\n)\n\ntype passThrough struct {\n\tpipe.Iterator\n}\n\nfunc (t *passThrough) Consume(results pipe.Iterator) error {\n\tt.Iterator = results\n\treturn nil\n}\n\nfunc (t *passThrough) Each(yield func(pipe.Record) error) error {\n\tpass := func(r pipe.Record) error {\n\t\t// fmt.Println(r.Fields())\n\t\t// fmt.Println(r.Int(\"visits\"))\n\t\treturn yield(r)\n\t}\n\n\treturn t.Iterator.Each(pass)\n}\n"
  },
  {
    "path": "logparser/v5/pipe/chartreport.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\n/*\n// You need to run:\n// go get -u github.com/wcharczuk/go-chart\n\n// Chart renders a chart.\ntype Chart struct {\n\tTitle         string\n\tWidth, Height int\n\n\tw io.Writer\n}\n\n// NewChartReport returns a Chart report generator.\nfunc NewChartReport(w io.Writer) *Chart {\n\treturn &Chart{w: w}\n}\n\n// Consume generates a chart report.\nfunc (c *Chart) Consume(records Iterator) error {\n\tw := os.Stdout\n\n\tdonut := chart.DonutChart{\n\t\tTitle: c.Title,\n\t\tTitleStyle: chart.Style{\n\t\t\tFontSize:  35,\n\t\t\tShow:      true,\n\t\t\tFontColor: chart.ColorAlternateGreen,\n\t\t},\n\t\tWidth:  c.Width,\n\t\tHeight: c.Height,\n\t}\n\n\terr := records.Each(func(r Record) error {\n\t\tv := chart.Value{\n\t\t\tLabel: r.Domain + r.Page + \": \" + strconv.Itoa(r.Visits),\n\t\t\tValue: float64(r.Visits),\n\t\t\tStyle: chart.Style{\n\t\t\t\tFontSize: 14,\n\t\t\t},\n\t\t}\n\n\t\tdonut.Values = append(donut.Values, v)\n\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn donut.Render(chart.SVG, w)\n}\n*/\n"
  },
  {
    "path": "logparser/v5/pipe/close.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"io\"\n)\n\n// readClose the reader if it's a io.Closer.\nfunc readClose(r io.Reader) {\n\tif rc, ok := r.(io.Closer); ok {\n\t\trc.Close()\n\t}\n}\n"
  },
  {
    "path": "logparser/v5/pipe/filter.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\n// FilterFunc represents a filtering pipeline func.\n// The type alias frees us from binding to a named type.\ntype FilterFunc = func(Record) (pass bool)\n\n// Filter the records.\ntype Filter struct {\n\tsrc     Iterator\n\tfilters []FilterFunc\n}\n\n// FilterBy returns a new filter pipeline.\nfunc FilterBy(fn ...FilterFunc) *Filter {\n\treturn &Filter{filters: fn}\n}\n\n// Consume the records for lazy filtering.\nfunc (f *Filter) Consume(records Iterator) error {\n\tf.src = records\n\treturn nil\n}\n\n// Each filtered records.\nfunc (f *Filter) Each(yield func(Record) error) error {\n\trecords := func(r Record) error {\n\t\tif !f.checkAll(r) {\n\t\t\treturn nil\n\t\t}\n\t\treturn yield(r)\n\t}\n\n\treturn f.src.Each(records)\n}\n\n// checkAll the filters against the record.\nfunc (f *Filter) checkAll(r Record) bool {\n\tfor _, fi := range f.filters {\n\t\tif !fi(r) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n"
  },
  {
    "path": "logparser/v5/pipe/filters.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport \"strings\"\n\n// NotFilter reverses a filter. True becomes false, and vice versa.\nfunc NotFilter(filter FilterFunc) FilterFunc {\n\treturn func(r Record) bool {\n\t\treturn !filter(r)\n\t}\n}\n\n// DomainExtFilter filters a set of domain extensions.\nfunc DomainExtFilter(domains ...string) FilterFunc {\n\treturn func(r Record) bool {\n\t\tfor _, domain := range domains {\n\t\t\tif strings.HasSuffix(r.domain, \".\"+domain) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n}\n\n// DomainFilter filters a domain if it contains the given text.\nfunc DomainFilter(text string) FilterFunc {\n\treturn func(r Record) bool {\n\t\treturn strings.Contains(r.domain, text)\n\t}\n}\n\n// DomainOrgFilter filters only the \".org\" domains.\nfunc DomainOrgFilter(r Record) bool {\n\treturn strings.HasSuffix(r.domain, \".org\")\n}\n"
  },
  {
    "path": "logparser/v5/pipe/group.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"sort\"\n)\n\n// GroupFunc represents a grouping func that returns a grouping key.\n// The type alias frees us from binding to a named type.\ntype GroupFunc = func(Record) (key string)\n\n// Group records by a key.\ntype Group struct {\n\tsum  map[string]record // metrics per group key\n\tkeys []string          // unique group keys\n\tkey  GroupFunc\n}\n\n// GroupBy returns a new Group.\n// It takes a group func that returns a group key.\n// The returned group will group the record using the key.\nfunc GroupBy(key GroupFunc) *Group {\n\treturn &Group{\n\t\tsum: make(map[string]record),\n\t\tkey: key,\n\t}\n}\n\n// Consume the records for grouping.\nfunc (g *Group) Consume(records Iterator) error {\n\tgroup := func(r Record) error {\n\t\tk := g.key(r)\n\n\t\tif _, ok := g.sum[k]; !ok {\n\t\t\tg.keys = append(g.keys, k)\n\t\t}\n\n\t\tg.sum[k] = r.sum(g.sum[k])\n\n\t\treturn nil\n\t}\n\n\treturn records.Each(group)\n}\n\n// Each sends the grouped and sorted records to upstream.\nfunc (g *Group) Each(yield func(Record) error) error {\n\tsort.Strings(g.keys)\n\n\tfor _, k := range g.keys {\n\t\terr := yield(Record{g.sum[k]})\n\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n"
  },
  {
    "path": "logparser/v5/pipe/groupers.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\n// DomainGrouper groups the records by domain.\n// It keeps the other fields intact.\n// For example: It returns the page field as well.\n// Exercise: Write a solution that removes the unnecessary data.\nfunc DomainGrouper(r Record) string {\n\treturn r.domain\n}\n\n// Page groups records by page.\nfunc Page(r Record) string {\n\treturn r.domain + r.page\n}\n"
  },
  {
    "path": "logparser/v5/pipe/jsonlog.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"encoding/json\"\n\t\"io\"\n)\n\n// JSON parses json records.\ntype JSON struct {\n\treader io.Reader\n}\n\n// NewJSONLog creates a json parser.\nfunc NewJSONLog(r io.Reader) *JSON {\n\treturn &JSON{reader: r}\n}\n\n// Each sends the records from a reader to upstream.\nfunc (j *JSON) Each(yield func(Record) error) error {\n\tdefer readClose(j.reader)\n\n\t// Use the same record for unmarshaling.\n\tvar r Record\n\n\tdec := json.NewDecoder(j.reader)\n\n\tfor {\n\t\terr := dec.Decode(&r)\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := yield(r); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n"
  },
  {
    "path": "logparser/v5/pipe/jsonreport.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"encoding/json\"\n\t\"io\"\n)\n\n// JSONReport generates a JSON report.\ntype JSONReport struct {\n\tw io.Writer\n}\n\n// NewJSONReport returns a JSON report generator.\nfunc NewJSONReport(w io.Writer) *JSONReport {\n\treturn &JSONReport{w: w}\n}\n\n// Consume the records and generate a JSON report.\nfunc (t *JSONReport) Consume(records Iterator) error {\n\tenc := json.NewEncoder(t.w)\n\n\tencode := func(r Record) error {\n\t\treturn enc.Encode(&r)\n\t}\n\n\treturn records.Each(encode)\n}\n"
  },
  {
    "path": "logparser/v5/pipe/logcount.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport \"fmt\"\n\n// logCount counts the yielded records.\ntype logCount struct {\n\tIterator\n\tn int\n}\n\n// Each yields to the inner iterator while counting the records.\n// Reports the record number on an error.\nfunc (lc *logCount) Each(yield func(Record) error) error {\n\tcount := func(r Record) error {\n\t\tlc.n++\n\t\treturn yield(r)\n\t}\n\n\terr := lc.Iterator.Each(count)\n\n\tif err != nil {\n\t\t// lc.n+1: iterator.each won't call yield on err\n\t\treturn fmt.Errorf(\"record %d: %v\", lc.n+1, err)\n\t}\n\treturn nil\n}\n\n// count returns the last read record number.\nfunc (lc *logCount) count() int {\n\treturn lc.n\n}\n"
  },
  {
    "path": "logparser/v5/pipe/pipe.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\n// Iterator yields a record.\ntype Iterator interface {\n\tEach(func(Record) error) error\n}\n\n// Consumer consumes records from an iterator.\ntype Consumer interface {\n\tConsume(Iterator) error\n}\n\n// Transform represents both a record consumer and producer.\n// It has an input and output.\n// It takes a single record and provides an iterator for all the records.\ntype Transform interface {\n\tIterator // producer: should never return on yield().err == nil\n\tConsumer\n}\n"
  },
  {
    "path": "logparser/v5/pipe/pipeline.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\n// Pipeline takes records from a source, transforms, and sends them to a destionation.\ntype Pipeline struct {\n\tsrc   Iterator\n\ttrans []Transform\n\tdst   Consumer\n}\n\n// New creates a new pipeline.\nfunc New(src Iterator, dst Consumer, t ...Transform) *Pipeline {\n\treturn &Pipeline{\n\t\tsrc:   &logCount{Iterator: src},\n\t\tdst:   dst,\n\t\ttrans: t,\n\t}\n}\n\n// Default creates a pipeline that reads from a text log and generates a text report.\nfunc Default(r io.Reader, w io.Writer, t ...Transform) *Pipeline {\n\treturn New(NewTextLog(r), NewTextReport(w), t...)\n}\n\n// Run the pipeline.\nfunc (p *Pipeline) Run() error {\n\tdefer func() {\n\t\tn := p.src.(*logCount).count()\n\t\tfmt.Fprintf(os.Stderr, \"%d records processed.\\n\", n)\n\t}()\n\n\tlast := p.src\n\n\tfor _, t := range p.trans {\n\t\tif err := t.Consume(last); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tlast = t\n\t}\n\n\treturn p.dst.Consume(last)\n}\n"
  },
  {
    "path": "logparser/v5/pipe/record.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst fieldsLength = 4\n\n// record stores fields of a log line.\ntype record struct {\n\tdomain  string\n\tpage    string\n\tvisits  int\n\tuniques int\n}\n\n// recordJSON is used for marshaling and unmarshaling JSON.\ntype recordJSON struct {\n\tDomain  string\n\tPage    string\n\tVisits  int\n\tUniques int\n}\n\n// sum the numeric fields with another record.\nfunc (r record) sum(other record) record {\n\tr.visits += other.visits\n\tr.uniques += other.uniques\n\treturn r\n}\n\n// UnmarshalText to a *record.\nfunc (r *record) UnmarshalText(p []byte) (err error) {\n\tfields := strings.Fields(string(p))\n\n\tif len(fields) != fieldsLength {\n\t\treturn fmt.Errorf(\"wrong number of fields %q\", fields)\n\t}\n\n\tr.domain, r.page = fields[0], fields[1]\n\n\tif r.visits, err = parseStr(\"visits\", fields[2]); err != nil {\n\t\treturn err\n\t}\n\tif r.uniques, err = parseStr(\"uniques\", fields[3]); err != nil {\n\t\treturn err\n\t}\n\n\treturn validate(*r)\n}\n\n// UnmarshalJSON to a *record.\nfunc (r *record) UnmarshalJSON(data []byte) error {\n\tvar rj recordJSON\n\n\tif err := json.Unmarshal(data, &rj); err != nil {\n\t\treturn err\n\t}\n\n\t*r = record{rj.Domain, rj.Page, rj.Visits, rj.Uniques}\n\n\treturn validate(*r)\n}\n\n// MarshalJSON of a *record.\nfunc (r *record) MarshalJSON() ([]byte, error) {\n\trj := recordJSON{r.domain, r.page, r.visits, r.uniques}\n\treturn json.Marshal(rj)\n}\n\n// parseStr helps UnmarshalText for string to positive int parsing.\nfunc parseStr(name, v string) (int, error) {\n\tn, err := strconv.Atoi(v)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"Record.UnmarshalText %q: %v\", name, err)\n\t}\n\treturn n, nil\n}\n\n// validate whether a parsed record is valid or not.\nfunc validate(r record) (err error) {\n\tswitch {\n\tcase r.domain == \"\":\n\t\terr = errors.New(\"record.domain cannot be empty\")\n\tcase r.page == \"\":\n\t\terr = errors.New(\"record.page cannot be empty\")\n\tcase r.visits < 0:\n\t\terr = errors.New(\"record.visits cannot be negative\")\n\tcase r.uniques < 0:\n\t\terr = errors.New(\"record.uniques cannot be negative\")\n\t}\n\treturn\n}\n"
  },
  {
    "path": "logparser/v5/pipe/recordshare.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n)\n\n// Record stores the log line fields.\n// The underlying fields are kept hidden.\n// The users of the package are decoupled from the underlying record fields.\n// When the fields change, the client won't feel the difference (at least in compile-time).\ntype Record struct {\n\trecord\n}\n\n// Str returns a string field. Panics when the field doesn't exist.\nfunc (r Record) Str(field string) string {\n\treturn r.mustGet(field, reflect.String).String()\n}\n\n// Int returns an int field. Panics when the field doesn't exist.\nfunc (r Record) Int(field string) int {\n\treturn int(r.mustGet(field, reflect.Int).Int())\n}\n\n// Fields returns all the field names.\n// The names can be used to query the Record.\nfunc (r Record) Fields() (fields []string) {\n\tt := reflect.TypeOf(record{})\n\n\tfor i := 0; i < t.NumField(); i++ {\n\t\tf := t.Field(i)\n\t\ts := fmt.Sprintf(\"(%s: %s)\", f.Name, f.Type.Name())\n\n\t\tfields = append(fields, s)\n\t}\n\n\treturn\n}\n\n// mustGet the field with the same kind or panics.\nfunc (r Record) mustGet(field string, kind reflect.Kind) reflect.Value {\n\tv := reflect.ValueOf(r.record).FieldByName(field)\n\tif !v.IsValid() {\n\t\tpanic(fmt.Errorf(\"record.%s does not exist\", field))\n\t}\n\tif v.Kind() != kind {\n\t\tpanic(fmt.Errorf(\"record.%s is not %q\", field, kind))\n\t}\n\treturn v\n}\n"
  },
  {
    "path": "logparser/v5/pipe/textlog.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"bufio\"\n\t\"io\"\n)\n\n// TextLog parses text based log lines.\ntype TextLog struct {\n\treader io.Reader\n}\n\n// NewTextLog creates a text parser.\nfunc NewTextLog(r io.Reader) *TextLog {\n\treturn &TextLog{reader: r}\n}\n\n// Each yields records from a text log.\nfunc (p *TextLog) Each(yield func(Record) error) error {\n\tdefer readClose(p.reader)\n\n\t// Use the same record for unmarshaling.\n\tvar r Record\n\n\tin := bufio.NewScanner(p.reader)\n\n\tfor in.Scan() {\n\t\tif err := r.UnmarshalText(in.Bytes()); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif err := yield(r); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn in.Err()\n}\n"
  },
  {
    "path": "logparser/v5/pipe/textreport.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage pipe\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"text/tabwriter\"\n)\n\nconst (\n\tminWidth = 0\n\ttabWidth = 4\n\tpadding  = 4\n\tflags    = 0\n)\n\n// TextReport report generator.\ntype TextReport struct {\n\tw io.Writer\n}\n\n// NewTextReport returns a TextReport report generator.\nfunc NewTextReport(w io.Writer) *TextReport {\n\treturn &TextReport{w: w}\n}\n\n// Consume generates a text report.\nfunc (t *TextReport) Consume(records Iterator) error {\n\tw := tabwriter.NewWriter(t.w, minWidth, tabWidth, padding, ' ', flags)\n\n\tfmt.Fprintf(w, \"DOMAINS\\tPAGES\\tVISITS\\tUNIQUES\\n\")\n\tfmt.Fprintf(w, \"-------\\t-----\\t------\\t-------\\n\")\n\n\tvar total record\n\n\tprintLine := func(r Record) error {\n\t\ttotal = r.sum(total)\n\n\t\tfmt.Fprintf(w, \"%s\\t%s\\t%d\\t%d\\n\",\n\t\t\tr.domain, r.page,\n\t\t\tr.visits, r.uniques,\n\t\t)\n\n\t\treturn nil\n\t}\n\n\tif err := records.Each(printLine); err != nil {\n\t\treturn err\n\t}\n\n\tfmt.Fprintf(w, \"\\t\\t\\t\\n\")\n\tfmt.Fprintf(w, \"%s\\t%s\\t%d\\t%d\\n\", \"TOTAL\", \"\",\n\t\ttotal.visits,\n\t\ttotal.uniques,\n\t)\n\n\treturn w.Flush()\n}\n"
  },
  {
    "path": "logparser/v6/logly/parse/count.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage parse\n\nimport \"fmt\"\n\n// Count the parsed records.\ntype Count struct {\n\t// Parser is wrapped by Count to count the parsed records.\n\tParser\n\tcount int\n}\n\n// CountRecords creates a record counter that wraps a parser.\nfunc CountRecords(p Parser) *Count {\n\treturn &Count{Parser: p}\n}\n\n// Parse increments the counter.\nfunc (c *Count) Parse() bool {\n\tc.count++\n\treturn c.Parser.Parse()\n}\n\n// Err returns the first error that was encountered by the Log.\nfunc (c *Count) Err() (err error) {\n\terr = c.Parser.Err()\n\tif err != nil {\n\t\terr = fmt.Errorf(\"record #%d: %v\", c.count, err)\n\t}\n\treturn\n}\n\n// You don't need to implement the Value() method.\n// Thanks to interface embedding.\n"
  },
  {
    "path": "logparser/v6/logly/parse/json.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage parse\n\nimport (\n\t\"encoding/json\"\n\t\"io\"\n\n\t\"github.com/inancgumus/learngo/logparser/v6/logly/record\"\n)\n\n// JSONParser parses json records.\ntype JSONParser struct {\n\tin   *json.Decoder\n\terr  error          // last error\n\tlast *record.Record // last parsed record\n}\n\n// JSON creates a json parser.\nfunc JSON(r io.Reader) *JSONParser {\n\treturn &JSONParser{\n\t\tin:   json.NewDecoder(r),\n\t\tlast: new(record.Record),\n\t}\n}\n\n// Parse the next line.\nfunc (p *JSONParser) Parse() bool {\n\tif p.err != nil {\n\t\treturn false\n\t}\n\n\tp.last.Reset()\n\n\terr := p.in.Decode(&p.last)\n\tif err == io.EOF {\n\t\treturn false\n\t}\n\n\tp.err = err\n\n\treturn err == nil\n}\n\n// Value returns the most recent record parsed by a call to Parse.\nfunc (p *JSONParser) Value() record.Record {\n\treturn *p.last\n}\n\n// Err returns the first error that was encountered by the Log.\nfunc (p *JSONParser) Err() error {\n\treturn p.err\n}\n"
  },
  {
    "path": "logparser/v6/logly/parse/parser.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage parse\n\nimport \"github.com/inancgumus/learngo/logparser/v6/logly/record\"\n\n// Parser is an interface for the parsers.\ntype Parser interface {\n\t// Parse the next record from the source.\n\tParse() bool\n\n\t// Value returns the last parsed record by a call to Parse.\n\tValue() record.Record\n\n\t// Err returns the first error that was encountered.\n\tErr() error\n}\n"
  },
  {
    "path": "logparser/v6/logly/parse/text.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage parse\n\nimport (\n\t\"bufio\"\n\t\"io\"\n\n\t\"github.com/inancgumus/learngo/logparser/v6/logly/record\"\n)\n\n// TextParser parses text based log lines.\ntype TextParser struct {\n\tin   *bufio.Scanner\n\terr  error          // last error\n\tlast *record.Record // last parsed record\n}\n\n// Text creates a text parser.\nfunc Text(r io.Reader) *TextParser {\n\treturn &TextParser{\n\t\tin:   bufio.NewScanner(r),\n\t\tlast: new(record.Record),\n\t}\n}\n\n// Parse the next line.\nfunc (p *TextParser) Parse() bool {\n\tif p.err != nil {\n\t\treturn false\n\t}\n\tif !p.in.Scan() {\n\t\treturn false\n\t}\n\n\tp.err = p.last.FromText(p.in.Bytes())\n\n\treturn true\n}\n\n// Value returns the most recent record parsed by a call to Parse.\nfunc (p *TextParser) Value() record.Record {\n\treturn *p.last\n}\n\n// Err returns the first error that was encountered by the Log.\nfunc (p *TextParser) Err() error {\n\treturn p.err\n}\n"
  },
  {
    "path": "logparser/v6/logly/record/json.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage record\n\nimport \"encoding/json\"\n\n// UnmarshalJSON to a record.\nfunc (r *Record) UnmarshalJSON(data []byte) error {\n\ttype rjson Record\n\n\terr := json.Unmarshal(data, (*rjson)(r))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn r.validate()\n}\n"
  },
  {
    "path": "logparser/v6/logly/record/record.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage record\n\nconst fieldsLength = 4\n\n// Record stores fields of a log line.\ntype Record struct {\n\tDomain  string\n\tPage    string\n\tVisits  int\n\tUniques int\n}\n\n// Sum the numeric fields with another record.\nfunc (r *Record) Sum(other Record) {\n\tr.Visits += other.Visits\n\tr.Uniques += other.Uniques\n}\n\n// Reset all the fields of this record.\nfunc (r *Record) Reset() {\n\tr.Domain = \"\"\n\tr.Page = \"\"\n\tr.Visits = 0\n\tr.Uniques = 0\n}\n"
  },
  {
    "path": "logparser/v6/logly/record/sum.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage record\n\n// Sum groups the records by summing their numeric fields.\ntype Sum struct {\n\tsum map[string]Record\n}\n\n// SumGroup the records by domain.\nfunc SumGroup() *Sum {\n\treturn &Sum{\n\t\tsum: make(map[string]Record),\n\t}\n}\n\n// Group the record.\nfunc (s *Sum) Group(r Record) {\n\tk := r.Domain\n\tr.Sum(s.sum[k])\n\ts.sum[k] = r\n}\n\n// Records returns the grouped records.\nfunc (s *Sum) Records() []Record {\n\tvar out []Record\n\tfor _, res := range s.sum {\n\t\tout = append(out, res)\n\t}\n\treturn out\n}\n"
  },
  {
    "path": "logparser/v6/logly/record/text.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage record\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// FromText unmarshals the log line into this record.\nfunc (r *Record) FromText(p []byte) (err error) {\n\tfields := strings.Fields(string(p))\n\n\tif len(fields) != fieldsLength {\n\t\treturn fmt.Errorf(\"wrong number of fields %q\", fields)\n\t}\n\n\tr.Domain = fields[0]\n\tr.Page = fields[1]\n\n\tconst msg = \"record.UnmarshalText %q: %v\"\n\tif r.Visits, err = strconv.Atoi(fields[2]); err != nil {\n\t\treturn fmt.Errorf(msg, \"visits\", err)\n\t}\n\tif r.Uniques, err = strconv.Atoi(fields[3]); err != nil {\n\t\treturn fmt.Errorf(msg, \"uniques\", err)\n\t}\n\n\treturn r.validate()\n}\n"
  },
  {
    "path": "logparser/v6/logly/record/validate.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage record\n\nimport \"errors\"\n\n// validate whether the current record is valid or not.\nfunc (r *Record) validate() error {\n\tvar msg string\n\n\tswitch {\n\tcase r.Domain == \"\":\n\t\tmsg = \"record.domain cannot be empty\"\n\tcase r.Page == \"\":\n\t\tmsg = \"record.page cannot be empty\"\n\tcase r.Visits < 0:\n\t\tmsg = \"record.visits cannot be negative\"\n\tcase r.Uniques < 0:\n\t\tmsg = \"record.uniques cannot be negative\"\n\t}\n\n\tif msg != \"\" {\n\t\treturn errors.New(msg)\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "logparser/v6/logly/report/json.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage report\n\nimport (\n\t\"encoding/json\"\n\t\"io\"\n\n\t\"github.com/inancgumus/learngo/logparser/v6/logly/record\"\n)\n\n// JSON generates a json report.\nfunc JSON(w io.Writer, rs []record.Record) error {\n\tenc := json.NewEncoder(w)\n\n\tfor _, r := range rs {\n\t\terr := enc.Encode(&r)\n\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "logparser/v6/logly/report/text.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage report\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"text/tabwriter\"\n\n\t\"github.com/inancgumus/learngo/logparser/v6/logly/record\"\n)\n\n// Text generates a text report.\nfunc Text(w io.Writer, rs []record.Record) error {\n\ttw := tabwriter.NewWriter(\n\t\tw,\n\t\t0,   // minWidth\n\t\t4,   // tabWidth\n\t\t4,   // padding\n\t\t' ', // padChar\n\t\t0,   // flags\n\t)\n\n\tfmt.Fprintf(tw, \"DOMAINS\\tPAGES\\tVISITS\\tUNIQUES\\n\")\n\tfmt.Fprintf(tw, \"-------\\t-----\\t------\\t-------\\n\")\n\n\tvar total record.Record\n\tfor _, r := range rs {\n\t\ttotal.Sum(r)\n\n\t\tfmt.Fprintf(tw, \"%s\\t%s\\t%d\\t%d\\n\",\n\t\t\tr.Domain, r.Page,\n\t\t\tr.Visits, r.Uniques,\n\t\t)\n\t}\n\n\tfmt.Fprintf(tw, \"\\t\\t\\t\\n\")\n\tfmt.Fprintf(tw, \"%s\\t%s\\t%d\\t%d\\n\",\n\t\t\"TOTAL\", \"\",\n\t\ttotal.Visits, total.Uniques,\n\t)\n\n\treturn tw.Flush()\n}\n"
  },
  {
    "path": "logparser/v6/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/inancgumus/learngo/logparser/v6/logly/parse\"\n\t\"github.com/inancgumus/learngo/logparser/v6/logly/record\"\n\t\"github.com/inancgumus/learngo/logparser/v6/logly/report\"\n)\n\nfunc main() {\n\tvar (\n\t\tp = parse.CountRecords(parse.Text(os.Stdin))\n\t\tg = record.SumGroup()\n\t)\n\n\tfor p.Parse() {\n\t\tg.Group(p.Value())\n\t}\n\tif err := p.Err(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tif err := report.Text(os.Stdout, g.Records()); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n"
  },
  {
    "path": "magic/detect.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage magic\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\n// Detect returns the files that have a valid header (file signature).\n// A valid header is determined by the format.\nfunc Detect(format string, filenames []string) (valids []string, err error) {\n\theader := headerOf(format)\n\tif header == \"unknown\" {\n\t\terr = fmt.Errorf(\"unknown format: %s\", format)\n\t\treturn\n\t}\n\n\tbuf := make([]byte, len(header))\n\n\tfor _, filename := range filenames {\n\t\tif read(filename, buf) != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif bytes.Equal([]byte(header), buf) {\n\t\t\tvalids = append(valids, filename)\n\t\t}\n\t}\n\treturn\n}\n\nfunc headerOf(format string) string {\n\tswitch format {\n\tcase \"png\":\n\t\treturn \"\\x89PNG\\r\\n\\x1a\\n\"\n\tcase \"jpg\":\n\t\treturn \"\\xff\\xd8\\xff\"\n\t}\n\t// this should never occur\n\t// panic(\"unknown format: \" + format)\n\treturn \"unknown\"\n}\n\n// read reads len(buf) bytes to buf from a file\nfunc read(filename string, buf []byte) error {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\tfi, err := file.Stat()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif fi.Size() <= int64(len(buf)) {\n\t\treturn errors.New(\"file size < len(buf)\")\n\t}\n\n\t_, err = io.ReadFull(file, buf)\n\treturn err\n}\n"
  },
  {
    "path": "magicpanic/detect.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage magic\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n)\n\n// Detect returns the files that have a valid header (file signature).\n// A valid header is determined by the format.\nfunc Detect(format string, filenames []string) (valids []string, err error) {\n\tdefer func() {\n\t\tif rerr := recover(); rerr != nil {\n\t\t\terr = fmt.Errorf(\"cannot detect: %v\", rerr)\n\t\t}\n\t}()\n\n\treturn detect(format, filenames), nil\n}\n\nfunc detect(format string, filenames []string) (valids []string) {\n\theader := headerOf(format)\n\tbuf := make([]byte, len(header))\n\n\tfor _, filename := range filenames {\n\t\tif read(filename, buf) != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif bytes.Equal([]byte(header), buf) {\n\t\t\tvalids = append(valids, filename)\n\t\t}\n\t}\n\treturn\n}\n\nfunc headerOf(format string) string {\n\tswitch format {\n\tcase \"png\":\n\t\treturn \"\\x89PNG\\r\\n\\x1a\\n\"\n\tcase \"jpg\":\n\t\treturn \"\\xff\\xd8\\xff\"\n\t}\n\t// this should never occur\n\tpanic(\"unknown format: \" + format)\n}\n\n// read reads len(buf) bytes to buf from a file\nfunc read(filename string, buf []byte) error {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\tfi, err := file.Stat()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif fi.Size() <= int64(len(buf)) {\n\t\treturn fmt.Errorf(\"file size < len(buf)\")\n\t}\n\n\t_, err = io.ReadFull(file, buf)\n\treturn err\n}\n"
  },
  {
    "path": "main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n  fmt.Println(\"Hi Gopher!\")\n}\n"
  },
  {
    "path": "translation/README.md",
    "content": "# This Repo Is Available In The Following Languages\n\n* **[English](https://github.com/inancgumus/learngo)**\n* **[Spanish](spanish/README.md)**"
  },
  {
    "path": "translation/chinese/01-安装与介绍/README.md",
    "content": "# GO 安装指引\n\n请根据你的操作系统获取安装详情\n\n* [OS X](osx-安装指南.md)\n* [Windows](windows-安装指南.md)\n* [Linux (Ubuntu)](ubuntu-安装指南.md)\n"
  },
  {
    "path": "translation/chinese/01-安装与介绍/osx-安装指南.md",
    "content": "# OS X 安装\n\n## 提示\n\n如果已经安装好[homebrew](https://brew.sh), 可以按照如下步骤安装Go\n\n```\n# 安装git可以参照如下命令:\nbrew install git\n\n# go 安装命令\nbrew install go\n\n# 添加 GOBIN 路径 ~/.bash_profile\nexport PATH=${HOME}/go/bin:$PATH\n```\n\n## 1- 安装 Visual Studio Code Editor\n\n1. 安装地址: [https://code.visualstudio.com](https://code.visualstudio.com)\n2. 选择 OS X (Mac) 下载\n3. 解压 添加到应用程序`~/Applications`路径.\n\n## 2- 安装 Git\n\n1. 下载Git. 官网: [https://git-scm.com/downloads](https://git-scm.com/downloads)\n2. 选择VSCode为默认编辑器\n\n## 3- 安装 Go\n\n1. 官网 [https://golang.org/dl](https://golang.org/dl)\n2. 选择 OS X (Mac)\n3. 下载\n\n## 4- 配置 VS Code\n\n1. 打开 VS Code; 点击扩展插件功能, 搜索 \"go\" 下载\n2. 下载完成后重启VS Code\n\n3. 选择 View 菜单; 选择 **Command Palette**\n    1. 输入 `cmd+shift+p`\n    2. 输入: `go install`\n    3. 选择 _\"Go: Install/Update Tools\"_\n    4. 选择所有 checkboxes\n\n4. 重启 **Command Palette** \n    1. 输入: `shell`\n    2. 选择: _\"Install 'code' command in PATH\"_\n        1. **提示:** Windows操作系统不需要上述操作.\n\n## 工作完成! Enjoy! 🤩\n\n<div style=\"page-break-after: always;\"></div>\n\n> 更多内容: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n> \n> Copyright © 2018 Inanc Gumus\n> \n> Learn Go Programming Course\n> \n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/chinese/01-安装与介绍/ubuntu-安装指南.md",
    "content": "# Linux 安装指南\n\n如果,只需要安装Go，请执行如下指令:\n\n    sudo snap install go --classic\n\n否则, 请按如下安装步骤安装:\n\n## 1. 更新本地依赖包\n\n  ```bash\n  sudo apt-get update\n  ```\n\n## 2. 安装 git\n\n  ```bash\n  sudo apt-get install git\n  ```\n\n## 3. 安装 Go\n\n安装Go环境有如下两种方法:\n\n1- 网站: 选择 Linux 版本并安装.\n\n  ```bash\n  firefox https://golang.org/dl\n  ```\n\n2- 使用snap: 如果选择snap安装, 可以直接跳到步骤5.\n\n  ```bash\n  sudo snap install go --classic\n  ```\n\n## 4. 将Go拷贝到适当的工作目录\n\n1. 找到下载好的文件\n\n2. 解压文件\n\n    ```bash\n    gofile=\"DELETE_THIS_AND_TYPE_THE_NAME_OF_THE_DOWNLOADED_FILE_HERE (替换为下载文件，省去后缀)\"\n    tar -C /usr/local -xzf ~/Downloads/$gofile\n    ```\n\n## 5. 添加Go的可执行路径\n\n1. 添加`go/bin`目录到 `$PATH`, 以便执行Go的基础命令.\n\n    ```bash\n    echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile\n    ```\n\n2. 添加 \"$HOME/go/bin\" 目录到 $PATH\n\n    ```bash\n    echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.profile\n    ```\n\n## 安装Go工具:\n\n* 有很多开发工具，可以让简化Go的开发 (如 goimports)\n\n* 如果系统中没有安装代码版本工具(如 Git), 将无法使用`go get`.\n\n* 上述命令会创建`~/go` 目录并下载到相应目录中.\n\n    * 此目录也将是我们存放代码的目录.(如果不实用Go Modules)\n\n    ```bash\n    go get -v -u golang.org/x/tools/...\n    ```\n\n## 安装 VSCode (可选)\n\n提示: 本课程将使用Visual Studio Code (VSCode). 但是, 可以使用任何代码编辑工具.\n\n1. 打开 \"Ubuntu Software\" 应用\n\n2. 搜索并安装VSCode\n\n\n## 可选步骤:\n\n1. 在`$GOPATH`之外的任何路径创建文件 hello.go\n\n    ```bash\n    cat <<EOF > hello.go\n    package main\n    import \"fmt\"\n    func main() {\n        fmt.Println(\"hello gopher!\")\n    }\n    EOF\n    ```\n2. 执行程序\n    ```bash\n    go run hello.go\n    It should print: hello gopher!\n    ```\n<div style=\"page-break-after: always;\"></div>\n> 更多内容: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2018 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
  },
  {
    "path": "translation/chinese/01-安装与介绍/windows-安装指南.md",
    "content": "# WINDOWS 安装指南\n\n## 笔记\n\n如果已安装 [chocolatey.org](https://chocolatey.org/) 包管理工具, 可以通过如下命令安装:\n\n```\nchoco install golang\n```\n\n## 1- 安装 Visual Studio Code Editor\n\n1. 安装但是不要直接打开.\n2. 打开 : [https://code.visualstudio.com](https://code.visualstudio.com)\n3. 选择 Windows并进行安装\n4. 执行installer\n\n## 2- 安装 Git\n\n1. 通过官网下载和安装. 官网地址: [https://gitforwindows.org](https://gitforwindows.org)\n2. 选择 VSCode为默认编辑器\n3. 勾选所以复选框,启用所有可选功能\n4. 选择: _\"Use Git from the Windows Command Prompt\"_\n5. 编码: 选择: _\"Checkout as is...\" option._\n\n## 3- 安装 Go\n\n1. 登陆Go官网 [https://golang.org/dl](https://golang.org/dl)\n2. 选择 Windows版本下载\n3. 执行Go安装器\n\n## 4- 配置 VS Code\n\n1. 运行 VS Code;在插件市场搜索\"go\"并安装\n2. 关闭 VS Code并重新打开\n\n3. 前往视图菜单; 选择 **Command Palette**\n    1. 执行 `ctrl+shift+p`\n    2. 键入: `go install`\n    3. 选择 _\"Go: Install/Update Tools\"_\n    4. 勾选所有复选框\n\n## 5- 使用 Git-Bash\n\n* 在本课程我们将使用bash作为命令行. Bash是在OS X 和 Linux系统上非常流行的命令行工具. \n  如果你也希望使用bash 而不是Windows提供的默认命令行, 可以使用已安装的bash命令行, 好似使用OS X 和 Linux系统.\n\n* 如果您不打算使用git bash也是可以的. 但是, 本课程将使用git bash. git bash可以提供本课程需要的许多高级特性.\n\n* 您也可以选择更加强大的工具来替代 git bash, 参考: [Linux Subsystem for Windows](https://docs.microsoft.com/en-us/windows/wsl/install-win10)\n\n* **因此, 如果使用 git bash, 请遵守如下步骤:**\n    1. 在开始栏搜索git bash\n    \n    2. 或者, 如果已经下载可以直接启用\n\n    3. 设置 VS Code 默认使用 git-bash:\n        1. 启动 VS Code\n        2. 转到命令面板\n            1. 输入: `terminal`\n            2. 选择: _\"Terminal: Select Default Shell\"_\n            3. 选择: _\"Git Bash\"_\n\n    4. **提示:** 一般, 可以在 `c:\\`文件夹找到自定义文件. 但是, 档我们使用git bash, 自定义问价会在文件夹 `/c/`. 事实上，这两个文件目录是同一个目录, 只是一个软链接.\n\n## 以上步骤完成，就可以使用了! 🤩\n\n<div style=\"page-break-after: always;\"></div>\n\n> 更多资料, 参考: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2018 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/chinese/01-安装与介绍/学习路线.md",
    "content": "# 学习路线\n\n大家好!\n\n如果您是有经验的开发者, 您只需要跟着课程学习50个小节即可，完整的课程是180节。\n\n本课程从Go基础内容开始,逐渐递进。我们希望让尽量多的Go学习者可以轻松入门。\n如果您觉得某些小节的内容您已掌握,可以跳过这部分直接做课后题。当然，您也可以\n回过头来复习本小节。\n\n\n## 课程\n\n* **写下第一个Go程序**\n  * 请看所有的课程.\n  * Go文档是什么?\n  * \"写一个库\"之前的准备课程\n\n* **掌握Go的类型系统**\n  * 每个Go类型都有一个零值\n  * blank标识符是什么?\n  * 让我们定义一组变量!\n  * 类型引用是什么?\n  * 怎样声明短变量?\n  * 为何不能在包中声明短变量?\n  * 重复声明是什么?\n  * 什么情况可以适合使用短变量声明?\n  * 学习从命令行获取输入和切片\n  * 学习 os.Args 基本用法\n  * 使用 os.Args 实现欢迎新人\n  * 使用Printf 进行格式化输出的准备工作\n  * 将摄氏度转换为华氏度\n  * 将换英尺转换为米\n  * 原始字符串是什么?\n  * 怎样获得字符串长度?\n  * 什么是预定义的类型之后的课程.\n  * 理解为定义类型的常量的后续课程, 章节的结束\n    * 学习常量的规则\n    * 复习: 常量\n    * 未定义类型的常量是怎样在钩子下运行的？\n    * 默认类型是什么?\n    * 例子: time.Duration\n    * iota 是什么?\n    * 推荐的命名法\n\n* **控制Go的错误处理流程**\n  * 观看所有 \"认证通过: 创建密码保护程序\"之前的课程\n  * 观看所有 \"理解Go的错误处理\"之前的课程\n  * case 条件语句中使用多个值\n  * 回滚语句是怎样工作的?\n  * 解决方案: 一天的部分\n  * 复习: Switch 语句\n  * 怎样继续一个循环? (+奖励: 调试)\n  * 创建一个乘法表\n  * 怎样循环一个切片\n  * 范围: 轻巧地统计方法!\n\n* **项目: 针对初学者**\n  * 请观看完整课程.\n\n* **余下章节**\n  * 到目前为止，Go的基础部分已经结束。您可以观看余下的所有课程，余下课程覆盖了Go的高级特性.\n\n## That's all! Enjoy! 🤩\n\n---\n\n# 奖励: 我们为什么要学Go?\n\n**总结:** Go犹如Python和Javascript一样简单,C/C++一样快.使用Go作为工作语言会比C/C++更有趣。我们既可以使用Go的low-level API也可以使用high-level API。\n\n## Go能用在哪些场景?\n\nGo在互联网公司经常被应用,例如: Google, Facebook, Twitter, Uber, Apple, Dropbox, Soundcloud, Medium, Mozilla Firefox, Github, Docker, Kubernetes, 和 Heroku.\n\n**Go 非常适合:** 跨平台命令行工具, 分布式网络系统, 微服务 和 Serverless, 网站APIs, 数据库引擎, 大数据处理流水线, 嵌入式开发, 等等.\n\n**Go 不是特别适合 (但是可以使用):** 桌面应用, 操作系统, 内核驱动, 游戏开发, etc.\n\n## Go的设计者是谁？\n\nGo的设计者在工业界非常有影响力， 他们是:\n\n* Unix: Ken Thompson\n* UTF-8, Plan 9: Rob Pike\n* Hotspot JVM (Java Virtual Machine): Robert Griesemer\n\n## Go的市场薪资待遇\n\n* [Go 薪资](https://www.payscale.com/research/US/Skill=Go_(Golang)_Programming_Language/Salary)\n\n## [Go的前8年](https://blog.golang.org/8years):\n\n> 如今, **每个云厂商的关键基础组件都可以看到Go语言的影子** 包括 Google Cloud, AWS, Microsoft Azure, Heroku, 等等. Go 是云厂商的重要部分.例如,Alibaba, Cloudflare, 和 Dropbox 都在使用Go. Go也是公共基础设施的重要组成部分。例如, Kubernetes, Cloud Foundry, Openshift, NATS, Docker, Istio, Etcd, Consul, Juju, 等都在使用Go. Companies are increasingly choosing Go,云基础设施方案选型中越来越多的公司开始采用Go.\n\n## 我们可以用Go做哪些事情?\n\n* [网络驱动程序](https://www.net.in.tum.de/fileadmin/bibtex/publications/theses/2018-ixy-go.pdf) (_与C驱动相比只有10%的性能差距_)\n* [Google gVisor](https://cloud.google.com/blog/products/gcp/open-sourcing-gvisor-a-sandboxed-container-runtime) (_Go实现用户空间内核_)\n* [多平台任天堂模拟器](https://humpheh.github.io/goboy/)\n* [Docker: 容器](https://github.com/moby/moby)\n* [Kubernetes: 容器编排管理](https://github.com/kubernetes/kubernetes)\n* 虚拟机镜像处理工具\n* 聊天服务器\n* RUM beacon收集器\n* 时间序列数据库引擎, 客户端, 命令行工具, 等等.\n* Map-reduce依赖包\n* 支持动态内容重写,图片放大缩放，缓存，Lua事件处理器功能的反向代理集群\n* 基于地理位置的反向代理CDN节点\n* 健康管理应用(时间处理&点对点报告)\n* Go DNS 服务器\n* 接入MySQL的API后台服务\n* Linux 进程处理工具\n* 作为反向代理隐藏后台服务器.\n* HTML -> PDF 转换器.\n* 短链接服务 类似 tinyurl.com 和 goo.gl\n* SMS 消息服务.\n* 信用卡支付网关\n* JSON Web Token工具包\n* 动态图像处理服务\n* 第三方内容渲染工作流(十分庞大的项目)\n* lxc 容器部署\n* 自动化测试框架\n\n参考: [This Reddit post](https://www.reddit.com/r/golang/comments/5nac2b/what_have_you_used_go_for_in_your_professional/).\n\n## 更多Go相关请参考:\n\n* [关于 Go: 概览](https://blog.learngoprogramming.com/about-go-language-an-overview-f0bee143597c)\n* [为什么要学习Go?](https://medium.com/@kevalpatel2106/why-should-you-learn-go-f607681fad65)\n* [云基础设施的新兴语言](https://redmonk.com/dberkholz/2014/03/18/go-the-emerging-language-of-cloud-infrastructure/)\n* [使用Go的公司](https://github.com/golang/go/wiki/GoUsers)\n* [Go的8年](https://blog.golang.org/8years)\n* [Twitter: 使用Go一天处理50 亿会话](https://blog.twitter.com/engineering/en_us/a/2015/handling-five-billion-sessions-a-day-in-real-time.html)\n* [C++工程师眼里的Go](https://www.murrayc.com/permalink/2017/06/26/a-c-developer-looks-at-go-the-programming-language-part-1-simple-features/)\n\n<div style=\"page-break-after: always;\"></div>\n\n> 更多内容: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n> \n> Copyright © 2019 Inanc Gumus\n> \n> 学习Go编程课程\n> \n> [点击查看认证许可.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/README.md",
    "content": "# 备忘录: 编写第一个 GO 程序\n\n嗨！\n\n作为参考，你可以在参加本节讲座后保存这个备忘录\n\n你也可以打印下来这个备忘录，然后和本节的视频讲座一起操作\n\n加油！\n\n---\n\n## 命令行命令:\n\n* 进入目录: `cd directoryPath`\n\n* **WINDOWS:**\n\n    * 列出目录所有文件: `dir`\n\n* **OS X & LINUXes:**\n\n    * 列出目录所有文件: `ls`\n\n## 编译 & 运行 GO 程序:\n\n* **编译一个 Go 程序:**\n\n    * 在程序所在目录，输入:\n        * `go build main.go`\n\n* **运行一个 Go 程序:**\n\n    * 在程序所在目录，输入:\n        * `go run main.go`\n\n## 你应该将源代码放在哪里？\n\n* 你想放到哪个目录都可以\n\n## 第一个程序\n\n### 新建一个目录\n* 新建一个目录:\n  * `mkdir myDirectoryName`\n* 进入目录:\n  * `cd myDirectoryName`\n\n### 添加源代码文件\n* 新建源代码文件 `code main.go` \n  * 这条命令会在当前目录新建一个文件并使用 Visual Studio Code 打开该文件。\n* 然后复制下面的代码到文件并保存文件\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi! I want to be a Gopher!\")\n}\n```\n\n### 运行程序\n* 最后，返回到命令行\n  * 执行命令: `go run main.go`\n* 如果你创建了其他文件并想同时执行它们，可以使用这个命令:\n  * `go run .`\n\n这就是全部内容了!\n\n> 更多资料, 参考: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2018 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// package main 是一个特殊的包\n// 它允许 Go 创建一个可执行文件\npackage main\n\n/*\n这是一个多行注释\n\nimport 关键字引入另一个包\n  对于这个 .go ”文件“\n\nimport \"fmt\" 允许你使用 fmt 包的各种函数\n  在这个文件\n*/\nimport \"fmt\"\n\n// \"func main\" 是特殊的\n//\n// Go 必须知道从哪里开始执行\n//\n// func main 对于 Go 而言就是开始执行的位置\n//\n// 代码编译后，\n// Go runtime 第一个执行该函数\nfunc main() {\n\t// import \"fmt\" 之后\n\t// \"fmt\" 包中的 Println 函数就可以使用\n\n\t// 在控制台输入下面的命令可以查看它的源代码:\n\t//   go doc -src fmt Println\n\n\t// Println 是一个 exported 函数来自\n\t//   \"fmt\" 包\n\n\t// Exported = 首字母大写\n\tfmt.Println(\"Hello Gopher!\")\n\n\t// Go 本身不能调用 Println 函数\n\t// 这就是为什么你需要在这里调用它\n\t// Go 只能自动地调用 `func main`\n\n\t// -----\n\n\t// Go 字符串支持 Unicode 字符\n\t// 源代码同时也支持: KÖSTEBEK!\n\t//\n\t// 因为: 字面值 ~= 源代码\n\n\t// 练习: 删除下行注释的 --> //\n\t// fmt.Println(\"Merhaba Köstebek!\")\n\n\t// 不重要的注释:\n\t// \"Merhaba Köstebek\" 的意思是 \"你好 Gopher\"\n\t// 在土耳其语\n}\n"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/带注释的 GO 程序.md",
    "content": "# 带注释的 Go 程序\n\n```go\n// package main 是一个特殊的包\n// 它允许 Go 创建一个可执行文件\npackage main\n\n/*\n这是一个多行注释\n\nimport 关键字引入另一个包\n  对于这个 .go ”文件“\n\nimport \"fmt\" 允许你使用 fmt 包的各种函数\n  在这个文件\n*/\nimport \"fmt\"\n\n// \"func main\" 是特殊的\n//\n// Go 必须知道从哪里开始执行\n//\n// func main 对于 Go 而言就是开始执行的位置\n//\n// 代码编译后，\n// Go runtime 第一个执行该函数\nfunc main() {\n\t// import \"fmt\" 之后\n\t// \"fmt\" 包中的 Println 函数就可以使用\n\n\t// 在控制台输入下面的命令可以查看它的源代码:\n\t//   go doc -src fmt Println\n\n\t// Println 是一个 exported 函数来自\n\t//   \"fmt\" 包\n\n\t// Exported = 首字母大写\n\tfmt.Println(\"Hello Gopher!\")\n\n\t// Go 本身不能调用 Println 函数\n\t// 这就是为什么你需要在这里调用它\n\t// Go 只能自动地调用 `func main`\n\n\t// -----\n\n\t// Go 字符串支持 Unicode 字符\n\t// 源代码同时也支持: KÖSTEBEK!\n\t//\n\t// 因为: 字面值 ~= 源代码\n}\n```\n\n\n<div style=\"page-break-after: always;\"></div>\n\n> 更多资料, 参考: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n> \n> Copyright © 2018 Inanc Gumus\n> \n> Learn Go Programming Course\n> \n> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/练习/01-print-names/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: Print names\n//\n//  打印你和你最好朋友的名字使用\n//  Println 两次\n//\n// 练习输出\n//  你的名字\n//  你朋友的名字\n//\n// 额外任务\n//  首先使用 `go run`\n//  然后使用 `go build` 并运行你的程序\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/练习/01-print-names/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// go run main.go\n\n// go build\n// ./solution\n\nfunc main() {\n\tfmt.Println(\"Nikola\")\n\tfmt.Println(\"Thomas\")\n}\n"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/练习/README.md",
    "content": "1. **打印你和你最好朋友的名字** 使用 Println 两次。 [练习点击这里](https://github.com/inancgumus/learngo/tree/master/02-write-your-first-program/exercises/01-print-names).\n\n2. **自娱自乐**\n\n    1. 使用 `go build` 编译程序\n\n    2. **发送程序给你的朋友**\n\n       他/她应该和你使用相同的操作系统\n\n       例如，如果你使用的是 Windows ，他/她应该也使用 Windows \n\n    3. **发送程序给你的朋友如果他使用不同的操作系统**\n\n       这样，你应该为他/她的操作系统编译程序\n\n       **编译 OSX 可执行程序:**\n       `GOOS=darwin GOARCH=386 go build`\n\n       **编译 Windows 可执行程序:**\n       `GOOS=windows GOARCH=386 go build`\n\n       **编译 Linux 可执行程序:**\n       `GOOS=linux GOARCH=arm GOARM=7 go build`\n\n       **通过这里可以获取全部列表:**\n       https://golang.org/doc/install/source#environment\n\n       **注意:** 如果你使用命令提示符或者 PowerShell , 你可能需要使用下面的命令:\n       `cmd /c \"set GOOS=darwin GOARCH=386 && go build\"`\n\n3. **调用 [Print](https://golang.org/pkg/fmt/#Print) 而不是 [Println](https://golang.org/pkg/fmt/#Println)** 看看会发生什么\n\n4. **调用 [Println](https://golang.org/pkg/fmt/#Println) 或者 [Print](https://golang.org/pkg/fmt/#Print) 输入多个数据** 通过逗号分隔\n\n5. **移除字符串两边的双引号** 看看会发生什么\n\n6. **将 package 和 import 声明** 移到文件末尾看看会发生什么\n\n7. **[阅读 Go 在线文档](https://golang.org/pkg)**.\n\n    1. 快速浏览 packages ，看看它们的用途\n\n    2. 通过点击标题查看其源代码\n\n    3. 你不必弄懂全部，只需要亲自写吧，这仅仅是为了后面的课程热身\n\n8. 对了, **打开 tour**: https://tour.golang.org/\n\n    1. 快速浏览一下，查看一下语言特点\n\n    2. 我们很快会讨论它们\n\n9. [关注我的 twitter 学习更多](https://twitter.com/inancgumus)."
  },
  {
    "path": "translation/chinese/02-编写第一个程序/问题/01-gopath/README.md",
    "content": "## 应该保存 Go 源代码到哪里？\n* 我的电脑任何地方\n* $GOPATH 下\n* $GOPATH/src 下 *正确*\n\n## $GOPATH 是什么?\n* 它是 Go 运行时的文件\n* 存储 Go 源代码文件和编译的包的目录\n* 它是 gophers 需要关注的地址\n\n## 需不需要设置 $GOPATH?\n* 需要\n* 不需要: 它保存在我的电脑里面\n* 不需要: 它保存在用户目录下 *正确*\n\n## 如何打印 $GOPATH 的值？\n* 使用 `ls` 命令\n* 使用 `go env GOPATH` 命令 *正确*\n* 使用 `go environment` 命令"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/问题/02-code-your-first-program/README.md",
    "content": "## 下面哪一个关键字用来定义一个包？\n```go\npackage main\n\nfunc main() {\n}\n```\n1. func\n2. package *正确*\n3. fmt.Println\n4. import\n\n> **1:** func 关键字用来新定义一个函数\n>\n>\n> **2:** 对，package 关键字用来在 Go 文件中定义包\n>\n>\n> **3:** 这不是关键字，它是 fmt 包中的一个函数\n>\n>\n> **4:** import 关键字用来导入一个包\n>\n>\n\n\n## 在下面代码中使用 package main 的目的是什么？\n```go\npackage main\n\nfunc main() {\n}\n```\n* 为了创建一个库包\n* 为了正确退出程序\n* 为了创建一个可执行的 Go 程序 *正确*\n\n\n## 在下面代码中使用 func main 的目的是什么？\n```go\npackage main\n\nfunc main() {\n}\n```\n1. 为了创建一个叫 main 的包\n2. 为了让 Go 开始执行程序 *正确*\n3. 为了向控制台打印一条消息\n\n> **1:** main function 不创建一个包\n>\n>\n> **2:** 对，Go 自动地从 main 函数开始执行\n>\n>\n> **3:** 它不会打印任何东西(目前为止)\n>\n>\n\n\n## 在下面代码中使用 import \"fmt\" 的目的是什么？\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi!\")\n}\n```\n1. 它打印 \"fmt\" 到控制台\n2. 它创建一个叫 \"fmt\" 的包\n3. 它导入了 `fmt` 包; 这样你就可以使用其功能 *正确*\n\n> **1:** `fmt.Println` 打印一条消息而不是 `import \"fmt\"`\n>\n>\n> **2:** `package` 关键字创建新包，而不是 `import`\n>\n>\n> **3:** 对，举个例子，导入 fmt 包后，你就可以使用 Println 打印一条消息到控制台\n>\n>\n\n\n## 下面哪一个用来定义函数？\n* func *正确*\n* package\n* Println\n* import\n\n\n## 函数是什么?\n1. 它就像迷你程序，它是可复用可执行的代码块 *正确*\n2. 它允许 Go 执行一个程序\n3. 它允许 Go 导入一个叫 function 的包\n4. 它打印一条消息到控制台\n\n> **2:** Go 寻找 main 包的 func main 去执行，一个函数自己不能执行\n>\n>\n> **3:** 这是 `import` 的作用\n>\n>\n> **4:** 举个例子: 这是 `fmt.Println` 的功能\n>\n>\n\n\n## 是否需要亲自调用 main 函数\n1. 是的，只有这样才能运行自己的程序\n2. 不必，Go 会自动地调用 main 函数 *正确*\n\n> **1:** 不必, 不需要调用 main 函数， Go 自动执行它\n>\n>\n\n\n## 是否需要调用一个函数去执行它?\n_(main 函数除外)_\n1. 需要，只有这样 Go 才能执行一个函数 *正确*\n2. 需要，只有这样 Go 才执行程序\n3. 不需要，函数会自动执行\n\n> **1:** 对的，需要自己调用函数，Go 不会自动执行函数，只有 main 函数自动调用(还有其他一些函数，不过目前还未学到)\n>\n>\n\n> **2:** 这是 `func main` 的唯一工作， 也只有 `func main` 才能执行程序\n>\n>\n\n> **3:** Go 不会自动调用函数，除了 main 函数(还有其他一些函数，不过目前还未学到)，所以，除了 main 函数，你需要手动调用函数\n>\n\n\n## 下面的程序输出是什么？\n```go\npackage main\n\nfunc main() {\n}\n```\n1. 它打印一条消息到控制台\n2. 它是正确的程序，但是什么都不输出 *正确*\n3. 它不是正确的程序\n\n> **1:** 它不是输出任何消息，可以使用 fmt.Println 函数来输出内容\n>\n>\n\n> **2:** 对，它是正确的程序，然后因为它不包含 fmt.Println 所以它什么也不输出\n>\n>\n\n> **3:** 它是正确的程序，它使用 package 关键字，并且有 main 函数。因此，这是一个有效且可执行的 Go 程序\n>\n>\n\n\n## 这个程序的输出是什么？\n```go\npackage main\n\nfunc main() {\n    fmt.Println(Hi! I want to be a Gopher!)\n}\n```\n* Hi! I want to be a Gopher!\n* 它什么都不打印\n* 它不是正确的程序 *正确*\n\n> **1:** 没有用双引号括起来，Println 不能获取值，应该是: fmt.Println(\"Hi! I want to be a Gopher\")\n>\n>\n\n> **3:** 它没有导入 \"fmt\" 包， 还有 #1.\n>\n>\n\n\n## 这个程序的输出是什么？\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi there!\")\n}\n```\n* Hi there! *正确*\n* fmt\n* 它不是正确的程序; 它导入的包里面没有函数叫 `Println`\n\n> **2:** import \"fmt\" 导入 fmt 包，就可以使用其功能\n>\n>\n> **3:** 实际上，这个程序是正确的\n>\n>"
  },
  {
    "path": "translation/chinese/02-编写第一个程序/问题/03-run-your-first-program/README.md",
    "content": "## `go build` 和 `go run` 有什么区别？\n1. `go run` 只编译程序; 而 `go build` 编译运行程序\n2. `go run` 编译运行程序; whereas `go build` 只编译程序。 *正确*\n\n> **1:** 实际上相反的\n>\n>\n> **2:** `go run` 编译程序并把它放在一个临时目录下，然后在临时目录里运行整个程序\n>\n>\n\n\n## Go 保存编译后的代码在那个目录下？\n1. 和执行 `go build` 相同的目录 *正确*\n2. $GOPATH/src 目录\n3. $GOPATH/pkg 目录\n4. 进入一个临时目录\n\n> **2:** 这里只有源代码文件\n>\n>\n> **3:** 当你执行 `go install`，Go 将你的代码安装在这里\n>\n>\n\n\n## 关于 runtime 哪个是正确的？\n1. 它发生在开始运行程序时 *正确*\n2. 它发生在编译程序时\n\n\n## 关于 compile-time 哪个是正确的？\n1. 它发生在开始运行程序时\n2. 它发生在编译程序时  *正确*\n\n\n## Go 程序什么时候打印一条信息到控制台？\n1. 编译程序时\n2. 程序运行时 (compile-time 之后) *正确*\n3. 程序运行时 (和 compile-time 同时)\n\n> **1:** 编译阶段，程序不能打印一条消息，因为它还没有被执行\n>\n>\n> **2:** 对， 程序只有这时才会计算机互交，向控制台打印一条消息\n>\n>\n> **3:** 程序只有编译之后才能运行\n>\n>"
  },
  {
    "path": "translation/chinese/03-包和作用域/01-packages/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/01-packages/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/01-packages/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// 你可以使用其他文件的函数\n\t// 只要它们在同一个包中\n\n\t// 因此, `main()` 可以调用 `bye()` and `hey()`\n\n\t// 因为 bye.go, hey.go 和 main.go\n\t//  都在 main package 中\n\n\tbye()\n\they()\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/02-scopes/01-scopes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// 文件作用域\nimport \"fmt\"\n\n// 包作用域\nconst ok = true\n\n// 包作用域\nfunc main() { // 块作用域开始\n\n\tvar hello = \"Hello\"\n\n\t// hello 和 ok 都可见\n\tfmt.Println(hello, ok)\n\n} // 块作用域结束\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/02-scopes/02-block-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc nope() { //块作用域开始\n\n\t// hello 和 ok 只定义在当前块作用域\n\tconst ok = true\n\tvar hello = \"Hello\"\n\n\t_ = hello\n} // 块作用域结束\n\nfunc main() { // 块作用域开始\n\n\t// hello 和 ok 不可见\n\n\t// ERROR:\n\t// fmt.Println(hello, ok)\n\n} // 块作用域结束\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/02-scopes/03-nested-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// 我不想在这节课中谈论这个话题\n// 作为旁注，我想把它放在这里\n// 记得复习\n\nvar declareMeAgain = 10\n\nfunc nested() { // 块作用域开始\n\n\t// 定义相同的变量\n\t// 它们可以同时存在\n\t// 这个只属于块作用域\n\t// 包作用域的变量仍然可以使用\n\tvar declareMeAgain = 5\n\tfmt.Println(\"inside nested:\", declareMeAgain)\n\n} // 块作用域结束\n\nfunc main() { // 块作用域开始\n\n\tfmt.Println(\"inside main:\", declareMeAgain)\n\n\tnested()\n\n\t// 包作用域的 declareMeAgain 不受 nested 函数的影响\n\tfmt.Println(\"inside main:\", declareMeAgain)\n\n} // 块作用域结束\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/02-scopes/04-package-scope/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/02-scopes/04-package-scope/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/02-scopes/04-package-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// 两个文件属于同一个包\n\t// 在这里调用 bye.go 的 `bye()`\n\tbye()\n}\n\n// 练习: 删除下面函数的注释\n//           分析错误信息\n\n// func bye() {\n// \tfmt.Println(\"Bye!\")\n// }\n\n// ***** EXPLANATION *****\n//\n// ERROR: \"bye\" function \"redeclared\"\n//        in \"this block\"\n//\n// \"this block\" 是指 = \"main package\"\n//\n// \"redeclared\" 是指在同一个作用域中使用了相同的名字\n//\n// main package's 作用域是:\n// main 包中的所有源代码文件\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/03-importing/01-file-scope/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// 取消下面代码的注释会出错\n// (只删除最后三行的 //)\n\n// 这个文件看不到 main.go's 导入的 (\"fmt\")的名字\n// 因为导入的名字在文件作用域\n\n// func bye() {\n// \tfmt.Println(\"Bye!\")\n// }\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/03-importing/01-file-scope/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/03-importing/02-renaming/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\nimport f \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\tf.Println(\"There!\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/01-packages/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 使用自己定义的包\n//\n//  创建几个 Go 文件，并在 main 函数里调用它们里面的函数\n//\n//  1- 创建 main.go, greet.go 和 bye.go 文件\n//  2- 在 main.go 中: 调用 greet 和 bye 函数\n//  3- 运行 `main.go`\n//\n// 提升\n//  greet 函数定义在 greet.go\n//  bye 定义在 bye.go\n//\n// 目标输出\n//  hi there\n//  goodbye\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这里调用其他文件的函数\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/01-packages/solution/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"goodbye\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/01-packages/solution/greet.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc greet() {\n\tfmt.Println(\"hi there\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/01-packages/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tgreet()\n\tbye()\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/02-scopes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 作用域的初体验\n//\n//  1. 创建两个文件: main.go 和 printer.go\n//\n//  2. 在 printer.go 中:\n//     1. 创建一个叫 hello 的函数\n//     2. hello 函数的作用是输出你的名字\n//\n//  3. 在 main.go 中:\n//     1. 和之前一样，创建 main 函数\n//     2. 调用你定义的函数，通过函数名 : hello\n//     3. 创建一个叫 bye 的函数\n//     4. 在 bye 函数中, 输出 \"bye bye\"\n//\n//  4. 在 printer.go 中:\n//     1. 在 hello 函数中\n//        调用 bye 函数\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/02-scopes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// as you can see, I don't need to import a package\n\t// and I can call `hello` function here.\n\t//\n\t// this is because, package-scoped names\n\t// are shared in the same package\n\thello()\n\n\t// but here, I can't access the fmt package without\n\t// importing it.\n\t//\n\t// this is because, it's in the printer.go's file scope.\n\t// it imports it.\n\n\t// this main func can also call bye function here\n\t// bye()\n}\n\n// printer.go can call this function\n//\n// this is because, bye function is in the package-scope\n// of the main package now.\n//\n// main func can also call this.\nfunc bye() {\n\tfmt.Println(\"bye bye\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/02-scopes/solution/printer.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hello() {\n\t// only this file can access the imported fmt package\n\t// when others also do so, they can also access\n\t//   their own `fmt` \"name\"\n\n\tfmt.Println(\"hi! this is inanc!\")\n\tbye()\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/03-importing/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: imports 重命名\n//\n//  1- 使用不同的名字导入 fmt 包三次\n//\n//  2- 使用它们输出一些消息\n//\n// 目标输出\n//  hello\n//  hey\n//  hi\n// ---------------------------------------------------------\n\n// ?\n// ?\n// ?\n\nfunc main() {\n\t// ?\n\t// ?\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/03-importing/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\nimport f \"fmt\"\nimport fm \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"hello\")\n\tf.Println(\"hey\")\n\tfm.Println(\"hi\")\n}\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/练习/README.md",
    "content": "1. **[使用自己定义的包](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/01-packages)**\n\n    创建几个 Go 文件，并在 main 函数里调用它们里面的函数\n\n\n2. **[作用域的初体验](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/02-scopes)**\n\n    了解跨包作用域的效果\n\n\n3. **[imports 重命名](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/03-importing)**\n\n    使用不同的名字导入同一个包"
  },
  {
    "path": "translation/chinese/03-包和作用域/问题/01-packages-A/README.md",
    "content": "## 属于同一个包的源代码存储在哪里？\n1. 每个文件应该存储在不同的目录\n2. 在同一个目录下 *正确*\n\n\n## 为什么 Go 源代码需要使用 package 语句？\n1. 用来导入包\n2. 用来让 Go 知道该文件属于哪个包 *正确*\n3. 用来声明新函数\n\n> **1:** `import` 语句的作用.\n>\n>\n> **3:** `func` 语句的作用\n>\n>\n\n\n## `package clause` 需要写在 Go 源文件的哪里？\n1. 写在 Go 源文件的开头 *正确*\n2. 写在 Go 源文件的末尾\n3. 写哪里都可以\n\n\n## 一个 Go 源文件使用 `package clause` 几次\n1. 一次 *正确*\n2. 零次\n3. 多次\n\n\n## 下面哪一个正确使用 `package clause`?\n1. `my package`\n2. `package main`\n3. `pkg main`\n\n\n## 哪一个说法是正确?\n1. 在同一个包下的文件不能调用其他文件定义的函数\n2. 在同一个包下的文件可以调用其他文件定义的函数 *正确*\n\n\n## 如何运行多个 Go 源代码\n1. go run *.*go\n2. go build *go\n3. go run go\n4. go run *.go *正确*\n\n> **4:** 也可以是 (假设目录下有 file1.go file2.go 和 file3.go): go run file1.go file2.go file3.go\n>\n>\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/问题/02-packages-B/README.md",
    "content": "## 下面哪一个是 Go 中正确的软件包类型？\n* Empty package\n* Executable package *正确*\n* Transferrable package\n* Librarian package\n\n## 下面哪一个 package `go run` 可以执行？\n* Empty package\n* Executable package *正确*\n* Transferrable package\n* Library package\n\n## 下面哪个 package  `go build` 可以编译\n* Empty package\n* Temporary package\n* Both of executable and library packages *正确*\n* Transferrable package\n\n## 下面哪一个是可执行的包\n* 有 `func main` 的 `package main` *正确*\n* 有 `func Main` 的 `package Main`\n* 有 `func exec` 的 `package exec`\n\n## 哪一个是 library package?\n* `main package`\n* `package lib` *正确*\n* `func package`\n* `package main` 有 `func main`\n\n## 下面哪个包用于可执行 Go 程序？\n* Empty package\n* Executable package *正确*\n* Transferrable package\n* Library package\n\n## 哪个包用于可重用并可以导入？\n* Empty package\n* Executable package\n* Transferrable package\n* Library package *正确*\n"
  },
  {
    "path": "translation/chinese/03-包和作用域/问题/03-scopes/README.md",
    "content": "## 作用域是什么？\n* 可执行的代码块\n* 声明变量的可见性 **正确**\n* 确定要运行的内容\n\n```go\npackage awesome\n\nimport \"fmt\"\n\nvar enabled bool\n\nfunc block() {\n    var counter int\n    fmt.Println(counter)\n}\n```\n\n## 哪个变量属于包作用域\n1. awesome\n2. fmt\n3. enabled **正确**\n4. counter\n\n> **3:** 是的， `enabled` 在任何函数之外，所以它是包作用域的变量 `block()` 也是包作用域，它也在任何函数之外\n>\n>\n\n\n## 哪一个变量属于文件作用域？\n1. awesome\n2. fmt **正确**\n3. enabled\n4. block()\n5. counter\n\n> **2:** 没错，导入的包名称属于文件作用域，而且它们只能在同一文件中使用。\n>\n>\n\n\n## 哪一个在 block() 函数的作用域?\n1. awesome\n2. fmt\n3. enabled\n4. block()\n5. counter **正确**\n\n> **5:** 是的， `counter` 在 `block()` 函数内部定义,所以它属于函数作用域，对 `block()` 函数外的其他代码不可见\n>\n>\n\n\n## `block()` 函数可以看见 `enabled` 变量吗？\n1. 可以: 它在包作用域里 **正确**\n2. 不可以: 它在文件作用域里\n3. 不可以: 它在 block() 函数作用域里\n\n> **1:** 包作用域的变量对同一个包下所有代码都可见\n>\n>\n\n\n## `awesome`中的其他文件可以看见 `counter` 变量吗？\n1. 可以\n2. 不可以: 它在包作用域里\n3. 不可以: 它在文件作用域里\n4. 不可以: 它在 block() 函数的作用域里 **正确**\n\n> **4:** 没错。其他代码都无法看到 `block()` 函数内部的变量。只有在 `block()` 函数内部的代码才能看到它们 (近在一定程度上 ，例如：函数内部的代码只能看到在它们之前声明的变量)\n>\n>\n\n\n## `awesome` 中的其他文件可以看见 `fmt` 变量吗?\n1. 可以\n2. 不可以: 它在包作用域里\n3. 不可以: 它在文件作用域里 **正确**\n4. 不可以: 它在 block() 函数的作用域里\n\n> **3:** 只有在 import 只定义在同一个文件内，不管是不是同一个包，其他文件都不可见\n>\n>\n\n\n## 如果在相同的作用域中声明相同的变量会发生什么？\n```go\npackage awesome\n\nimport \"fmt\"\n\n// 在包作用域中声明两次\nvar enabled bool\nvar enabled bool\n\nfunc block() {\n    var counter int\n    fmt.Println(counter)\n}\n```\n1. 新声明的变量将覆盖前一个变量\n2. 不能这样做，它已经在包作用域中声明了 *正确*\n3. 不能这样做，它已经在文件作用域中声明了\n\n> **2:** 没错，不能在同一个作用域内声明同一个变量，如果这样做，使用变量时获取的是前一个还是后一个声明的变量？\n>\n>\n\n\n## 如果在不同的作用域中声明相同的变量会发生什么？\n```go\npackage awesome\n\nimport \"fmt\"\n\n// 在包作用域中声明\nvar enabled bool\n\nfunc block() {\n    // 在函数作用域中声明\n    var enabled bool\n\n    var counter int\n    fmt.Println(counter)\n}\n```\n1. 新声明的变量将覆盖前一个变量 *正确*\n2. 不能这样做，它已经在包作用域中声明了\n3. 不能这样做，它已经在文件作用域中声明了\n\n> **1:** 实际上，可以在内部作用域中声明相同的变量，例如 `block()`'的作用域在包作用域里面。这意味这它可以获取到包作用域的变量(反之则不同). 所以, `block()`'作用域在包作用域之内。这意味着你可以再次声明相同的变量。它会覆盖掉父作用域的变量，它们同时存在，请查看课程存储库中的示例以找出答案。\n>\n>\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/01-statements/01-execution-flow/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// 语句改变执行顺序\n\t// 特别是流程控制语句，如 `if`\n\tif 5 > 1 {\n\t\tfmt.Println(\"bigger\")\n\t}\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/01-statements/02-semicolons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello\"); fmt.Println(\"World!\")\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/02-expressions/01-operator/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello!\" + \"!\")\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/02-expressions/02-call-expression/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n)\n\nfunc main() {\n\t// runtime.NumCPU() 是一个调用表达式\n\tfmt.Println(runtime.NumCPU() + 1)\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/03-comments/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// Package main makes this package an executable program\npackage main\n\nimport \"fmt\"\n\n/*\nmain 函数\nGo 通过这个函数执行这个程序\n在 main package 有且只有一个 main 函数\n可执行程序也可以称为 `commands`\n*/\nfunc main() {\n\tfmt.Println(\"Hello Gopher!\")\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/01-shy-semicolons/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 害羞的分号\n//\n//  1. 尝试使用分号来分隔表达式\n//\n//\n//  2. 观察 Go 如何修复它们\n//\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/01-shy-semicolons/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// 取消下面代码行的注释，然后保存文件。\n\t//\n\t// 可以看到 Gofmt 工具将自动格式化代码。\n\t// https://golang.org/cmd/gofmt/\n\t//\n\t// 这是因为，Go 语言并不关心\n\t// 在语句之间是否使用分号\n\t//\n\t// 毕竟，它会自动添加它们\n\n\t/*\n\t\tfmt.Println(\"inanc\"); fmt.Println(\"lina\"); fmt.Println(\"ebru\");\n\t*/\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/02-naked-expression/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 裸表达式\n//\n//  1. 尝试单独输入 \"Hello\" 在一行\n//  2. 不要使用 Println\n//  3. 查看错误\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/02-naked-expression/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// 取消下面一行的代码的注释，以查看错误。\n\n\t/*\n\t\t\"Hello\"\n\t*/\n\n\t// 会显示: \"evaluted but not used\"\n\t//\n\t// 因为:\n\t// \"Hello\" 字面值返回了一个值但是\n\t// 没有语句使用它\n\t//\n\t// 因此:\n\t// 不能单独使用表达式而不使用语句\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/03-operators-combine/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 运算符组合表达式\n//\n//  输出下面的期待的输出结果\n//  使用字符串连接运算符\n//\n// 提示\n//  使用 + 运算符多次来组成 \"Hello!!!?\".\n//\n// EXPECTED OUTPUT\n//  \"Hello!!!?\"\n// ---------------------------------------------------------\n\nfunc main() {\n\n\t// fmt.Println(\"Hello!\" + ?)\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/03-operators-combine/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 操作符可以将多个表达式\n\t// 连接成一个表达式\n\tfmt.Println(\"Hello!\" + \"!\" + \"!\" + \"?\")\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/04-print-go-version/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 打印 Go 版本号\n//\n//  1. 查看 runtime 包的文档\n//  2. 寻找返回 Go 版本号的函数\n//  3. 打印 Go 版本号通过调用这个函数\n//\n// 提示\n//  文档地址: https://golang.org/pkg/runtime\n//\n// 期待输出\n//  \"go1.10\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/04-print-go-version/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n)\n\nfunc main() {\n\tfmt.Println(runtime.Version())\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/05-comment-out/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// 练习: 注释掉它\n//\n//  使用单行注释和多行注释注释掉下面的输出\n//\n// 期待输出\n// 没有输出\n// ---------------------------------------------------------\n\nfunc main() {\n\tfmt.Println(\"hello\")\n\tfmt.Println(\"how\")\n\tfmt.Println(\"are\")\n\tfmt.Println(\"you\")\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/05-comment-out/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// fmt.Println(\"hello\")\n\t/*\n\t\tfmt.Println(\"how\")\n\t\tfmt.Println(\"are\")\n\t\tfmt.Println(\"you\")\n\t*/\n}\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/06-use-godoc/exercise.md",
    "content": "## 练习\n\n- 在命令行中打印 `runtime.NumCPU` 函数的文档\n- 在命令行中打印 `runtime.NumCPU` 函数的源码\n\n## 提示\n\n需要正确使用 `go doc` 工具\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/06-use-godoc/solution/solution.md",
    "content": "## 文档:\n\n  go doc runtime NumCPU\n\n## 源代码:\n\n  go doc -src runtime NumCPU\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/练习/README.md",
    "content": "1. **[害羞的分号](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/01-shy-semicolons)**\n\n    观察 Go 是怎么处理分号\n\n2. **[裸表达式](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/02-naked-expression)**\n\n    观察使用不带语句的表达式时发生的情况\n\n3. **[运算符组合表达式](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/03-operators-combine)**\n\n    使用运算符组合表达式\n\n4. **[打印 Go 版本号](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/04-print-go-version)**\n\n   使用 Go 标准库中的软件包打印当前系统(当前运行 Go 程序的系统)安装的 Go 版本号\n\n5. **[注释掉它](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/05-comment-out)**\n\n    了解如何注释代码\n\n6. **[使用 GoDoc](https://github.com/inancgumus/learngo/tree/master/04-statements-expressions-comments/exercises/06-use-godoc)**\n\n    尝试使用 Godoc\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/问题/01-statements/README.md",
    "content": "## 下面关于语句的描述哪个是正确的？\n1. 一个语句指示 Go 执行某些操作 *正确*\n2. 一个语句产生一个值\n3. 一个语句无法改变执行流\n\n> **2:** 一个语句不能产生一个值，但它可以间接的帮助产生一个值\n>\n>\n> **3:** 不，它可以\n>\n>\n\n\n## 下面关于 Go 代码的执行顺序哪个是正确的？\n1. 从左到右\n2. 从上到下 *正确*\n3. 从右到左\n4. 从下到上\n\n> **2:** 是的，Go 的执行顺序是从上到下，一次一个语句\n>\n>\n\n\n## 下面关于表达式的描述哪个是正确的？\n1. 表达式指示 Go 执行某些操作\n2. 一个表达式产生一个值 *正确*\n3. 表达式可以改变执行流\n\n> **1:** 不，语句可以\n>\n>\n> **3:** 不，只有语句可以\n>\n>\n\n\n## 下面关于运算符的描述哪个是正确的？\n1. 运算符指示 Go 执行某些操作\n2. 运算符可以改变执行流\n3. 运算符可以组合表达式 *正确*\n\n> **1:** 不，语句可以\n>\n>\n> **2:** 不，只有语句可以\n>\n>\n\n\n## 下面的程序为什么不起作用？\n```go\npackage main\nimport \"fmt\"\n\nfunc main() {\n    \"Hello\"\n}\n```\n\n1. \"Hello\"是一个表达式，它不能没有语句单独在一行 *正确*\n2. 去掉 “Hello” 的双引号，像这样: Hello\n3. 将 \"Hello\" 移到 main 函数外面\n\n\n## 下面的程序可以运行吗？\n```go\npackage main\nimport (\n    \"fmt\"\n    \"runtime\"\n)\n\nfunc main() {\n    fmt.Println(runtime.NumCPU()); fmt.Println(\"cpus\"); fmt.Println(\"the machine\")\n}\n```\n\n1. 可以运行: 可以用分号来分隔表达式\n2. 不能运行: 只能一行一个语句\n3. 可以运行: Go 会自动地在每条语句的后面添加分号 *正确*\n\n> **1:** 它可以运行，但不是这个原因，另外，表达式不能这样做\n>\n>\n> **2:** 确定吗?\n>\n>\n> **3:** 是的，无论是否有分号，Go 会自动的添加分号. 这些语句还是认为自己在不同的一行中\n>\n>\n\n\n## 为什么下面的代码可以运行\n```go\npackage main\nimport (\n    \"fmt\"\n    \"runtime\"\n)\n\nfunc main() {\n    fmt.Println(runtime.NumCPU() + 10)\n}\n```\n\n1. 运算符可以组合表达式 *正确*\n2. 语句可以和表达式一起使用\n3. 表达式可以返回多值\n\n> **1:** 是的， + 运算可以组合 `runtime.NumCPU()` 和 `10` 表达式\n>\n>\n> **2:** 不对，不可以组合使用。例如，不能这样做：`import \"fmt\" + 3`. 一些语句需要表达式，但这不意味着语句和表达式可以组合使用\n>\n>\n> **3:** 对的，但不能解释上面代码为什么可以运行\n>\n>\n"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/问题/02-expressions/README.md",
    "content": "## 请查看 statements 目录下的问题"
  },
  {
    "path": "translation/chinese/04-语句-表达式-注释/问题/03-comments/README.md",
    "content": "## 为什么有时需要用到注释？\n1. 为了将不同的表达式组合起来\n2. 为了给代码提供说明或者自动生成文档 *正确*\n3. 为了让代码看起来更漂亮\n\n\n## 下面的代码哪个是正确的？\n1.\n```go\npackage main\n\n/ main function is an entry point /\nfunc main() {\n    fmt.Println(\"Hi\")\n}\n```\n\n2. *正确*\n```go\npackage main\n\n// main function is an entry point /*\nfunc main() {\n    fmt.Println(/* this will print Hi! */ \"Hi\")\n}\n```\n\n3.\n```go\npackage main\n\n/*\nmain function is an entry point\n\nIt allows Go to find where to start executing an executable program.\n*/\nfunc main() {\n    fmt.Println(// \"this will print Hi!\")\n}\n```\n\n> **1:** `/` 不是注释，单行注释是 `//`.\n>\n>\n> **2:** 多行注释可以放在任何位置。但是，当有一个以 `/*`开头的注释，需要以 `*/` 结尾。 这里，Go 不关心 `/* ... */` 里面的内容， 它直接跳过。同时，Go 看到以 `//` 开头的代码，直接跳过整行代码。\n>\n>\n> **3:** `//` 阻止 Go 解析后面的内容，这就是它不能运行的原因， Go 不能解析 `\"this will print Hi!\")` 因为它们是注释。\n>\n>\n\n## 应该如何命名代码，以便 Go 可以从代码自动生成文档？\n1. 通过注释的每一行代码，这样就会自动生成文档\n2. 通过在声明变量后开始进行注释 *正确*\n3. 通过使用多行注释\n\n> **1:** 对不起，这没用\n>\n>\n> **3:** 它不关心使用单行注释还是多行注释\n>\n>\n\n\n## 在命令行打印文档需要用到下面哪个？\n1. go build\n2. go run\n3. go doctor\n4. go doc *正确*\n\n\n## `godoc` 和 `go doc` 有什么不同?\n1. `go doc` 是 `godoc` 背后真实的工具\n2. `godoc` 是 `go doc` 背后真实的工具 *正确*\n3. `go` 是 `go doc` 背后真实的工具\n4. `go` 是 `godoc` 背后真实的工具\n\n> **2:** 是的， go doc 背后使用 godoc， go doc 只是简单版本的 godoc\n>\n>\n"
  },
  {
    "path": "translation/chinese/05-编写你的第一个库程序包/printer/cmd/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// 自动导入！... 好耶！\nimport \"github.com/inancgumus/learngo/05-write-your-first-library-package/printer\"\n\nfunc main() {\n\tprinter.Hello()\n}\n"
  },
  {
    "path": "translation/chinese/05-编写你的第一个库程序包/printer/printer.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage printer\n\nimport \"fmt\"\n\n// Hello 是一个导出函数\nfunc Hello() {\n\tfmt.Println(\"exported hello\")\n}\n"
  },
  {
    "path": "translation/chinese/05-编写你的第一个库程序包/练习/README.md",
    "content": "[Check out the exercise and its solution here.](https://github.com/inancgumus/learngo/tree/master/05-write-your-first-library-package/exercise)\n\n---\n\n# 练习\n\n1. 新建一个库\n2. 在库中，创建一个返回 Go 版本的函数。\n3. 创建一个可执行程序并导入你的库\n4. 调用你创建的返回 Go 版本的函数\n5. 执行你的程序\n\n## 提示\n\n**像这样创建你的包函数:**\n\n```go\nfunc Version() string {\n    return runtime.Version()\n}\n```\n\n## 期望输出\n\n他应该打印出你系统安装的 Go 的版本\n\n## 警告\n\n你应该在你自己的文件夹下创建这个包，而不是在 github.com/inancgumus/learngo 目录下。同时，注意 VS Code 可能会自动导入我位于 github.com/inancgumus/learngo 的库而非你自己的库。\n\n所以，如果你想要 VS Code 自动在保存时导入你自己的包，只需要将 github.com/inancgumus/learngo 移动到非 GOPATH 的某处，比如，你的桌面（记得在之后移动回来）\n\nSee [this question](https://www.udemy.com/learn-go-the-complete-bootcamp-course-golang/learn/v4/questions/5518190) in Q&A for more information."
  },
  {
    "path": "translation/chinese/05-编写你的第一个库程序包/练习/solution/golang/cmd/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\" // 你应该将这里替换成你自己的用户名\n\n\t\"github.com/inancgumus/learngo/05-write-your-first-library-package/exercise/solution/golang\"\n)\n\nfunc main() {\n\tfmt.Println(golang.Version())\n}\n"
  },
  {
    "path": "translation/chinese/05-编写你的第一个库程序包/练习/solution/golang/go.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage golang\n\nimport (\n\t\"runtime\"\n)\n\n// Version 返回当前的 Go 版本\nfunc Version() string {\n\treturn runtime.Version()\n}\n"
  },
  {
    "path": "translation/chinese/05-编写你的第一个库程序包/问题/README.md",
    "content": "## 下面哪一个是正确的？\n\n**注意** _答案当中含有解释。即便你已经知道答案，也请逐一选择每个选项，这样可以阅读到解释。_\n\n1. 你可以运行一个库程序包。\n2. 在一个库程序包中，应该含有一个叫做 main 的函数 (func main)。\n3. 你可以编译一个库程序包。*正确*\n4. 你必须编译一个库程序包。\n\n> **1:** 你不能运行，但你可以从其他包中导入它。\n>\n> **2:** 在一个库程序包中，没有必要包含 main 函数。因为它并非一个可执行的包。只有在可执行的包中才需要 main 函数。\n>\n> **4:** 你没有必要编译它。当你导入它时，它会自动在编译或运行时被其他程序或库构建。\n\n\n## 在导出名称时你需要做什么？\n\n1. 你需要将名称全部大写\n2. 你需要将名称的首字母大写 *正确*\n3. 你需要把名称放到一个函数作用域里\n4. 你需要用这个名称创建一个新的文件\n\n> **1:** 当你这样做时，它的确会被导出，但不要这样做；因此我认为这个答案不正确 :)\n>\n> **2:** 正确的。这样做之后其他包便可以访问它。\n>\n> **3:** 它应该在包作用域内，而不是函数作用域内。\n>\n> **4:** 没必要这样做。\n\n\n## 你要怎么在一个可执行程序中使用一个你的库中的函数呢？\n\n1. 你需要首先导出你的库程序包；然后你可以访问它的导入名称\n2. 你需要首先导入你的库程序包；然后你可以访问它的导出名称 *正确*\n3. 你可以像它本来就在你的可执行程序中一样，访问你的库程序包\n4. 你可以通过使用它的名称来导入它\n\n> **1:** 你不能导出包。所有的包都是已经导出的。除非你将它们放到一个叫做 \"internal\" 的目录中。但是，这是一个对于现在过于进阶的话题。\n>\n> **2:** 正确的。\n>\n> **3:** 你不能在不导入的情况下，在一个包中访问另一个包。\n>\n> **4:** 你不能这么做。你需要在 GOPATH 后使用完整的路径来导入它。顺带一提，在不久的将来，这可能会随着 Go 模块的支持而改变。\n\n\n## 在下面的程序中，哪些名称被导出了？\n\n```go\npackage wizard\n\nimport \"fmt\"\n\nfunc doMagic() {\n    fmt.Println(\"enchanted!\")\n}\n\nfunc Fireball() {\n    fmt.Println(\"fireball!!!\")\n}\n```\n\n1. fmt\n2. doMagic\n3. Fireball *正确*\n4. Println\n\n> **1:** 这是导入包的名称。\n>\n> **2:** 它以小写字母开头；所以，它没有被导出。\n>\n> **3:** 正确的。它以大写字母开头。\n>\n> **4:** 这不是你写的函数。它已经在 fmt 包中被导出了。但它没有在这里被导出。\n\n\n## 在下面的程序中，哪些名称被导出了？\n\n```go\npackage wizard\nimport \"fmt\"\n\nvar one string\nvar Two string\nvar greenTrees string\n\nfunc doMagic() {\n    fmt.Println(\"enchanted!\")\n}\n\nfunc Fireball() {\n    fmt.Println(\"fireball!!!\")\n}\n```\n\n1. doMagic 和 Fireball\n2. Fireball 和 Two *CORRECT*\n3. Fireball, greenTrees 和 Two\n4. Fireball, greenTrees, one 和 Two\n\n> **1:** doMagic 以小写字母开头；所以没有被导出。\n>\n> **2:** 正确的。Fireball 和 Two 都以大写字母开头。\n>\n> **3:** greenTrees  以小写字母开头；所以没有被导出。\n>\n> **4:** one 和 greenTrees  没有以大写字母开头；所以没有被导出。"
  },
  {
    "path": "translation/chinese/06-变量/01-基础数据类型/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 整数型\n\tfmt.Println(\n\t\t-200, -100, 0, 50, 100, 100,\n\t)\n\n\t// 浮点型\n\tfmt.Println(\n\t\t-50.5, -20.5, -0., 1., 100.56, // ...\n\t)\n\n\t// 布尔值\n\tfmt.Println(\n\t\ttrue, false,\n\t)\n\n\t// 字符串 - utf-8\n\tfmt.Println(\n\t\t\"\", // 空字符串, 只打印一个空格\n\t\t\"hi\",\n\n\t\t// unicode\n\t\t\"nasılsın?\",   // 土耳其语的 \"你好吗\"\n\t\t\"hi there 星!\", // \"你好，star！\"\n\t)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/01-基础数据类型/练习/01-print-the-literals/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 打印字面量\n//\n//  1. 打印一些整数型\n//\n//  2. 打印一些浮点型\n//\n//  3. 打印 true 和 false 的布尔值\n//\n//  4. 用字符串打印你的名字\n//\n//  5. 用字符串打印一句非英文的句子\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 使用 fmt.Println()\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/01-基础数据类型/练习/01-print-the-literals/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(42, 8500, 344433, -2323)\n\tfmt.Println(3.14, 6.28, -42.)\n\tfmt.Println(true, false)\n\tfmt.Println(\"Hi! I'm Inanc!\")\n\tfmt.Println(\"Merhaba, adım İnanç!\")\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/01-基础数据类型/练习/02-print-hexes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// 这个练习是可选的\n\n// ---------------------------------------------------------\n// 练习: 打印十六进制\n//\n//  1. 打印十六进制的 0 到 9\n//\n//  2. 打印十六进制的 10 到 15\n//\n//  3. 打印十六进制的 17\n//\n//  4. 打印十六进制的 25\n//\n//  5. P打印十六进制的 50\n//\n//  6. 打印十六进制的 100\n//\n// 期望输出\n//  0 1 2 3 4 5 6 7 8 9\n//  10 11 12 13 14 15\n//  17\n//  25\n//  50\n//  100\n//\n// NOTE\n//  https://stackoverflow.com/questions/910309/how-to-turn-hexadecimal-into-decimal-using-brain\n//\n// https://simple.wikipedia.org/wiki/Hexadecimal_numeral_system\n//\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 例子\n\n\t// 我要打印十六进制的 10\n\tfmt.Println(0xa)\n\n\t// 我要打印十六进制的 16\n\t// 0x10\n\t//   ^^-----  1 * 0 = 0\n\t//   |\n\t//   +------ 16 * 1 = 16\n\t//                  = 16\n\tfmt.Println(0x10)\n\n\t// 我要打印十六进制的 150\n\t// 0x96\n\t//   ^^-----  1 * 6 = 6\n\t//   |\n\t//   +------ 16 * 9 = 144\n\t//                  = 150\n\tfmt.Println(0x96)\n\n\t// 把上面的所有代码注释掉, 然后\n\t// 在下面写下你的代码\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/01-基础数据类型/练习/02-print-hexes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9)\n\tfmt.Println(0xa, 0xb, 0xc, 0xd, 0xe, 0xf)\n\tfmt.Println(0x11) // 17\n\tfmt.Println(0x19) // 25\n\tfmt.Println(0x32) // 50\n\tfmt.Println(0x64) // 100\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/01-基础数据类型/练习/README.md",
    "content": "1. **[打印字面量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/01-基础数据类型/练习/01-print-the-literals)**\n\n   使用字面量打印一些值\n\n2. **[打印十六进制数](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/01-基础数据类型/练习/02-print-hexes)** (可选练习)\n\n   打印十六进制的数\n\n\n"
  },
  {
    "path": "translation/chinese/06-变量/01-基础数据类型/问题/README.md",
    "content": "## 下面哪个是整数型 (int)？\n\n* -42 *正确*\n  * 这是整数型\n* \"Hello\"\n  * 这是字符串\n* false\n  * 这是布尔值\n* 3.14\n  * 这是浮点型\n\n## 下面哪个是浮点型 (float)?\n\n* -42\n* \"Hello\"\n* false\n* 3.14 *正确*\n\n## 下面哪个是浮点型 (float)?\n\n* 6,28\n* ,28\n* .28 *正确*\n* 628\n\n## 下面哪个是字符串 (string)?\n\n* -42\n* \"Hello\" *正确*\n* false\n* 3.14\n\n## 下面哪个是布尔值 (bool)?\n\n* -42\n* \"Hello\"\n* false *正确*\n* 3.14"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/01-声明语法/01-语法/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar speed int\n\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/01-声明语法/02-命名规则/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// 变量声明规则\n\nfunc main() {\n\t// 正确的声明\n\tvar speed int\n\tvar SpeeD int\n\n\t// 下划线开头是允许但不推荐的\n\tvar _speed int\n\n\t// Unicode 字母是允许的\n\tvar 速度 int\n\n\t// 让编译器开心\n\t_, _, _, _ = speed, SpeeD, _speed, 速度\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/01-声明语法/03-声明顺序/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// fmt.Println(speed)\n\t// var speed int\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/02-声明示例/01-int/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar nFiles int\n\tvar counter int\n\tvar nCPU int\n\n\tfmt.Println(\n\t\tnFiles,\n\t\tcounter,\n\t\tnCPU,\n\t)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/02-声明示例/02-float64/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar heat float64\n\tvar ratio float64\n\tvar degree float64\n\n\tfmt.Println(\n\t\theat,\n\t\tratio,\n\t\tdegree,\n\t)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/02-声明示例/03-bool/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar off bool\n\tvar valid bool\n\tvar closed bool\n\n\tfmt.Println(\n\t\toff,\n\t\tvalid,\n\t\tclosed,\n\t)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/02-声明示例/04-string/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar msg string\n\tvar name string\n\tvar text string\n\n\tfmt.Println(\n\t\tmsg,\n\t\tname,\n\t\ttext,\n\t)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/03-零值/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// 练习: 运行这个, 然后自己查看这些零值 (这里的 零值 指的是变量未初始化时的值, 根据类型的不同会有不同的结果, 而非字面意义上的 \"0\")\nfunc main() {\n\tvar speed int    // 数字类型\n\tvar heat float64 // 数字类型\n\tvar off bool\n\tvar brand string\n\n\tfmt.Println(speed)\n\tfmt.Println(heat)\n\tfmt.Println(off)\n\n\t// 我用 Printf 来打印空字符串\n\t// 练习: 用 Println 看看会发生什么\n\tfmt.Printf(\"%q\\n\", brand)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/04-未使用的变量和空白标识符/01-未使用的变量/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// 对包级变量没有警告\nvar packageLevelVar string\n\nfunc main() {\n\t// 未使用变量错误\n\t// var speed int\n\n\t// 如果你使用了它, 错误就会消失\n\t// fmt.Println(speed)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/04-未使用的变量和空白标识符/02-空白标识符/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar speed int\n\n\t// 让我们把变量赋值给空白标识符\n\t// 这样，Go编译器就不会发脾气了\n\t_ = speed\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/05-多重声明/01-多重声明/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tspeed int\n\t\theat  float64\n\n\t\toff   bool\n\t\tbrand string\n\t)\n\n\tfmt.Println(speed)\n\tfmt.Println(heat)\n\tfmt.Println(off)\n\tfmt.Printf(\"%q\\n\", brand)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/05-多重声明/02-平行声明/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 这等同于\n\t//\n\t//   var (\n\t//     speed int\n\t//     velocity int\n\t//   )\n\t//\n\t// 或者:\n\t//\n\t//   var speed int\n\t//   var velocity int\n\t//\n\tvar speed, velocity int\n\n\tfmt.Println(speed, velocity)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/06-例子/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 变量名是大小写敏感的\n\t// MyAge, myAge 和 MYAGE 是不同的变量\n\n\t// 使用例:\n\t// 什么时候使用平行声明?\n\t//\n\t// 不好:\n\t// var myAge int\n\t// var yourAge int\n\t//\n\t// 一般:\n\t// var (\n\t// \tmyAge int\n\t// \tyourAge int\n\t// )\n\t//\n\t// 推荐:\n\tvar myAge, yourAge int\n\tfmt.Println(myAge, yourAge)\n\n\tvar temperature float64\n\tfmt.Println(temperature)\n\n\tvar success bool\n\tfmt.Println(success)\n\n\tvar language string\n\tfmt.Println(language)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/01-int/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 声明 int\n//\n//  1. 声明并打印一个 int 型变量\n//\n//  2. 变量名应该叫做: height\n//\n// 期望输出\n//  0\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? ?\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/01-int/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar height int\n\n\tfmt.Println(height)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/02-bool/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 声明 bool\n//\n//  1. 声明并打印一个 bool 型变量\n//\n//  2. 变量名应该叫做: isOn\n//\n// 期望输出\n//  false\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? ?\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/02-bool/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar isOn bool\n\tfmt.Println(isOn)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/03-float64/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 声明 float64\n//\n//  1. 声明并打印一个 float64 型变量\n//\n//  2. 变量名应该叫做: brightness\n//\n// 期望输出\n//  0\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? ?\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/03-float64/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tvar brightness float64\n\n\tfmt.Println(brightness)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/04-string/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 声明 string\n//\n//  1. 声明一个 string 型变量\n//\n//  2. 打印这个变量\n//\n// 期望输出\n//  \"\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 使用下面的代码\n\t// 你会在之后学习到 Printf 函数\n\n\t// var ?\n\t// fmt.Printf(\"s (%T): %q\\n\", s, s)\n\n\t// %T 打印变量的类型\n\t// %q 打印一个空字符串\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/04-string/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar s string\n\tfmt.Printf(\"s (%T): %q\\n\", s, s)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/05-undeclarables/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 不可声明的变量\n//\n//  1. 声明以下的变量\n//      3speed\n//      !speed\n//      spe?ed\n//      var\n//      func\n//      package\n//\n//  2. 观察报错信息\n//\n// NOTE\n//  上面这些变量的类型不重要\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var ? int\n\t// var ? int\n\t// var ? int\n\t// var ? int\n\t// var ? int\n\t// var ? int\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/05-undeclarables/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// var 3speed int\n\t// var !speed int\n\t// var spe?ed int\n\t// var var int\n\t// var func int\n\t// var package int\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/06-with-bits/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: 用 bit 声明\n//\n//  1. 使用以下类型声明几个变量\n//    int\n//    int8\n//    int16\n//    int32\n//    int64\n//    float32\n//    float64\n//    complex64\n//    complex128\n//    bool\n//    string\n//    rune\n//    byte\n//\n// 2. 观察他们的输出\n//\n// 3. 完成后，请查看 solution\n//    并阅读在那的注释\n//\n// 期望输出\n//  0 0 0 0 0 0 0 (0+0i) (0+0i) false 0 0\n//  \"\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var i int\n\t// var i8 int8\n\n\t// 从这里开始继续....\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/06-with-bits/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 整数类型\n\tvar i int\n\tvar i8 int8\n\tvar i16 int16\n\tvar i32 int32\n\tvar i64 int64\n\n\t// 浮点类型\n\tvar f32 float32\n\tvar f64 float64\n\n\t// 复杂类型\n\tvar c64 complex64\n\tvar c128 complex128\n\n\t// 布尔型\n\tvar b bool\n\n\t// 字符串类型\n\tvar s string\n\tvar r rune  // 同样是数字类型\n\tvar by byte // 同样是数字类型\n\n\tfmt.Println(\n\t\ti, i8, i16, i32, i64,\n\t\tf32, f64,\n\t\tc64, c128,\n\t\tb, r, by,\n\t)\n\n\t// 你也可以使用 Println 做到\n\tfmt.Printf(\"%q\\n\", s)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/07-multiple/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 多重声明\n//\n//  1. 使用多重变量声明语句声明两个变量\n//\n//  2. 第一个变量的名称应该叫 active\n//  3. 第二个变量的名称应该叫 delta\n//\n//  4. 把它们全打印出来\n//\n// HINT\n//  你应该声明一个 bool 类型和一个 int 类型的变量\n//\n// 期望输出\n//  false 0\n// ---------------------------------------------------------\n\nfunc main() {\n\t// var (\n\t//   ?\n\t// )\n\t// fmt.Println(active, delta)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/07-multiple/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tactive bool\n\t\tdelta  int\n\t)\n\tfmt.Println(active, delta)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/08-multiple-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 多重声明 #2\n//\n//  1. 使用多重变量声明语句声明并初始化两个字符串变量\n//\n//  2. 在声明变量的时候使用一次类型\n//\n//  3. 第一个变量的名称应该叫 firstName\n//  4. 第二个变量的名称应该叫 lastName\n//\n//  5. 把它们全打印出来\n//\n// 期望输出\n//  \"\" \"\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 你的声明写在这里\n\t//\n\n\t// 使用你的变量的名称替换下面的问号\n\n\t// fmt.Printf(\"%q %q\\n\", ?, ?)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/08-multiple-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar firstName, lastName string = \"\", \"\"\n\tfmt.Printf(\"%q %q\\n\", firstName, lastName)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/09-unused/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 未使用的\n//\n//  1. 声明一个变量\n//\n//  2. 变量的名称应该叫: isLiquid\n//\n//  3. 使用空白标识符丢弃它\n//\n// NOTE\n//  不要打印这个变量\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/09-unused/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tvar isLiquid bool\n\t_ = isLiquid\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/10-package-variable/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 包变量\n//\n//  1. 在包作用域内声明一个变量\n//\n//  2. 观察当你不使用它时是否会发生一些事情\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/10-package-variable/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nvar isLiquid bool\n\nfunc main() {\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/11-wrong-doer/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EXERCISE: 做错事的人\n//\n//  1. 打印一个变量\n//\n//  2. 然后声明它\n//  (意思是: 试着在它的声明前打印它)\n//\n//  3. 观察报错\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 先打印它:\n\t// fmt.Println(?)\n\n\t// 然后声明它:\n\t// var ? ?\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/11-wrong-doer/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\t// 去掉下面代码的注释来查看报错\n\n\t// fmt.Println(age)\n\t// var age int\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/练习/README.md",
    "content": "# 声明并打印变量\n\n热身。声明几个变量，获得一些经验。熟悉变量声明的语法。\n\n1. **[声明 int](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/01-int)**\n\n2. **[声明 bool](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/02-bool)**\n\n3. **[声明 float64](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/03-float64)**\n\n4. **[声明 string](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/04-string)**\n\n5. **[声明 不可声明的变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/05-undeclarables)**\n\n6. **[使用 bits 声明变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/translation/chinese/06-with-bits)**\n\n7. **[多重声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/07-multiple)**\n\n8. **[多重声明 2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/08-multiple-2)**\n\n9. **[声明一个未使用的变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/09-unused)**\n\n10. **[声明一个包变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/10-package-variable)**\n\n11. **[在声明前使用](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/02-声明/练习/11-wrong-doer)**\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/问题/01-what/README.md",
    "content": "# 问题: 什么是变量?\n\n## 变量“住”在哪里?\n\n* 硬盘\n* 内存 - *正确*\n* CPU\n\n## 你使用变量名来做什么?\n\n* 为了以后能够访问它 - *正确*\n* 这只是一个标签\n* 我不需要使用它。\n\n## 如何改变一个变量的值?\n\n* 通过变量名 - *正确*\n* 通过变量值\n* 通过向 Go 要求\n\n## 在变量声明之后，你可以改变变量的类型吗？?\n\n* 可以 : Go 是动态类型\n* 不行  : Go 是静态类型 - *正确*\n* 两者都有: Go 支持两者"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/问题/02-declaration/README.md",
    "content": "## 你需要使用哪条语句来声明变量?\n\n* name int\n* vars string name\n* var name integer\n* var width int *正确*\n\n## 下面哪句话是正确的?\n\n* 你可以在声明一个变量之前使用它\n* 在使用一个变量之前，你必须先声明它 *正确*\n\n## Go 是什么类型的语言?\n\n* 弱类型\n* 动态类型\n* 强类型 *正确*\n* 自由类型\n\n## 下面哪个变量名是正确的?\n\n* int\n* four *正确*\n* 2computers\n* one?there"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/问题/03-unused-variables/README.md",
    "content": "## 当你不使用一个块作用域中声明的变量会发生什么？\n\n* 什么都不会发生, 它会正常工作\n* 它将被自动删除\n* 程序无法编译 *正确*\n\n## 当你不使用一个包作用域中声明的变量会发生什么？\n\n* 什么都不会发生, 它会正常工作 *正确*\n* 它将被自动删除\n* 程序无法编译\n\n## 如何防止未使用变量的错误?\n\n* 你可以改变变量的名称\n* 你可以使用空白标识符来避免它 *正确*\n* 你可以改变变量的类型\n\n"
  },
  {
    "path": "translation/chinese/06-变量/02-声明/问题/04-zero-values/README.md",
    "content": "## 哪种变量类型的零值是 0?\n\n- bool\n- pointer\n- string\n- 所有的数字类型 *正确*\n\n## 哪种变量类型的零值是 false?\n\n- bool *正确*\n- pointer\n- string\n- 所有的数字类型\n\n## 哪种变量类型的零值是 \"\"?\n\n- bool\n- pointer\n- string *正确*\n- 所有的数字类型\n\n## 哪种变量类型的零值是 nil?\n\n- bool\n- pointer *正确*\n- string\n- 所有的数字类型"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/01-初始化以及简短声明/01-初始化/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// = 是赋值操作符\n\t// 当在一个变量声明中使用时，它将该变量初始化为给定的值\n\n\t// 在这, Go 将 safe 变量初始化为 true\n\n\t// 方案 #1（方案 #2 更好）\n\t// var safe bool = true\n\n\t// 方案 #2\n\tvar safe = true\n\n\tfmt.Println(safe)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/01-初始化以及简短声明/02-简短声明/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 方案 #1（方案 #2 更好）\n\t// var safe bool = true\n\n\t// 方案 #2 (还行)\n\t// var safe = true\n\n\t// 方案 #3 - 简短声明 (最佳)\n\t//\n\t// 你甚至不需要输入 var 关键词\n\t//\n\t// 简短声明等同于:\n\t//   var safe bool = true\n\t//   var safe = true\n\t//\n\t// Go从初始值中获取（推断）类型\n\t//\n\t// true 的默认类型是 bool\n\t// 所以，变量 safe 的类型变成了 bool\n\tsafe := true\n\n\tfmt.Println(safe)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/01-初始化以及简短声明/03-编码示例/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// var name string = \"Carl\"\n\t// var name = \"Carl\"\n\tname := \"Carl\"\n\n\t// var isScientist bool = true\n\t// var isScientist = true\n\tisScientist := true\n\n\t// var age int = 62\n\t// var age = 62\n\tage := 62\n\n\t// var degree float64 = 5.\n\t// var degree = 5.\n\tdegree := 5.\n\n\tfmt.Println(name, isScientist, age, degree)\n\n\t// 类型推断也适用于变量\n\t//\n\t// Go 获取变量的类型并将其分配给新声明的变量\n\t//\n\t// 现在name2变量的类型也是 `string`\n\tname2 := name\n\tfmt.Println(name2)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/02-包作用域/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// 你不能使用没有关键字的声明语句\n// 简短声明没有关键字 (`var`)\n// 所以, 它不能在包作用域上使用\n//\n// 语法错误:\n// \"函数体外的非声明语句\"\n// 原文:\n// SYNTAX ERROR:\n// \"non-declaration statement outside function body\"\n\n// safe := true\n\n// 然而, 你可以在包作用域上正常声明一个变量, 因为它有关键词: `var`\nvar safe = true\n\nfunc main() {\n\tfmt.Println(safe)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/03-多重简短声明/01-声明/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// the number of variables and values should be equal\n\n\t// -> `true` is being assigned to `safe`\n\t// -> `50` is being assigned to `speed`\n\n\tsafe, speed := true, 50\n\n\tfmt.Println(safe, speed)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/03-多重简短声明/02-编码示例/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tname, lastname := \"Nikola\", \"Tesla\"\n\tfmt.Println(name, lastname)\n\n\tbirth, death := 1856, 1943\n\tfmt.Println(birth, death)\n\n\ton, off := true, false\n\tfmt.Println(on, off)\n\n\t// 这里没有限制\n\t// 然而, 随着你声明变量数量的增多, 代码的可读性会越来越差\n\tdegree, ratio, heat := 10.55, 30.5, 20.\n\tfmt.Println(degree, ratio, heat)\n\n\t// 你可以简短声明不同的变量类型\n\tnFiles, valid, msg := 10, true, \"hello\"\n\n\tfmt.Println(nFiles, valid, msg)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/03-多重简短声明/03-重声明/01/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// `safe` 的值是 `false`\n\tvar safe bool\n\n\t// `safe` 的值现在是 `true`\n\n\t// `speed` 被声明并初始化成了 `50`\n\n\t// 只在以下情况下能进行重声明\n\t//\n\t// 至少一个重声明的变量是新变量\n\n\tsafe, speed := true, 50\n\n\tfmt.Println(safe, speed)\n\n\t// 练习\n\t//\n\t// 在\"再次\"简短声明前声明变量 speed ( 即在重声明语句前声明 speed 变量 )\n\t//\n\t// Observe what happens\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/03-多重简短声明/03-重声明/02-编码示例/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 例 #1\n\n\tname := \"Nikola\"\n\tfmt.Println(name)\n\n\t// name 已经在代码块里存在了\n\t// name := \"Marie\"\n\n\t// 给 name 赋了一个新值\n\t// 并且声明一个新变量 age 并赋值 66\n\tname, age := \"Marie\", 66\n\tfmt.Println(name, age)\n\n\t// 例 #2\n\n\t// name = \"Albert\"\n\t// birth := 1879\n\n\t// 下面的重声明等同于上面的语句.\n\t//\n\t// `name` 是一个已经存在的变量\n\t//   Go 给变量 name 赋值了 \"Albert\"\n\t//\n\t// `birth` 是一个新变量\n\t//   Go 声明并给它赋值了 `1879`\n\tname, birth := \"Albert\", 1879\n\n\tfmt.Println(name, birth)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/04-简短-vs-正常/01-声明/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// 正常声明的使用例\n\n// -----------------------------------------------------\n// 当你需要一个包作用域变量时\n// -----------------------------------------------------\n\n// version := 0 // 不能这样\nvar version int\n\nfunc main() {\n\n\t// -----------------------------------------------------\n\t// 如果你不知道初始值时\n\t// -----------------------------------------------------\n\n\t// 别这样做:\n\t// score := 0\n\n\t// 这样做:\n\t// var score int\n\n\t// -----------------------------------------------------\n\t// 对变量进行分组以提高可读性\n\t// -----------------------------------------------------\n\n\t// var (\n\t// \tvideo    string\n\n\t// \tduration int\n\t// \tcurrent  int\n\t// )\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/04-简短-vs-正常/02-简短声明/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// 简短声明的使用例\n\nfunc main() {\n\n\t// -----------------------------------------------------\n\t// 如果你知道初始值\n\t// -----------------------------------------------------\n\n\t// 别这样做:\n\t// var width, height = 100, 50\n\n\t// 这样做 (简洁):\n\t// width, height := 100, 50\n\n\t// -----------------------------------------------------\n\t// 重声明\n\t// -----------------------------------------------------\n\n\t// 别这样做:\n\t// width = 50\n\t// color := red\n\n\t// 这样做 (简洁):\n\t// width, color := 50, \"red\"\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/01-short-declare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 简短声明\n//\n//  声明并打印四个变量，使用简短声明语句\n//\n// 期望输出\n//  i: 314 f: 3.14 s: Hello b: true\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这里写下你的声明语句\n\t//\n\n\t// 然后去掉下面代码的注释\n\n\t// fmt.Println(\n\t// \t\"i:\", i,\n\t// \t\"f:\", f,\n\t// \t\"s:\", s,\n\t// \t\"b:\", b,\n\t// )\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/01-short-declare/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ti := 314\n\tf := 3.14\n\ts := \"Hello\"\n\tb := true\n\n\tfmt.Println(\n\t\t\"i:\", i,\n\t\t\"f:\", f,\n\t\t\"s:\", s,\n\t\t\"b:\", b,\n\t)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/02-multiple-short-declare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 多重简短声明\n//\n//  使用多重简短声明语句声明两个变量\n//\n// 期望输出\n//  14 true\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这里写下你的声明语句\n\t//\n\n\t// 然后去掉下面代码的注释\n\n\t// fmt.Println(a, b)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/02-multiple-short-declare/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ta, b := 14, true\n\n\tfmt.Println(a, b)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/03-multiple-short-declare-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 多重简短声明 #2\n//\n//  1. 使用多重简短声明语句声明两个变量\n//\n//  2. 变量 `a` 的值应该是 42\n//  3. 变量 `c` 的值应该是 \"good\"\n//\n// 期望输出\n//  42 good\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这里写下你的声明语句\n\t//\n\n\t// 然后去掉下面代码的注释\n\n\t// fmt.Println(a, c)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/03-multiple-short-declare-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ta, c := 42, \"good\"\n\n\tfmt.Println(a, c)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/04-short-with-expression/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 简短表达式\n//\n// \t1. 间断声明一个变量 `sum`\n//\n//  2. 用一个 27 和 3.5 相加的语句初始化它的值\n//\n// 期望输出\n//  30.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这里写下你的声明语句\n\t//\n\n\t// 然后去掉下面代码的注释\n\t// fmt.Println(sum)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/04-short-with-expression/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tsum := 27 + 3.5\n\n\tfmt.Println(sum)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/05-short-discard/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 简短丢弃\n//\n// \t1. 简短声明两个 bool 变量\n//     (使用多重简短声明语法)\n//\n//  2. 初始化两个变量为 true\n//\n//  3. 改变你的声明并使用空白标识符\n//     丢弃第二个变量的值\n//\n//  4. 仅打印第一个变量\n//\n// 期望输出\n//  true\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这里写下你的声明语句\n\t//\n\n\t// 然后去掉下面代码的注释\n\n\t// fmt.Println(on)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/05-short-discard/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t// 你可以在简短的声明中舍弃数值\n\n\ton, _ := true, true\n\n\tfmt.Println(on)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/06-redeclare/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 重声明\n//\n// \t1. 短声明两个 int 变量：age 和 yourAge\n//     (使用多重简短声明语法)\n//\n//  2. 声明一个新的 float 类型变量 ratio\n//     修改变量 'age' 的值为 42\n//\n//     (! 你应该用重声明)\n//\n//  4. 打印所有变量\n//\n// 期望输出\n//  42, 20, 3.14\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这里写下你的声明语句\n\t//\n\n\t// 然后去掉下面代码的注释\n\n\t// fmt.Println(age, yourAge, ratio)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/06-redeclare/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tage, yourAge := 10, 20\n\tage, ratio := 42, 3.14\n\n\tfmt.Println(age, yourAge, ratio)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/练习/README.md",
    "content": "# 简短声明\n\n是时候使用简短的声明语法来声明一些变量了。除此之外还有重声明变量以及丢弃变量。\n\n1. **[简短声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/01-short-declare)**\n\n2. **[多重简短声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/02-multiple-short-declare)**\n\n3. **[多重简短声明 #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/03-multiple-short-declare-2)**\n\n4. **[简短表达式](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/04-short-with-expression)**\n\n5. **[简短丢弃](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/05-short-discard)**\n\n6. **[重声明](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/03-简短声明/练习/06-redeclare)**"
  },
  {
    "path": "translation/chinese/06-变量/03-简短声明/问题/README.md",
    "content": "## 哪个是正确的声明?\n* var int safe := 3\n* var safe bool := 3\n* safe := true *正确*\n\n## 哪个是正确的声明?\n* var short := true\n* int num := 1\n* speed := 50 *正确*\n* num int := 2\n\n## 哪个是正确的声明?\n* x, y, z := 10, 20\n* x = 10,\n* y, x, p := 5, \"hi\", 1.5 *正确*\n* y, x = \"hello\", 10\n\n## 哪个声明和下面的声明等价?\n```go\nvar s string = \"hi\"\n```\n\n* var s int = \"hi\"\n* s := \"hi\" *正确*\n* s, p := 2, 3\n\n## 哪个声明和下面的声明等价?\n```go\nvar n = 10\n```\n\n* n := 10.0\n* m, n := 1, 0\n* var n int = 10 *正确*\n\n## 变量 `s` 的类型是什么?\n```go\ns := \"hmm...\"\n```\n\n* bool\n* string *正确*\n* int\n* float64\n\n## 变量 `b` 的类型是什么?\n```go\nb := true\n```\n\n* bool *正确*\n* string\n* int\n* float64\n\n## 变量 `i` 的类型是什么?\n```go\ni := 42\n```\n\n* bool\n* string\n* int *正确*\n* float64\n\n## 变量 `f` 的类型是什么?\n```go\nf := 6.28\n```\n\n* bool\n* string\n* int\n* float64 *正确*\n\n## 变量 `x` 的类型是什么?\n\n```go\ny, x := false, 20\n```\n\n* 10\n* 20 *正确*\n* false\n\n## 变量 `x` 的类型是什么?\n\n```go\ny, x := false, 20\nx, z := 10, \"hi\"\n```\n\n* 10 *正确*\n* 20\n* false\n\n## 下面哪个声明能在包作用域上使用?\n\n* x := 10\n* y, x := 10, 5\n* var x, y = 5, 10 *正确*\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/01-概述/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar counter int\n\n\tfmt.Println(\"counter's name : counter\")\n\tfmt.Println(\"counter's value:\", counter)\n\tfmt.Printf(\"counter's type : %T\\n\", counter)\n\n\tcounter = 10 // OK\n\t// counter = \"ten\" // NOT OK\n\n\tfmt.Println(\"counter's value:\", counter)\n\n\tcounter++\n\tfmt.Println(\"counter's value:\", counter)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/01-赋值/01-赋值/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar speed int\n\tfmt.Println(speed)\n\n\tspeed = 100\n\tfmt.Println(speed)\n\n\tspeed = speed - 25\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/01-赋值/02-强类型/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Go 是一个强类型的编程语言\n\n// 即使是 浮点 (float) 和 整数 (int) 也是不同的类型\n// 甚至: int32 和 int 也是不同的类型\n\n// 练习: 尝试去掉注释并观察错误\n\nfunc main() {\n\tvar speed int\n\t// speed = \"100\"\n\n\tvar running bool\n\t// running = 1\n\n\tvar force float64\n\t// speed = force\n\n\t// Go 自动将无标注的 int 转换为 float64\n\tforce = 1\n\n\t// 让编译器开心\n\t_, _, _ = speed, running, force\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/01-赋值/03-例子/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tname   string\n\t\tage    int\n\t\tfamous bool\n\t)\n\n\t// Example #1\n\tname = \"Newton\"\n\tage = 84\n\tfamous = true\n\n\tfmt.Println(name, age, famous)\n\n\t// Example #2\n\tname = \"Somebody\"\n\tage = 20\n\tfamous = false\n\n\tfmt.Println(name, age, famous)\n\n\t// Example #3\n\t// EXERCISE: Why this doesn't work? Think about it.\n\n\t// name = 20\n\t// name = age\n\n\t// save the previous value of the variable\n\t// to a new variable\n\tvar prevName string\n\tprevName = name\n\n\t// overwrite the value of the original variable\n\t// by assigning to it\n\tname = \"Einstein\"\n\n\tfmt.Println(\"previous name:\", prevName)\n\tfmt.Println(\"current name :\", name)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/05-多重赋值/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tvar (\n\t\tspeed int\n\t\tnow   time.Time\n\t)\n\n\tspeed, now = 100, time.Now()\n\n\tfmt.Println(speed, now)\n\n\t// 练习:\n\t//   尝试用这个替代式 (格式化时间).\n\n\t// fmt.Println(speed, now.Format(time.Kitchen))\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/06-交换/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tspeed     = 100\n\t\tprevSpeed = 50\n\t)\n\n\tspeed, prevSpeed = prevSpeed, speed\n\n\tfmt.Println(speed, prevSpeed)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/07-路径/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\tvar dir, file string\n\n\tdir, file = path.Split(\"css/main.css\")\n\n\tfmt.Println(\"dir :\", dir)\n\tfmt.Println(\"file:\", file)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/08-路径丢弃/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\tvar file string\n\n\t_, file = path.Split(\"css/main.css\")\n\n\tfmt.Println(\"file:\", file)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/09-路径简短声明/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\t_, file := path.Split(\"css/main.css\")\n\n\t// 或者这样:\n\t// dir, file := path.Split(\"css/main.css\")\n\n\tfmt.Println(\"file:\", file)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/01-make-it-blue/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 让它变蓝\n//\n//  1. 修改 `color` 变量的值为 \"blue\"\n//\n//  2. 打印它\n//\n// 期望输出\n//  blue\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉下面代码的注释:\n\n\t// color := \"green\"\n\n\t// 在下面写上你的代码:\n\n\t// ?\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/01-make-it-blue/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcolor := \"green\"\n\n\tcolor = \"blue\"\n\n\tfmt.Println(color)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/02-vars-to-vars/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 变量到变量\n//\n//  1. 修改 `color` 变量的值为 \"dark green\"\n//\n//  2. 不要直接将 \"dark green\" 赋值给 `color`\n//\n//     相反的, 在赋值时再次使用 `color` 变量 (即在赋值表达式中再次用到 `color`)\n//\n//  3. 打印它\n//\n// 限制\n//  错误的答案, 别像这样做:\n//  `color = \"dark green\"`\n//\n// 提示\n//  + 操作符可以串联字符串的值\n//\n//  例子:\n//\n//  \"h\" + \"e\" + \"y\" 返回 \"hey\"\n//\n// 期望输出\n//  dark green\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉下面代码的注释:\n\n\t// color := \"green\"\n\n\t// 在下面写上你的代码:\n\n\t// ?\n\n\t// 去掉下面代码的注释以打印变量\n\n\t// fmt.Println(color)\n\n}"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/02-vars-to-vars/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcolor := \"green\"\n\n\t// `\"dark \" + color` 是一个表达式\n\n\tcolor = \"dark \" + color\n\n\tfmt.Println(color)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/03-assign-with-expressions/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// 练习: 用表达式赋值\n//\n//  1. 用 3.14 乘 2 并赋值到变量 `n`\n//\n//  2. 打印 `n`\n//\n// 提示\n//  例子: 3 * 2 = 6\n//  * 是乘法操作符 (它使数字相乘)\n//\n// 期望输出\n//  6.28\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 别修改这里\n\n\t// 声明一个新的 float64 变量\n\t// 0. 代表 0.0\n\tn := 0.\n\n\t// 在下面写上你的代码:\n\n\t// ?\n\n\tfmt.Println(n)\n\n}"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/03-assign-with-expressions/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tn := 0.\n\n\tn = 3.14 * 2\n\n\tfmt.Println(n)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/04-find-the-rectangle-perimeter/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 找到矩形的周长\n//\n//  1. 找到矩形的周长\n//     宽为 5\n//     高为 6\n//\n//  2. 把结果复制到 `perimeter` 变量上\n//\n//  3. 打印 `perimeter`\n//\n// 提示\n//  公式 = 2 × (宽 + 高)\n//\n// 期望输出\n//  22\n//\n// 附加题\n//  在这里找到更多的公式，并在新的程序中计算它们\n//  https://www.mathsisfun.com/area.html\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉下面代码的注释\n\n\t// var (\n\t// \tperimeter        int\n\t// \twidth, height = 5, 6\n\t// )\n\n\t// 计算结果时使用上述变量\n\n\t// 在下面写上你的代码:\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/04-find-the-rectangle-perimeter/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tperimeter     int\n\t\twidth, height = 5, 6\n\t)\n\n\t// 首先计算: (宽 + 高)\n\t// 然后            :  用 2 与它相乘\n\n\t// 就和在数学里一样\n\n\tperimeter = 2 * (width + height)\n\n\tfmt.Println(perimeter)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/05-multi-assign/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// 练习: 多重赋值\n//\n//  1. 使用多重赋值语句把 \"go\" 赋值到变量 `lang` 上\n//     以及 2 到变量 `version` 上\n//  2. 打印这些变量\n//\n// 期望输出\n//  go version 2\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 别动这些\n\tvar (\n\t\tlang    string\n\t\tversion int\n\t)\n\n\t// 在下面写上你的代码:\n\n\t// 别碰这个\n\tfmt.Println(lang, \"version\", version)\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/05-multi-assign/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tlang    string\n\t\tversion int\n\t)\n\n\tlang, version = \"go\", 2\n\n\tfmt.Println(lang, \"version\", version)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/06-multi-assign-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 多重赋值 #2\n//\n//  1. 将正确的值赋给各变量以和下面的 期望输出 相匹配\n//\n//  2. 打印这些变量\n//\n// 提示\n//  使用多个 Println 调用来打印每个句子\n//\n// 期望输出\n//  Air is good on Mars\n//  It's true\n//  It is 19.5 degrees\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉下面代码的注释\n\n\t// var (\n\t// \tplanet string\n\t// \tisTrue bool\n\t// \ttemp   float64\n\t// )\n\n\t// 在下面写上你的代码\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/06-multi-assign-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tplanet string\n\t\tisTrue bool\n\t\ttemp   float64\n\t)\n\n\tplanet, isTrue, temp = \"Mars\", true, 19.5\n\n\tfmt.Println(\"Air is good on\", planet)\n\tfmt.Println(\"It's\", isTrue)\n\tfmt.Println(\"It is\", temp, \"degrees\")\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/07-multi-short-func/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 多重简短函数\n//\n// \t1. 使用多重简短声明语法声明两个变量\n//\n//  2. 使用下方的 `multi` 函数初始化变量\n//\n//  3. 在声明中丢弃第一个变量\n//\n//  4. 只打印第二个变量\n//\n// 注意\n//  你应该在初始化时使用 `multi` 函数\n//\n// 期望输出\n//  4\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这添加你的声明\n\t//\n\n\t// 然后删掉下面代码的注释\n\n\t// fmt.Println(b)\n\n}\n\n// multi 是一个返回多个 int 值的函数\nfunc multi() (int, int) {\n\treturn 5, 4\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/07-multi-short-func/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\t_, b := multi()\n\n\tfmt.Println(b)\n}\n\nfunc multi() (int, int) {\n\treturn 5, 4\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/08-swapper/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 交换器\n//\n//  1. 同时将`color`改为 \"orange\", `color2` 改为 \"绿色\"。\n//     (使用多重赋值)\n//\n//  2. 打印这些变量\n//\n// 期望输出\n//  orange green\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉下面代码的注释\n\n\t// color, color2 := \"red\", \"blue\"\n\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/08-swapper/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcolor, color2 := \"red\", \"blue\"\n\n\tcolor, color2 = \"orange\", \"green\"\n\n\tfmt.Println(color, color2)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/09-swapper-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 交换器 #2\n//\n//  1. 交换 `red` 和 `blue` 这两个变量的值\n//\n//  2. 打印它们\n//\n// 期望输出\n//  blue red\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉下面代码的注释:\n\n\t// red, blue := \"red\", \"blue\"\n\t// ?\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/09-swapper-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tred, blue := \"red\", \"blue\"\n\n\tred, blue = blue, red\n\n\tfmt.Println(red, blue)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/10-discard-the-file/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 丢弃文件\n//\n//  1. 使用 `path.Split`, 只打印 directory\n//\n//  2. 丢弃它 file 的部分\n//\n// 限制\n//  使用简短声明\n//\n// 期望输出\n//  secret/\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉下面代码的注释:\n\n\t// ? ?= path.Split(\"secret/file.txt\")\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/10-discard-the-file/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"path\"\n)\n\nfunc main() {\n\tdir, _ := path.Split(\"secret/file.txt\")\n\n\tfmt.Println(dir)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/练习/README.md",
    "content": "# 赋值\n\n赋值意味着 \"复制\" 值。在 Go 中, 所有东西都被复制了。之后你会了解更多这方面的信息。\n\n现在, 脚踏实地尝试一些赋值练习\n\n1. **[让他变蓝](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/01-make-it-blue)**\n\n2. **[变量到变量](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/02-vars-to-vars)**\n\n3. **[用表达式赋值](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/03-assign-with-expressions)**\n\n4. **[找到矩形的周长](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/04-find-the-rectangle-perimeter)**\n\n5. **[多重赋值](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/05-multi-assign)**\n\n6. **[多重赋值 #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/06-multi-assign-2)**\n\n7. **[多重简短函数](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/07-multi-short-func)**\n\n8. **[交换器](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/08-swapper)**\n\n9. **[交换器 #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/09-swapper-2)**\n\n10. **[丢弃文件](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/04-赋值/练习/10-discard-the-file)**\n\n"
  },
  {
    "path": "translation/chinese/06-变量/04-赋值/问题/README.md",
    "content": "## 当你把一个变量赋值给另一个变量时会发生什么？\n\n* 变量们变成同一个\n* 被赋值的变量被删除\n* 变量的值被改变为赋值变量的值 *正确*\n\n## 哪个是正确的赋值语句?\n\n```go\nopened := true\n```\n\n* `closed := true`\n* `opened = false` *正确*\n* `var x = 2`\n\n## 哪个是正确的赋值语句?\n\n* `a, b = 3; 5`\n* `c, d = true, false` *正确*\n* `a, b, c = 5, 3`\n\n## 哪个是正确的赋值语句?\n\n```go\nvar (\n  n = 3\n  m int\n)\n```\n\n* `m = \"4\"`\n* `n = 10` *正确*\n* `n = true`\n* `m = false`\n\n## 哪个是正确的赋值语句?\n\n```go\nvar (\n  n = 3\n  m int\n  f float64\n)\n\n// one of the assignments below will be here\n\nfmt.Println(n, m, f)\n```\n\n* `n, m = 4, f`\n* `n = false`\n* `n, m, f = m + n, n + 5, 0.5` *正确*\n* `n, m = 3.82, \"hi\"`\n\n## 哪个是正确的赋值语句?\n\n```go\nvar (\n  a int\n  c bool\n)\n```\n\n* `a = _`\n* `c, _ = _, false`\n* `_, _ = a, c` *正确*\n\n## 哪个是正确的赋值语句?\n\n**记住:** `path.Split` 返回两个 `string` 值\n\n```go\n  var c, f string\n```\n\n* `_ = path.Split(\"assets/profile.png\")`\n* `_, _, c = path.Split(\"assets/profile.png\")`\n* `f = path.Split(\"assets/profile.png\")`\n* `_, f = path.Split(\"assets/profile.png\")` *正确*\n\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/01-破坏性的/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tspeed := 100 // int\n\tforce := 2.5 // float64\n\n\t// 错误: 无效的操作符\n\t// ERROR: invalid op\n\t// speed = speed * force\n\n\t// 转换可以是一个破坏性的操作\n\t// `force` 失去了它的分数部分...\n\n\tspeed = speed * int(force)\n\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/02-正确的/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// 转化的顺序很重要...\n\nfunc main() {\n\tspeed := 100\n\tforce := 2.5\n\n\tfmt.Printf(\"speed     : %T\\n\", speed)\n\tfmt.Printf(\"conversion: %T\\n\", float64(speed))\n\tfmt.Printf(\"expression: %T\\n\", float64(speed)*force)\n\n\t// 类型不匹配:\n\t//   speed 是 int\n\t//   expression 是 float64\n\t// speed = float64(speed) * force\n\n\t// 正确: int * int\n\tspeed = int(float64(speed) * force)\n\n\tfmt.Println(speed)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/03-数型转换/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar apple int\n\tvar orange int32\n\n\t// 错误:\n\t// 不能将 orange 赋值到 apple 上 (不同的类型)\n\t// ERROR:\n\t// cannot assign orange to apple (different types)\n\t// apple = orange\n\n\t// 你需要将 orange 转换为 apple\n\n\t// orange 能够被转换为 int ,\n\t//   因为 int 和 int32 都是数字类型\n\n\tapple = int(orange)\n\n\t// 你不能将一个数字类型转换为布尔类型\n\t// isDelicious := bool(orange)\n\n\t// 但是你可以将 int 转换为 string\n\t// 这只对 int 类型生效\n\torange = 65 // 65 is A\n\tcolor := string(orange)\n\tfmt.Println(color)\n\n\t// 这不能运行。 65.0 是 float.\n\t// fmt.Println(string(65.0))\n\n\t// 这能运行: 这有两个 byte 值\n\t// byte 也是 int\n\tfmt.Println(string([]byte{104, 105}))\n\n\t_ = apple\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/01-convert-and-fix/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 转换并修复\n//\n//  使用类型转换表达式修复这些代码.\n//\n// 期望输出\n//  15.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// a, b := 10, 5.5\n\t// fmt.Println(a + b)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/01-convert-and-fix/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ta, b := 10, 5.5\n\tfmt.Println(float64(a) + b)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/02-convert-and-fix-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 转换并修复 #2\n//\n//  使用类型转换表达式修复这些代码.\n//\n// 期望输出\n//  10.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// a, b := 10, 5.5\n\t// a = b\n\t// fmt.Println(a + b)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/02-convert-and-fix-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ta, b := 10, 5.5\n\ta = int(b)\n\tfmt.Println(float64(a) + b)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/03-convert-and-fix-3/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 转换并修复 #3\n//\n//  修复代码.\n//\n// 期望输出\n//  5.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// fmt.Println(int(5.5))\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/03-convert-and-fix-3/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(5.5)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/04-convert-and-fix-4/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 转换并修复 #4\n//\n//  修复代码.\n//\n// 期望输出\n//  9.5\n// ---------------------------------------------------------\n\nfunc main() {\n\t// age := 2\n\t// fmt.Println(int(7.5) + int(age))\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/04-convert-and-fix-4/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tage := 2\n\tfmt.Println(7.5 + float64(age))\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/05-convert-and-fix-5/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// ---------------------------------------------------------\n// 练习: 转换并修复 #5\n//\n//  修复代码.\n//\n// 提示\n//   int8 的最大值是 127\n//   int16 的最大值是 32767\n//\n// 期望输出\n//  1127\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 不要修改这些变量\n\tmin := int8(127)\n\tmax := int16(1000)\n\n\t// 修复代码\n\tfmt.Println(int8(max) + min)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/05-convert-and-fix-5/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tmin := int8(127)\n\tmax := int16(1000)\n\n\tfmt.Println(max + int16(min))\n\n\t// 解释\n\t//\n\t// `int8(max)` 损失了 max 的信息\n\t// 导致它减小到了 127\n\t// 也就是 int8 的最大值\n\t//\n\t// 正确的转换时 int16(min)\n\t// 因为 int16 > int8\n\t// 当你这样做时, min 不会损失信息\n\t//\n\t// 你会在 \"Go 类型系统\" 这节学到更多\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/练习/README.md",
    "content": "# 类型转换\n\n这里为你准备了 5 个练习。你必须找到这些错误，然后用正确的类型转换来修复它们。\n\n1. **[Convert and Fix #1](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/01-convert-and-fix)**\n\n2. **[Convert and Fix #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/02-convert-and-fix-2)**\n\n3. **[Convert and Fix #3](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/03-convert-and-fix-3)**\n\n4. **[Convert and Fix #4](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/04-convert-and-fix-4)**\n\n5. **[Convert and Fix #5](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/05-类型转换/练习/05-convert-and-fix-5)**\n\n"
  },
  {
    "path": "translation/chinese/06-变量/05-类型转换/问题/questions.md",
    "content": "## 哪一个是正确的类型转换表达式?\n\n* convert(40)\n* var(\"hi\")\n* int(4.) *正确*\n* int[4]\n\n## 这段代码打印什么?\n\n```go\nage := 6.5\nfmt.Print(int(age))\n```\n\n* 6.5\n* 65\n* 6 *正确*\n* .5\n\n> 当你把一个 float 转换为 int 时\n> 它失去了它的小数部分\n\n## 这段代码打印什么?\n\n```go\nfmt.Print(int(6.5))\n```\n\n* 6.5\n* 65\n* 6\n* Compile-Time Error *正确*\n\n> Go可以在编译时检测转换错误\n\n## 这段代码打印什么?\n\n```go\narea := 10.5\nfmt.Print(area/2)\n```\n\n* 5.25 *正确*\n* 5\n* 0\n* Error\n\n## 这段代码打印什么?\n\n```go\narea := 10.5\ndiv := 2\nfmt.Print(area/div)\n```\n\n* 5.25\n* 5\n* ERROR *正确*\n\n> 你不能除以不同类型的值\n> 你需要转换:`area / float64(div)`\n\n## 下面哪段代码能修复这段代码?\n\n```go\narea := 10.5\ndiv := 2\nfmt.Print(area/div)\n```\n\n* `fmt.Print(int(area)/div)`      // 5\n* `fmt.Print(area/int(div))`      // 类型不匹配\n* `fmt.Print(int(area)/int(div))` // 5\n* `fmt.Print(area/float64(div))`  *正确*\n\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/01-演示/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// 注意: 至少要用3个参数来运行这个程序\n//      否则它会报错\n\nfunc main() {\n\tfmt.Printf(\"%#v\\n\", os.Args)\n\n\t// 从 os.Args 字符串切片中获取一个 item\n\t//     os.Args[INDEX]\n\t// INDEX 可以是 0 或者更大\n\tfmt.Println(\"Path:\", os.Args[0])\n\tfmt.Println(\"1st argument:\", os.Args[1])\n\tfmt.Println(\"2nd argument:\", os.Args[2])\n\tfmt.Println(\"3rd argument:\", os.Args[3])\n\n\t// `len` 可以知道有多少个 item 在切片值中\n\tfmt.Println(\"Items inside os.Args:\", len(os.Args))\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/02-版本1/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// 因为, 还没有学到关于控制流语句的知识\n// 在这里没有包含错误检测\n//\n// 所以, 如果你没有传递 name,\n// 程序会出错,\n// 这是有意为之的\n\nfunc main() {\n\tvar name string\n\n\t// 给下面的字符串变量赋一个新值\n\tname = os.Args[1]\n\tfmt.Println(\"Hello great\", name, \"!\")\n\n\t// 修改 name, 声明 age 并赋值 85\n\tname, age := \"gandalf\", 85\n\n\tfmt.Println(\"My name is\", name)\n\tfmt.Println(\"My age is\", age)\n\tfmt.Println(\"BTW, you shall pass!\")\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/03-版本2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// 因为, 还没有学到关于控制流语句的知识\n// 在这里没有包含错误检测\n//\n// 所以, 如果你没有传递 name,\n// 程序会出错,\n// 这是有意为之的\n\nfunc main() {\n\t// 给下面的字符串变量赋一个新值\n\tname := os.Args[1]\n\tfmt.Println(\"Hello great\", name, \"!\")\n\n\t// 修改 name, 声明 age 并赋值 85\n\tname, age := \"gandalf\", 85\n\n\tfmt.Println(\"My name is\", name)\n\tfmt.Println(\"My age is\", age)\n\tfmt.Println(\"BTW, you shall pass!\")\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/01-count-arguments/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 数参数\n//\n//  打印命令行参数的个数\n//\n// 输入\n//  bilbo balbo bungo\n//\n// 期望输出\n//  There are 3 names.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 去掉注释 & 修复代码\n\t// count := ?\n\n\t// 去掉注释 & 然后别动他\n\t// fmt.Printf(\"There are %d names.\\n\", count)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/01-count-arguments/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tcount := len(os.Args) - 1\n\n\tfmt.Printf(\"There are %d names.\\n\", count)\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/02-print-the-path/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 打印路径\n//\n//  从变量 `os.Args` 中获取运行程序的路径并打印它\n//\n// 提示\n//  用 `go build` 来构建你的程序\n//  然后通过编译后的可执行程序运行它\n//\n// 预期输出应包含\n//  myprogram\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/02-print-the-path/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// 步骤:\n//\n// 输入下面的命令来编译:\n//   go build -o myprogram\n//\n// 然后输入下面的命令来运行:\n//   ./myprogram\n//\n// 如果是 Windows, 输入:\n//   myprogram\n\nfunc main() {\n\tfmt.Println(os.Args[0])\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/03-print-your-name/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 打印你的名字\n//\n//  从第一个命令行参数来获取名字\n//\n// 输入\n//  用你的名字来运行这个程序 (指传入你的名字作为参数)\n//\n// 期望输出\n//  你的名字\n//\n// 例子\n//  go run main.go inanc\n//\n//    inanc\n//\n// 附加题: 让输出变成下面这样:\n//\n//  go run main.go inanc\n//    Hi inanc\n//    How are you?\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 从第一个命令行参数来获取名字\n\t// 打印它\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/03-print-your-name/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tfmt.Println(os.Args[1])\n\n\t// 附加题答案\n\tfmt.Println(\"Hello\", os.Args[1])\n\tfmt.Println(\"How are you?\")\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/04-greet-more-people/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 问候更多人\n//\n// 限制\n//  1. 请确保与下面的预期输出相匹配\n//  2. 将参数的长度存储在一个变量中\n//  3. 将所有参数也存储在变量中\n//\n// 输入\n//  bilbo balbo bungo\n//\n// 期望输出\n//  There are 3 people!\n//  Hello great bilbo !\n//  Hello great balbo !\n//  Hello great bungo !\n//  Nice to meet you all.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这写你的代码\n\n\t// 附加题 #1:\n\t// 传递少于3个参数, 然后观察错误。\n\t// 在网上搜索如何解决这个问题\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/04-greet-more-people/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tvar (\n\t\tl  = len(os.Args) - 1\n\t\tn1 = os.Args[1]\n\t\tn2 = os.Args[2]\n\t\tn3 = os.Args[3]\n\t)\n\n\tfmt.Println(\"There are\", l, \"people !\")\n\tfmt.Println(\"Hello great\", n1, \"!\")\n\tfmt.Println(\"Hello great\", n2, \"!\")\n\tfmt.Println(\"Hello great\", n3, \"!\")\n\tfmt.Println(\"Nice to meet you all.\")\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/05-greet-5-people/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 问候 5 个人\n//\n//  这次问候 5 个人\n//\n//  不要从上一个练习中复制粘贴代码\n//\n// 限制\n//  这次不要用变量\n//\n// 输入\n//  bilbo balbo bungo gandalf legolas\n//\n// 期望输出\n//  There are 5 people!\n//  Hello great bilbo !\n//  Hello great balbo !\n//  Hello great bungo !\n//  Hello great gandalf !\n//  Hello great legolas !\n//  Nice to meet you all.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 在这写你的代码\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/05-greet-5-people/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tfmt.Println(\"There are\", len(os.Args)-1, \"people !\")\n\tfmt.Println(\"Hello great\", os.Args[1], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[2], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[3], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[4], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[5], \"!\")\n\tfmt.Println(\"Nice to meet you all.\")\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/README.md",
    "content": "# 命令行参数\n\n1. **[数参数](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/01-count-arguments)**\n\n2. **[打印路径](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/02-print-the-path)**\n\n3. **[打印你的名字](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/03-print-your-name)**\n\n4. **[问候更多人](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/04-greet-more-people)**\n\n5. **[问候 5 个人](https://github.com/inancgumus/learngo/tree/master/translation/chinese/06-变量/06-问候员项目/练习/05-greet-5-people)**\n\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/练习/solution-to-the-lecture-exercise/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// ---------------------------------------------------------\n// 这是我在讲座中提到的练习的答案\n// ---------------------------------------------------------\n\n// 注意: 你至少要用 3 个参数来运行这个程序\n//       否则它会报错\n\nfunc main() {\n\t// 给下面的字符串变量赋一个新值\n\tvar (\n\t\tname  = os.Args[1]\n\t\tname2 = os.Args[2]\n\t\tname3 = os.Args[3]\n\t)\n\n\tfmt.Println(\"Hello great\", name, \"!\")\n\tfmt.Println(\"And hellooo to you magnificient\", name2, \"!\")\n\tfmt.Println(\"Welcome\", name3, \"!\")\n\n\t// 修改 name, 声明 age 变量并赋值 131\n\tname, age := \"bilbo baggins\", 131 // 未知年龄!\n\n\tfmt.Println(\"My name is\", name)\n\tfmt.Println(\"My age is\", age)\n\tfmt.Println(\"And, I love adventures!\")\n\n}\n"
  },
  {
    "path": "translation/chinese/06-变量/06-问候员项目/问题/questions.md",
    "content": "## `os.Args` 变量在其第一项中存储了什么?\n\n* 传递给程序的第一个参数\n* 传递给程序的第二个参数\n* 运行程序的路径 *正确*\n\n## `Args` 变量的类型是什么？\n\n```go\nvar Args []string\n```\n\n* string\n* string 数组\n* strings 的切片 *正确*\n\n## `Args` 变量中每个值的类型是什么？\n\n```go\nvar Args []string\n```\n\n* string *正确*\n* string 数组\n* strings 的切片\n\n## 如何获得 `Args` 变量的第一项？\n\n```go\nvar Args []string\n```\n\n* Args.0\n* Args{1}\n* Args[0] *正确*\n* Args(1)\n\n## 如何获得 `Args` 变量的第二项？\n\n```go\nvar Args []string\n```\n\n* Args.2\n* Args[1] *正确*\n* Args{1}\n* Args(2)\n\n## 如何获得 `Args` 变量的长度？\n\n```go\nvar Args []string\n```\n\n* length(Args)\n* Args.len\n* len(Args) *正确*\n* Args.Length\n\n## 如何从命令行获得第一个 \"argument\"？\n\n* os.Args[0]\n* os.Args[1] *正确*\n* os.Args[2]\n* os.Args[3]\n\n"
  },
  {
    "path": "translation/chinese/07-打印/01-介绍/01-println-vs-printf/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tops, ok, fail := 2350, 543, 433\n\n\tfmt.Println(\n\t\t\"total:\", ops, \"- success:\", ok, \"/\", fail,\n\t)\n\n\tfmt.Printf(\n\t\t\"total: %d - success: %d / %d\\n\",\n\t\tops, ok, fail,\n\t)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/01-介绍/02/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar brand string\n\n\t// 像这样 \"\" 引用形式打印字符串\n\tfmt.Printf(\"%q\\n\", brand)\n\n\tbrand = \"Google\"\n\tfmt.Printf(\"%q\\n\", brand)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/02-转义序列/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 没有换行符\n\tfmt.Println(\"hihi\")\n\n\t// 使用换行符:\n\t//   \\n = 转义序列\n\t//   \\  = 转义字符\n\tfmt.Println(\"hi\\nhi\")\n\n\t// 转义字符:\n\t//   \\\\ = \\\n\t//   \\\" = \"\n\tfmt.Println(\"hi\\\\n\\\"hi\\\"\")\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/03-打印类型/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// 我正在使用一次声明多个变量，而不是一次声明一个变量\n\tvar (\n\t\tspeed int\n\t\theat  float64\n\t\toff   bool\n\t\tbrand string\n\t)\n\n\tfmt.Printf(\"%T\\n\", speed)\n\tfmt.Printf(\"%T\\n\", heat)\n\tfmt.Printf(\"%T\\n\", off)\n\tfmt.Printf(\"%T\\n\", brand)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/04-编程/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar (\n\t\tplanet   = \"venus\"\n\t\tdistance = 261\n\t\torbital  = 224.701\n\t\thasLife  = false\n\t)\n\n\t// 全能打印 %v 动词\n\tfmt.Printf(\"Planet: %v\\n\", planet)\n\tfmt.Printf(\"Distance: %v millions kms\\n\", distance)\n\tfmt.Printf(\"Orbital Period: %v days\\n\", orbital)\n\tfmt.Printf(\"Does %v have life? %v\\n\", planet, hasLife)\n\n\t// 参数索引 - 索引从 1 开始\n\tfmt.Printf(\n\t\t\"%v is %v away. Think! %[2]v kms! %[1]v OMG.\\n\",\n\t\tplanet, distance,\n\t)\n\n\t// 为什么不使用别的打印词?\n\t// 原因: 有可能因为类型不正确导致报错\n\t//\n\t// fmt.Printf(\"Planet: %d\\n\", planet)\n\t// fmt.Printf(\"Distance: %s millions kms\\n\", distance)\n\t// fmt.Printf(\"Orbital Period: %t days\\n\", orbital)\n\t// fmt.Printf(\"Does %v has life? %f\\n\", planet, hasLife)\n\n\t// 正确的打印动词:\n\t// fmt.Printf(\"Planet: %s\\n\", planet)\n\t// fmt.Printf(\"Distance: %d millions kms\\n\", distance)\n\t// fmt.Printf(\"Orbital Period: %f days\\n\", orbital)\n\t// fmt.Printf(\"Does %s has life? %t\\n\", planet, hasLife)\n\n\t// 更加精确的打印动词\n\tfmt.Printf(\"Orbital Period: %f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.0f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.1f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.2f days\\n\", orbital)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/01-print-your-age/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: 打印你的年来\n//\n//  使用 Printf 打印你的年龄\n//\n// 期望输出\n//  I'm 30 years old.\n//\n// 注意\n//  你应该把你的年龄给程 30 岁\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/01-print-your-age/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"I'm %d years old.\\n\", 30)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/02-print-your-name-and-lastname/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：打印您的名字和姓氏\n//\n//  使用 Printf 您的名字和姓氏\n//\n// 期望输出\n//  My name is Inanc and my lastname is Gumus.\n//\n// 额外\n//  把打印格式声明字符串 (Printf 的第一个参数) 存到一个变量\n//  然后传递到 Printf\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 额外: 使用一个变量存打印格式声明字符串\n\n\t// fmt.Printf(\"?\", ?, ?)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/02-print-your-name-and-lastname/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"My name is %s and my lastname is %s.\\n\", \"Inanc\", \"Gumus\")\n\n\t// 额外\n\tmsg := \"My name is %s and my lastname is %s.\\n\"\n\tfmt.Printf(msg, \"Inanc\", \"Gumus\")\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/03-false-claims/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习: false 声明\n//\n//  使用 Printf 使用变量打印预期输出\n//\n// 期望输出\n//  These are false claims.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 将注释下的代码去掉注释\n\t// 然后移到你的代码中\n\t// tf := false\n\n\t// 将你的代码写到下面\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/03-false-claims/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\ttf := false\n\tfmt.Printf(\"These are %t claims.\\n\", tf)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/04-print-the-temperature/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：打印温度\n//\n//  使用 Printf 打印您所在地区的当前温度\n//\n// 注意\n//  不要使用 %v 动词\n//  输出不应该是 29.500000\n//\n// 期望输出\n//  Temperature is 29.5 degrees.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/04-print-the-temperature/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Temperature is %.1f degrees.\\n\", 29.5)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/05-double-quotes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：双引号\n//\n// 使用 Printf 打印带有双引号的 \"hello world\"\n//（正如你在这里看到的）\n//\n// 注意\n//  输出不应该只是 hello world\n//\n// 期待输出\n//  \"hello world\"\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/05-double-quotes/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"%q\\n\", \"hello world\")\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/06-print-the-type/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：打印字体\n//\n//  使用 fmt.Printf 打印 3 的类型和值\n//\n// 期望输出\n//  Type of 3 is int\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/06-print-the-type/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %d is %[1]T\\n\", 3)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/07-print-the-type-2/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：打印类型#2\n//\n//  使用 fmt.Printf 打印 3.14 的类型和值\n//\n// 期望输出\n//  Type of 3.14 is float64\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/07-print-the-type-2/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %.2f is %[1]T\\n\", 3.14)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/08-print-the-type-3/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：打印类型#3\n//\n//  使用 fmt.Printf 打印 \"hello\" 的类型和值\n//\n// 期望输出\n// \tType of hello is string\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/08-print-the-type-3/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %s is %[1]T\\n\", \"hello\")\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/09-print-the-type-4/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：打印类型#4\n//  使用 fmt.Printf 打印 true 的类型和值\n//\n// 期望输出\n//  Type of true is bool\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/09-print-the-type-4/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"Type of %t is %[1]T\\n\", true)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/10-print-your-fullname/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// 练习：打印您的全名\n//\n// 1. 从命令行获取您的名字和姓氏\n// 2. 使用 Printf 打印它们\n//\n// 输入示例\n//  Inanc Gumus\n//\n// 期望输出\n//  Your name is Inanc and your lastname is Gumus.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// 额外: 使用一个变量存打印格式\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/10-print-your-fullname/solution/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\t// 警告: 该程序如果允许时不输入你的名字和姓氏将会报错\n\n\tname, lastname := os.Args[1], os.Args[2]\n\n\tmsg := \"Your name is %s and your lastname is %s.\\n\"\n\tfmt.Printf(msg, name, lastname)\n}\n"
  },
  {
    "path": "translation/chinese/07-打印/练习/README.md",
    "content": "# 打印\n\n1. **[Print Your Age](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/01-print-your-age)**\n\n2. **[Print Your Name and LastName](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/02-print-your-name-and-lastname)**\n\n3. **[False Claims](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/03-false-claims)**\n\n4. **[Print the Temperature](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/04-print-the-temperature)**\n\n5. **[Double Quotes](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/05-double-quotes)**\n\n6. **[Print the Type](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/06-print-the-type)**\n\n7. **[Print the Type #2](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/07-print-the-type-2)**\n\n8. **[Print the Type #3](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/08-print-the-type-3)**\n\n9. **[Print the Type #4](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/09-print-the-type-4)**\n\n10. **[Print Your Fullname](https://github.com/inancgumus/learngo/tree/master/translation/chinese/07-变量/练习/10-print-your-fullname)**\n"
  },
  {
    "path": "translation/chinese/07-打印/问题/questions.md",
    "content": "## 哪个代码是正确的?\n* `fmt.Printf(\"Hi %s\")`\n* `fmt.Printf(\"Hi %s\", \"how\", \"are you\")`\n* `fmt.Printf(\"Hi %s\", \"hello\")` *正确*\n* `fmt.Printf(\"Hi %s\", true)`\n\n## 哪个代码是正确的?\n* `fmt.Printf(\"Hi %s %s\", \"there\")`\n* `fmt.Printf(\"Hi %s %s\", \"5\", true)`\n* `fmt.Printf(\"Hi %s %s\", \"there\", \".\")` *正确*\n* `fmt.Printf(\"Hi %s %s\", \"true\", false)`\n\n## 哪个动词用于 int 值?\n* %f\n* %d *正确*\n* %s\n* %t\n\n## 哪个动词用于 float 值?\n* %f *正确*\n* %d\n* %s\n* %t\n\n## 哪个动词用于 string 值?\n* %f\n* %d\n* %s *正确*\n* %t\n\n## 哪个动词用于 bool 值?\n* %f\n* %d\n* %s\n* %t *正确*\n\n## 你可以用哪个动词来形容任何类型的值?\n* %f\n* %d\n* %v *正确*\n* %t\n\n## 哪个是 `\"\\n\"` 正确打印?\n* \\n\n* Prints a newline *正确*\n* Prints an empty string\n\n## 哪个是 `\"\\\\n\"` 正确打印?\n* \\n *正确*\n* Prints a newline\n* Prints an empty string\n\n## 哪个是 \"c:\\\\secret\\\\directory\" 正确打印?\n* \"c:\\\\secret\\\\directory\"\n* c:\\\\secret\\\\directory\n* c:\\secret\\directory *正确*\n\n## 哪个是 `\"\\\"heisenberg\\\"\"` 正确打印?\n* ERROR\n* heisenberg\n* \"heisenberg\" *正确*\n* 'heisenberg'\n\n## 哪个是 `fmt.Printf(\"%T\", 3.14)` 正确输出?\n* ERROR\n* int\n* float64 *正确*\n* string\n* bool\n\n## 哪个是 `fmt.Printf(\"%T\", true)` 正确输出?\n* ERROR\n* int\n* float64\n* string\n* bool *正确*\n\n## 哪个是 `fmt.Printf(\"%T\", 42)` 正确输出?\n* ERROR\n* int *正确*\n* float64\n* string\n* bool\n\n## 哪个是 `fmt.Printf(\"%T\", \"hi\")` 正确输出?\n* ERROR\n* int\n* float64\n* string *正确*\n* bool\n"
  },
  {
    "path": "translation/spanish/01-empecemos/README.md",
    "content": "# Guias De Instalación Para Go\n\nPor favor seleciona tu sistema operativo:\n\n- [OS X](instalacion-osx.md)\n- [Windows](instalacion-windows.md)\n- [Linux (Ubuntu)](instalacion-ubuntu.md)\n"
  },
  {
    "path": "translation/spanish/01-empecemos/instalacion-osx.md",
    "content": "# Instalación OSX\n\n## NOTA\n\nSi tienes [homebrew](https://brew.sh) instalado, puedes instalar Go facilmente de la siguiente forma:\n\n```bash\n# si no tienes git instalado instálalo asi\nbrew install git\n\n# despues instala go\nbrew install go\n\n# añade la ruta GOBIN a tu ruta en ~/.bash_profile\nexport PATH=${HOME}/go/bin:$PATH\n```\n\n## 1. Instala el editor [Visual Studio Code](https://code.visualstudio.com)\n\n1. Instálalo pero no lo abras todavia\n2. Ve a [https://code.visualstudio.com](https://code.visualstudio.com)\n3. Selecciona la version OS X (Mac) para comenzar la descarga\n4. Descomprime los archivos descargados y muevelos a la carpeta `~/Applications`\n\n## 2. Instala [Git](https://git-scm.com/)\n\n1. Descarga y ejecuta el instalador. Ve a: [https://git-scm.com/downloads](https://git-scm.com/downloads)\n2. Selecciona VSCode como editor por defecto\n\n## 3. Instala [Go](https://golang.org/)\n\n1. Ve a [https://golang.org/dl](https://golang.go/dl)\n2. Elige la versión OS X (Mac)\n3. Ejecuta el instalador\n\n## 4. Configura Visual Studio Code\n\n1. Abre VS Code; haz click en la pestaña de extensiones situada a la izquierda, busca \"go\" e instálalo\n2. Cierra VS Code por completo y ábrelo de nuevo\n\n3. Ve al menu 'Ver' y selecciona **Paleta de Comandos**\n\n   1. O simplemente presiona: `ctrl+shift+p`\n   2. Escribe: `go install`\n   3. Elige: _\"Go: Install/Update Tools\"_\n   4. Marca todas las casillas\n\n4. Una vez acabado abre la **Paleta de Comandos** de nuevo\n   1. Escribe: `shell`\n   2. Elige: \"Install 'code' command in PATH\"\n      1. **NOTA:** No tienes que hacer esto si estas en Windows.\n\n## Eso es todo! Disfrutad! 🤩\n\n<div style=\"page-break-after: always;\"></div>\n\n> Para mas tutoriales: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2021 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click aqui para leer la licencia.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/spanish/01-empecemos/instalacion-ubuntu.md",
    "content": "# Instalación Linux (Ubuntu)\n\nSi quieres usar snap puedes instalar Go facilmente con este comando:\n\n```bash\nsudo snap install go --classic\n```\n\nSino, puedes seguir los siguientes pasos\n\n## 1. Actualiza los paquetes locales\n\n```bash\nsudo apt-get update\n```\n\n## 2. Instala [Git](https://git-scm.com/)\n\n```bash\nsudo apt-get install git\n```\n\n## 3. Instala [Go](https://golang.org/)\n\nHay dos formas:\n\n1. Ve a [https://golang.org/dl](https://golang.go/dl)\n2. Elige la versión Linux\n3. Ejecuta el instalador\n\n4. Si estas usando snap: avanza hasta el paso 5.\n\n   ```bash\n   sudo snap install go --classic\n   ```\n\n## 4. Copia Go en el directorio apropiado\n\n1. Encuentra el nombre del archivo descargado\n\n2. Usa el nombre de ese archivo para descomprimirlo\n\n   ```bash\n   gofile=\"BORRA_ESTO_Y_ESCRIBE_EL_NOMBRE_DEL_ARCHIVO_DESCARGADO (sin la extension)\"\n   tar -C /usr/local -xzf ~/Downloads/$gofile\n   ```\n\n## 5. Añade los executables de Go a tu PATH\n\n1. Añade el directorio `go/bin` al `$PATH` para poder ejecutar los comandos principales de Go.\n\n   ```bash\n   echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile\n   ```\n\n2. Añade el directorio `$HOME/go/bin` a tu `$PATH`\n\n   ```bash\n   echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.profile\n   ```\n\n## Instala Las Herramientas de Go\n\n- Estas son utiles herramientas que ayudan a facilitar el desarrollo (como goimports)\n\n- `go get` no puede ser usado sin haber instalado un programa de control de versiones como Git.\n\n- Esto creara un directorio llamado `~/go` donde se descargaran las herramientas\n\n- Este directorio tambien es el lugar donde deberias poner tu codigo. (Si no vas a usar los modulos de Go)\n\n  ```bash\n  go get -v -u golang.org/x/tools/...\n  ```\n\n## Instala El Editor Visual Studio Code\n\nNota: Puedes usar otro editor de codigo si quieres. Igualmente, el curso usa Visual Studio Code (VS Code).\n\n1. Abre la aplicación \"Ubuntu Software\"\n2. Busca \"VSCode\" y clicka en el boton de Instalar\n\n## PASO OPCIONAL\n\n1. Crea un archivo llamado `hola.go` en un nuevo directorio alejado de `$GOPATH`\n\n   ```bash\n   cat <<EOF > hola.go\n   package main\n\n   import \"fmt\"\n\n   func main() {\n       fmt.Println(\"hola gopher!\")\n   }\n   EOF\n   ```\n\n2. Ejecuta el programa\n\n   ```bash\n   go run hola.go\n   Deberia imprimir: hola gopher!\n   ```\n\n## Eso es todo! Disfrutad! 🤩\n\n<div style=\"page-break-after: always;\"></div>\n\n> Para mas tutoriales: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2021 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click aqui para leer la licencia.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/spanish/01-empecemos/instalacion-windows.md",
    "content": "# Instalación Windows\n\n## NOTA\n\nSi tienes el administrador de paquetes [chocolatey.org](https://chocolatey.org/) puedes instalar Go facilmente con este comando:\n\n```bash\nchoco install golang\n```\n\n### 1. Instala el editor [Visual Studio Code](https://code.visualstudio.com)\n\n1. Instálalo pero no lo abras todavia\n2. Ve a: [https://code.visualstudio.com](https://code.visualstudio.com)\n3. Elige la versión para Windows\n4. Ejecuta el instalador\n\n## 2. Instala Git\n\n1. Descarga y ejecuta el instalador: Ve a: [https://gitforwindows.org](https://gitforwindows.org)\n2. Elige VSCode como editor por defecto\n3. Marca todas las casillas\n4. Elige: \"Utilizar Git desde la Consola de Comandos de Windows\"\n5. Codificaciones: Elige la opción: \\_\"Dejar como esta...\"\n\n## 3. Instala [Go](https://golang.org/)\n\n1. Ve a: [https://golang.org/dl](https://golang.org/dl)\n2. Elige Windows y descargalo\n3. Ejecuta el instalador\n\n## 4. Configura Visual Studio Code\n\n1. Abre VS Code; haz click en la pestaña de extensiones situada a la izquierda, busca \"go\" e instálalo\n2. Cierra VS Code por completo y ábrelo de nuevo\n\n3. Ve al menu 'Ver' y selecciona **Paleta de Comandos**\n   1. O simplemente presiona: `ctrl+shift+p`\n   2. Escribe: `go install`\n   3. Elige: _\"Go: Install/Update Tools\"_\n   4. Marca todas las casillas\n\n## 5. Usando Git-Bash\n\n- En este curso hare uso de comandos bash. Bash es simplemente una linea de comandos usada en OS X y en Linux. Es una de las interfaces de linea de comandos mas populares. Asi que, si quieres usarla tambien, en vez de usar la linea de comandos por defecto de Windows, puedes usar Git-Bash. Con ella puedes escribir comandos tanto de OS X como de Linux.\n\n- Si no quieres hacer uso de Git-Bash no pasa nada, depende de ti. Pero ten en cuenta que yo hare uso constante de comandos bash.\n\n- Tambien puedes utilizar algo mas potente que Git-Bash como podria ser el: [Subsistema de Linux para Windows](https://docs.microsoft.com/es-es/windows/wsl/install-win10)\n\n- **Para usar git bash sigue los siguientes pasos:**\n\n  1. Busca git bash desde la barra de busqueda\n  2. O, si hay un icono en tu escritorio, clicka en el\n\n  3. Usa git bash por defecto en VS Code:\n     1. Abre VS Code\n     2. Ves a la **Paleta de Comandos**\n        1. Escribe: `terminal`\n        2. Elige: _\"Terminal: Terminal por Defecto\"_\n        3. Y elige: _\"Git Bash\"_\n     3. **NOTA:** Normalmente, puedes encontrar tus archivos en `c:\\`, pero, cuando estas usando git bash los encontraras en `/c/`, que es el mismo directorio pero mas abreviada\n\n## Eso es todo! Disfrutad! 🤩\n\n<div style=\"page-break-after: always;\"></div>\n\n> Para mas tutoriales: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2021 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click aqui para leer la licencia.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/README.md",
    "content": "# Escribe Tu Primer Programa Usando Go\n\n¡Hola!\n\nPuedes guardar este documento después de ver los vídeos de esta sección en particular.\n\nTambien puedes imprimirla y usarlo junto a los vídeos de esta sección.\n\n¡Disfruta!\n\n---\n\n## COMANDOS DE LA CONSOLA DE COMANDOS\n\nEntra al siguiente directorio: `cd directoryPath`\n\n- **WINDOWS:**\n\n  - Muestra los archivos en ese directorio: `dir`\n\n- **OS X distribuciones linux:**\n\n  - Muestra los archivos en ese directorio: `ls`\n\n## COMPILANDO Y EJECUTANDO PROGRAMAS CON GO:\n\n- **Compilando Un Programa En Go:**\n\n  - Dentro del directorio del programa, escribe:\n    - `go build`\n\n- **Ejecuta Un Programa En Go:**\n\n  - Dentro del directorio del programa, escribe:\n    - `go run main.go`\n\n## QUE ES EL $GOPATH?\n\n- _$GOPATH_ es una variable de entorno que apunta a un directorio donde los archivos descargados por Go y los tuyos propios se encuentran.\n\n  - **En Windows**, Esta en: `%USERPROFILE%\\go`\n\n  - **En OS X y en Linux**, Esta en: `~/go`\n\n  - **NOTE:** Nunca introduzcas tu `GOPATH` de forma manual. Siempre se encuentra en el directorio de usuario por defecto.\n\n- **GOPATH tiene tres directorios:**\n\n  - **src:** Contiene los archivos fuente para tus paquetes o para otros paquetes que descargues. Puedes compilar y ejecutar programas mientras te encuentres en el directorio del programa.\n\n  - **pkg:** Contiene paquetes de archivos compilados. Go usa esto para compilar de forma eficiente.\n\n  - **bin:** Contiene programas compilados y ejecutables. Cuando usas el comando go install en el directorio de un programa, Go creara un archivo ejecutable en el mismo.\n\n    - _Quizas quieras añadir esto a tu variable de entorno`PATH` si no esta ahi._\n\n## DONDE DEBERÍA PONER MIS ARCHIVOS FUENTE?\n\n- `$GOPATH/src/github.com/yourUsername/programDirectory`\n\n- **Ejemplo:**\n\n  - Mi nombre en github es: inancgumus\n\n  - Asi que añado todos mis programas bajo: `~/go/src/github.com/inancgumus/`\n\n  - Asi que, digamos que tengo un programa llamado hello, este se encontrará en: `~/go/src/github.com/inancgumus/hello`\n\n## TU PRIMER PROGRAMA!\n\n- **Crea Los Directorios:**\n\n  - **OS X & Linux (o git bash):**\n\n    - Crea un nuevo directorio:\n      - `mkdir -p ~/go/src/yourname/hello`\n    - Ve a ese directorio:\n      - `cd ~/go/src/yourname/hello`\n\n  - **Windows:**\n    - Crea un nuevo directorio:\n      - `mkdir c:\\Go\\src\\yourname\\hello`\n    - Ve a ese directorio:\n      - `cd c:\\Go\\src\\yourname\\hello`\n\n- Crea un nuevo archivo usando `code main.go` Visual Studio Code.\n- Añade el siguiente codigo y guardalo.\n- Vuelve a la consola de comandos.\n  - Ejecútalo con el comando: `go run main.go`\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hi! I want to be a Gopher!\")\n}\n```\n\nEso es todo! Disfruta!\n\n## NOTA:\n\n- Hay un nuevo _Go Modules_ que te permite ejecutar tus programas en cualquier directorio de tu elección. Es todavia una caracteristica experimental, cuando se estabilize actualizare el curso para incluir los Go Modules.\n\n> Para mas tutoriales: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2021 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click aqui para leer la licencia.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/anotaciones-ejemplo-programa-go.md",
    "content": "# Anotaciones Ejemplo Programa en Go\n\n```go\n// package main es un paquete especial\n// le permite a Go crear un archivo ejecutable\npackage main\n\n/*\nEsto es un comentario multilinea.\n\nla palabra import hace que otro paquete este disponible\n  para este \"archivo\" .go.\n\nimport \"fmt\" te permite acceder a la funcionaliddad del paquete fmt\n  en este archivo.\n*/\nimport \"fmt\"\n\n// \"func main\" es especial.\n//\n// Go tiene que saber por donde empezar\n//\n// func main crea un punto de inicio para Go\n//\n// Después de compilar el codigo,\n// Go ejecutará esta función primero.\nfunc main() {\n\t// después del: import \"fmt\"\n\t// La función Println del paquete \"fmt\" estará disponible\n\n\t// Lee sobre ella escribiendo los siguiente en la consola:\n\t//   go doc -src fmt Println\n\n\t// Println es simplemente una función exportada de:\n\t//   \"fmt\" package\n\n\t// Para poder exportar una función tendrás que escribir el\n\t// primer caracter del nombre de la función en mayúscula.\n\tfmt.Println(\"Hello Gopher!\")\n\n\t// Go no puede llamar a la función Println por si mismo.\n\t// Por eso la tienes que llamar aqui.\n\t// Solo llama a la `func main` de forma automatica.\n\n\t// -----\n\n    // Go soporta caracteres unicode en cadenas de texto literal\n\t// y tambien en el codigo fuente: KÖSTEBEK!\n\t//\n\t// Porque: Literal ~= Codigo Fuente\n}\n```\n\n<div style=\"page-break-after: always;\"></div>\n\n> Para mas tutoriales: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)\n>\n> Copyright © 2021 Inanc Gumus\n>\n> Learn Go Programming Course\n>\n> [Click aqui para leer la licencia.](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/ejercicios/01-imprimiendo-nombres/main.go",
    "content": "// Copyright © 2021 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para mas tutoriales : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en Twitter  : https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EJERCICIO: Imprimir nombres\n//\n//\tImprime tu nombre y el de tu mejor amigo usando\n//  Println dos veces\n//\n// RESULTADO ESPERADO\n//  TuNombre\n//  ElNombreDeTuMejorAmigo\n//\n// BONUS\n//  Usa `go run` primero.\n//  Y despues de eso usa `go build` y ejecuta tu programa.\n// ---------------------------------------------------------\n\nfunc main() {\n\t// ?\n\t// ?\n}\n"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/ejercicios/01-imprimiendo-nombres/solucion/main.go",
    "content": "// Copyright © 2021 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para mas tutoriales : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en Twitter  : https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// go run main.go\n\n// go build\n// ./solution\n\nfunc main() {\n\tfmt.Println(\"Nikola\")\n\tfmt.Println(\"Thomas\")\n}\n"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/ejercicios/02-imprimiendo-gopath/ejercicio.md",
    "content": "- **Ejercicio: Imprime tu GOPATH**\n\nImprime tu GOPATH usando la herramienta `go env`\n\n- **RESULTADO ESPERADO:**\n\nLa ruta física de la carpeta que hace referencia al `$GOPATH`\n"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/ejercicios/02-imprimiendo-gopath/solucion/solucion.md",
    "content": "* **Debes de escribir esto en tu consola de comandos:**\n\n```bash\ngo env GOPATH\n```"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/ejercicios/README.md",
    "content": "1. **Imprime tu nombre y el nombre de tu mejor amigo** usando Println dos veces. [Échale un vistazo a este ejercicio](https://github.com/inancgumus/learngo/tree/master/translation/spanish/02-tu-primer-programa/ejericios/01-imprimir-nombres).\n\n2. **Imprime tu GOPATH** usando la herramienta `go env` [Échale un vistazo a este ejercicio](https://github.com/inancgumus/learngo/tree/master/translation/spanish/02-tu-primer-programa/ejercicios/02-imprimir-gopath).\n\n3. **Saludate a ti mismo.**\n\n   1. Complila tu programa usando `go build`\n\n   2. **Envíaselo a tu amigo**\n\n      Debería tener el mismo sistema operativo.\n\n      Por ejemplo si estás usando Windows envíaselo a un amigo que también tenga Windows.\n\n   3. **Envíaselo a un amigo con un sistema operativo diferente**\n\n      Deberías compilar el programa especificamente para su sistema operativo.\n\n      **Crea un ejecutable para OS X:**\n      `GOOS=darwin GOARCH=386 go build`\n\n      **Crea un ejecutable para Windows:**\n      `GOOS=windows GOARCH=386 go build`\n\n      **Crea un ejecutable para Linux:**\n      `GOOS=linux GOARCH=arm GOARM=7 go build`\n\n      **Puedes encontrar una lista completa aquí:**\n      https://golang.org/doc/install/source#environment\n\n      **NOTA:** Si estás usando la consola de comandos o PowerShell, quizás necesites usarlo de la siguiente forma:\n      `cmd /c \"set GOOS=darwin GOARCH=386 && go build\"`\n\n4. **Llama a [Print](https://golang.org/pkg/fmt/#Print) en vez de a [Println](https://golang.org/pkg/fmt/#Println)** y observa que pasa.\n\n5. **Llama a [Println](https://golang.org/pkg/fmt/#Println) o a [Print](https://golang.org/pkg/fmt/#Print) con multiples valores** separados por comas.\n\n6. **Elimina las comillas dobles de una cadena de texto literal** y observa que pasa.\n\n7. **Mueve tanto el package como import** al final del archivo y observa que pasa.\n\n8. **[Lee la documentación en línea](https://golang.org/pkg)**.\n\n   1. Échale un vistazo a qué son los packages y qué es lo que hacen.\n\n   2. Mira su codigo fuente clickeando sobre su titulo.\n\n   3. No tienes porque entenderlo todo, simplemente hazlo. Esto te dará un empujón de cara a las siguientes clases.\n\n9. También, puedes tomar **un tour con Go**: https://tour.golang.org/\n\n   1. Échale un vistazo rápido. Mira las caracteristicas del lenguaje.\n\n   2. Hablaremos de ellas proximamente.\n"
  },
  {
    "path": "translation/spanish/02-tu-primer-programa/main.go",
    "content": "// Copyright © 2021 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para mas tutoriales: https://learngoprogramming.com\n// Clases particulares: https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\n// package main es un paquete especial\n// le permite a Go crear un archivo ejecutable\npackage main\n\n/*\nEsto es un comentario multilinea.\n\nla palabra import hace que otro paquete este disponible\n  para este \"archivo\" .go.\n\nimport \"fmt\" te permite acceder a la funcionaliddad del paquete fmt\n  en este archivo.\n*/\nimport \"fmt\"\n\n// \"func main\" es especial.\n//\n// Go tiene que saber por donde empezar\n//\n// func main crea un punto de inicio para Go\n//\n// Después de compilar el codigo,\n// Go ejecutará esta función primero.\nfunc main() {\n\t// después del: import \"fmt\"\n\t// La función Println del paquete \"fmt\" estará disponible\n\n\t// Lee sobre ella escribiendo los siguiente en la consola:\n\t//   go doc -src fmt Println\n\n\t// Println es simplemente una función exportada de:\n\t//   \"fmt\" package\n\n\t// Para poder exportar una función tendrás que escribir el\n\t// primer caracter del nombre de la función en mayúscula.\n\tfmt.Println(\"Hello Gopher!\")\n\n\t// Go no puede llamar a la función Println por si mismo.\n\t// Por eso la tienes que llamar aqui.\n\t// Solo llama a la `func main` de forma automatica.\n\n\t// -----\n\n\t// Go soporta caracteres unicode en cadenas de texto literal\n\t// y tambien en el codigo fuente: KÖSTEBEK!\n\t//\n\t// Porque: Literal ~= Codigo Fuente\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/01-paquetes/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/01-paquetes/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/01-paquetes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\n\t// Puedes acceder a funciones desde otros archivos\n\t// los cuales esten en el mismo paquete\n\t// Por ejemplo, `main()` puede acceder a `bye()` y `hey()`\n\n\t// Porque bye.go, hey.go y main.go\n\t//   estan en el mismo paquete.\n\n\tbye()\n\they()\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/02-funciones/01-funciones/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Librerias importadas\nimport \"fmt\"\n\n// variables del paquete\nconst ok = true\n\n// función del paquete\nfunc main() { // Empieza el bloque de la función\n\tvar hola = \"Hola\"\n\n\t// hola y ok son visibles aquí\n\tfmt.Println(hola, ok)\n\n} // Termina el bloque de la función\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/02-funciones/02-bloque-de-funcion/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc nope() { // Empieza el bloque de la función\n\n\t// hola y ok solamente son visibles aquí\n\tconst ok = true\n\tvar hola = \"Hola\"\n\n\t_ = hola\n} // Termina el bloque de la función\n\nfunc main() { // Empieza el bloque de la función\n\n\t// hola y ok no son visibles aquí\n\n\t// ERROR:\n\t// fmt.Println(hola, ok)\n\n} // Termina el bloque de la función\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/02-funciones/03-funciones-anidadas/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// No hable de esto en la lectura\n// quiero dejarlo aqui como una pequeña nota\n// Por favor revisalo.\n\nvar declarameOtraVez = 10\n\nfunc anidado() { // Empieza el bloque de la función\n\n\t// declara las misma variables\n\t// ambas pueden existir juntas\n\t// Esta solo pertenece a esta función\n\t// la variable del paquete sigue intacta\n\tvar declarameOtraVez = 5\n\tfmt.Println(\"Dentro del anidado:\", declarameOtraVez)\n\n} // Termina el bloque de la función\n\nfunc main() { // Empieza el bloque de la función\n\n\tfmt.Println(\"Dentro de main:\", declarameOtraVez)\n\n\tanidado()\n\n\t// a nivel paquete, declarameOtraVez no fue alterado\n\t// desde el cambio dentro de la funcion anidado\n\tfmt.Println(\"Dentro de main:\", declarameOtraVez)\n\n} // Termina el bloque de la función\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/02-funciones/04-funcion-del-paquete/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"Bye!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/02-funciones/04-funcion-del-paquete/hey.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\npackage main\n\nimport \"fmt\"\n\nfunc hey() {\n\tfmt.Println(\"Hey!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/02-funciones/04-funcion-del-paquete/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\t//Dos archivos pertenecen al mismo paquete\n\t// llamando `bye()` de bye.go a aqui\n\tbye()\n}\n\n// Ejercicio: Quita los comentarios de la siguiente función y analiza el error\n\n// func bye() {\n// \tfmt.Println(\"Bye!\")\n// }\n\n// ***** EXPLICACIÓN *****\n//\n// ERROR: \"bye\" function \"redeclared\"\n//        in \"this block\"\n//\n// \"this block\" significa = \"main package\"\n//\n// \"redeclared\" significa = Estas usando el mismo nompre en la funcion otra vez\n//\n// La función main package es:\n// todo el codigo que esta en el mismo paquete main\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/03-importando/01-funcion-del-archivo/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\n// quita los comentarios del codigo para ver el error\n// (Solo quita las // del codigo en las 3 lineas siguientes)\n\n// Este archivo no puede ver los nombres importados de main.go (\"fmt\")\n// porque los nombres importados pertenecen a la funcion del archivo (librerias)\n\n// func bye() {\n// \tfmt.Println(\"Bye!\")\n// }\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/03-importando/01-funcion-del-archivo/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/03-importando/02-renombrando/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\tf \"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello!\")\n\tf.Println(\"There!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/01-paquetes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n\n// EJERCICIO: Usa tu propio paquete\n//\n// Crea algunos archivos Go y llama sus funciónes desde\n// la funcion main\n//\n//  1- Crea los archivos main.go, greet.go y bye.go\n//  2- En main.go: Llama a las funciones greet y bye.\n//  3- Corre `main.go`\n//\n// PISTA\n// La funcion greet deberia de estar en greet,go\n// La funcion bye deberia de estar en bye.go\n//\n// SALIDA ESPERADA\n//  Hola!!\n//  Adios!!\n// ---------------------------------------------------------\n\nfunc main() {\n\t// Llama a las funciones de los otros archivos aqui.\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/01-paquetes/solucion/bye.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc bye() {\n\tfmt.Println(\"adios!!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/01-paquetes/solucion/greet.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc greet() {\n\tfmt.Println(\"hola!!\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/01-paquetes/solucion/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nfunc main() {\n\tgreet()\n\tbye()\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/02-scopes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EJERCICIO: Prueba las funciones\n//\n//  1. Crea 2 archivos: main.go y printer.go\n//\n//  2. En printer.go:\n//     1. Crea una funcion llamada hello\n//     2. Dentro de la funcion hello, imprime tu nombre\n//\n//  3. En main.go:\n//     1. Crea la tipica funcion func main\n//     2. Llama a tu funcion solo usando su nombre: hello\n//     3. Crea una funcion llamda bye\n//     4. Dentro de la funcion bye, imprime \"bye bye\"\n//\n//  4. En printer.go:\n//     1. Llama a la funcion bye desde dentro de la funcion hello\n// ---------------------------------------------------------\n\nfunc main() {\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/02-scopes/solucion/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Como puedes verm no necesito importar el un paquete\n\t// y puedo llamar a la funcion 'hello' aqui\n\t//\n\t// Esto es porque las funciones de paquetes (librerias)\n\t// estan compartidas en el mismo paquete\n\thello()\n\t// pero aqui no puedo acceder al paquete fmt sin importarlo\n\t//\n\t// Esto es porque esta en la funcion del archivo printer.go\n\t// lo importa\n\t//\n\n\t// esta funcion main puede tambien llamar a la funcion bye aqui\n\t// bye()\n}\n\n// printer.go puede llamar a esta funcion\n//\n// Esto es porque la funcion bye esta en la funcion del paquete (libreria)\n// del paquete main ahora\n// .\n//\n// La funcion main tambien puede llamar aqui.\nfunc bye() {\n\tfmt.Println(\"bye bye\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/02-scopes/solucion/printer.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc hello() {\n\t// Solo este archivo puede acceder a la funcion de paquete fmt\n\t// cuando otros ya lo hiciero, ellos tamvien pueden acceder\n\t// Su propio 'fmt' \"name\"\n\n\tfmt.Println(\"hi! this is inanc!\")\n\tbye()\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/03-importando/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\n// ---------------------------------------------------------\n// EJERCICIO: Renombra las importaciones\n//\n//  1- Importa el paquete fmt tres veces con diferentes nombres\n//  2- Imprime algunos mensajes usando esas importaciones\n//\n// SALIDA ESPERADA\n//  hello\n//  hey\n//  hi\n// ---------------------------------------------------------\n\n// ?\n// ?\n// ?\n\nfunc main() {\n\t// ?\n\t// ?\n\t// ?\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/03-importando/solucion/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// Licencia: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// Para más tutoriales  : https://learngoprogramming.com\n// Clases particulares : https://www.linkedin.com/in/inancgumus/\n// Sigueme en twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\tf \"fmt\"\n\n\tfm \"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"hello\")\n\tf.Println(\"hey\")\n\tfm.Println(\"hi\")\n}\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/ejercicios/README.md",
    "content": "1. **[Usa tus propios paquetes](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/01-packages)**\n\n    Crea algunos archivos Go y llama sus funciones desde la función main.\n\n\n2. **[Prueba las funciones](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/02-scopes)**\n\n    Aprende los efectos del acceso de funciones de paquetes ó Librerias.\n\n\n3. **[Renombra las importaciones](https://github.com/inancgumus/learngo/tree/master/03-packages-and-scopes/exercises/03-importing)**\n\n    Importa los mismos paquetes usando diferentes nombres."
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/preguntas/01-paquetes-A/README.md",
    "content": "## ¿Dónde almacenar los archivos de código fuente que pertenecen a un paquete?\n1. Cada archivo debe ir a un directorio diferente\n2. En un solo directorio *CORRECTO*\n\n\n## ¿Por qué se utiliza una cláusula de paquete en un archivo de código fuente de Go?\n1. Se usa para importar un paquete.\n2. Se utiliza para informarle a Go que el archivo pertenece a un paquete *CORRECTO*\n3. Se usa para declarar una nueva función\n\n> **1:** `import` declaración hace eso.\n>\n>\n> **3:** `func` declaración hace eso.\n>\n>\n\n\n## ¿Dónde debería poner el `package clause` en un archivo de código fuente de Go?\n1. Como primer código en un archivo de código fuente de Go *CORRECTO*\n2. Como último código en un archivo de código fuente de Go\n3. Puedes ponerlo en cualquier lugar\n\n\n## ¿Cuántas veces puede usar`package clause` para un solo archivo de código fuente?\n1. Una vez *CORRECTO*\n2. Ninguna\n3. Varias veces\n\n\n## ¿Cuál es el uso correcto de`package clause`?\n1. `my package`\n2. `package main`\n3. `pkg main`\n\n\n## ¿Cual es la correcta?\n1. Todos los archivos pertenecen al mismo paquete no pueden llamar a las funciones de los demás\n2. Todos los archivos pertenecen al mismo paquete pueden llamar a las funciones de los demás *CORRECTO*\n\n\n## ¿Cómo ejecutar varios archivos Go?\n1. go run *.*go\n2. go build *go\n3. go run go\n4. go run *.go *CORRECTO*\n\n> **4:** También puede llamarlo como (asumiendo que hay file1.go file2.go y file3.go en el mismo directorio): vaya a ejecutar file1.go file2.go file3.go\n>\n>\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/preguntas/02-paquete-B/README.md",
    "content": "## ¿Cuál de los siguientes es un tipo de paquete correcto en Go?\n* Paquete vacio\n* Paquete ejecutable  *CORRECTO*\n* Paquete transferible\n* Paquete de libreria\n\n## ¿Qué tipo de paquete `go run` puede ejecutar?\n* Paquete vacio\n* Paquete ejecutable  *CORRECTO*\n* Paquete transferible\n* Paquete de libreria\n\n## ¿Qué tipo de paquete `go run` puede compilar?\n* Paquete vacio\n* Paquete temporal\n* Ambos paquetes ejecutables y de libreria *CORRECTO*\n* Paquete transferible\n\n\n## ¿Cuál es un paquete ejecutable?\n* `package main` con `func main` *CORRECTO*\n* `package Main` con `func Main`\n* `package exec` con `func exec`\n\n## ¿Cuál es un paquete de libreria?\n* `main package`\n* `package lib` *CORRECTO*\n* `func package`\n* `package main` con `func main`\n\n## ¿Qué paquete se utiliza para un programa Go ejecutable?\n* Paquete vacio\n* Paquete ejecutable *CORRECTO*\n* Paquete transferible\n* Paquete de libreria\n\n## ¿Qué paquete se utiliza para la reutilización y se puede importar?\n* Paquete vacio\n* Paquete ejecutable\n* Paquete transferible\n* Paquete de libreria *CORRECTO*\n"
  },
  {
    "path": "translation/spanish/03-paquetes-y-funciones/preguntas/03-funciones/README.md",
    "content": "## ¿Qué es una funcion?\n* Bloque de código ejecutable \n* La visibilidad de los nombres declarados **CORRECTO**\n* Determina qué ejecutar\n\n```go\npackage awesome\n\nimport \"fmt\"\n\nvar enabled bool\n\nfunc block() {\n    var counter int\n    fmt.Println(counter)\n}\n```\n\n## ¿Qué nombre a continuación tiene la fuincion del paquete(libreria)?\n1. awesome\n2. fmt\n3. enabled **CORRECTO**\n4. counter\n\n> **3:** Eso es correcto.`enabled` enabledestá fuera de cualquier función, por lo que es un nombre de ámbito de paquete. La funcion `block()` también tiene el alcance del paquete; también está fuera de cualquier función.\n>\n>\n\n\n## ¿Qué nombre a continuación tiene la funcion del archivo?\n1. awesome\n2. fmt **CORRECTO**\n3. enabled\n4. block()\n5. counter\n\n> **2:** Eso es correcto. Los nombres de los paquetes importados tienen un ámbito de archivo. Y solo se pueden usar dentro del mismo archivo.\n>\n>\n\n\n## ¿Qué nombre a continuación está en el alcance de la función block ()?\n1. awesome\n2. fmt\n3. enabled\n4. block()\n5. counter **CORRECTO*\n\n> **5:** Eso es correcto.  `counter` se declara dentro de la funcion `block()` por lo que está en el alcance del bloque func. Fuera de la funcion `block()`, otro código no puede verlo.\n>\n>\n\n\n## ¿Puede `block()` ver el nombre `enabled`?\n1. Sí: está en el alcance del paquete **CORRECTO**\n2. No: está en el alcance del archivo\n3. No: está en el alcance del bloque de block ()\n\n> **1:** Todo el código dentro del mismo paquete puede ver todos los demás nombres declarados a nivel de paquete.\n>\n>\n\n\n## ¿Pueden otros archivos en el paquete `awesome` ver el nombre de `counter`?\n1. Si\n2. No: está en la funcion del paquete\n3. No: está en la funcion del archivo\n4. No: está en la funcion del block() **CORRECTO**\n\n> **4:** Eso es correcto. Ninguno de los otros códigos puede ver los nombres dentro de la funcion `block()` .Solo el código dentro de la funcion `block()` puede verlos (Solo hasta cierto punto. Por ejemplo: Dentro del bloque, el código solo puede ver las variables declaradas antes).\n>\n\n\n## ¿Pueden otros archivos en el paquete `awesome` ver el nombre de`fmt` ?\n1. Si\n2. No: está en la funcion del paquete\n3. No: está en la funcion del archivo **CORRECTO**\n4. No: está en la funcion del bloque() \n\n> **3:** Solo el mismo archivo puede ver los paquetes importados, no los otros archivos, ya sea que estén en el mismo paquete o no.\n>\n>\n\n\n## ¿Qué sucede si declaras el mismo nombre en el mismo ámbito que este?\n```go\npackage awesome\n\nimport \"fmt\"\n\n// declared twice in the package scope\nvar enabled bool\nvar enabled bool\n\nfunc block() {\n    var counter int\n    fmt.Println(counter)\n}\n```\n1. El nombre recién declarado prevalecerá sobre el anterior.\n2. No puedo hacer eso. Ya se ha declarado en la funcion del paquete.  *CORRECTO*\n3. No puedo hacer eso. Ya se ha declarado en la funcion del archivo.\n\n> **2:** Eso es correcto. No puede declarar el mismo nombre en el mismo ámbito. Si pudiera hacerlo, ¿cómo volvería a acceder a él? ¿O a cuál?\n>\n>\n\n\n## ¿Qué sucede si declaras el mismo nombre en otro ámbito como este?:\n```go\npackage awesome\n\nimport \"fmt\"\n\n// declared at the package scope\nvar enabled bool\n\nfunc block() {\n    // also declared in the block scope\n    var enabled bool\n\n    var counter int\n    fmt.Println(counter)\n}\n```\n1. El nombre recién declarado prevalecerá sobre el anterior. *CORRECTO*\n2. No puedo hacer eso. Ya se ha declarado en la funcion del paquete.  \n3. No puedo hacer eso. Ya se ha declarado en la funcion del archivo.\n\n> **1:** En realidad, puede declarar el mismo nombre en los ámbitos internos de esta manera. La funcion `block()` está dentro de su paquete. Esto significa que puede acceder al alcance de su paquete (pero no al revés). Entonces, la funcion `block()`de 'está bajo el alcance de su paquete. Esto significa que puede volver a declarar el mismo nombre. Anulará el nombre del ámbito principal. Ambos pueden existir juntos. Consulte el ejemplo en el repositorio de cursos para averiguarlo.\n>\n>\n"
  },
  {
    "path": "translation/spanish/README.md",
    "content": "# Aprendiendo a usar Go con ejemplos, ejercicios y puzzles\n\nLa mejor forma de aprender es haciendo. En este repositorio encontrarás miles de ejemplos, ejercicios y puzzles hechos con Go. Inicialmente creé este repositorio para mi **[Go: Bootcamp Course](https://udemy.com/course/learn-go-the-complete-bootcamp-course-golang/?referralCode=5CE6EB34E2B1EF4A7D37)**. Tiempo después seguí añadiendo ejercicios y quise que todo programador no inscrito a mi curso también pudiese aprender de forma gratuita. Así que aquí está. Disfrutad.\n\n## ❤️ Ayuda a otros desarrolladores\n\nCompartir es gratis pero cuidar no tiene precio, [así que por favor haz click aquí](https://twitter.com/intent/tweet?text=I%27m%20learning%20%23golang%20with%201000%2B%20hand-crafted%20examples%2C%20exercises%2C%20and%20quizzes.&url=https://github.com/inancgumus/learngo&via=inancgumus) y comparte este repositorio en Twitter.\n\n## Mantente en contacto\n\n* **[Sígueme en Twitter](https://twitter.com/inancgumus)**\n\n  _Usualmente twiteo trucos y consejos sobre Go._\n\n  [![@inancgumus](https://img.shields.io/twitter/follow/inancgumus.svg?style=social&label=@inancgumus)](https://twitter.com/inancgumus)\n\n* **[Suscríbete a mi Newsletter](https://eepurl.com/c4DMNX)**\n\n  _Recibe actualizaciones de mi parte._\n\n* **[Lee mi Blog](https://blog.learngoprogramming.com)**\n\n  _Seguido por más de 5 mil desarrolladores y con decenas de artículos ilustrados sobre Go._\n\n* **[Mira mi canal de Youtube](https://www.youtube.com/channel/UCYxepZhtnFIVRh8t5H_QAdg?view_as=subscriber)**\n\n---\n\n### Licencia\n\nTodos los materiales están protegidos bajo la licencia <a rel=\"license\" href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.<br/>\n<a rel=\"license\" href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png\"/></a>\n"
  },
  {
    "path": "x-tba/README.md",
    "content": "This folder contains directories and files that belong to unreleased lectures and sections. So, it's your responsibility to do something with those; they can work or cannot, they are not stable. I change these files all the time. This is my scratch-pad."
  },
  {
    "path": "x-tba/foundations/01-print-args/01-printf/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// zero-values\n\tvar (\n\t\tplanet   string\n\t\tdistance int\n\t\torbital  float64\n\t\thasLife  bool\n\t)\n\n\t// assignment\n\tplanet = \"venus\"\n\tdistance = 261\n\torbital = 224.701\n\thasLife = false\n\n\t// var (\n\t// \tplanet   = \"venus\"\n\t// \tdistance = 261\n\t// \torbital  = 224.701\n\t// \thasLife  = false\n\t// )\n\n\tdistance += 5\n\tdistance *= 2\n\tdistance++\n\tdistance--\n\torbital++\n\n\t// orbital *= 10\n\tconst constFactor = 10\n\torbital *= constFactor\n\n\tfactor := 10\n\t// orbital *= factor\n\torbital *= float64(factor)\n\n\t// swiss army knife %v verb\n\tfmt.Printf(\"Planet: %v\\n\", planet)\n\tfmt.Printf(\"Distance: %v millions kms\\n\", distance)\n\tfmt.Printf(\"Orbital Period: %v days\\n\", orbital)\n\tfmt.Printf(\"Does %v have life? %v\\n\", planet, hasLife)\n\n\t// argument indexing - indexes start from 1\n\tfmt.Printf(\n\t\t\"%v is %v away. Think! %[2]v kms! %[1]v OMG.\\n\",\n\t\tplanet, distance,\n\t)\n\n\t// why use other verbs than? because: type-safety\n\t// uncomment to see the warnings:\n\t//\n\t// fmt.Printf(\"Planet: %d\\n\", planet)\n\t// fmt.Printf(\"Distance: %s millions kms\\n\", distance)\n\t// fmt.Printf(\"Orbital Period: %t days\\n\", orbital)\n\t// fmt.Printf(\"Does %v has life? %f\\n\", planet, hasLife)\n\n\t// correct verbs:\n\t// fmt.Printf(\"Planet: %s\\n\", planet)\n\t// fmt.Printf(\"Distance: %d millions kms\\n\", distance)\n\t// fmt.Printf(\"Orbital Period: %f days\\n\", orbital)\n\t// fmt.Printf(\"Does %s has life? %t\\n\", planet, hasLife)\n\n\t// precision\n\tfmt.Printf(\"Orbital Period: %f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.0f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.1f days\\n\", orbital)\n\tfmt.Printf(\"Orbital Period: %.2f days\\n\", orbital)\n}\n"
  },
  {
    "path": "x-tba/foundations/01-print-args/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tfmt.Println(\"There are\", len(os.Args)-1, \"people !\")\n\tfmt.Println(\"Hello great\", os.Args[1], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[2], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[3], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[4], \"!\")\n\tfmt.Println(\"Hello great\", os.Args[5], \"!\")\n\tfmt.Println(\"Nice to meet you all.\")\n\n\tpath := `c:\\program files\\duper super\\fun.txt\nc:\\program files\\really\\funny.png`\n\n\tfmt.Println(path)\n}\n"
  },
  {
    "path": "x-tba/foundations/02-variables/01-basics/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\t// var (\n\t// \tname string\n\t// \tname2 string\n\t// \tname3 string\n\t// )\n\n\t// var name, name2, name3 string\n\t// name = os.Args[1]\n\t// name2 = os.Args[2]\n\t// name3 = os.Args[3]\n\n\t// name := os.Args[1]\n\t// name2 := os.Args[2]\n\t// name3 := os.Args[3]\n\n\tname, name2, name3 := os.Args[1], os.Args[2], os.Args[3]\n\n\tfmt.Println(\"Hello great\", name, \"!\")\n\tfmt.Println(\"And hellooo to you magnificient\", name2, \"!\")\n\tfmt.Println(\"Welcome\", name3, \"!\")\n\n\t// changes the name, declares the age with 131\n\tname, age := \"bilbo baggins\", 131 // unknown age!\n\n\tfmt.Println(\"My name is\", name)\n\tfmt.Println(\"My age is\", age)\n\tfmt.Println(\"And, I love adventures!\")\n}\n"
  },
  {
    "path": "x-tba/foundations/02-variables/02-short-discard/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"os\"\n\t\"path\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tvar radius, area float64\n\n\tradius, _ = strconv.ParseFloat(os.Args[1], 64)\n\n\tarea = 4 * math.Pi * math.Pow(radius, 2)\n\t// area := 4 * math.Pi * math.Pow(radius, 2)\n\n\tfmt.Printf(\"radius: %g -> area: %.2f\\n\",\n\t\tradius, area)\n\n\tdir, _ := path.Split(\"secret/file.txt\")\n\tfmt.Println(dir)\n\n\tcolor, color2 := \"red\", \"blue\"\n\tcolor, color2 = color2, color\n\tfmt.Println(color, color2)\n}\n"
  },
  {
    "path": "x-tba/foundations/02-variables/03-conversion/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tmin := int8(127)\n\tmax := int16(1000)\n\n\tfmt.Println(max + int16(min))\n\n\t// EXPLANATION\n\t//\n\t// `int8(max)` destroys the information of max\n\t// It reduces it to 127\n\t// Which is the maximum value of int8\n\t//\n\t// Correct conversion is int16(min)\n\t// Because, int16 > int8\n\t// When you do so, min doesn't lose information\n\t//\n\t// You will learn more about this in\n\t// the \"Go Type System\" section.\n}\n"
  },
  {
    "path": "x-tba/foundations/02-variables/types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"os\"\n\t\"runtime\"\n\t\"time\"\n)\n\nfunc main() {\n\t// int, float64, bool, string\n\tvar (\n\t\tcpus      int\n\t\tpath, dir string\n\t\tmax       float64\n\t)\n\n\tcpus = runtime.NumCPU()\n\tpath = os.Getenv(\"PATH\")\n\tmax = math.Max(1.5, 2.5)\n\tdir, _ = os.Getwd()\n\tnow := time.Now()\n\n\t// cpus := runtime.NumCPU()\n\t// path := os.Getenv(\"PATH\")\n\t// max := math.Max(1.5, 2.5)\n\t// dir, _ := os.Getwd()\n\n\t// dir = `\"` + dir + `\"`\n\t// dir = strconv.Quote(dir)\n\t// cpus++\n\t// cpus *= 2.5\n\t// max++\n\t// max /= 2.5\n\t// paths = strings.Split(path, \":\")\n\t// path = paths[0]\n\n\tfmt.Printf(\"# of CPUS        : %d\\n\", cpus)\n\tfmt.Printf(\"Path             : %s\\n\", path)\n\tfmt.Printf(\"max(1.5, 2.5)    : %g\\n\", max)\n\tfmt.Printf(\"Current Directory: %s\\n\", dir)\n\tfmt.Printf(\"Current Time     : %s\\n\", now)\n}\n"
  },
  {
    "path": "x-tba/foundations/03-if-switch-loop/01-for-crunch-the-primes/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n// go run . {1..100}\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tconst usageMsg = `Type a couple of unique numbers.\nSeparate them with spaces.`\n\n\t// remember [1:] skips the first argument\n\targs := os.Args[1:]\n\tif len(args) == 0 {\n\t\tfmt.Println(usageMsg)\n\t\treturn\n\t}\n\nmain:\n\tfor _, arg := range args {\n\t\tn, err := strconv.Atoi(arg)\n\t\tif err != nil {\n\t\t\t// skip non-numerics\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch {\n\t\t// prime\n\t\tcase n == 2, n == 3:\n\t\t\tfmt.Print(n, \" \")\n\t\t\tcontinue\n\n\t\t// not a prime\n\t\tcase n <= 1, n%2 == 0, n%3 == 0:\n\t\t\tcontinue\n\t\t}\n\n\t\tfor i, w := 5, 2; i*i <= n; {\n\t\t\t// not a prime\n\t\t\tif n%i == 0 {\n\t\t\t\tcontinue main\n\t\t\t}\n\n\t\t\ti += w\n\t\t\tw = 6 - w\n\t\t}\n\n\t\t// all checks ok: it's a prime\n\t\tfmt.Print(n, \" \")\n\t}\n\n\tfmt.Println()\n}\n"
  },
  {
    "path": "x-tba/foundations/03-if-switch-loop/02-switch-months/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\t\"time\"\n)\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Give me a month name\")\n\t\treturn\n\t}\n\n\tyear := time.Now().Year()\n\tleap := year%4 == 0 && (year%100 != 0 || year%400 == 0)\n\n\tdays, month := 28, os.Args[1]\n\n\tswitch strings.ToLower(month) {\n\tcase \"april\", \"june\", \"september\", \"november\":\n\t\tdays = 30\n\tcase \"january\", \"march\", \"may\", \"july\",\n\t\t\"august\", \"october\", \"december\":\n\t\tdays = 31\n\tcase \"february\":\n\t\tif leap {\n\t\t\tdays = 29\n\t\t}\n\tdefault:\n\t\tfmt.Printf(\"%q is not a month.\\n\", month)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%q has %d days.\\n\", month, days)\n}\n"
  },
  {
    "path": "x-tba/foundations/03-if-switch-loop/03-math-table-if-switch-loop/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst (\n\tvalidOps       = \"* / + - mul div add sub\"\n\tusageMsg       = \"Usage: [valid ops: \" + validOps + \"] [size]\"\n\tsizeMissingMsg = \"Size is missing\\n\" + usageMsg\n\tinvalidOpMsg   = `Invalid operator.\nValid ops one of: ` + validOps\n)\n\nfunc main() {\n\t// CHECK THE ARGUMENTS\n\targs := os.Args[1:]\n\tif l := len(args); l == 1 {\n\t\tfmt.Println(sizeMissingMsg)\n\t\treturn\n\t} else if l < 1 {\n\t\tfmt.Println(usageMsg)\n\t\treturn\n\t}\n\n\tsize, err := strconv.Atoi(args[1])\n\tif err != nil || size <= 0 {\n\t\tfmt.Println(\"Wrong size\")\n\t\treturn\n\t}\n\n\t// CHECK THE VALIDITY OF THE OP\n\top, ops := args[0], strings.Fields(validOps)\n\n\tvar ok bool\n\tfor _, o := range ops {\n\t\tif strings.ToLower(o) == op {\n\t\t\tok = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif !ok {\n\t\tfmt.Println(invalidOpMsg)\n\t\treturn\n\t}\n\n\t// PRINT THE TABLE\n\n\t// HEADER\n\tfmt.Printf(\"%5s\", op)\n\tfor i := 0; i <= size; i++ {\n\t\tfmt.Printf(\"%5d\", i)\n\t}\n\tfmt.Println()\n\n\t// CELLS\n\tfor i := 0; i <= size; i++ {\n\t\tfmt.Printf(\"%5d\", i)\n\n\t\tfor j := 0; j <= size; j++ {\n\t\t\tvar res int\n\n\t\t\tswitch op {\n\t\t\tdefault:\n\t\t\t\tfallthrough // default is multiplication\n\t\t\tcase \"*\", \"mul\":\n\t\t\t\tres = i * j\n\t\t\tcase \"+\", \"add\":\n\t\t\t\tres = i + j\n\t\t\tcase \"-\", \"sub\":\n\t\t\t\tres = i - j\n\t\t\tcase \"%\", \"mod\":\n\t\t\t\tif j == 0 {\n\t\t\t\t\t// continue // will continue the loop\n\t\t\t\t\tbreak // breaks the switch\n\t\t\t\t}\n\t\t\t\tres = i % j\n\t\t\t}\n\n\t\t\t// break // breaks the loop\n\n\t\t\tfmt.Printf(\"%5d\", res)\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n"
  },
  {
    "path": "x-tba/foundations/03-if-switch-loop/04-lucky-number-if-for-switch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\nconst (\n\tmaxTurns = 5 // less is more difficult\n\tusage    = `Welcome to the Lucky Number Game! 🍀\n\nThe program will pick %d random numbers.\nYour mission is to guess one of those numbers.\n\nThe greater your number is, harder it gets.\n\nWanna play?\n\n(Provide -v flag to see the picked numbers.)\n`\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\n\targs := os.Args[1:]\n\tif len(args) != 1 {\n\t\tfmt.Printf(usage, maxTurns)\n\t\treturn\n\t}\n\n\tvar verbose bool\n\tif args[0] == \"-v\" {\n\t\tverbose = true\n\t}\n\n\tguess, err := strconv.Atoi(args[len(args)-1])\n\tif err != nil {\n\t\tfmt.Println(\"Not a number.\")\n\t\treturn\n\t}\n\n\tif guess < 0 {\n\t\tfmt.Println(\"Please pick a positive number.\")\n\t\treturn\n\t}\n\n\tfor turn := 0; turn < maxTurns; turn++ {\n\t\tn := rand.Intn(guess + 1)\n\n\t\tif verbose {\n\t\t\tfmt.Printf(\"%d \", n)\n\t\t}\n\n\t\tif n == guess {\n\t\t\tswitch rand.Intn(3) {\n\t\t\tcase 0:\n\t\t\t\tfmt.Println(\"🎉  YOU WIN!\")\n\t\t\tcase 1:\n\t\t\t\tfmt.Println(\"🎉  YOU'RE AWESOME!\")\n\t\t\tcase 2:\n\t\t\t\tfmt.Println(\"🎉  PERFECT!\")\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t}\n\n\t// msg, n := \"%s Try again?\\n\", rand.Intn(5)\n\t// if msg, n := \"%s Try again?\\n\", rand.Intn(5); n <= 2 {\n\t// \tfmt.Printf(msg, \"☠️  YOU LOST...\")\n\t// } else if n < 3 {\n\t// \tfmt.Printf(msg, \"☠️  JUST A BAD LUCK...\")\n\t// } else if n == 4 {\n\t// \tfmt.Printf(msg, \"☠️  TRY NEXT TIME...\")\n\t// }\n\n\t// var msg string\n\t// switch rand.Intn(10) {\n\t// // more probability\n\t// case 0, 1, 2, 3, 4, 5:\n\t// \tmsg = \"☠️  YOU LOST...\"\n\t// case 6, 7, 8:\n\t// \tmsg = \"☠️  JUST A BAD LUCK...\"\n\t// default:\n\t// \tmsg = \"☠️  TRY NEXT TIME...\"\n\t// }\n\t// fmt.Printf(\"%s Try again?\\n\", msg)\n\n\tvar msg string\n\tswitch n := rand.Intn(10); {\n\t// more probability\n\tcase n <= 5:\n\t\tmsg = \"☠️  YOU LOST...\"\n\tcase n <= 8:\n\t\tmsg = \"☠️  JUST A BAD LUCK...\"\n\tdefault:\n\t\tmsg = \"☠️  TRY NEXT TIME...\"\n\t}\n\tfmt.Printf(\"%s Try again?\\n\", msg)\n}\n"
  },
  {
    "path": "x-tba/foundations/03-if-switch-loop/05-path-searcher-for-range/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// Get and split the PATH environment variable\n\n\t// SplitList function automatically finds the\n\t// separator for the path env variable\n\twords := filepath.SplitList(os.Getenv(\"PATH\"))\n\n\t// Alternative way, but above one is better:\n\t// words := strings.Split(\n\t// \tos.Getenv(\"PATH\"),\n\t// \tstring(os.PathListSeparator))\n\n\tquery := os.Args[1:]\n\n\tfor _, q := range query {\n\t\tfor i, w := range words {\n\t\t\tq, w = strings.ToLower(q), strings.ToLower(w)\n\n\t\t\tif !strings.Contains(w, q) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfmt.Printf(\"#%-2d: %q\\n\", i+1, w)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "x-tba/foundations/area-of-a-circle/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n)\n\nfunc main() {\n\tvar (\n\t\tradius = 10.\n\t\tarea   float64\n\t)\n\n\tarea = math.Pi * radius * radius\n\n\tfmt.Printf(\"radius: %g -> area: %.2f\\n\",\n\t\tradius, area)\n\n\t// ALTERNATIVE:\n\t// math.Pow calculates the power of a float number\n\t// area = math.Pi * math.Pow(radius, 2)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/01-shortdecl-int-conv/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// 1.\n\t// var a int\n\t// var b int\n\n\t// 2.\n\t// var (\n\t//   a int\n\t//   b int\n\t// )\n\n\t// 3.\n\t// var a, b int\n\n\t// 1.\n\t// fmt.Println(a, \"+\", b, \"=\", a+b)\n\n\t// 2.\n\t// fmt.Printf(\"%v + %v = %v\\n\", a, b, a+b)\n\n\t// ----\n\t// lesson: multi-return funcs, %v, and _\n\n\ta, _ := strconv.Atoi(os.Args[1])\n\tb, _ := strconv.Atoi(os.Args[2])\n\n\tfmt.Printf(\"%v + %v = %v\\n\", a, b, a+b)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/02-if/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// lesson: if\n\n\tif len(os.Args) != 3 {\n\t\tfmt.Println(\"Usage: calc <number1> <number2>\")\n\t\treturn\n\t}\n\n\ta, _ := strconv.Atoi(os.Args[1])\n\tb, _ := strconv.Atoi(os.Args[2])\n\n\tfmt.Printf(\"%v + %v = %v\\n\", a, b, a+b)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/03-floats-conv/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// lesson: len(), floats encompass integers too\n\n\tif len(os.Args) != 3 {\n\t\tfmt.Println(\"Usage: calc <number1> <number2>\")\n\t\treturn\n\t}\n\n\ta, _ := strconv.ParseFloat(os.Args[1], 64)\n\tb, _ := strconv.ParseFloat(os.Args[2], 64)\n\n\tfmt.Printf(\"%v + %v = %v\\n\", a, b, a+b)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/04-error-handling/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// lesson: error handling + short decl. assignment\n\n\tif len(os.Args) != 3 {\n\t\tfmt.Println(\"Usage: calc <number1> <number2>\")\n\t\treturn\n\t}\n\n\ta, err := strconv.ParseFloat(os.Args[1], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\tb, err := strconv.ParseFloat(os.Args[2], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\t// err1 := ...\n\t// err2 := ...\n\t// if err1 != nil || err2 != nil {\n\t// \tfmt.Println(\"Please provide a valid number\")\n\t// \treturn\n\t// }\n\n\tfmt.Printf(\"%v + %v = %v\\n\", a, b, a+b)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/05-switch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// lesson: switch\n\n\tif len(os.Args) != 4 {\n\t\tfmt.Println(\"Usage: calc <number1> <operator> <number2>\")\n\t\treturn\n\t}\n\n\ta, err := strconv.ParseFloat(os.Args[1], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\tb, err := strconv.ParseFloat(os.Args[3], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\t// multiple declare\n\tvar (\n\t\t// declare & assign\n\t\top  = os.Args[2]\n\t\tres float64\n\t)\n\n\tswitch op {\n\tcase \"+\":\n\t\tres = a + b\n\tcase \"-\":\n\t\tres = a - b\n\tcase \"*\":\n\t\tres = a * b\n\tcase \"/\":\n\t\tres = a / b\n\t}\n\n\tfmt.Printf(\"%v %v %v = %v\\n\", a, op, b, res)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/06-switch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// lesson: switch default + multiple case\n\n\tif len(os.Args) != 4 {\n\t\tfmt.Println(\"Usage: calc <number1> <operator> <number2>\")\n\t\treturn\n\t}\n\n\ta, err := strconv.ParseFloat(os.Args[1], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\tb, err := strconv.ParseFloat(os.Args[3], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\tvar (\n\t\top  = os.Args[2]\n\t\tres float64\n\t)\n\n\tswitch op {\n\tcase \"+\", \"plus\":\n\t\top, res = \"+\", a+b\n\tcase \"-\", \"minus\":\n\t\top, res = \"-\", a-b\n\tcase \"*\", \"times\":\n\t\top, res = \"*\", a*b\n\tcase \"/\", \"div\":\n\t\top, res = \"/\", a/b\n\tdefault:\n\t\tfmt.Println(\"Please provide a valid operation.\")\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%v %v %v = %v\\n\", a, op, b, res)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/07/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// lesson: modulo operator and type conversion\n\n\tif len(os.Args) != 4 {\n\t\tfmt.Println(\"Usage: calc <number1> <operator> <number2>\")\n\t\treturn\n\t}\n\n\ta, err := strconv.ParseFloat(os.Args[1], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\tb, err := strconv.ParseFloat(os.Args[3], 64)\n\tif err != nil {\n\t\tfmt.Println(\"Please provide a valid number\")\n\t\treturn\n\t}\n\n\tvar (\n\t\top  = os.Args[2]\n\t\tres float64\n\t)\n\n\tswitch op {\n\tcase \"+\", \"plus\":\n\t\top, res = \"+\", a+b\n\tcase \"-\", \"minus\":\n\t\top, res = \"-\", a-b\n\tcase \"*\", \"times\":\n\t\top, res = \"*\", a*b\n\tcase \"/\", \"div\":\n\t\top, res = \"/\", a/b\n\tcase \"%\", \"mod\":\n\t\tres = float64(int(a) % int(b))\n\tdefault:\n\t\tfmt.Println(\"Please provide a valid operation.\")\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%v %v %v = %v\\n\", a, op, b, res)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/08-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// lesson: many - split this\n\n\tif len(os.Args) != 4 {\n\t\tfmt.Println(\"Usage: calc <number1> <operator> <number2>\")\n\t\treturn\n\t}\n\n\tvar (\n\t\ta, b float64\n\t\terr  error\n\t)\n\n\tif a, err = parse(os.Args[1]); err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tif b, err = parse(os.Args[3]); err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\top := os.Args[2]\n\tres, err := calc(a, b, op)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%v %s %v = %v\\n\", a, op, b, res)\n}\n\nfunc parse(snum string) (n float64, err error) {\n\tn, err = strconv.ParseFloat(snum, 64)\n\tif err != nil {\n\t\terr = errors.New(\"Please provide a valid number\")\n\t}\n\treturn\n}\n\nfunc calc(a, b float64, op string) (res float64, err error) {\n\tswitch op {\n\tcase \"+\", \"plus\":\n\t\top, res = \"+\", a+b\n\tcase \"-\", \"minus\":\n\t\top, res = \"-\", a-b\n\tcase \"*\", \"times\":\n\t\top, res = \"*\", a*b\n\tcase \"/\", \"div\":\n\t\top, res = \"/\", a/b\n\tcase \"%\", \"mod\":\n\t\tres = float64(int(a) % int(b))\n\tdefault:\n\t\treturn 0, errors.New(\"Wrong operation: '\" + op + \"'\")\n\t}\n\treturn\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/09-packages/calc/calc.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage calc\n\nimport (\n\t\"errors\"\n\t\"strconv\"\n)\n\n// Parse ...\nfunc Parse(snum string) (n float64, err error) {\n\tn, err = strconv.ParseFloat(snum, 64)\n\tif err != nil {\n\t\t// Don't loose the actual error for debugging\n\t\terr = errors.New(\"Please provide a valid number: \" +\n\t\t\terr.Error())\n\t}\n\treturn\n}\n\n// Do ...\nfunc Do(a, b float64, op string) (res float64, err error) {\n\tswitch op {\n\tcase \"+\", \"plus\":\n\t\top, res = \"+\", a+b\n\tcase \"-\", \"minus\":\n\t\top, res = \"-\", a-b\n\tcase \"*\", \"times\":\n\t\top, res = \"*\", a*b\n\tcase \"/\", \"div\":\n\t\top, res = \"/\", a/b\n\tcase \"%\", \"mod\":\n\t\tres = float64(int(a) % int(b))\n\tdefault:\n\t\treturn 0, errors.New(\"Wrong operation: '\" + op + \"'\")\n\t}\n\treturn\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/09-packages/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/inancgumus/learngo/x-tba/foundations/calc/09-packages/calc\"\n)\n\nfunc main() {\n\t// lesson: packaging\n\n\t// separate dependencies like getting and validating\n\t// user data as in here.\n\t//\n\t// we only put calc to another packages, not the other\n\t// stuff.\n\t//\n\t// so, we can reuse the same calc package and use it\n\t// over a web api if we want.\n\n\tif len(os.Args) != 4 {\n\t\tfmt.Println(\"Usage: calc <number1> <operator> <number2>\")\n\t\treturn\n\t}\n\n\tvar (\n\t\ta, b float64\n\t\terr  error\n\t)\n\n\tif a, err = calc.Parse(os.Args[1]); err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tif b, err = calc.Parse(os.Args[3]); err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\top := os.Args[2]\n\tres, err := calc.Do(a, b, op)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Printf(\"%v %s %v = %v\\n\", a, op, b, res)\n}\n"
  },
  {
    "path": "x-tba/foundations/calc/calc-scanner/calculations.txt",
    "content": "4 + 5\n6.5 + 2\n5 - 3\nq\n"
  },
  {
    "path": "x-tba/foundations/calc/calc-scanner/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\n/*\ngo run main.go < ./calculations.txt\n\nIf you're not on Linux or OS X, etc but on Windows,\nThen, use Windows PowerShell to do the same thing.\n*/\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\n// After functions, you'll see that how we're going to refactor this\n// into a more readable version.\n\nfunc main() {\n\tconst (\n\t\tpromptChar     = \"> \"\n\t\terrWrongOp     = \"%s operation is not supported\\n\"\n\t\terrWrongFormat = \"operation is not recognized\\n\"\n\t\tusage          = `\nusage: number operation number\nquit : type q to quit\nexamples:\n  3 + 5\n  5 - 3\n`\n\t)\n\n\tfmt.Println(strings.TrimSpace(usage))\n\n\tfor s := bufio.NewScanner(os.Stdin); ; {\n\t\tvar (\n\t\t\ta, b, res float64\n\t\t\top        string\n\t\t)\n\n\t\tfmt.Print(promptChar, \" \")\n\t\tif !s.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\t_, err := fmt.Sscanf(s.Text(), \"%f %s %f\", &a, &op, &b)\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, errWrongFormat)\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch op {\n\t\tcase \"+\":\n\t\t\tres = a + b\n\t\tcase \"-\":\n\t\t\tres = a - b\n\t\tdefault:\n\t\t\tfmt.Printf(errWrongOp, op)\n\t\t\tcontinue\n\t\t}\n\n\t\tfmt.Printf(\"%g %s %g = %g\\n\", a, op, b, res)\n\t}\n\n\tfmt.Println(\"bye.\")\n}\n"
  },
  {
    "path": "x-tba/foundations/cels-to-fahr/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tcelsius := 35.\n\n\t// Wrong formula  :  9*celsius + 160  / 5\n\t// Correct formula: (9*celsius + 160) / 5\n\tfahrenheit := (9*celsius + 160) / 5\n\n\tfmt.Printf(\"%g ºC is %g ºF\\n\", celsius, fahrenheit)\n}\n"
  },
  {
    "path": "x-tba/foundations/counter/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc main() {\n\t// var counter int\n\t// var factor float64\n\tvar (\n\t\tcounter int\n\t\tfactor  float64\n\t)\n\n\t// counter = counter + 1\n\tcounter++\n\tfmt.Println(counter)\n\n\t// counter = counter - 1\n\tcounter--\n\tfmt.Println(counter)\n\n\t// counter = counter + 5\n\tcounter += 5\n\tfmt.Println(counter)\n\n\t// counter = counter * 10\n\tcounter *= 10\n\tfmt.Println(counter)\n\n\t// counter = counter / 2.0\n\tcounter /= 2.0\n\tfmt.Println(counter)\n\n\tfactor += float64(counter)\n\tfmt.Println(counter)\n\n\tvar bigCounter int64\n\tcounter += int(bigCounter)\n\tfmt.Println(counter)\n\n\tfmt.Println(\n\t\t\"hello\" + \", \" + \"how\" + \" \" + \"are\" + \" \" + \"today?\",\n\t)\n\n\t// you can combine raw string and string literals\n\tfmt.Println(\n\t\t`hello` + `, ` + `how` + ` ` + `are` + ` ` + \"today?\",\n\t)\n\n\t// ------------------------------------------\n\t// Converting non-string values into string\n\t// ------------------------------------------\n\n\teq := \"1 + 2 = \"\n\tsum := 1 + 2\n\n\t// invalid op\n\t// string concat op can only be used with strings\n\t// fmt.Println(eq + sum)\n\n\t// you need to convert it using strconv.Itoa\n\t// Itoa = Integer to ASCII\n\n\tfmt.Println(eq + strconv.Itoa(sum))\n}\n"
  },
  {
    "path": "x-tba/foundations/feet-to-meters/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tc, _ := strconv.ParseFloat(os.Args[1], 64)\n\tf := c*1.8 + 32\n\n\t// Like this:\n\tfmt.Printf(\"%g ºC is %g ºF\\n\", c, f)\n\n\t// Or just like this (both are correct):\n\tfmt.Printf(\"%g ºF\\n\", f)\n}\n"
  },
  {
    "path": "x-tba/foundations/lookup/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net\"\n\t\"os\"\n\t\"strings\"\n)\n\nconst (\n\tmissingHost = \"Please provide at least one domain. --help for more information.\"\n\n\thelp = `\nHost to IP Lookup:\n------------------\n\nIt finds the ip addresses of the given hosts. You can provide hosts by separating them with spaces.\n\nExample:\n\n  host google.com\n  host google.com uber.com`\n)\n\nfunc main() {\n\t// url := \"google.com\"\n\tvar message string\n\n\targs := os.Args\n\tswitch l := len(args); {\n\t// case len(args) == 1:\n\tcase l == 1:\n\t\tmessage = missingHost\n\tcase l == 2 && args[1] == \"--help\":\n\t\tmessage = strings.TrimSpace(help)\n\t}\n\n\tif message != \"\" {\n\t\tfmt.Println(message)\n\t\treturn\n\t}\n\n\t// for i := 0; i < len(args); i++ {}\n\t// for i, url := range args {\n\tfor _, url := range args[1:] {\n\t\t// if i == 0 {\n\t\t// \tcontinue\n\t\t// }\n\n\t\tips, err := net.LookupIP(url)\n\t\tif err != nil {\n\t\t\tfmt.Printf(\"%-20s => %s\\n\", url, err)\n\t\t\t// break\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, ip := range ips {\n\t\t\tif ip = ip.To4(); ip != nil {\n\t\t\t\tfmt.Printf(\"%-20s => %s\\n\", url, ip)\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "x-tba/foundations/volume-of-a-sphere/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tvar radius, vol float64\n\n\tradius, _ = strconv.ParseFloat(os.Args[1], 64)\n\n\tvol = (4 * math.Pi * math.Pow(radius, 3)) / 3\n\n\tfmt.Printf(\"radius: %g -> volume: %.2f\\n\", radius, vol)\n}\n"
  },
  {
    "path": "x-tba/project-png-parser/png-parser-project/1-png-anatomy-format.md",
    "content": "# The Brief Anatomy of a PNG image\n\n```\nThe first 24 bytes:\n\n+=================================+\n|  PNG Header         |  8 bytes  | -> 89 50 4e 47 0d 0a 1a 0a\n+---------------------+-----------+\n|  IHDR Chunk Header  |           |\n|    Chunk Length     |  4 bytes  | -> The length of the IHDR Chunk Data\n|    Chunk Type       |  4 bytes  | -> 49 48 44 52\n+---------------------+-----------+\n|  IHDR Chunk Data    |           |\n|    Width            |  4 bytes  | -> uint32 — big endian\n|    Height           |  4 bytes  | -> uint32 — big endian\n+=================================+\n```"
  },
  {
    "path": "x-tba/project-png-parser/png-parser-project/2-png-anatomy-example.md",
    "content": "# The Brief Anatomy of a PNG image\n\n```\nThe first 24 bytes:\n(all numbers are uint32 big-endian)\n\nPNG HEADER\n╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗\n║ 89 ║║ 50 ║║ 4e ║║ 47 ║║ 0d ║║ 0a ║║ 1a ║║ 0a ║\n╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝\n   0     1     2     3     4     5     6     7\n\nCHUNK LENGTH            CHUNK TYPE (IHDR)\n╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗\n║ 00 ║║ 00 ║║ 00 ║║ 0d ║║ 49 ║║ 48 ║║ 44 ║║ 52 ║\n╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝\n   8     9    10    11    12    13    14    15\n\nWIDTH                   HEIGHT\n╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗\n║ 00 ║║ 00 ║║ 02 ║║ 4c ║║ 00 ║║ 00 ║║ 03 ║║ 20 ║\n╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝\n  16    17    18    19    20    21    22    23\n\n... rest of the bytes in the png image ...\n```"
  },
  {
    "path": "x-tba/project-png-parser/png-parser-project/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"encoding/binary\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"runtime\"\n)\n\nfunc main() {\n\targs := os.Args[1:]\n\tif len(args) == 0 {\n\t\tfmt.Println(\"run with a PNG file\")\n\t\treturn\n\t}\n\n\t// this is not the best way\n\t// it's better only to read the first 24 bytes\n\t// this reads the whole file into memory\n\timg, err := ioutil.ReadFile(args[0])\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\treport()\n\timg = append([]byte(nil), img[:24]...)\n\t// img = img[:24:24] // unnecessary\n\treport()\n\n\t// s.PrintBacking = true\n\t// s.MaxPerLine = 8\n\t// s.MaxElements = 24\n\t// s.PrintBytesHex = true\n\t// s.Show(\"first 24 bytes\", img)\n\n\tvar (\n\t\tpngHeader     = [...]byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}\n\t\tihdrChunkType = [...]byte{0x49, 0x48, 0x44, 0x52}\n\t)\n\n\t// ------------------------------------------\n\t// Read the PNG header\n\t// https://www.w3.org/TR/2003/REC-PNG-20031110/#5PNG-file-signature\n\t// ------------------------------------------\n\tlpng := len(pngHeader)\n\tif !bytes.Equal(img[:lpng], pngHeader[:]) {\n\t\tfmt.Println(\"missing PNG header\")\n\t\treturn\n\t}\n\n\t// skip the png header\n\timg = img[lpng:]\n\n\t// ------------------------------------------\n\t// Read the IHDR chunk header\n\t// The IHDR chunk shall be the first chunk in the PNG datastream.\n\t// https://www.w3.org/TR/2003/REC-PNG-20031110/#11IHDR\n\t// ------------------------------------------\n\theader := img[:8] // get the length and chunk type\n\n\t// ensure that the chunk type is IHDR\n\tif !bytes.Equal(header[4:8], ihdrChunkType[:]) {\n\t\tfmt.Println(\"missing IHDR chunk\")\n\t\treturn\n\t}\n\n\t// ------------------------------------------\n\t// Read the IHDR Chunk Data\n\t// ------------------------------------------\n\timg = img[len(header):] // skip the IHDR chunk header data\n\tihdr := img[:8]         // read the width&height from the ihdr chunk\n\n\t// All integers that require more than one byte shall be in:\n\t// network byte order = Big Endian\n\t// https://www.w3.org/TR/2003/REC-PNG-20031110/#7Integers-and-byte-order\n\tfmt.Printf(\"dimensions: %dx%d\\n\",\n\t\t// read the first 4 bytes (width)\n\t\tbinary.BigEndian.Uint32(ihdr[:4]),\n\t\t// read the next 4 bytes (height)\n\t\tbinary.BigEndian.Uint32(ihdr[4:8]))\n}\n\nfunc report() {\n\tvar m runtime.MemStats\n\truntime.GC()\n\truntime.ReadMemStats(&m)\n\tfmt.Printf(\" > Memory Usage: %v KB\\n\", m.Alloc/1024)\n}\n"
  },
  {
    "path": "x-tba/slicing-allocs-gotcha/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Before running this program:\n//\n//     RUN: `go run nums/main.go`\n//     It will create a 12 MB long nums.txt file.\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"runtime\"\n\n\ts \"github.com/inancgumus/prettyslice\"\n)\n\nconst (\n\tloops = 1000\n\tfile  = \"nums.txt\"\n)\n\nvar buf []byte\n\nfunc main() {\n\t{\n\t\tb, _ := ioutil.ReadFile(file)\n\t\tbuf = b[:1]\n\n\t\ts.Show(\"sliced buf\", buf)\n\t}\n\treport()\n\n\t{\n\t\tvar nilBuf []byte\n\n\t\tb, _ := ioutil.ReadFile(file)\n\t\tbuf = append(nilBuf, b[:1]...)\n\n\t\ts.Show(\"copied buf\", buf)\n\t}\n\treport()\n}\n\nfunc report() {\n\tconst KB = 1024\n\n\tvar m runtime.MemStats\n\tr := func() {\n\t\truntime.ReadMemStats(&m)\n\t\tfmt.Printf(\"%v KB\\n\", m.Alloc/KB)\n\t}\n\n\tfmt.Print(\" > Before Garbage Collection: \")\n\tr()\n\n\truntime.GC()\n\tfmt.Print(\" > After Garbage Colletion  : \")\n\tr()\n}\n\nfunc init() {\n\ts.Width = 50\n\ts.PrintBacking = true\n\ts.MaxElements = 10\n}\n"
  },
  {
    "path": "x-tba/slicing-allocs-gotcha/nums/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tconst path = \"nums.txt\"\n\n\t_ = os.Remove(path)\n\n\tf, _ := os.OpenFile(path,\n\t\tos.O_CREATE|os.O_WRONLY,\n\t\t0644)\n\tdefer f.Close()\n\n\tconst size = 1000000\n\tw := bufio.NewWriterSize(f, 1<<16)\n\tfor i := 1; i <= size; i++ {\n\t\tfmt.Fprintf(w, \"num: %d\\n\", i)\n\t}\n\tw.Flush()\n}\n"
  },
  {
    "path": "x-tba/swapi-api-client/fetch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"net/http\"\n\t\"os\"\n)\n\nconst base = \"https://swapi.co/api/\"\n\nfunc main() {\n\tif len(os.Args) != 2 {\n\t\tfmt.Println(\"Please provide a Ship ID\")\n\t\treturn\n\t}\n\n\turl := base + \"starships/\" + os.Args[1]\n\n\tresponse, err := http.Get(url)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tif code := response.StatusCode; code != http.StatusOK {\n\t\tfmt.Println(\"Error:\", http.StatusText(code))\n\t\treturn\n\t}\n\n\t// var r *http.Response\n\t// _ = r\n\n\tbodyBytes, err := ioutil.ReadAll(response.Body)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tbody := string(bodyBytes)\n\tfmt.Println(body)\n}\n"
  },
  {
    "path": "x-tba/swapi-api-client/film.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strings\"\n)\n\n// Film represents a single Star Wars film\ntype Film struct {\n\t// All fields should be exported to be decoded\n\tTitle     string   `json:\"title\"`\n\tOpening   string   `json:\"opening_crawl\"`\n\tStarships []string `json:\"starships\"`\n}\n\nfunc (f Film) String() string {\n\tvar buf strings.Builder\n\n\tfmt.Fprintln(&buf, f.Title)\n\tfmt.Fprintln(&buf, strings.Repeat(\"-\", len(f.Title)))\n\tbuf.WriteByte('\\n')\n\tfmt.Fprintln(&buf, f.Opening)\n\n\treturn buf.String()\n}\n\n// fetchFilm returns a Film resource by its id\nfunc fetchFilm(ctx context.Context, id int) (film Film, err error) {\n\tfmt.Println(\"requesting\", fmt.Sprintf(swapi+\"films/%d/\", id))\n\tc, err := request(ctx, fmt.Sprintf(swapi+\"films/%d/\", id))\n\tif err != nil {\n\t\treturn film, err\n\t}\n\n\treturn film, json.Unmarshal(c, &film)\n}\n"
  },
  {
    "path": "x-tba/swapi-api-client/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\n// const\n// nil, string, int, float64, bool, comparison\n// variables\n//   multiple short variables\n//   assignment?\n// if\n// error handling\n// functions\n//   returns\n//   defer\n// struct\n//   encoding/json\n// pointers\n// concurrency\n//   select\n//   chan receive\n// fmt\n//   Printf\n//   Sprintf\n//   Errorf\n// net/http\n//   Get\n// context/Context\n\n// TODO: convert fmt calls to log\n// TODO: you can make the fetcher a library and main package the user\n// TODO: you can generate an html for the ship details? template pkg.\n\nconst timeout = 10 * time.Second\n\nfunc main() {\n\targs := os.Args[1:]\n\tquit(\"give me a film id\", len(args) != 1)\n\n\tid, err := strconv.Atoi(args[0])\n\tquit(\"film id is incorrrect\", err)\n\n\tctx, cancel := context.WithTimeout(context.Background(), timeout)\n\tdefer cancel()\n\n\t// TODO: print the ship details to a text file (or any io.Writer)\n\n\tfilm, err := fetchFilm(ctx, id)\n\tquit(\"Error occurred while fetching the film data\", err)\n\tfmt.Println(film)\n\n\t// a channel also can be used to print as they come\n\tships := make([]Starship, len(film.Starships))\n\terr = fetchStarships(ctx, film.Starships, ships)\n\tquit(\"Error occurred while fetching starships\", err)\n\n\tfmt.Println(\"Ships used in the movie:\")\n\tfmt.Println(\"------------------------\")\n\tfor _, ship := range ships {\n\t\tfmt.Println(ship)\n\t}\n}\n\nfunc quit(message string, cond interface{}) {\n\tvar quit bool\n\n\tswitch v := cond.(type) {\n\tcase error:\n\t\tquit = true\n\t\tmessage += \": \" + v.Error()\n\tcase bool:\n\t\tquit = v\n\t}\n\n\tif quit {\n\t\tfmt.Fprintln(os.Stderr, message)\n\t\tos.Exit(1)\n\t}\n}\n"
  },
  {
    "path": "x-tba/swapi-api-client/request.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"net/http\"\n)\n\n// MaxResponseSize limits the response bytes from the API\nconst MaxResponseSize = 2 << 16\n\n// creating a robust http getter (lecture? :))\nfunc request(ctx context.Context, url string) ([]byte, error) {\n\treq, err := http.NewRequest(\"GET\", url, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treq = req.WithContext(ctx)\n\n\tresp, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\t// Get the error from the context.\n\t\t// It may contain more useful data.\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\terr = ctx.Err()\n\t\tdefault:\n\t\t}\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"Bad Status: %d\", resp.StatusCode)\n\t}\n\n\t// Prevents the api to shoot us unlimited amount of data\n\tr := io.LimitReader(resp.Body, MaxResponseSize)\n\n\treturn ioutil.ReadAll(r)\n}\n"
  },
  {
    "path": "x-tba/swapi-api-client/starship.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"regexp\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// Starship represents a Star Wars space ship\ntype Starship struct {\n\t// All fields should be exported to be decoded\n\tName    string      `json:\"name\"`\n\tCredits json.Number `json:\"cost_in_credits\"`\n\tRating  float64     `json:\"hyperdrive_rating,string\"`\n}\n\nfunc (ship Starship) String() string {\n\tvar buf strings.Builder\n\n\tfmt.Fprintf(&buf, \"Ship Name: %s\\n\", ship.Name)\n\tfmt.Fprintf(&buf, \"Price    : %s\\n\", ship.Credits)\n\n\treturn buf.String()\n}\n\n// TODO: return error instead of quit()\nfunc fetchStarships(ctx context.Context, shipUrls []string, ships []Starship) error {\n\tships = ships[:0]\n\n\tre := regexp.MustCompile(`/([0-9]+)/$`)\n\tfor _, url := range shipUrls {\n\t\tids := re.FindAllStringSubmatch(url, -1)\n\t\tif ids == nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tsid := ids[0][1]\n\t\tid, _ := strconv.Atoi(sid)\n\n\t\t// TODO: goroutine\n\t\tship, err := fetchStarship(ctx, id)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tships = append(ships, ship)\n\t}\n\treturn nil\n}\n\n// fetchStarship returns Starship info by its id\nfunc fetchStarship(ctx context.Context, id int) (ship Starship, err error) {\n\tc, err := request(ctx, fmt.Sprintf(swapi+\"starships/%d/\", id))\n\tif err != nil {\n\t\treturn ship, err\n\t}\n\n\t// -> If your response body is small enough,\n\t//    just read it all into memory using ioutil.ReadAll\n\t//    and use json.Unmarshal.\n\t//\n\t// -> Do not use json.Decoder if you are not dealing\n\t//    with JSON streaming.\n\n\treturn ship, json.Unmarshal(c, &ship)\n}\n"
  },
  {
    "path": "x-tba/swapi-api-client/swapi.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst swapi = \"https://swapi.co/api/\"\n"
  },
  {
    "path": "x-tba/tictactoe/00-print/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\nfunc main() {\n\t// VERSION #1: String Concat +\n\t/*\n\t\tfmt.Print(\"\" +\n\t\t\t\" TIC~TAC~TOE\\n\" +\n\t\t\t\"\\n\" +\n\t\t\t\"/---+---+---\\\\\\n\" +\n\t\t\t\"| X | O | X |\\n\" +\n\t\t\t\"+---+---+---+\\n\" +\n\t\t\t\"| X | X |   |\\n\" +\n\t\t\t\"+---+---+---+\\n\" +\n\t\t\t\"| O | O | O |\\n\" +\n\t\t\t\"\\\\---+---+---/\\n\")\n\t*/\n\n\t// VERSION #2: String Concat +\n\t/*\n\t\tfmt.Println(\"\" +\n\t\t\t\" TIC~TAC~TOE\\n\" +\n\t\t\t\"\\n\" +\n\t\t\t\"/---+---+---\\\\\\n\" +\n\t\t\t\"| X | O | X |\\n\" +\n\t\t\t\"+---+---+---+\\n\" +\n\t\t\t\"| X | X |   |\\n\" +\n\t\t\t\"+---+---+---+\\n\" +\n\t\t\t\"| O | O | O |\\n\" +\n\t\t\t\"\\\\---+---+---/\")\n\t*/\n\n\t// VERSION #3: Raw Literals (multi line strings)\n\tfmt.Println(`\n TIC~TAC~TOE\n\n/---+---+---\\\n| X | O | X |\n+---+---+---+\n| X | X |   |\n+---+---+---+\n| O | O | O |\n\\---+---+---/`)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/01-vars/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\nfunc main() {\n\t/*\n\t\tVERSION #1: Declare variables\n\n\t\tEvery type has a zero-value:\n\t\t  numeric types => 0\n\t\t  bool          => false\n\t\t  string        => \"\"\n\t*/\n\n\t// var banner string\n\t// var board string\n\t// var turn int\n\t// var maxTurns int\n\t// var won bool\n\n\t/*\n\t\tVERSION #2: Declare variables parallel (same as above)\n\n\t\tturn and lastPos are int\n\t\twon and wrongMove are bool\n\t*/\n\t// var banner, board string\n\t// var turn, maxTurns int\n\t// var won bool\n\n\t/*\n\t\tVERSION #3: Declare variables in a group and parallel (same as above)\n\t*/\n\t// var (\n\t//  banner, board  string\n\t// \tturn, maxTurns int\n\t// \twon            bool\n\t// )\n\n\t/*\n\t\tVERSION #4: Declare variables in a group (same as above)\n\t*/\n\tvar (\n\t\tbanner string // tictactoe banner\n\t\tboard  string // tictactoe board\n\n\t\tturn     int // total valid turns played\n\t\tmaxTurns int // maximum number of turns\n\n\t\twon bool // is there any winner?\n\n\t\tprogress float64 // remaining progress\n\t)\n\n\t/*\n\t\t#5: Assignment\n\t*/\n\tbanner = \" TIC~TAC~TOE\"\n\tboard = `\n/---+---+---\\\n|   | X |   |\n+---+---+---+\n|   | O |   |\n+---+---+---+\n|   |   |   |\n\\---+---+---/`\n\n\t// maxTurns = 9\n\t// turn = 2\n\n\t// multiple assignment\n\tmaxTurns, turn = 9, 2\n\n\t// cannot assign int to float\n\t// progress = 1 - (turn / maxTurns) * 100\n\t// convert ints to float so that the result will be float\n\t// literals are typeless: they automatically get converted to the surrounding operands\n\tprogress = (1 - (float64(turn) / float64(maxTurns))) * 100\n\n\tfmt.Println(banner)\n\tfmt.Println(board)\n\n\tfmt.Println()\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n\n\t// This is also valid: the expression is evaluated on the fly.\n\t// fmt.Printf(\"Turns left             : %.1f%%\\n\",\n\t// \t(1 - (float64(turn) / float64(maxTurns))) * 100)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/02-short-decl/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\nfunc main() {\n\tvar won bool // is there any winner?\n\n\tbanner := \" TIC~TAC~TOE\"\n\tboard := `\n/---+---+---\\\n|   |   |   |\n+---+---+---+\n|   |   |   |\n+---+---+---+\n|   |   |   |\n\\---+---+---/`\n\n\t// short declaration (type-inference)\n\tmaxTurns, turn := 9, 0\n\tprogress := (1 - (float64(turn) / float64(maxTurns))) * 100\n\n\tfmt.Println(banner)\n\tfmt.Println(board)\n\tfmt.Println()\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/03-consts/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\nfunc main() {\n\tvar (\n\t\twon  bool\n\t\tturn int\n\t)\n\n\t// VERSION 1\n\t// const banner = \" TIC~TAC~TOE\"\n\t// const board = `\n\t// /---+---+---\\\n\t// | X | O | X |\n\t// +---+---+---+\n\t// | X | X |   |\n\t// +---+---+---+\n\t// | O | O | O |\n\t// \\---+---+---/`\n\t//\n\t// const maxTurns = 9\n\n\t// VERSION 2\n\t// Benefit of constants:\n\t// + Resolved to literals at compile-time\n\t// + Fast at runtime\n\t// + Provides overwriting unlike variables\n\t// + Typeless: Can change type\n\tconst (\n\t\tbanner = `\n TIC~TAC~TOE\n\n/---+---+---\\\n| X | O | X |\n+---+---+---+\n| X | X |   |\n+---+---+---+\n| O | O | O |\n\\---+---+---/`\n\n\t\tmaxTurns = 9\n\t)\n\n\t// Constants have default types\n\t// 1    => int\n\t// 1.5  => float64\n\t// true => bool\n\t// \"hi\" => string\n\t// 'a'  => rune\n\n\t// You cannot assign to constants\n\t// banner = \"TIC TAC TOE\"\n\t// maxTurns = 10\n\n\t// no need: float64(maxTurns) — constants are typeless (like basic literals)\n\t// if maxTurns was `const maxTurns int`; then it'd be needed.\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\n\tfmt.Println(banner)\n\t// fmt.Println(board)\n\tfmt.Println()\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/04-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst (\n\tbanner = `\n TIC~TAC~TOE\n\n/---+---+---\\\n| X | O | X |\n+---+---+---+\n| X | X |   |\n+---+---+---+\n| O | O | O |\n\\---+---+---/`\n\n\tmaxTurns = 9\n)\n\nvar (\n\twon  bool\n\tturn int\n)\n\nfunc main() {\n\t// you need to call the other functions but the main\n\tprintBoard()\n\tprintStatus()\n}\n\n// printBoard cannot use the banner\nfunc printBoard() {\n\t// it can only use the package-level names (identifiers)\n\tfmt.Println(banner)\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/05-testing/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\t// let the printBoard function print an output\n\n\tprintBoard()\n\n\t// the output should exactly match the following (after Output:)\n\n\t// Output:\n\t//  TIC~TAC~TOE\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/05-testing/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst (\n\tbanner = `\n TIC~TAC~TOE\n\n/---+---+---\\\n|   |   |   |\n+---+---+---+\n|   |   |   |\n+---+---+---+\n|   |   |   |\n\\---+---+---/`\n\n\tmaxTurns = 9\n)\n\nvar (\n\twon  bool\n\tturn int\n)\n\nfunc main() {\n\t// you need to call the other functions but the main\n\tprintBoard()\n\tprintStatus()\n}\n\n// printBoard cannot use the banner\nfunc printBoard() {\n\t// it can only use the package-level names (identifiers)\n\tfmt.Println(banner)\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/06-if-switch/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\t// let the printBoard function print an output\n\n\tprintBoard()\n\n\t// the output should exactly match the following (after Output:)\n\n\t// Output:\n\t//  TIC~TAC~TOE\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/06-if-switch/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst (\n\tbanner = `\n TIC~TAC~TOE\n\n/---+---+---\\\n|   |   |   |\n+---+---+---+\n|   |   |   |\n+---+---+---+\n|   |   |   |\n\\---+---+---/`\n\n\tmaxTurns = 9\n)\n\nvar (\n\twon  bool\n\tturn int\n)\n\nfunc main() {\n\t// you need to call the other functions but the main\n\tprintBoard()\n\tprintStatus()\n\tprintEnding()\n}\n\n// printBoard cannot use the banner\nfunc printBoard() {\n\t// it can only use the package-level names (identifiers)\n\tfmt.Println(banner)\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n\nfunc printEnding() {\n\tfmt.Println()\n\n\t// creates a new variable that belongs to printEnding()\n\t// current player\n\tplayer := \"X\"\n\n\t// accesses to the package-level vars: won, turn\n\t// won = true\n\t// turn = maxTurns\n\n\t// if won {\n\t// \tfmt.Printf(\">>> WINNER: %s\\n\", player)\n\t// } else if turn == maxTurns { // != >= <= < >\n\t// \tfmt.Println(\">>> TIE!\")\n\t// } else {\n\t// \tfmt.Println(\">> NEXT TURN!\")\n\t// }\n\n\tswitch {\n\tcase won:\n\t\t// player := \"X\"\n\t\tfmt.Printf(\">>> WINNER: %s\\n\", player)\n\tcase turn == maxTurns:\n\t\tfmt.Println(\">>> TIE!\")\n\tdefault:\n\t\tfmt.Println(\">> NEXT TURN!\", player)\n\n\t}\n\n\t// invalid if the player is within the scope of the switch:\n\t// fmt.Println(\">> Current Player: \", player)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/07-loop/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X | O | X |\n\t// +---+---+---+\n\t// | O | X | O |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tconst cellsPerLine = 3\n\n\t// Prevents the Println '\\n' warning\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i := 0; i < maxTurns; i++ {\n\t\tlineStarts := i%cellsPerLine == 0\n\t\tlineEnds := (i+1)%cellsPerLine == 0\n\t\tlastLine := (i + 1) == maxTurns\n\n\t\tif lineStarts {\n\t\t\tfmt.Print(sepCell)\n\t\t}\n\n\t\tswitchPlayer()\n\t\tfmt.Printf(\" %s \", player)\n\n\t\tif lineEnds {\n\t\t\tfmt.Println(sepCell)\n\t\t}\n\n\t\tif lineEnds && !lastLine {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\n\t\tif lineEnds {\n\t\t\tcontinue // prevents printing the sepCell below\n\t\t}\n\n\t\t// print the cell separator until 3 cells per line\n\t\tfmt.Print(sepCell)\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/07-loop/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\t// let the printBoard function print an output\n\n\tprintBoard()\n\n\t// the output should exactly match the following (after Output:)\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X | O | X |\n\t// +---+---+---+\n\t// | O | X | O |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/07-loop/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon    bool\n\tturn   int\n\tplayer string // current player\n)\n\nfunc main() {\n\tplayer = player1\n\tturn = maxTurns\n\n\t// you need to call the other functions but the main\n\tprintBoard()\n\tprintStatus()\n\tprintEnding()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n\nfunc printEnding() {\n\tfmt.Println()\n\n\tswitch {\n\tcase won:\n\t\tfmt.Printf(\">>> WINNER: %s\\n\", player)\n\tcase turn == maxTurns:\n\t\tfmt.Println(\">>> TIE!\")\n\tdefault:\n\t\tfmt.Println(\">> NEXT TURN!\", player)\n\t}\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/07-loop/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n\n\t/*\n\t\tTry it with this instead :)\n\n\t\tsepHeader = \"╔═══╦═══╦═══╗\"\n\t\tsepLine   = \"╠═══╬═══╬═══╣\"\n\t\tsepFooter = \"╚═══╩═══╩═══╝\"\n\t\tsepCell   = \"║\"\n\t*/\n)\n"
  },
  {
    "path": "x-tba/tictactoe/08-multi-loop/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X | O | X |\n\t// +---+---+---+\n\t// | O | X | O |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < maxTurns; i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tswitchPlayer()\n\t\t\tfmt.Printf(\" %s %s\", player, sepCell)\n\t\t}\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != maxTurns {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/08-multi-loop/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\t// let the printBoard function print an output\n\n\tprintBoard()\n\n\t// the output should exactly match the following (after Output:)\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X | O | X |\n\t// +---+---+---+\n\t// | O | X | O |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/08-multi-loop/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon    bool\n\tturn   int\n\tplayer string // current player\n)\n\nfunc main() {\n\tplayer = player1\n\tturn = maxTurns\n\n\t// you need to call the other functions but the main\n\tprintBoard()\n\tprintStatus()\n\tprintEnding()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n\nfunc printEnding() {\n\tfmt.Println()\n\n\tswitch {\n\tcase won:\n\t\tfmt.Printf(\">>> WINNER: %s\\n\", player)\n\tcase turn == maxTurns:\n\t\tfmt.Println(\">>> TIE!\")\n\tdefault:\n\t\tswitchPlayer()\n\t\tfmt.Println(\">> NEXT TURN!\", player)\n\t}\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/08-multi-loop/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/09-slices/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/09-slices/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tinitCells()\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tinitCells()\n\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/09-slices/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\t// // create a string with empty cells\n\t// // \" , , , , , , , , ,\"\n\t// var s string\n\n\t// // number of cells = maxTurns\n\t// for i := 1; i <= maxTurns; i++ {\n\t// \ts += emptyCell // add an empty move\n\t// \ts += \",\"       // separate the cells with a comma\n\t// }\n\n\t// // strings are immutable — you should create a new one\n\t// // fortunately: most of this happens in the stack memory\n\t// // \" , , , , , , , , ,\" -> // \" , , , , , , , , \"\n\t// s = strings.TrimSuffix(s, \",\")\n\n\t// // store the cells in a slice (slice = list, array in other langs)\n\t// // Split() returns a list of strings: []string (a string slice)\n\t// // [\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \" ]\n\t// cells = strings.Split(s, \",\")\n\n\t// Right way:\n\t// cells = []string{\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \"}\n\t//\n\t// Or:\n\tcells = make([]string, maxTurns)\n\tfor i := range cells {\n\t  cells[i] = emptyCell\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/09-slices/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon    bool     // is there any winner?\n\tturn   int      // total valid turns played\n\tplayer string   // current player\n\tcells  []string // used to draw the board: contains the players' moves\n)\n\nfunc main() {\n\tplayer = player1\n\n\tinitCells()\n\n\tplay()\n\n\tprintBoard()\n\tprintStatus()\n\tprintEnding()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n\nfunc printEnding() {\n\tfmt.Println()\n\n\tswitch {\n\tcase won:\n\t\tfmt.Printf(\">>> WINNER: %s\\n\", player)\n\tcase turn == maxTurns:\n\t\tfmt.Println(\">>> TIE!\")\n\tdefault:\n\t\tswitchPlayer()\n\t\tfmt.Println(\">> NEXT TURN!\", player)\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/09-slices/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// [\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \" ] -> cells slice\n\t//   0    1    2    3    4    5    6    7    8    -> indexes\n\n\t// /---+---+---\\\n\t// | 0 | 1 | 2 |\n\t// +---+---+---+\n\t// | 3 | 4 | 5 |\n\t// +---+---+---+\n\t// | 6 | 7 | 8 |\n\t// \\---+---+---/\n\n\t// current player plays to the 4th position (index)\n\t// play to a fixed position \"for now\".\n\tpos := 4\n\n\t// register the move: put the player's sign on the board\n\tcells[pos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/09-slices/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\temptyCell        = \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/10-arrays/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/10-arrays/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tinitCells()\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tinitCells()\n\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/10-arrays/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\tfor i := range cells {\n\t\tcells[i] = emptyCell\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/10-arrays/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon    bool             // is there any winner?\n\tturn   int              // total valid turns played\n\tplayer string           // current player\n\tcells  [maxTurns]string // used to draw the board: contains the players' moves\n)\n\nfunc main() {\n\tplayer = player1\n\n\tinitCells()\n\n\tplay()\n\n\tprintBoard()\n\tprintStatus()\n\tprintEnding()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n\nfunc printEnding() {\n\tfmt.Println()\n\n\tswitch {\n\tcase won:\n\t\tfmt.Printf(\">>> WINNER: %s\\n\", player)\n\tcase turn == maxTurns:\n\t\tfmt.Println(\">>> TIE!\")\n\tdefault:\n\t\tswitchPlayer()\n\t\tfmt.Println(\">> NEXT TURN!\", player)\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/10-arrays/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// [\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \" ] -> cells slice\n\t//   0    1    2    3    4    5    6    7    8    -> indexes\n\n\t// /---+---+---\\\n\t// | 0 | 1 | 2 |\n\t// +---+---+---+\n\t// | 3 | 4 | 5 |\n\t// +---+---+---+\n\t// | 6 | 7 | 8 |\n\t// \\---+---+---/\n\n\t// current player plays to the 4th position (index)\n\t// play to a fixed position \"for now\".\n\tpos := 4\n\n\t// register the move: put the player's sign on the board\n\tcells[pos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/10-arrays/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\temptyCell        = \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/11-randomization/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/11-randomization/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/11-randomization/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"math/rand\"\n\t\"time\"\n)\n\n// init is another special function\n// Go calls it before the main function\nfunc init() {\n\trand.Seed(time.Now().UnixNano())\n\tinitCells()\n}\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\tfor i := range cells {\n\t\tcells[i] = emptyCell\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/11-randomization/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon    bool   // is there any winner?\n\tturn   int    // total valid turns played\n\tplayer string // current player\n\n\tcells     [maxTurns]string // used to draw the board: contains the players' moves\n\tlastPos   int              // last played position\n\twrongMove bool             // was the last move wrong?\n)\n\nfunc main() {\n\tplayer = player1\n\tprintBoard()\n\n\tfor i := 0; i < 4; i++ {\n\t\twait()\n\t\tplay()\n\t\tprintBoard()\n\n\t\tfmt.Printf(\"\\n>>> PLAYER %q PLAYS to %d\\n\", player, lastPos+1)\n\t\tprintEnding()\n\t}\n}\n\nfunc wait() {\n\tfmt.Println()\n\tfmt.Scanln()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n\nfunc printEnding() {\n\tswitch {\n\tdefault:\n\t\tswitchPlayer()\n\t\tprintStatus()\n\n\tcase wrongMove:\n\t\tfmt.Printf(\">>> CELL IS OCCUPIED: PLAY AGAIN!\\n\")\n\t\twrongMove = false // reset for the next turn\n\n\tcase won:\n\t\tfmt.Printf(\">>> WINNER: %s\\n\", player)\n\n\tcase turn == maxTurns:\n\t\tfmt.Println(\">>> TIE!\")\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/11-randomization/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"math/rand\"\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// [\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \" ] -> cells slice\n\t//   0    1    2    3    4    5    6    7    8    -> indexes\n\n\t// /---+---+---\\\n\t// | 0 | 1 | 2 |\n\t// +---+---+---+\n\t// | 3 | 4 | 5 |\n\t// +---+---+---+\n\t// | 6 | 7 | 8 |\n\t// \\---+---+---/\n\n\t// pick a random move (very intelligent AI!)\n\t// it can play to the same position!\n\tlastPos = rand.Intn(maxTurns)\n\n\t// is it a valid move?\n\tif cells[lastPos] != emptyCell {\n\t\twrongMove = true\n\n\t\t// skip the rest of the function from running\n\t\treturn\n\t}\n\n\t// register the move: put the player's sign on the board\n\tcells[lastPos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/11-randomization/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\temptyCell        = \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/12-infinite-loop/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/12-infinite-loop/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/12-infinite-loop/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"math/rand\"\n\t\"time\"\n)\n\n// init is another special function\n// Go calls it before the main function\nfunc init() {\n\trand.Seed(time.Now().UnixNano())\n\tinitCells()\n}\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\tfor i := range cells {\n\t\tcells[i] = emptyCell\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/12-infinite-loop/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon    bool      // is there any winner?\n\tturn   int       // total valid turns played\n\tplayer = player1 // current player\n\n\tcells     [maxTurns]string // used to draw the board: contains the players' moves\n\tlastPos   int              // last played position\n\twrongMove bool             // was the last move wrong?\n)\n\nfunc main() {\n\tprintBoard()\n\n\t// alternative:\n\t// for won || tie {}\n\n\t// this a label: it can be used by break, continue and goto\ntheGameLoop:\n\t// loop forever until the game ends (tie or win)\n\tfor {\n\t\twait()\n\t\tplay()\n\t\tprintBoard()\n\n\t\tfmt.Printf(\"\\n>>> PLAYER %q PLAYS to %d\\n\", player, lastPos+1)\n\n\t\t// simple statement\n\t\tswitch tie := turn == maxTurns; {\n\t\tdefault:\n\t\t\tswitchPlayer()\n\t\t\tprintStatus()\n\n\t\tcase wrongMove:\n\t\t\tfmt.Printf(\">>> CELL IS OCCUPIED: PLAY AGAIN!\\n\")\n\t\t\twrongMove = false // reset for the next turn\n\n\t\tcase won, tie:\n\t\t\tif won {\n\t\t\t\tfmt.Println(\">>> WINNER:\", player)\n\t\t\t} else {\n\t\t\t\tfmt.Println(\">>> TIE!\")\n\t\t\t}\n\t\t\tbreak theGameLoop\n\t\t}\n\t}\n}\n\nfunc wait() {\n\tfmt.Println()\n\tfmt.Scanln()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/12-infinite-loop/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"math/rand\"\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// [\" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \" \" ] -> cells slice\n\t//   0    1    2    3    4    5    6    7    8    -> indexes\n\n\t// /---+---+---\\\n\t// | 0 | 1 | 2 |\n\t// +---+---+---+\n\t// | 3 | 4 | 5 |\n\t// +---+---+---+\n\t// | 6 | 7 | 8 |\n\t// \\---+---+---/\n\n\t// pick a random move (very intelligent AI!)\n\t// it can play to the same position!\n\tlastPos = rand.Intn(maxTurns)\n\n\t// is it a valid move?\n\tif cells[lastPos] != emptyCell {\n\t\twrongMove = true\n\n\t\t// skip the rest of the function from running\n\t\treturn\n\t}\n\n\t// register the move: put the player's sign on the board\n\tcells[lastPos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/12-infinite-loop/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\temptyCell        = \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/13-detect-winning/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/13-detect-winning/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/13-detect-winning/ending.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// -------------------------------------------------\n// IS THERE A WINNER? OR IS IT A TIE?\n// -------------------------------------------------\n\n// /---+---+---\\\n// | 0 | 1 | 2 |\n// +---+---+---+\n// | 3 | 4 | 5 |\n// +---+---+---+\n// | 6 | 7 | 8 |\n// \\---+---+---/\n\nfunc checkWinOrTie() {\n\t// intentional bug: tie shouldn't happen before winning detection\n\tif tie = turn == maxTurns; tie {\n\t\t// if tie don't check for the winning\n\t\treturn\n\t}\n\n\t// loop over all the players\n\tfor i := 1; i <= 2; i++ {\n\t\t// check for the next player\n\t\tp := player2\n\t\tif i == 1 {\n\t\t\tp = player1\n\t\t}\n\n\t\t/* check horizontals */\n\t\thor := (cells[0] == p && cells[1] == p && cells[2] == p) ||\n\t\t\t(cells[3] == p && cells[4] == p && cells[5] == p) ||\n\t\t\t(cells[6] == p && cells[7] == p && cells[8] == p)\n\n\t\t/* check verticals */\n\t\tver := (cells[0] == p && cells[3] == p && cells[6] == p) ||\n\t\t\t(cells[1] == p && cells[4] == p && cells[7] == p) ||\n\t\t\t(cells[2] == p && cells[5] == p && cells[8] == p)\n\n\t\t/* check diagonals */\n\t\tdiag := (cells[0] == p && cells[4] == p && cells[8] == p) ||\n\t\t\t(cells[2] == p && cells[4] == p && cells[6] == p)\n\n\t\t// any winner?\n\t\tif hor || ver || diag {\n\t\t\twon = true\n\n\t\t\t// this player wins\n\t\t\tplayer = p\n\n\t\t\t// there is a winner so don't check for tie!\n\t\t\treturn\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/13-detect-winning/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"math/rand\"\n\t\"time\"\n)\n\n// init is another special function\n// Go calls it before the main function\nfunc init() {\n\trand.Seed(time.Now().UnixNano())\n\tinitCells()\n}\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\tfor i := range cells {\n\t\tcells[i] = emptyCell\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/13-detect-winning/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon, tie bool      // is there any winner or a tie?\n\tturn     int       // total valid turns played\n\tplayer   = player1 // current player\n\n\tcells     [maxTurns]string // used to draw the board: contains the players' moves\n\tlastPos   int              // last played position\n\twrongMove bool             // was the last move wrong?\n)\n\n//\n// VERSION 2: HELPER FUNC\n//\nfunc main() {\n\tprintBoard()\n\twait()\n\n\tfor nextTurn() {\n\t\twait()\n\t}\n\n\t// loop forever until the game ends (tie or win)\n\t// for {\n\t// \t// wait()\n\t// \tif !nextTurn() {\n\t// \t\tbreak\n\t// \t}\n\t// }\n}\n\nfunc nextTurn() bool {\n\tplay()\n\tprintBoard()\n\n\tfmt.Printf(\"\\n>>> PLAYER %q PLAYS to %d\\n\", player, lastPos+1)\n\n\t// the switch below is about winning and tie conditions.\n\t// so it is good have checkWinOrTie() as a simple statement.\n\t// totally optional.\n\tswitch checkWinOrTie(); {\n\tdefault:\n\t\tswitchPlayer()\n\t\tprintStatus()\n\n\tcase wrongMove:\n\t\tfmt.Printf(\">>> CELL IS OCCUPIED: PLAY AGAIN!\\n\")\n\t\twrongMove = false // reset for the next turn\n\n\tcase won, tie:\n\t\tif won {\n\t\t\tfmt.Println(\">>> WINNER:\", player)\n\t\t} else {\n\t\t\tfmt.Println(\">>> TIE!\")\n\t\t}\n\t\treturn false\n\t}\n\treturn true\n}\n\n//\n// VERSION 1: LABELED BREAK\n//\n// func main() {\n// \tprintBoard()\n\n// \t// this a label: it can be used by break, continue and goto\n// theGameLoop:\n// \t// loop forever until game ends (tie or win)\n// \tfor {\n// \t\t// wait()\n// \t\tplay()\n// \t\tprintBoard()\n\n// \t\tfmt.Printf(\"\\n>>> PLAYER %q PLAYS to %d\\n\", player, lastPos+1)\n\n// \t\t// the switch below is about winning and tie conditions.\n// \t\t// so it is good have checkWinOrTie() as a simple statement.\n// \t\t// totally optional.\n// \t\tswitch checkWinOrTie(); {\n// \t\tdefault:\n// \t\t\tprintStatus()\n\n// \t\tcase wrongMove:\n// \t\t\tfmt.Printf(\">>> CELL IS OCCUPIED: PLAY AGAIN!\\n\")\n// \t\t\twrongMove = false // reset for the next turn\n\n// \t\tcase won, tie:\n// \t\t\tif won {\n// \t\t\t\tfmt.Println(\">>> WINNER:\", player)\n// \t\t\t} else {\n// \t\t\t\tfmt.Println(\">>> TIE!\")\n// \t\t\t}\n// \t\t\tbreak theGameLoop\n// \t\t}\n// \t}\n// }\n\nfunc wait() {\n\tfmt.Println()\n\tfmt.Scanln()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/13-detect-winning/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"math/rand\"\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// pick a random move (very intelligent AI!)\n\t// it can play to the same position!\n\tlastPos = rand.Intn(maxTurns)\n\n\t// is it a valid move?\n\tif cells[lastPos] != emptyCell {\n\t\twrongMove = true\n\n\t\t// skip the rest of the function from running\n\t\treturn\n\t}\n\n\t// register the move: put the player's sign on the board\n\tcells[lastPos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/13-detect-winning/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\temptyCell        = \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/ending.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// -------------------------------------------------\n// IS THERE A WINNER? OR IS IT A TIE?\n// -------------------------------------------------\n\n// /---+---+---\\\n// | 0 | 1 | 2 |\n// +---+---+---+\n// | 3 | 4 | 5 |\n// +---+---+---+\n// | 6 | 7 | 8 |\n// \\---+---+---/\n\nfunc checkWinOrTie() {\n\t// intentional bug: tie shouldn't happen before winning detection\n\t// if tie = turn == maxTurns; tie {\n\t// \t// if tie don't check for the winning\n\t// \treturn\n\t// }\n\n\t// loop over all the players\n\tfor i := 1; i <= 2; i++ {\n\t\t// check for the next player\n\t\tp := player2\n\t\tif i == 1 {\n\t\t\tp = player1\n\t\t}\n\n\t\t/* check horizontals */\n\t\thor := (cells[0] == p && cells[1] == p && cells[2] == p) ||\n\t\t\t(cells[3] == p && cells[4] == p && cells[5] == p) ||\n\t\t\t(cells[6] == p && cells[7] == p && cells[8] == p)\n\n\t\t/* check verticals */\n\t\tver := (cells[0] == p && cells[3] == p && cells[6] == p) ||\n\t\t\t(cells[1] == p && cells[4] == p && cells[7] == p) ||\n\t\t\t(cells[2] == p && cells[5] == p && cells[8] == p)\n\n\t\t/* check diagonals */\n\t\tdiag := (cells[0] == p && cells[4] == p && cells[8] == p) ||\n\t\t\t(cells[2] == p && cells[4] == p && cells[6] == p)\n\n\t\t// any winner?\n\t\tif hor || ver || diag {\n\t\t\twon = true\n\n\t\t\t// this player wins\n\t\t\tplayer = p\n\n\t\t\t// there is a winner so don't check for tie!\n\t\t\treturn\n\t\t}\n\t}\n\n\t// check for tie\n\ttie = turn == maxTurns\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/ending_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"testing\"\n\nfunc TestWin(t *testing.T) {\n\t// /---+---+---\\\n\t// | O | X | X |\n\t// +---+---+---+\n\t// | O | O | X |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tcells[0] = player2\n\tcells[1] = player1\n\tcells[2] = player1\n\tcells[3] = player2\n\tcells[4] = player2\n\tcells[5] = player1\n\tcells[6] = player1\n\tcells[7] = player2\n\tcells[8] = player1\n\tturn = maxTurns\n\n\tif checkWinOrTie(); !won {\n\t\tt.Errorf(\"won = %t; want true\", won)\n\t}\n\n\t// TestWin was messing up with the results.\n\t// Test ordering shouldn't be important.\n\tinitCells()\n}\n\nfunc TestTie(t *testing.T) {\n\t// /---+---+---\\\n\t// | O | X | X |\n\t// +---+---+---+\n\t// | X | O | O |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tcells[0] = player2\n\tcells[1] = player1\n\tcells[2] = player1\n\tcells[3] = player1\n\tcells[4] = player2\n\tcells[5] = player2\n\tcells[6] = player1\n\tcells[7] = player2\n\tcells[8] = player1\n\tturn = maxTurns\n\n\tif checkWinOrTie(); !tie {\n\t\tt.Errorf(\"tie = %t; want true\", tie)\n\t}\n\n\tinitCells()\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"math/rand\"\n\t\"time\"\n)\n\n// init is another special function\n// Go calls it before the main function\nfunc init() {\n\trand.Seed(time.Now().UnixNano())\n\tinitCells()\n}\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\tfor i := range cells {\n\t\tcells[i] = emptyCell\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst maxTurns = 9\n\nvar (\n\twon, tie bool      // is there any winner or a tie?\n\tturn     int       // total valid turns played\n\tplayer   = player1 // current player\n\n\tcells     [maxTurns]string // used to draw the board: contains the players' moves\n\tlastPos   int              // last played position\n\twrongMove bool             // was the last move wrong?\n)\n\n// main is only responsible for the game loop, that's it.\nfunc main() {\n\tprintBoard()\n\twait()\n\n\tfor nextTurn() {\n\t\twait()\n\t}\n}\n\n// nextTurn prints the board for the next turn and checks for the winning conditions.\n// if win or tie: returns false, otherwise true.\nfunc nextTurn() bool {\n\tplay()\n\tprintBoard()\n\n\tfmt.Printf(\"\\n>>> PLAYER %q PLAYS to %d\\n\", player, lastPos+1)\n\n\t// the switch below is about winning and tie conditions.\n\t// so it is good have checkWinOrTie() as a simple statement.\n\t// totally optional.\n\tswitch checkWinOrTie(); {\n\tdefault:\n\t\tswitchPlayer()\n\t\tprintStatus()\n\n\tcase wrongMove:\n\t\tfmt.Printf(\">>> CELL IS OCCUPIED: PLAY AGAIN!\\n\")\n\t\twrongMove = false // reset for the next turn\n\n\tcase won, tie:\n\t\tif won {\n\t\t\tfmt.Println(\">>> WINNER:\", player)\n\t\t} else {\n\t\t\tfmt.Println(\">>> TIE!\")\n\t\t}\n\t\treturn false\n\t}\n\treturn true\n}\n\nfunc wait() {\n\tfmt.Println()\n\tfmt.Scanln()\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"math/rand\"\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// pick a random move (very intelligent AI!)\n\t// it can play to the same position!\n\tlastPos = rand.Intn(maxTurns)\n\n\t// is it a valid move?\n\tif cells[lastPos] != emptyCell {\n\t\twrongMove = true\n\n\t\t// skip the rest of the function from running\n\t\treturn\n\t}\n\n\t// register the move: put the player's sign on the board\n\tcells[lastPos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/play_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"testing\"\n\nfunc TestWrongMove(t *testing.T) {\n\t// /---+---+---\\\n\t// | X | X | X |\n\t// +---+---+---+\n\t// | X | X | X |\n\t// +---+---+---+\n\t// | X | X | X |\n\t// \\---+---+---/\n\n\t// fill the board with artificial cells\n\tfor i := range cells {\n\t\tcells[i] = player1\n\t}\n\n\t// any move beyond this point is wrong.\n\t// reason: every cell is occupied.\n\tif play(); !wrongMove {\n\t\tt.Errorf(\"wrongMove = %t; want true\", wrongMove)\n\t}\n\n\tinitCells()\n}\n"
  },
  {
    "path": "x-tba/tictactoe/14-more-tests/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\temptyCell        = \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/ending.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// -------------------------------------------------\n// IS THERE A WINNER? OR IS IT A TIE?\n// -------------------------------------------------\n\n// /---+---+---\\\n// | 0 | 1 | 2 |\n// +---+---+---+\n// | 3 | 4 | 5 |\n// +---+---+---+\n// | 6 | 7 | 8 |\n// \\---+---+---/\n\nfunc checkWinOrTie() {\n\t// intentional bug: tie shouldn't happen before winning detection\n\t// if tie = turn == maxTurns; tie {\n\t// \t// if tie don't check for the winning\n\t// \treturn\n\t// }\n\n\t// loop over all the players\n\tfor i := 1; i <= 2; i++ {\n\t\t// check for the next player\n\t\tp := player2\n\t\tif i == 1 {\n\t\t\tp = player1\n\t\t}\n\n\t\t/* check horizontals */\n\t\thor := (cells[0] == p && cells[1] == p && cells[2] == p) ||\n\t\t\t(cells[3] == p && cells[4] == p && cells[5] == p) ||\n\t\t\t(cells[6] == p && cells[7] == p && cells[8] == p)\n\n\t\t/* check verticals */\n\t\tver := (cells[0] == p && cells[3] == p && cells[6] == p) ||\n\t\t\t(cells[1] == p && cells[4] == p && cells[7] == p) ||\n\t\t\t(cells[2] == p && cells[5] == p && cells[8] == p)\n\n\t\t/* check diagonals */\n\t\tdiag := (cells[0] == p && cells[4] == p && cells[8] == p) ||\n\t\t\t(cells[2] == p && cells[4] == p && cells[6] == p)\n\n\t\t// any winner?\n\t\tif hor || ver || diag {\n\t\t\twon = true\n\n\t\t\t// this player wins\n\t\t\tplayer = p\n\n\t\t\t// there is a winner so don't check for tie!\n\t\t\treturn\n\t\t}\n\t}\n\n\t// check for tie\n\ttie = turn == maxTurns\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/ending_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"testing\"\n\nfunc TestWin(t *testing.T) {\n\t// /---+---+---\\\n\t// | O | X | X |\n\t// +---+---+---+\n\t// | O | O | X |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tcells[0] = player2\n\tcells[1] = player1\n\tcells[2] = player1\n\tcells[3] = player2\n\tcells[4] = player2\n\tcells[5] = player1\n\tcells[6] = player1\n\tcells[7] = player2\n\tcells[8] = player1\n\tturn = maxTurns\n\n\tif checkWinOrTie(); !won {\n\t\tt.Errorf(\"won = %t; want true\", won)\n\t}\n\n\t// TestWin was messing up with the results.\n\t// Test ordering shouldn't be important.\n\tinitCells()\n}\n\nfunc TestTie(t *testing.T) {\n\t// /---+---+---\\\n\t// | O | X | X |\n\t// +---+---+---+\n\t// | X | O | O |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tcells[0] = player2\n\tcells[1] = player1\n\tcells[2] = player1\n\tcells[3] = player1\n\tcells[4] = player2\n\tcells[5] = player2\n\tcells[6] = player1\n\tcells[7] = player2\n\tcells[8] = player1\n\tturn = maxTurns\n\n\tif checkWinOrTie(); !tie {\n\t\tt.Errorf(\"tie = %t; want true\", tie)\n\t}\n\n\tinitCells()\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\n// init is another special function\n// Go calls it before the main function\nfunc init() {\n\trand.Seed(time.Now().UnixNano())\n\tinitCells()\n}\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\tfor i := range cells {\n\t\tcells[i] = emptyCell\n\t}\n}\n\nfunc setGameSpeed() {\n\t// args can be used within the if block\n\t// gs and err can be used in the else if and else branches\n\tif args := os.Args; len(args) == 1 {\n\t\tfmt.Println(\"Setting game speed to default.\")\n\t} else if gs, err := strconv.Atoi(args[1]); err != nil {\n\t\tfmt.Println(\"Wrong game speed. Provide an integer.\")\n\t} else {\n\t\tgameSpeed = time.Duration(gs) * time.Second\n\t}\n\n\tfmt.Printf(\"Game speed is %q.\\n\", gameSpeed)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst (\n\tmaxTurns         = 9\n\tdefaultGameSpeed = time.Second * 2 // time between plays\n)\n\nvar (\n\twon, tie bool // is there any winner or a tie?\n\tturn     int  // total valid turns played\n\n\tcells     [maxTurns]string // used to draw the board: contains the players' moves\n\tlastPos   int              // last played position\n\twrongMove bool             // was the last move wrong?\n\n\tplayer    = player1          // current player\n\tgameSpeed = defaultGameSpeed // sets the default game speed\n)\n\n// main is only responsible for the game loop, that's it.\nfunc main() {\n\tsetGameSpeed()\n\tprintBoard()\n\twait()\n\n\tfor nextTurn() {\n\t\twait()\n\t}\n}\n\nfunc wait() {\n\tfmt.Println()\n\ttime.Sleep(gameSpeed) // player thinks...\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"math/rand\"\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// pick a random move (very intelligent AI!)\n\t// it can play to the same position!\n\tlastPos = rand.Intn(maxTurns)\n\n\t// is it a valid move?\n\tif cells[lastPos] != emptyCell {\n\t\twrongMove = true\n\n\t\t// skip the rest of the function from running\n\t\treturn\n\t}\n\n\t// register the move: put the player's sign on the board\n\tcells[lastPos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/play_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"testing\"\n\nfunc TestWrongMove(t *testing.T) {\n\t// /---+---+---\\\n\t// | X | X | X |\n\t// +---+---+---+\n\t// | X | X | X |\n\t// +---+---+---+\n\t// | X | X | X |\n\t// \\---+---+---/\n\n\t// fill the board with artificial cells\n\tfor i := range cells {\n\t\tcells[i] = player1\n\t}\n\n\t// any move beyond this point is wrong.\n\t// reason: every cell is occupied.\n\tif play(); !wrongMove {\n\t\tt.Errorf(\"wrongMove = %t; want true\", wrongMove)\n\t}\n\n\tinitCells()\n}\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\t// skin options :-)\n\tplayer1, player2 = \"X\", \"O\"\n\temptyCell        = \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/15-os-args/turn.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// nextTurn prints the board for the next turn and checks for the winning conditions.\n// if win or tie: returns false, otherwise true.\nfunc nextTurn() bool {\n\tplay()\n\tprintBoard()\n\n\tfmt.Printf(\"\\n>>> PLAYER %q PLAYS to %d\\n\", player, lastPos+1)\n\n\t// the switch below is about winning and tie conditions.\n\t// so it is good have checkWinOrTie() as a simple statement.\n\t// totally optional.\n\tswitch checkWinOrTie(); {\n\tdefault:\n\t\tswitchPlayer()\n\t\tprintStatus()\n\n\tcase wrongMove:\n\t\tfmt.Printf(\">>> CELL IS OCCUPIED: PLAY AGAIN!\\n\")\n\t\twrongMove = false // reset for the next turn\n\n\tcase won, tie:\n\t\tif won {\n\t\t\tfmt.Println(\">>> WINNER:\", player)\n\t\t} else {\n\t\t\tfmt.Println(\">>> TIE!\")\n\t\t}\n\t\treturn false\n\t}\n\treturn true\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/board.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// printBoard prints the board\nfunc printBoard() {\n\tfmt.Printf(\"%s\\n\\n\", banner)\n\tfmt.Printf(\"%s\\n\", sepHeader)\n\n\tfor i, step := 0, 3; i < len(cells); i += step {\n\t\tfmt.Print(sepCell)\n\n\t\tfor j := 0; j < step; j++ {\n\t\t\tmove := cells[i+j]\n\t\t\tfmt.Printf(\" %s %s\", move, sepCell)\n\t\t}\n\n\t\tfmt.Println()\n\n\t\tif lastLine := (i + step); lastLine != len(cells) {\n\t\t\tfmt.Println(sepLine)\n\t\t}\n\t}\n\n\tfmt.Printf(\"%s\\n\", sepFooter)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/board_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// Examples are normally used for showing how to use your package.\n// But you can also use them as output testing.\n\nfunc ExamplePrintBoard() {\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// +---+---+---+\n\t// |   |   |   |\n\t// \\---+---+---/\n}\n\nfunc ExamplePrintBoardCells() {\n\tcells[0] = player1\n\tcells[4] = player2\n\tcells[8] = player1\n\tprintBoard()\n\n\t// Output:\n\t// ~~~~~~~~~~~~~~~\n\t//   TIC~TAC~TOE\n\t// ~~~~~~~~~~~~~~~\n\t//\n\t// /---+---+---\\\n\t// | X |   |   |\n\t// +---+---+---+\n\t// |   | O |   |\n\t// +---+---+---+\n\t// |   |   | X |\n\t// \\---+---+---/\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/ending.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// -------------------------------------------------\n// IS THERE A WINNER? OR IS IT A TIE?\n// -------------------------------------------------\n\n// /---+---+---\\\n// | 0 | 1 | 2 |\n// +---+---+---+\n// | 3 | 4 | 5 |\n// +---+---+---+\n// | 6 | 7 | 8 |\n// \\---+---+---/\n\nfunc checkWinOrTie() {\n\t// intentional bug: tie shouldn't happen before winning detection\n\t// if tie = turn == maxTurns; tie {\n\t// \t// if tie don't check for the winning\n\t// \treturn\n\t// }\n\n\t// loop over all the players\n\tfor i := 1; i <= 2; i++ {\n\t\t// check for the next player\n\t\tp := player2\n\t\tif i == 1 {\n\t\t\tp = player1\n\t\t}\n\n\t\t/* check horizontals */\n\t\thor := (cells[0] == p && cells[1] == p && cells[2] == p) ||\n\t\t\t(cells[3] == p && cells[4] == p && cells[5] == p) ||\n\t\t\t(cells[6] == p && cells[7] == p && cells[8] == p)\n\n\t\t/* check verticals */\n\t\tver := (cells[0] == p && cells[3] == p && cells[6] == p) ||\n\t\t\t(cells[1] == p && cells[4] == p && cells[7] == p) ||\n\t\t\t(cells[2] == p && cells[5] == p && cells[8] == p)\n\n\t\t/* check diagonals */\n\t\tdiag := (cells[0] == p && cells[4] == p && cells[8] == p) ||\n\t\t\t(cells[2] == p && cells[4] == p && cells[6] == p)\n\n\t\t// any winner?\n\t\tif hor || ver || diag {\n\t\t\twon = true\n\n\t\t\t// this player wins\n\t\t\tplayer = p\n\n\t\t\t// there is a winner so don't check for tie!\n\t\t\treturn\n\t\t}\n\t}\n\n\t// check for tie\n\ttie = turn == maxTurns\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/ending_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"testing\"\n\nfunc TestWin(t *testing.T) {\n\t// /---+---+---\\\n\t// | O | X | X |\n\t// +---+---+---+\n\t// | O | O | X |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tcells[0] = player2\n\tcells[1] = player1\n\tcells[2] = player1\n\tcells[3] = player2\n\tcells[4] = player2\n\tcells[5] = player1\n\tcells[6] = player1\n\tcells[7] = player2\n\tcells[8] = player1\n\tturn = maxTurns\n\n\tif checkWinOrTie(); !won {\n\t\tt.Errorf(\"won = %t; want true\", won)\n\t}\n\n\t// TestWin was messing up with the results.\n\t// Test ordering shouldn't be important.\n\tinitCells()\n}\n\nfunc TestTie(t *testing.T) {\n\t// /---+---+---\\\n\t// | O | X | X |\n\t// +---+---+---+\n\t// | X | O | O |\n\t// +---+---+---+\n\t// | X | O | X |\n\t// \\---+---+---/\n\n\tcells[0] = player2\n\tcells[1] = player1\n\tcells[2] = player1\n\tcells[3] = player1\n\tcells[4] = player2\n\tcells[5] = player2\n\tcells[6] = player1\n\tcells[7] = player2\n\tcells[8] = player1\n\tturn = maxTurns\n\n\tif checkWinOrTie(); !tie {\n\t\tt.Errorf(\"tie = %t; want true\", tie)\n\t}\n\n\tinitCells()\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/init.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"os\"\n\t\"strconv\"\n\t\"time\"\n)\n\n// init is another special function\n// Go calls it before the main function\nfunc init() {\n\trand.Seed(time.Now().UnixNano())\n\tinitCells()\n}\n\n// initCells initialize the played cells to empty\nfunc initCells() {\n\tfor i := range cells {\n\t\tcells[i] = emptyCell\n\t}\n}\n\nfunc setGameSpeed() {\n\t// args can be used within the if block\n\t// gs and err can be used in the else if and else branches\n\tif args := os.Args; len(args) == 1 {\n\t\tfmt.Println(\"Setting game speed to default.\")\n\t} else if gs, err := strconv.Atoi(args[1]); err != nil {\n\t\tfmt.Println(\"Wrong game speed. Provide an integer.\")\n\t} else {\n\t\tgameSpeed = time.Duration(gs) * time.Second\n\t}\n\n\tfmt.Printf(\"Game speed is %q.\\n\", gameSpeed)\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\n/*\n~ TICTACTOE GAME IN GO ~\n+ This example uses the very basics of the Go language.\n+ The goal is learning all the basics.\n*/\n\nconst (\n\tmaxTurns         = 9\n\tdefaultGameSpeed = time.Second * 2 // time between plays\n)\n\nvar (\n\twon, tie bool // is there any winner or a tie?\n\tturn     int  // total valid turns played\n\n\tcells     [maxTurns]cell // used to draw the board: contains the players' moves\n\tlastPos   int            // last played position\n\twrongMove bool           // was the last move wrong?\n\n\tplayer    = player1          // current player\n\tgameSpeed = defaultGameSpeed // sets the default game speed\n)\n\n// main is only responsible for the game loop, that's it.\nfunc main() {\n\tsetGameSpeed()\n\tprintBoard()\n\twait()\n\n\tfor nextTurn() {\n\t\twait()\n\t}\n}\n\nfunc wait() {\n\tfmt.Println()\n\ttime.Sleep(gameSpeed) // player thinks...\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/play.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"math/rand\"\n\n// play plays the game for the current player.\n// + registers the player's move in the board.\n// if the move is valid:\n// + increases the turn.\nfunc play() {\n\t// pick a random move (very intelligent AI!)\n\t// it can play to the same position!\n\tlastPos = rand.Intn(maxTurns)\n\n\t// is it a valid move?\n\tif cells[lastPos] != emptyCell {\n\t\twrongMove = true\n\n\t\t// skip the rest of the function from running\n\t\treturn\n\t}\n\n\t// register the move: put the player's sign on the board\n\tcells[lastPos] = player\n\n\t// increment the current turns\n\tturn++\n}\n\n// switchPlayer switches to the next player\nfunc switchPlayer() {\n\t// switch the player\n\tif player == player1 {\n\t\tplayer = player2\n\t} else {\n\t\tplayer = player1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/play_test.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"testing\"\n\nfunc TestWrongMove(t *testing.T) {\n\t// /---+---+---\\\n\t// | X | X | X |\n\t// +---+---+---+\n\t// | X | X | X |\n\t// +---+---+---+\n\t// | X | X | X |\n\t// \\---+---+---/\n\n\t// fill the board with artificial cells\n\tfor i := range cells {\n\t\tcells[i] = player1\n\t}\n\n\t// any move beyond this point is wrong.\n\t// reason: every cell is occupied.\n\tif play(); !wrongMove {\n\t\tt.Errorf(\"wrongMove = %t; want true\", wrongMove)\n\t}\n\n\tinitCells()\n}\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/skin.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\n// cell represents a tictactoe board cell\ntype cell string\n\n// skin options :-)\nconst (\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~`\n\n\tplayer1, player2, emptyCell cell = \"X\", \"O\", \" \"\n\n\tsepHeader = `/---+---+---\\`\n\tsepLine   = `+---+---+---+`\n\tsepFooter = `\\---+---+---/`\n\tsepCell   = \"|\"\n)\n"
  },
  {
    "path": "x-tba/tictactoe/16-types/turn.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"fmt\"\n\n// nextTurn prints the board for the next turn and checks for the winning conditions.\n// if win or tie: returns false, otherwise true.\nfunc nextTurn() bool {\n\tplay()\n\tprintBoard()\n\n\tfmt.Printf(\"\\n>>> PLAYER %q PLAYS to %d\\n\", player, lastPos+1)\n\n\t// the switch below is about winning and tie conditions.\n\t// so it is good have checkWinOrTie() as a simple statement.\n\t// totally optional.\n\tswitch checkWinOrTie(); {\n\tdefault:\n\t\tswitchPlayer()\n\t\tprintStatus()\n\n\tcase wrongMove:\n\t\tfmt.Printf(\">>> CELL IS OCCUPIED: PLAY AGAIN!\\n\")\n\t\twrongMove = false // reset for the next turn\n\n\tcase won, tie:\n\t\tif won {\n\t\t\tfmt.Println(\">>> WINNER:\", player)\n\t\t} else {\n\t\t\tfmt.Println(\">>> TIE!\")\n\t\t}\n\t\treturn false\n\t}\n\treturn true\n}\n\n// printStatus prints the current status of the game\n// it cannot access to the names (vars, consts, etc) inside any other func\nfunc printStatus() {\n\tfmt.Println()\n\n\tprogress := (1 - (float64(turn) / maxTurns)) * 100\n\tfmt.Printf(\"Current Turn           : %d\\n\", turn)\n\tfmt.Printf(\"Is there a winner      : %t\\n\", won)\n\tfmt.Printf(\"Turns left             : %.1f%%\\n\", progress)\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/00-without-bufio/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"strings\"\n\t\"time\"\n\n\trainbow \"github.com/guineveresaenger/golang-rainbow\"\n)\n\nconst (\n\tmaxTurn = 9\n\n\t// skin options :-)\n\tempty     = \"   \"\n\tplayer1   = \" X \"\n\tplayer2   = \" O \"\n\theader    = \"---+---+---\"\n\tfooter    = \"---+---+---\"\n\tseparator = \"|\"\n\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE \n~~~~~~~~~~~~~~~`\n)\n\n// -------------------------------------------------\n// INITIALIZE THE GAME\n// -------------------------------------------------\nvar (\n\tturn int\n\twon  bool\n\n\tboard = [][]string{\n\t\t{empty, empty, empty},\n\t\t{empty, empty, empty},\n\t\t{empty, empty, empty},\n\t}\n\n\tplayer = player1\n)\n\nfunc main() {\n\trand.Seed(time.Now().UnixNano())\n\trainbow.Rainbow(banner, strings.Count(banner, \"\\n\"))\n\n\tfor {\n\t\t// -------------------------------------------------\n\t\t// PRINT THE BOARD AND THE PROMPT\n\t\t// -------------------------------------------------\n\t\tfmt.Printf(\"\\n %s\\n\", header)\n\t\tfor _, line := range board {\n\t\t\tfmt.Printf(\" %s\\n\", strings.Join(line, separator))\n\t\t\tfmt.Printf(\" %s\\n\", footer)\n\t\t}\n\n\t\t// -------------------------------------------------\n\t\t// IS THERE A WINNER? OR IS IT A TIE?\n\t\t// -------------------------------------------------\n\t\tfor i := 1; i <= 2; i++ {\n\t\t\tm := player2\n\t\t\tif i == 1 {\n\t\t\t\tm = player1\n\t\t\t}\n\n\t\t\tb, mmm := board, strings.Repeat(m, 3)\n\n\t\t\t/* horizontals */\n\t\t\thor := strings.Join(b[0], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[1], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[2], \"\") == mmm\n\n\t\t\t\t/* verticals */\n\t\t\tver := b[0][0]+b[1][0]+b[2][0] == mmm ||\n\t\t\t\tb[0][1]+b[1][1]+b[2][1] == mmm ||\n\t\t\t\tb[0][2]+b[1][2]+b[2][2] == mmm\n\n\t\t\t\t/* diagonals */\n\t\t\tdiag := b[0][0]+b[1][1]+b[2][2] == mmm ||\n\t\t\t\tb[0][2]+b[1][1]+b[2][0] == mmm\n\n\t\t\twon = hor || ver || diag\n\n\t\t\tif won {\n\t\t\t\tplayer = m\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif won {\n\t\t\tplayer = strings.TrimSpace(player)\n\t\t\tfmt.Printf(\"\\n>>> WINNER: %s\\n\", player)\n\t\t\tbreak\n\t\t} else if turn == maxTurn {\n\t\t\tfmt.Printf(\"\\n>>> TIE!\\n\")\n\t\t\tbreak\n\t\t}\n\n\t\t// -------------------------------------------------\n\t\t// PLAY\n\t\t// -------------------------------------------------\n\n\t\tpos := rand.Intn(9) + 1\n\t\tfmt.Printf(\"\\nPlayer %s plays to %d\\n\", player, pos)\n\n\t\t// -------------------------------------------------\n\t\t// IS IT A VALID MOVE?\n\t\t// -------------------------------------------------\n\n\t\tvar row int\n\t\tswitch {\n\t\tcase pos <= 3:\n\t\t\trow = 0\n\t\tcase pos <= 6:\n\t\t\trow = 1\n\t\tcase pos <= 9:\n\t\t\trow = 2\n\t\tdefault:\n\t\t\tfmt.Println(\">>>\", \"wrong position!\")\n\t\t\tcontinue\n\t\t}\n\n\t\tcol := pos - row*3 - 1\n\n\t\tif board[row][col] != empty {\n\t\t\tfmt.Println(\">>>\", \"already played!\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// -------------------------------------------------\n\t\t// MARK THE MOVE AND INCREMENT THE TURN\n\t\t// -------------------------------------------------\n\n\t\t// put a mark on the board\n\t\tboard[row][col] = player\n\n\t\t// switch to the next player\n\t\tif player == player1 {\n\t\t\tplayer = player2\n\t\t} else {\n\t\t\tplayer = player1\n\t\t}\n\n\t\tturn++\n\t\t// time.Sleep(time.Millisecond * 100)\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/01-without-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n\n\trainbow \"github.com/guineveresaenger/golang-rainbow\"\n)\n\nconst (\n\tmaxTurn = 9\n\n\t// skin options :-)\n\tempty     = \"   \"\n\tplayer1   = \" X \"\n\tplayer2   = \" O \"\n\theader    = \"---+---+---\"\n\tfooter    = \"---+---+---\"\n\tseparator = \"|\"\n\n\tbanner = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE \n~~~~~~~~~~~~~~~`\n)\n\n// -------------------------------------------------\n// INITIALIZE THE GAME\n// -------------------------------------------------\nvar (\n\tturn int\n\twon  bool\n\n\tboard = [3][3]string{\n\t\t{empty, empty, empty},\n\t\t{empty, empty, empty},\n\t\t{empty, empty, empty},\n\t}\n\n\tplayer = player1\n\n\t// for saving the replay.log\n\tinputs []byte\n)\n\nfunc main() {\n\trainbow.Rainbow(banner, strings.Count(banner, \"\\n\"))\n\n\tin := bufio.NewScanner(os.Stdin)\n\tfor {\n\t\t// -------------------------------------------------\n\t\t// PRINT THE BOARD AND THE PROMPT\n\t\t// -------------------------------------------------\n\t\tfmt.Printf(\"\\n %s\\n\", header)\n\t\tfor _, line := range board {\n\t\t\tfmt.Printf(\" %s\\n\", strings.Join(line[:], separator))\n\t\t\tfmt.Printf(\" %s\\n\", footer)\n\t\t}\n\n\t\t// -------------------------------------------------\n\t\t// IS THERE A WINNER? OR IS IT A TIE?\n\t\t// -------------------------------------------------\n\t\tfor _, m := range [2]string{player1, player2} {\n\t\t\tb, mmm := board, strings.Repeat(m, 3)\n\n\t\t\twon = /* horizontals */\n\t\t\t\tstrings.Join(b[0][:], \"\") == mmm ||\n\t\t\t\t\tstrings.Join(b[1][:], \"\") == mmm ||\n\t\t\t\t\tstrings.Join(b[2][:], \"\") == mmm ||\n\n\t\t\t\t\t/* verticals */\n\t\t\t\t\tb[0][0]+b[1][0]+b[2][0] == mmm ||\n\t\t\t\t\tb[0][1]+b[1][1]+b[2][1] == mmm ||\n\t\t\t\t\tb[0][2]+b[1][2]+b[2][2] == mmm ||\n\n\t\t\t\t\t/* diagonals */\n\t\t\t\t\tb[0][0]+b[1][1]+b[2][2] == mmm ||\n\t\t\t\t\tb[0][2]+b[1][1]+b[2][0] == mmm\n\n\t\t\tif won {\n\t\t\t\tplayer = m\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif won {\n\t\t\tplayer = strings.TrimSpace(player)\n\t\t\tfmt.Printf(\"\\n>>> WINNER: %s\\n\", player)\n\t\t\tbreak\n\t\t} else if turn++; turn == maxTurn+1 {\n\t\t\tfmt.Printf(\"\\n>>> TIE!\\n\")\n\t\t\tbreak\n\t\t}\n\n\t\t// -------------------------------------------------\n\t\t// CHECK THE MOVE AND PLAY\n\t\t// -------------------------------------------------\n\n\t\t// get the input\n\t\tfmt.Printf(\"\\nPLAYER: %q [1-9]: \", player)\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\t// Atoi already return 0 on error; no need to check\n\t\t// it for the following switch to work\n\t\tpos, _ := strconv.Atoi(in.Text())\n\n\t\t// Save the input for replaying\n\t\tinputs = append(inputs, byte(pos+48), '\\n')\n\n\t\tvar row int\n\t\tswitch {\n\t\tcase pos >= 1 && pos <= 3:\n\t\t\trow = 0\n\t\tcase pos >= 4 && pos <= 6:\n\t\t\trow = 1\n\t\tcase pos >= 7 && pos <= 9:\n\t\t\trow = 2\n\t\tdefault:\n\t\t\tfmt.Println(\"\\n>>>\", \"wrong position!\")\n\t\t\tcontinue\n\t\t}\n\n\t\tcol := pos - row*3 - 1\n\n\t\tif board[row][col] != empty {\n\t\t\tfmt.Println(\"\\n>>>\", \"already played!\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// put a mark on the board\n\t\tboard[row][col] = player\n\n\t\t// switch to the next player\n\t\tif player == player1 {\n\t\t\tplayer = player2\n\t\t} else {\n\t\t\tplayer = player1\n\t\t}\n\t}\n\n\tif err := ioutil.WriteFile(\"replay.log\", inputs, 0644); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"Cannot save replay: %v\", err)\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/02-with-funcs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst (\n\t// skin options :-)\n\temptyMark = \"☆\"\n\tmark1     = \"💀\"\n\tmark2     = \"🎈\"\n\tbanner    = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE \n~~~~~~~~~~~~~~~`\n\n\tmaxTurn = 9\n)\n\nfunc main() {\n\tfmt.Println(banner)\n\n\tloop(bufio.NewScanner(os.Stdin))\n}\n\nfunc loop(in *bufio.Scanner) {\n\tvar (\n\t\tturn   int\n\t\tplayer = mark1\n\t\tboard  = createBoard()\n\t)\n\n\tfor {\n\t\tprompt(board, player)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tmsg := play(board, player, getMove(in.Text()))\n\t\tif msg != \"\" {\n\t\t\tfmt.Println(\"\\n>>>\", msg)\n\t\t\tcontinue\n\t\t}\n\n\t\tturn++\n\t\tif msg := finito(board, turn, player); msg != \"\" {\n\t\t\tprintBoard(board, player)\n\t\t\tfmt.Printf(\"\\n%s\\n\", msg)\n\t\t\tbreak\n\t\t}\n\n\t\tplayer = switchTo(player)\n\t}\n}\n\nfunc createBoard() [][]string {\n\treturn [][]string{\n\t\t{emptyMark, emptyMark, emptyMark},\n\t\t{emptyMark, emptyMark, emptyMark},\n\t\t{emptyMark, emptyMark, emptyMark},\n\t}\n}\n\nfunc prompt(board [][]string, player string) {\n\tprintBoard(board, player)\n\tfmt.Printf(\"\\n%s [1-9]: \", player)\n}\n\nfunc printBoard(board [][]string, player string) {\n\tfmt.Println()\n\tfmt.Println(\"---+----+---\")\n\tfor _, line := range board {\n\t\tfmt.Printf(\"%s\\n\", strings.Join(line, \"  | \"))\n\t\tfmt.Println(\"---+----+---\")\n\t}\n}\n\nfunc getMove(move string) int {\n\t// Atoi already return 0 on error; no need to check\n\t// it for the following switch to work\n\tpos, _ := strconv.Atoi(move)\n\treturn pos\n}\n\nfunc play(board [][]string, player string, pos int) string {\n\tvar row int\n\n\tswitch {\n\tcase pos >= 7 && pos <= 9:\n\t\trow = 2\n\tcase pos >= 4 && pos <= 6:\n\t\trow = 1\n\tcase pos >= 1 && pos <= 3:\n\t\trow = 0\n\tdefault:\n\t\treturn \"wrong position\"\n\t}\n\n\tcol := pos - row*3 - 1\n\n\tif board[row][col] != emptyMark {\n\t\treturn \"already played!\"\n\t}\n\n\t// put the player\n\tboard[row][col] = player\n\n\treturn \"\"\n}\n\nfunc finito(board [][]string, turn int, player string) string {\n\tswitch {\n\tcase won(board):\n\t\treturn fmt.Sprintf(\"WINNER: %s\", player)\n\tcase turn == maxTurn:\n\t\treturn \"TIE!\"\n\t}\n\treturn \"\"\n}\n\nfunc won(board [][]string) (won bool) {\n\tfor _, m := range [2]string{mark1, mark2} {\n\t\tb, mmm := board, strings.Repeat(m, 3)\n\n\t\twon = /* horizontals */\n\t\t\tstrings.Join(b[0], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[1], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[2], \"\") == mmm ||\n\n\t\t\t\t/* verticals */\n\t\t\t\tb[0][0]+b[1][0]+b[2][0] == mmm ||\n\t\t\t\tb[0][1]+b[1][1]+b[2][1] == mmm ||\n\t\t\t\tb[0][2]+b[1][2]+b[2][2] == mmm ||\n\n\t\t\t\t/* diagonals */\n\t\t\t\tb[0][0]+b[1][1]+b[2][2] == mmm ||\n\t\t\t\tb[0][2]+b[1][1]+b[2][0] == mmm\n\n\t\tif won {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc switchTo(player string) string {\n\tif player == mark1 {\n\t\treturn mark2\n\t}\n\treturn mark1\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/03-with-structs/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst (\n\t// skin options :-)\n\temptyMark = \"☆\"\n\tmark1     = \"💀\"\n\tmark2     = \"🎈\"\n\tbanner    = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE \n~~~~~~~~~~~~~~~`\n\n\tmaxTurn = 9\n)\n\ntype game struct {\n\tboard  [][]string\n\tturn   int\n\tplayer string\n}\n\nfunc main() {\n\tfmt.Println(banner)\n\n\tloop(bufio.NewScanner(os.Stdin))\n}\n\nfunc loop(in *bufio.Scanner) {\n\tg := game{\n\t\tplayer: mark1,\n\t\tboard:  createBoard(),\n\t}\n\n\tfor {\n\t\tprompt(g)\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\tmsg := play(g, getMove(in.Text()))\n\t\tif msg != \"\" {\n\t\t\tfmt.Println(\"\\n>>>\", msg)\n\t\t\tcontinue\n\t\t}\n\n\t\tg.turn++\n\t\tif msg := finito(g); msg != \"\" {\n\t\t\tprintBoard(g.board)\n\t\t\tfmt.Printf(\"\\n%s\\n\", msg)\n\t\t\tbreak\n\t\t}\n\n\t\tg.player = switchTo(g.player)\n\t}\n}\n\nfunc createBoard() [][]string {\n\treturn [][]string{\n\t\t{emptyMark, emptyMark, emptyMark},\n\t\t{emptyMark, emptyMark, emptyMark},\n\t\t{emptyMark, emptyMark, emptyMark},\n\t}\n}\n\nfunc prompt(g game) {\n\tprintBoard(g.board)\n\tfmt.Printf(\"\\n%s [1-9]: \", g.player)\n}\n\nfunc printBoard(board [][]string) {\n\tfmt.Println()\n\tfmt.Println(\"---+----+---\")\n\tfor _, line := range board {\n\t\tfmt.Printf(\"%s\\n\", strings.Join(line, \"  | \"))\n\t\tfmt.Println(\"---+----+---\")\n\t}\n}\n\nfunc getMove(move string) int {\n\t// Atoi already return 0 on error; no need to check\n\t// it for the following switch to work\n\tpos, _ := strconv.Atoi(move)\n\treturn pos\n}\n\n// NOTE: manipulates the game object\nfunc play(g game, pos int) string {\n\tvar row int\n\n\tswitch {\n\tcase pos >= 7 && pos <= 9:\n\t\trow = 2\n\tcase pos >= 4 && pos <= 6:\n\t\trow = 1\n\tcase pos >= 1 && pos <= 3:\n\t\trow = 0\n\tdefault:\n\t\treturn \"wrong position\"\n\t}\n\n\tcol := pos - row*3 - 1\n\n\tif g.board[row][col] != emptyMark {\n\t\treturn \"already played!\"\n\t}\n\n\t// put the player\n\tg.board[row][col] = g.player\n\n\treturn \"\"\n}\n\nfunc finito(g game) string {\n\tswitch {\n\tcase won(g.board):\n\t\treturn fmt.Sprintf(\"WINNER: %s\", g.player)\n\tcase g.turn == maxTurn:\n\t\treturn \"TIE!\"\n\t}\n\treturn \"\"\n}\n\nfunc won(board [][]string) (won bool) {\n\tfor _, m := range [2]string{mark1, mark2} {\n\t\tb, mmm := board, strings.Repeat(m, 3)\n\n\t\twon = /* horizontals */\n\t\t\tstrings.Join(b[0], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[1], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[2], \"\") == mmm ||\n\n\t\t\t\t/* verticals */\n\t\t\t\tb[0][0]+b[1][0]+b[2][0] == mmm ||\n\t\t\t\tb[0][1]+b[1][1]+b[2][1] == mmm ||\n\t\t\t\tb[0][2]+b[1][2]+b[2][2] == mmm ||\n\n\t\t\t\t/* diagonals */\n\t\t\t\tb[0][0]+b[1][1]+b[2][2] == mmm ||\n\t\t\t\tb[0][2]+b[1][1]+b[2][0] == mmm\n\n\t\tif won {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc switchTo(player string) string {\n\tif player == mark1 {\n\t\treturn mark2\n\t}\n\treturn mark1\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/04-with-methods/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nconst (\n\t// skin options :-)\n\temptyMark = \"☆\"\n\tmark1     = \"💀\"\n\tmark2     = \"🎈\"\n\tbanner    = `\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE \n~~~~~~~~~~~~~~~`\n\n\tmaxTurn = 9\n)\n\nfunc main() {\n\tfmt.Println(banner)\n\n\tloop(bufio.NewScanner(os.Stdin))\n}\n\ntype game struct {\n\tboard  [][]string\n\tturn   int\n\tplayer string\n}\n\nfunc loop(in *bufio.Scanner) {\n\tg := newGame()\n\n\tfor {\n\t\tg.prompt()\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\t// Atoi already return 0 on error; no need to check\n\t\t// it for the following switch to work\n\t\tpos, _ := strconv.Atoi(in.Text())\n\n\t\tmsg := g.play(pos)\n\t\tif msg != \"\" {\n\t\t\tfmt.Println(\"\\n>>>\", msg)\n\t\t\tcontinue\n\t\t}\n\n\t\tg.turn++\n\t\tif msg := g.finito(); msg != \"\" {\n\t\t\tg.print()\n\t\t\tfmt.Printf(\"\\n%s\\n\", msg)\n\t\t\tbreak\n\t\t}\n\n\t\tg.player = switchTo(g.player)\n\t}\n}\n\nfunc newGame() game {\n\treturn game{\n\t\tplayer: mark1,\n\t\tboard: [][]string{\n\t\t\t{emptyMark, emptyMark, emptyMark},\n\t\t\t{emptyMark, emptyMark, emptyMark},\n\t\t\t{emptyMark, emptyMark, emptyMark},\n\t\t},\n\t}\n}\n\nfunc (g game) prompt() {\n\tg.print()\n\tfmt.Printf(\"\\n%s [1-9]: \", g.player)\n}\n\nfunc (g game) print() {\n\tfmt.Println()\n\tfmt.Println(\"---+----+---\")\n\tfor _, line := range g.board {\n\t\tfmt.Printf(\"%s\\n\", strings.Join(line, \"  | \"))\n\t\tfmt.Println(\"---+----+---\")\n\t}\n}\n\nfunc (g game) play(pos int) string {\n\tvar row int\n\n\tswitch {\n\tcase pos >= 7 && pos <= 9:\n\t\trow = 2\n\tcase pos >= 4 && pos <= 6:\n\t\trow = 1\n\tcase pos >= 1 && pos <= 3:\n\t\trow = 0\n\tdefault:\n\t\treturn \"wrong position\"\n\t}\n\n\tcol := pos - row*3 - 1\n\n\tif g.board[row][col] != emptyMark {\n\t\treturn \"already played!\"\n\t}\n\n\t// put the player\n\tg.board[row][col] = g.player\n\n\treturn \"\"\n}\n\nfunc (g game) finito() string {\n\tswitch {\n\tcase g.won():\n\t\treturn fmt.Sprintf(\"WINNER: %s\", g.player)\n\tcase g.turn == maxTurn:\n\t\treturn \"TIE!\"\n\t}\n\treturn \"\"\n}\n\nfunc (g game) won() (won bool) {\n\tfor _, m := range [2]string{mark1, mark2} {\n\t\tb, mmm := g.board, strings.Repeat(m, 3)\n\n\t\twon = /* horizontals */\n\t\t\tstrings.Join(b[0], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[1], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[2], \"\") == mmm ||\n\n\t\t\t\t/* verticals */\n\t\t\t\tb[0][0]+b[1][0]+b[2][0] == mmm ||\n\t\t\t\tb[0][1]+b[1][1]+b[2][1] == mmm ||\n\t\t\t\tb[0][2]+b[1][2]+b[2][2] == mmm ||\n\n\t\t\t\t/* diagonals */\n\t\t\t\tb[0][0]+b[1][1]+b[2][2] == mmm ||\n\t\t\t\tb[0][2]+b[1][1]+b[2][0] == mmm\n\n\t\tif won {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc switchTo(player string) string {\n\tif player == mark1 {\n\t\treturn mark2\n\t}\n\treturn mark1\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/05-with-pointers/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(`\n~~~~~~~~~~~~~~~\n  TIC~TAC~TOE \n~~~~~~~~~~~~~~~`)\n\n\tloop(bufio.NewScanner(os.Stdin))\n}\n\nconst (\n\t// skin options :-)\n\temptyMark = \"☆\"\n\tmark1     = \"💀\"\n\tmark2     = \"🎈\"\n\n\tmaxTurn = 9\n)\n\ntype game struct {\n\tboard  [][]string\n\tturn   int\n\tplayer string\n\n\tbuf strings.Builder\n}\n\nfunc loop(in *bufio.Scanner) {\n\tg := newGame()\n\n\tfor {\n\t\tg.prompt()\n\n\t\tif !in.Scan() {\n\t\t\tbreak\n\t\t}\n\n\t\t// Atoi already return 0 on error; no need to check\n\t\t// it for the following switch to work\n\t\tpos, _ := strconv.Atoi(in.Text())\n\n\t\tmsg := g.play(pos)\n\t\tif msg != \"\" {\n\t\t\tfmt.Println(\"\\n>>>\", msg)\n\t\t\tcontinue\n\t\t}\n\n\t\tif msg := g.finito(); msg != \"\" {\n\t\t\tfmt.Printf(\"\\n%s%s\\n\", g, msg)\n\t\t\tbreak\n\t\t}\n\n\t\tg.next()\n\t}\n}\n\nfunc newGame() *game {\n\treturn &game{\n\t\tplayer: mark1,\n\t\tboard: [][]string{\n\t\t\t{emptyMark, emptyMark, emptyMark},\n\t\t\t{emptyMark, emptyMark, emptyMark},\n\t\t\t{emptyMark, emptyMark, emptyMark},\n\t\t},\n\t}\n}\n\nfunc (g *game) prompt() {\n\tfmt.Printf(\"\\n%s%s [1-9]: \", g, g.player)\n}\n\nfunc (g *game) String() string {\n\tg.buf.Reset()\n\n\tg.buf.WriteRune('\\n')\n\tg.buf.WriteString(\"---+----+---\\n\")\n\n\tfor _, line := range g.board {\n\t\tg.buf.WriteString(strings.Join(line, \"  | \"))\n\t\tg.buf.WriteRune('\\n')\n\n\t\tg.buf.WriteString(\"---+----+---\\n\")\n\t}\n\n\treturn g.buf.String()\n}\n\nfunc (g *game) play(pos int) string {\n\tvar row int\n\n\tswitch {\n\tcase pos >= 7 && pos <= 9:\n\t\trow = 2\n\tcase pos >= 4 && pos <= 6:\n\t\trow = 1\n\tcase pos >= 1 && pos <= 3:\n\t\trow = 0\n\tdefault:\n\t\treturn \"wrong position\"\n\t}\n\n\tcol := pos - row*3 - 1\n\n\tif g.board[row][col] != emptyMark {\n\t\treturn \"already played!\"\n\t}\n\n\t// put the player\n\tg.board[row][col] = g.player\n\n\treturn \"\"\n}\n\nfunc (g *game) finito() string {\n\tg.turn++\n\n\tswitch {\n\tcase g.won():\n\t\treturn fmt.Sprintf(\"WINNER: %s\", g.player)\n\tcase g.turn == maxTurn:\n\t\treturn \"TIE!\"\n\t}\n\treturn \"\"\n}\n\nfunc (g *game) won() (won bool) {\n\tfor _, m := range [2]string{mark1, mark2} {\n\t\tb, mmm := g.board, strings.Repeat(m, 3)\n\n\t\twon = /* horizontals */\n\t\t\tstrings.Join(b[0], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[1], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[2], \"\") == mmm ||\n\n\t\t\t\t/* verticals */\n\t\t\t\tb[0][0]+b[1][0]+b[2][0] == mmm ||\n\t\t\t\tb[0][1]+b[1][1]+b[2][1] == mmm ||\n\t\t\t\tb[0][2]+b[1][2]+b[2][2] == mmm ||\n\n\t\t\t\t/* diagonals */\n\t\t\t\tb[0][0]+b[1][1]+b[2][2] == mmm ||\n\t\t\t\tb[0][2]+b[1][1]+b[2][0] == mmm\n\n\t\tif won {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc (g *game) next() {\n\tif g.player == mark1 {\n\t\tg.player = mark2\n\t} else {\n\t\tg.player = mark1\n\t}\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/06-refactor/game.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"strings\"\n)\n\ntype state int\n\nconst (\n\tmaxTurn = 9\n\n\twrongPosition = -2\n\n\tstatePlaying state = iota\n\tstateWon\n\tstateTie\n\n\tstateAlreadyPlayed\n\tstateWrongPosition\n)\n\ntype game struct {\n\tboard [][]string\n\n\tturn   int\n\tplayer string\n\n\tskin   // embed the skin\n\tlogger // embed the logger\n}\n\nfunc newGame(s skin, l logger) *game {\n\treturn &game{\n\t\tplayer: s.mark1,\n\t\tboard: [][]string{\n\t\t\t{s.empty, s.empty, s.empty},\n\t\t\t{s.empty, s.empty, s.empty},\n\t\t\t{s.empty, s.empty, s.empty},\n\t\t},\n\t\tskin:   s,\n\t\tlogger: l,\n\t}\n}\n\nfunc (g *game) play(pos int) state {\n\tif st := g.move(pos); st != statePlaying {\n\t\treturn st\n\t}\n\n\tg.turn++ // increment the turn\n\n\t// first check the winner then check the tie\n\t// or the last mover won't win\n\tswitch {\n\tcase g.won():\n\t\treturn stateWon\n\tcase g.turn == maxTurn:\n\t\treturn stateTie\n\t}\n\n\tg.changePlayer()\n\treturn statePlaying\n}\n\nfunc (g *game) move(pos int) state {\n\trow, col := position(pos)\n\tif row+col == wrongPosition {\n\t\treturn stateWrongPosition\n\t}\n\n\tif g.board[row][col] != g.empty {\n\t\treturn stateAlreadyPlayed\n\t}\n\n\t// put the player's mark on the board\n\tg.board[row][col] = g.player\n\n\treturn statePlaying\n}\n\n// we can detect the winning state just by comparing the strings\n// because, the game board is a bunch of strings\nfunc (g *game) won() (won bool) {\n\tfor _, m := range [2]string{g.mark1, g.mark2} {\n\t\tb, mmm := g.board, strings.Repeat(m, 3)\n\n\t\twon = /* horizontals */\n\t\t\tstrings.Join(b[0], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[1], \"\") == mmm ||\n\t\t\t\tstrings.Join(b[2], \"\") == mmm ||\n\n\t\t\t\t/* verticals */\n\t\t\t\tb[0][0]+b[1][0]+b[2][0] == mmm ||\n\t\t\t\tb[0][1]+b[1][1]+b[2][1] == mmm ||\n\t\t\t\tb[0][2]+b[1][2]+b[2][2] == mmm ||\n\n\t\t\t\t/* diagonals */\n\t\t\t\tb[0][0]+b[1][1]+b[2][2] == mmm ||\n\t\t\t\tb[0][2]+b[1][1]+b[2][0] == mmm\n\n\t\tif won {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// this method should have a pointer receiver\n// because, it changes the game value\nfunc (g *game) changePlayer() {\n\tif g.player == g.mark1 {\n\t\tg.player = g.mark2\n\t} else {\n\t\tg.player = g.mark1\n\t}\n}\n\nfunc (g *game) print() {\n\tg.Println()\n\tg.Println(g.header)\n\n\tfor i, line := range g.board {\n\t\tg.Print(g.separator)\n\n\t\tfor _, m := range line {\n\t\t\tg.Printf(\"%2s%s\", m, g.separator)\n\t\t}\n\n\t\tif i+1 != len(g.board) {\n\t\t\tg.Printf(\"\\n%s\\n\", g.middle)\n\t\t}\n\t}\n\n\tg.Printf(\"\\n%s\\n\", g.footer)\n}\n\n// this function doesn't depend on the game state\n// so, make it a function instead of a method\nfunc position(pos int) (row, col int) {\n\tswitch {\n\tcase pos >= 1 && pos <= 3:\n\t\trow = 0\n\tcase pos >= 4 && pos <= 6:\n\t\trow = 1\n\tcase pos >= 7 && pos <= 9:\n\t\trow = 2\n\tdefault:\n\t\treturn -1, -1\n\t}\n\n\treturn row, pos - row*3 - 1\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/06-refactor/logger.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\ntype logger struct {\n\tprint   func(...interface{}) (int, error)\n\tprintf  func(fmt string, args ...interface{}) (int, error)\n\tprintln func(...interface{}) (int, error)\n}\n\nfunc (l logger) Print(args ...interface{}) {\n\tl.print(args...)\n}\n\nfunc (l logger) Printf(fmt string, args ...interface{}) {\n\tl.printf(fmt, args...)\n}\n\nfunc (l logger) Println(args ...interface{}) {\n\tl.println(args...)\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/06-refactor/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\n\tc \"github.com/fatih/color\"\n\trainbow \"github.com/guineveresaenger/golang-rainbow\"\n)\n\n// TODO: move the main logic into a helper\n\nfunc main() {\n\tconst banner = `\n~~~~~~~~~~~~~~~~\n  TIC~TAC~TOE\n~~~~~~~~~~~~~~~~`\n\n\tin := bufio.NewScanner(os.Stdin)\n\tsk := selectSkin(in)\n\tlg := logger{\n\t\tprint:   fmt.Print,\n\t\tprintf:  fmt.Printf,\n\t\tprintln: fmt.Println,\n\t}\n\n\tfor {\n\t\tg := newGame(sk, lg)\n\n\tgame:\n\t\tfor {\n\t\t\trainbow.Rainbow(banner, 3)\n\t\t\tg.print()\n\t\t\tfmt.Printf(c.CyanString(\"\\n%s [1-9]: \", g.player))\n\n\t\t\tif !in.Scan() {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tpos, _ := strconv.Atoi(in.Text())\n\n\t\t\tswitch st := g.play(pos); st {\n\t\t\tcase stateAlreadyPlayed, stateWrongPosition:\n\t\t\t\tannounce(g, st)\n\t\t\t\tcontinue\n\t\t\tcase stateWon, stateTie:\n\t\t\t\tannounce(g, st)\n\t\t\t\tbreak game\n\t\t\t}\n\t\t\tg.Print(\"\\033[2J\")\n\n\t\t}\n\n\t\tfmt.Print(c.MagentaString(\"One more game? [y/n]: \"))\n\t\tif in.Scan(); in.Text() != \"y\" {\n\t\t\tfmt.Println(\"OK, bye!\")\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nfunc announce(g *game, st state) {\n\tred := c.New(c.FgRed, c.Bold)\n\tgreen := c.New(c.BgBlack, c.FgGreen, c.Bold)\n\n\tswitch st {\n\tcase stateAlreadyPlayed, stateWrongPosition:\n\t\tred.Printf(\"\\n>>> You can't play there!\\n\")\n\tcase stateWon:\n\t\tg.print()\n\t\tgreen.Printf(\"\\nWINNER: %s\\n\", g.player)\n\tcase stateTie:\n\t\tg.print()\n\t\tgreen.Printf(\"\\nTIE!\\n\")\n\t}\n}\n\nfunc selectSkin(in *bufio.Scanner) skin {\n\tfmt.Println(c.MagentaString(\"Our finest selection of skins:\"))\n\tfor name := range skins {\n\t\tfmt.Printf(\"- %s\\n\", name)\n\t}\n\n\tfmt.Print(c.GreenString(\"\\nEnter the name of the skin: \"))\n\n\tin.Scan()\n\tif sk, ok := skins[in.Text()]; ok {\n\t\treturn sk\n\t}\n\treturn defaultSkin\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/06-refactor/resources.md",
    "content": "https://github.com/mattn/go-runewidth\n\nhttps://github.com/olekukonko/tablewriter\n\nhttps://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/06-refactor/skins.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"github.com/fatih/color\"\n\n// skin options :-)\ntype skin struct {\n\tempty, mark1, mark2               string\n\theader, middle, footer, separator string\n\n\tunicode bool\n}\n\nvar skins = map[string]skin{\n\t\"colorful\": colorfulSkin,\n\t\"poseidon\": poseidonSkin,\n\t\"statues\":  statuesSkin,\n\t\"aliens\":   aliensSkin,\n\t\"snow\":     snowSkin,\n\t\"monkeys\":  monkeysSkin,\n}\n\nvar defaultSkin = skin{\n\tempty: \"   \",\n\tmark1: \" X \",\n\tmark2: \" O \",\n\n\theader:    \"┌───┬───┬───┐\",\n\tmiddle:    \"├───┼───┼───┤\",\n\tfooter:    \"└───┴───┴───┘\",\n\tseparator: \"│\",\n}\n\nvar colorfulSkin = skin{\n\tempty:     \"   \",\n\tmark1:     color.CyanString(\" X \"),\n\tmark2:     color.HiMagentaString(\" O \"),\n\theader:    color.HiBlueString(\"┌───┬───┬───┐\"),\n\tmiddle:    color.HiBlueString(\"├───┼───┼───┤\"),\n\tfooter:    color.HiBlueString(\"└───┴───┴───┘\"),\n\tseparator: color.BlueString(\"│\"),\n}\n\nvar poseidonSkin = skin{\n\tempty:     \"❓  \",\n\tmark1:     \"🔱  \",\n\tmark2:     \"⚓️  \",\n\theader:    \"●————●————●————●\",\n\tmiddle:    \"●————●————●————●\",\n\tfooter:    \"●————●————●————●\",\n\tseparator: \"⎮ \",\n}\n\nvar statuesSkin = skin{\n\tempty:     \"❓  \",\n\tmark1:     \"🗿  \",\n\tmark2:     \"🗽  \",\n\theader:    \"┌────┬────┬────┐\",\n\tmiddle:    \"├────┼────┼────┤\",\n\tfooter:    \"└────┴────┴────┘\",\n\tseparator: \"│ \",\n}\n\nvar aliensSkin = skin{\n\tempty:     \"❓  \",\n\tmark1:     \"👽  \",\n\tmark2:     \"👾  \",\n\theader:    \"┌────┬────┬────┐\",\n\tmiddle:    \"├────┼────┼────┤\",\n\tfooter:    \"└────┴────┴────┘\",\n\tseparator: \"│ \",\n}\n\nvar snowSkin = skin{\n\tempty:     \"❓  \",\n\tmark1:     \"⛄ ️ \",\n\tmark2:     \"❄️  \",\n\theader:    \"╔════╦════╦════╗\",\n\tmiddle:    \"╠════╬════╬════╣\",\n\tfooter:    \"╚════╩════╩════╝\",\n\tseparator: \"║ \",\n}\n\nvar monkeysSkin = skin{\n\tempty:     \"🍌  \",\n\tmark1:     \"🙈  \",\n\tmark2:     \"🙉  \",\n\theader:    \"┌────┬────┬────┐\",\n\tmiddle:    \"├────┼────┼────┤\",\n\tfooter:    \"└────┴────┴────┘\",\n\tseparator: \"│ \",\n}\n"
  },
  {
    "path": "x-tba/tictactoe-experiments/README.md",
    "content": "**Check out:**\nTic-Tac-Toe Gist:\nhttps://gist.github.com/agalal/bff3cb779c337274d2a3462c630f4d74"
  },
  {
    "path": "x-tba/wizards-structs/marshal/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\n// Wizard is one of the greatest of people\ntype Wizard struct {\n\t// name won't be marshalled (should be exported)\n\tName     string `json:\"name,omitempty\"`\n\tLastname string `json:\"last_name\"`\n\tNick     string `json:\"-\"`\n}\n\nfunc main() {\n\twizards := []Wizard{\n\t\t{Name: \"Albert\", Lastname: \"Einstein\", Nick: \"emc2\"},\n\t\t{Name: \"Isaac\", Lastname: \"Newton\", Nick: \"apple\"},\n\t\t{Name: \"Stephen\", Lastname: \"Hawking\", Nick: \"blackhole\"},\n\t\t{Name: \"Marie\", Lastname: \"Curie\", Nick: \"radium\"},\n\t\t{Name: \"\", Lastname: \"Darwin\", Nick: \"fittest\"},\n\t}\n\n\tbytes, err := json.MarshalIndent(wizards, \"\", \"\\t\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(string(bytes))\n}\n"
  },
  {
    "path": "x-tba/wizards-structs/server/list.tmpl.html",
    "content": "<h1>There are {{len .}} wizards.</h1>\n\n{{range .}}\n👉 {{.Name}} {{.Lastname}} ({{.Nick}})\n{{end}}"
  },
  {
    "path": "x-tba/wizards-structs/server/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"net/http\"\n)\n\nfunc main() {\n\thttp.HandleFunc(\"/add\", onlyPost(add))\n\thttp.HandleFunc(\"/list\", list)\n\tpanic(http.ListenAndServe(\":8000\", nil))\n}\n\nfunc add(w http.ResponseWriter, r *http.Request) {\n\tvar wiz wizard\n\tif err := json.NewDecoder(r.Body).Decode(&wiz); err != nil {\n\t\tpanic(err)\n\t}\n\n\tdb.add(wiz)\n\tw.WriteHeader(http.StatusOK)\n}\n\nfunc list(w http.ResponseWriter, r *http.Request) {\n\tw.Header().Set(\"Content-Type\", \"text/html; charset=UTF-8\")\n\tw.WriteHeader(http.StatusOK)\n\ttmpl.Execute(w, db.list())\n}\n\nfunc onlyPost(next http.HandlerFunc) http.HandlerFunc {\n\treturn func(w http.ResponseWriter, r *http.Request) {\n\t\tif r.Method == \"POST\" {\n\t\t\tnext(w, r)\n\t\t\treturn\n\t\t}\n\t\tw.WriteHeader(http.StatusBadRequest)\n\t\tw.Write([]byte(\"NOT OK\"))\n\t}\n}\n"
  },
  {
    "path": "x-tba/wizards-structs/server/store.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"sync\"\n\ntype wizard struct {\n\tName     string `json:\"name\"`\n\tLastname string `json:\"last_name\"`\n\tNick     string `json:\"nick\"`\n}\n\ntype storage struct {\n\tsync.RWMutex\n\twizards []wizard\n}\n\nfunc (db *storage) add(w wizard) {\n\tdb.Lock()\n\tdefer db.Unlock()\n\tdb.wizards = append(db.wizards, w)\n}\n\nfunc (db *storage) list() []wizard {\n\tdb.RLock()\n\tdefer db.RUnlock()\n\treturn db.wizards\n}\n\nvar db *storage\n\nfunc init() {\n\tdb = new(storage)\n}\n"
  },
  {
    "path": "x-tba/wizards-structs/server/templates.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport \"html/template\"\n\nvar tmpl *template.Template\n\nfunc init() {\n\ttmpl = template.Must(\n\t\ttemplate.New(\"list.tmpl\").\n\t\t\tParseFiles(\"list.tmpl\"))\n}\n"
  },
  {
    "path": "x-tba/wizards-structs/unmarshal/main.go",
    "content": "// Copyright © 2018 Inanc Gumus\n// Learn Go Programming Course\n// License: https://creativecommons.org/licenses/by-nc-sa/4.0/\n//\n// For more tutorials  : https://learngoprogramming.com\n// In-person training  : https://www.linkedin.com/in/inancgumus/\n// Follow me on twitter: https://twitter.com/inancgumus\n\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"strings\"\n)\n\n// Wizard is one of the greatest of people\ntype Wizard struct {\n\t// name won't be marshalled (should be exported)\n\tName     string `json:name`\n\tLastname string `json:\"-\"`\n\tNick     string `json:\"nick\"`\n}\n\nfunc main() {\n\tfile, err := ioutil.ReadFile(\"../marshal/wizards.json\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\twizards := make([]Wizard, 10)\n\tif json.Unmarshal(file, &wizards) != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"%-15s %-15s\\n%s\",\n\t\t\"Name\", \"Nick\", strings.Repeat(\"=\", 25))\n\n\tfor _, w := range wizards {\n\t\tfmt.Printf(\"%-15s %-15s\\n\", w.Name, w.Nick)\n\t}\n}\n"
  }
]