├── .gitignore ├── 001-Work-Environment-Setup ├── README.md ├── osx-installation.md ├── ubuntu-installation.md └── windows-installation.md ├── 002-First-Program ├── README.md └── main.go ├── 003-Scopes └── main.go ├── 004-Print-Number-Of-CPU └── main.go ├── 005-Exporting ├── README.md ├── goversion │ ├── cmd │ │ └── main.go │ └── goversion.go └── printer │ ├── cmd │ └── main.go │ └── printer.go ├── 006-Variables-And-Data-Types ├── 01-Basic-Data-Types │ └── main.go ├── 02-Declarations │ ├── 01-declaration-syntax │ │ ├── 01-syntax │ │ │ └── main.go │ │ └── 02-naming-rules │ │ │ └── main.go │ ├── 02-example-declarations │ │ ├── 01-int │ │ │ └── main.go │ │ ├── 02-float64 │ │ │ └── main.go │ │ ├── 03-bool │ │ │ └── main.go │ │ └── 04-string │ │ │ └── main.go │ ├── 03-zero-values │ │ └── main.go │ ├── 04-unused-variables-and-blank-identifier │ │ └── 02-blank-identifier │ │ │ └── main.go │ ├── 05-multiple-declarations │ │ ├── 01-multiple │ │ │ └── main.go │ │ └── 02-parallel │ │ │ └── main.go │ └── 06-examples │ │ └── main.go ├── 03-Short-Declarations │ ├── 01-initialization-and-short-declaration │ │ ├── 01-initialization │ │ │ └── main.go │ │ ├── 02-short-declaration │ │ │ └── main.go │ │ └── 03-coding-example │ │ │ └── main.go │ ├── 02-package-scope │ │ └── main.go │ ├── 03-multiple-short-declaration │ │ ├── 01-declaration │ │ │ └── main.go │ │ ├── 02-coding-example │ │ │ └── main.go │ │ └── 03-redeclaration │ │ │ ├── 01 │ │ │ └── main.go │ │ │ └── 02-coding-example │ │ │ └── main.go │ └── 04-short-vs-normal │ │ ├── 01-declaration │ │ └── main.go │ │ └── 02-short-declaration │ │ └── main.go ├── 04-Swapping-Variable-Values │ └── main.go ├── 05-Assignments │ ├── 01-assignment │ │ ├── 01-assignment │ │ │ └── main.go │ │ ├── 02-strongly-typed │ │ │ └── main.go │ │ └── 03-examples │ │ │ └── main.go │ ├── 01-overview │ │ └── main.go │ ├── 05-multiple-assignment │ │ └── main.go │ ├── 06-swapping │ │ └── main.go │ ├── 07-path-project │ │ └── main.go │ └── 08-path-project-discarding-shorthand │ │ └── main.go ├── 06-Type-Conversion │ ├── 01-destructive │ │ └── main.go │ ├── 02-correct │ │ └── main.go │ └── 03-numeric-conversion │ │ └── main.go ├── 07-Command-Line-Args-Greeter │ └── main.go └── 08-Shadowed-Variables │ └── main.go ├── 007-Naming-Conventions └── README.md ├── 008-Printf ├── 01-Println-vs-Printf │ └── main.go ├── 02-Escape-Sequences │ └── main.go ├── 03-Printing-Variable-Types │ └── main.go ├── 04-Argument-Indexing │ └── main.go ├── 05-Float-Precisions │ └── main.go └── printf cheatsheet.pdf ├── 009-Numbers ├── 01-arithmetic-operators │ ├── 01 │ │ └── main.go │ ├── 02 │ │ └── main.go │ └── 03-float-inaccuracy │ │ ├── 01 │ │ └── main.go │ │ ├── 02 │ │ └── main.go │ │ └── 03 │ │ └── main.go ├── 02-arithmetic-operators-examples │ ├── 01 │ │ └── main.go │ └── 02 │ │ └── main.go ├── 03-precedence │ ├── 01 │ │ └── main.go │ ├── 02 │ │ └── main.go │ ├── 03 │ │ └── main.go │ └── 04 │ │ └── main.go ├── 04-incdec-statement │ ├── 01 │ │ └── main.go │ ├── 02 │ │ └── main.go │ └── 03 │ │ └── main.go ├── 05-assignment-operations │ └── main.go ├── 06-Feets-To-Meters-Calculator │ └── main.go └── 07-Celsius-To-Fahrenheit-Calculator │ └── main.go ├── 010-Strings ├── 01-raw-string-literal │ └── main.go ├── 02-concatenation │ ├── 01 │ │ └── main.go │ ├── 02-assignment-operation │ │ └── main.go │ └── 03-concat-non-strings │ │ └── main.go ├── 03-string-length │ ├── 01-len │ │ └── main.go │ └── 02-unicode-len │ │ └── main.go ├── 04-project-banger │ └── main.go ├── 05-windows-path │ └── main.go ├── 06-print-json │ └── main.go ├── 07-raw-concat │ └── main.go ├── 08-count-the-chars │ └── main.go ├── 09-improved-banger │ └── main.go ├── 10-tolowercase │ └── main.go ├── 11-trim-it │ └── main.go └── 12-right-trim-it │ └── main.go ├── 011-Type-System-In-Go ├── 01-bits │ └── main.go ├── 02-bytes │ └── main.go ├── 03-predeclared-types │ └── main.go ├── 04-overflow │ ├── 01-problem │ │ └── main.go │ ├── 02-explain │ │ └── main.go │ └── 03-destructive │ │ └── main.go ├── 05-defined-types │ ├── 01-duration-example │ │ └── main.go │ ├── 02-type-definition-create-your-own-type │ │ └── main.go │ └── 03-underlying-types │ │ ├── main.go │ │ └── weights │ │ └── weights.go ├── 06-aliased-types │ └── main.go ├── 07-Find-The-Optimal-Types │ └── main.go ├── 08-Type-Problem │ └── main.go ├── 09-Parse-Argument-Numbers │ └── main.go ├── 10-Time-Multiplier │ └── main.go ├── 11-Refactor-Feets-To-Meters-Converter │ └── main.go └── 12-Type-Conversions │ └── main.go ├── 012-Constants ├── 01-Declarations │ ├── 01-Syntax │ │ ├── 01-magic-numbers │ │ │ └── main.go │ │ ├── 02-constants │ │ │ └── main.go │ │ ├── 03-safety │ │ │ └── main.go │ │ └── 04-rules │ │ │ ├── 01-immutability │ │ │ └── main.go │ │ │ ├── 02-runtime-func │ │ │ └── main.go │ │ │ ├── 03-runtime-var │ │ │ └── main.go │ │ │ └── 04-len │ │ │ └── main.go │ ├── 02-constant-types-and-expressions │ │ ├── 01 │ │ │ └── main.go │ │ ├── 02 │ │ │ └── main.go │ │ └── 03 │ │ │ └── main.go │ └── 03-multiple-declaration │ │ ├── 01 │ │ └── main.go │ │ ├── 02 │ │ └── main.go │ │ └── 03 │ │ └── main.go ├── 02-Typeless-Constants │ ├── 01-typeless-constants │ │ └── main.go │ ├── 02-typed-vs-typeless │ │ ├── 01 │ │ │ └── main.go │ │ ├── 02 │ │ │ └── main.go │ │ ├── 03 │ │ │ └── main.go │ │ └── 04 │ │ │ └── main.go │ ├── 03-default-type │ │ ├── 01 │ │ │ └── main.go │ │ ├── 02 │ │ │ └── main.go │ │ ├── 03 │ │ │ └── main.go │ │ ├── 04 │ │ │ └── main.go │ │ └── 05 │ │ │ └── main.go │ └── 04-demo │ │ ├── 01 │ │ └── main.go │ │ └── 02 │ │ └── main.go ├── 03-Refactor-Feets-To-Meeters │ └── main.go ├── 04-IOTA │ ├── 01-manually │ │ └── main.go │ ├── 02-with-iota │ │ └── main.go │ ├── 03-expressions │ │ └── main.go │ └── 04-blank-identifier │ │ ├── 01 │ │ └── main.go │ │ ├── 02 │ │ └── main.go │ │ └── 03 │ │ └── main.go ├── 05-minutes-in-weeks │ └── main.go ├── 06-remove-the-magic │ └── main.go ├── 07-constant-length │ └── main.go ├── 08-tau │ └── main.go ├── 09-area │ └── main.go ├── 10-no-conversions-allowed │ └── main.go ├── 11-iota-months │ └── main.go ├── 12-iota-months-2 │ └── main.go └── 13-iota-seasons │ └── main.go ├── 013-If-Statements ├── 01-boolean-operators │ ├── 01-comparison-operators │ │ └── main.go │ ├── 02-comparison-and-assignability │ │ ├── 01 │ │ │ └── main.go │ │ ├── 02 │ │ │ └── main.go │ │ └── 03 │ │ │ └── main.go │ └── 03-logical-operators │ │ ├── 01-and-operator │ │ ├── 01 │ │ │ └── main.go │ │ └── 02 │ │ │ └── main.go │ │ ├── 02-or-operator │ │ ├── 01 │ │ │ └── main.go │ │ └── 02 │ │ │ └── main.go │ │ └── 03-not-operator │ │ ├── 01 │ │ └── main.go │ │ └── 02 │ │ └── main.go └── 02-if-statement │ ├── 01-if-branch │ └── main.go │ ├── 02-else-branch │ └── main.go │ ├── 03-else-if-branch │ ├── 01 │ │ └── main.go │ └── 02 │ │ └── main.go │ ├── 04-refactor-feet-to-meters │ └── main.go │ └── 05-challenge-userpass │ ├── 01-1st-challenge │ ├── 01-challenge │ │ └── main.go │ ├── 02-solution │ │ └── main.go │ └── 03-solution-refactor │ │ └── main.go │ └── 02-2nd-challenge │ ├── 01-challenge │ └── main.go │ └── 02-solution │ └── main.go ├── 014-Error-Handling ├── 01-itoa │ └── main.go ├── 02-atoi │ └── main.go ├── 03-atoi-error-handling │ └── main.go └── 04-challenge-feet-to-meters │ ├── 01-challenge │ └── main.go │ └── 02-solution │ └── main.go ├── 015-Short-If-Statement ├── 01-without-short-if │ └── main.go ├── 02-with-short-if │ └── main.go ├── 03-scope │ └── main.go └── 04-scope-shadowing │ ├── 01-shadowing │ └── main.go │ └── 02-shadowing-solution │ └── main.go ├── 016-Switch-Statements ├── 01-one-case │ └── main.go ├── 02-multiple-cases │ └── main.go ├── 03-default-clause │ └── main.go ├── 04-multiple-conditions │ └── main.go ├── 05-bool-expressions │ └── main.go ├── 06-fallthrough │ ├── 01-without │ │ └── main.go │ └── 02-with │ │ └── main.go ├── 07-short-switch │ └── main.go ├── 08-parts-of-the-day │ └── main.go ├── 09-when-to-use │ └── main.go ├── 10-richter-scale │ └── main.go ├── 11-richter-scale-2 │ └── main.go ├── 12-Login │ └── main.go ├── 13-string-manipulator │ └── main.go └── 14-days-in-month │ └── main.go ├── 017-Loops-In-Go ├── 01-basics │ └── main.go ├── 02-break │ └── main.go ├── 03-continue │ ├── 01-a-before │ │ └── main.go │ └── 01-b-after │ │ └── main.go ├── 04-nested-loops-multiplication-table │ └── main.go ├── 05-for-range │ ├── 01-loop-over-slices │ │ └── main.go │ └── 02-loop-over-words │ │ └── main.go ├── 06-Lucky-Number-Game │ ├── 01-randomization │ │ └── main.go │ └── 02-game │ │ └── main.go ├── 07-Word-Finder-Project │ └── main.go ├── 08-Labeled-Break-Statements-Word-Finder │ └── main.go ├── 09-Labeled-Continue-Statements-Word-Finder │ └── main.go ├── 10-Labeled-Switch-Statements-Word-Finder │ └── main.go ├── 11-Goto-Statement │ └── main.go ├── 12-sum-the-numbers │ └── main.go ├── 13-sum-the-numbers-verbose │ └── main.go ├── 14-sum-up-to-n │ └── main.go ├── 15-only-evens │ └── main.go ├── 16-break-up │ └── main.go ├── 17-infinite-kill │ └── main.go ├── 18-multiplication-table-extended │ ├── 01-dynamic-table │ │ └── main.go │ ├── 02-math-tables │ │ └── main.go │ └── main.go ├── 19-Lucky-Number-Game-Extended │ ├── 01-first-turn-winner │ │ ├── solution-better │ │ │ └── main.go │ │ └── solution │ │ │ └── main.go │ ├── 02-random-messages │ │ └── main.go │ ├── 03-double-guesses │ │ └── main.go │ ├── 04-verbose-mode │ │ └── main.go │ ├── 05-enough-picks │ │ └── main.go │ └── 06-dynamic-difficulty │ │ └── main.go ├── 20-Word-Finder-Project-Extended │ ├── 01-case-insensitive │ │ └── main.go │ └── 02-path-searcher │ │ └── main.go └── 21-Prime-Numbers │ └── main.go ├── 018-Arrays-Composite-Types ├── 01-whats-an-array │ └── main.go ├── 02-examples-1-hipsters-love-bookstore │ └── main.go ├── 03-examples-2-hipsters-love-bookstore │ └── main.go ├── 04-array-literal │ └── main.go ├── 05-examples-3-hipsters-love-bookstore │ └── main.go ├── 06-challenge-moodly │ └── main.go ├── 07-Comparing-Arrays │ └── main.go ├── 08-Assigning-One-Array-To-Another │ ├── 01 │ │ └── main.go │ └── 02-example │ │ └── main.go ├── 09-Multi-Dimensional-Array │ └── main.go ├── 10-Moodly-2-Multi-Dimensional-Array │ └── main.go ├── 11-Rarely-Known-Features │ ├── 01-unkeyed │ │ └── main.go │ ├── 02-keyed │ │ └── main.go │ ├── 03-keyed-order │ │ └── main.go │ ├── 04-keyed-auto-initialize │ │ └── main.go │ ├── 05-keyed-auto-initialize-ellipsis │ │ └── main.go │ ├── 06-keyed-and-unkeyed │ │ └── main.go │ └── 07-Xratio-Cryptocurrency-Exchange-Ratio │ │ ├── 01-without-keys │ │ └── main.go │ │ └── 02-with-keys │ │ └── main.go ├── 12-Comparing-Unnamed-Type-Arrays │ └── main.go ├── 13-declare-empty │ └── main.go ├── 14-get-set-arrays │ └── main.go ├── 15-array-literal │ └── main.go ├── 16-ellipsis │ └── main.go ├── 17-Simplifying-Complex-Code │ └── main.go ├── 18-compare │ └── main.go ├── 19-assign │ └── main.go ├── 20-wizard-printer │ └── main.go ├── 21-currency-converter │ └── main.go ├── 22-hipsters-love-search │ └── main.go ├── 23-average │ └── main.go ├── 24-sorter │ └── main.go └── 25-word-finder │ └── main.go ├── 019-Retro-LED-Clock ├── 01-Printing-The-Digits │ └── main.go ├── 02-Printing-The-Clock │ └── main.go ├── 03-Animating-The-Clock │ └── main.go ├── 04-Blinking-The-Separators │ └── main.go ├── 05-Fully-Commented-Solution │ └── main.go ├── 06-Refactored │ ├── main.go │ └── placeholders.go ├── 07-Alarm-Functionality │ ├── main.go │ └── placeholders.go ├── 08-Split-Second-Functionality │ ├── main.go │ └── placeholders.go └── 09-Ticker-Functionality │ ├── main.go │ └── placeholders.go ├── 020-Slices-In-Go ├── 01-slices-vs-arrays │ └── main.go ├── 02-slices-vs-arrays │ └── main.go ├── 03-slices-vs-arrays-examples │ └── main.go ├── 04-slices-vs-arrays-unique-nums │ ├── 01-with-arrays │ │ └── main.go │ └── 02-with-slices │ │ └── main.go ├── 05-Append-Function │ ├── 1-theory │ │ └── main.go │ └── 2-example │ │ └── main.go ├── 06-Slice-Expressions │ ├── 1-theory │ │ └── main.go │ └── 2-example │ │ └── main.go ├── 07-Slice-Expressions-Pagination │ └── main.go ├── 08-Slice-Internals-Backing-Array │ ├── 1-theory │ │ └── main.go │ └── 2-example │ │ └── main.go ├── 09-Slice-Internals-Header │ ├── 1-theory │ │ └── main.go │ └── 2-example │ │ └── main.go ├── 10-Slice-Internals-Len-And-Cap-Functions │ ├── 1-theory │ │ └── main.go │ └── 2-example │ │ └── main.go ├── 11-Slice-Internals-Append-Function │ ├── 1-theory │ │ └── main.go │ ├── 2-example │ │ └── main.go │ ├── 3-example-growth │ │ └── main.go │ └── 4-example-growth │ │ └── main.go ├── 12-Full-Slice-Expressions │ ├── 1-theory │ │ └── main.go │ └── 2-example │ │ └── main.go ├── 13-Make-Function │ ├── 1-theory │ │ └── main.go │ └── 2-example │ │ └── main.go ├── 14-Copy-Function │ ├── 01-usage │ │ └── main.go │ └── 02-hacker-incident │ │ └── main.go ├── 16-declare-nil │ └── main.go ├── 17-empty │ └── main.go ├── 18-slice-literal │ └── main.go ├── 19-declare-arrays-as-slices │ └── main.go ├── 20-fix-the-problems │ └── main.go ├── 21-compare-the-slices │ └── main.go ├── 22-append │ └── main.go ├── 23-append-2 │ └── main.go ├── 24-append-3-fix │ └── main.go ├── 25-append-sort-nums │ └── main.go ├── 26-housing-prices │ └── main.go ├── 27-housing-prices-averages │ └── main.go ├── 28-slicing-basics │ └── main.go ├── 29-slicing-by-args │ └── main.go ├── 30-slicing-housing-prices │ └── main.go ├── 31-internals-backing-array-fix │ └── main.go ├── 32-internals-backing-array-sort │ └── main.go ├── 33-internals-slice-header │ └── main.go ├── 34-observe-len-cap │ └── main.go ├── 35-observe-the-cap-growth │ └── main.go ├── 36-correct-the-lyric │ └── main.go ├── 37-Advanced-Slice-Operations │ └── main.go ├── 38-Limiting-The-Backing-Array-Sharing │ ├── api │ │ └── api.go │ └── main.go ├── 39-Fixing-The-Memory-Leak │ ├── api │ │ └── api.go │ └── main.go ├── 40-Add-Lines │ └── main.go └── 41-Print-Daily-Requests │ └── main.go ├── 021-Empty-Files-Finder-Program-IO ├── 01-Fetch-Files │ ├── files │ │ ├── empty1.txt │ │ ├── empty2.txt │ │ ├── empty3.txt │ │ ├── nonEmpty1.txt │ │ ├── nonEmpty2.txt │ │ └── nonEmpty3.txt │ └── main.go ├── 02-Write-To-A-File │ ├── files │ │ ├── empty1.txt │ │ ├── empty2.txt │ │ ├── empty3.txt │ │ ├── nonEmpty1.txt │ │ ├── nonEmpty2.txt │ │ └── nonEmpty3.txt │ ├── main.go │ └── out.txt ├── 03-Optimize-For-Millions-Of-Files │ └── main.go ├── 04-sort-to-a-file │ └── main.go ├── 05-sort-to-a-file-2 │ └── main.go ├── 06-print-directories │ ├── dir │ │ ├── .gitignore │ │ ├── subdir1 │ │ │ └── .gitignore │ │ └── subdir2 │ │ │ └── .gitignore │ ├── dir2 │ │ ├── .gitignore │ │ ├── subdir1 │ │ │ └── .gitignore │ │ ├── subdir2 │ │ │ └── .gitignore │ │ └── subdir3 │ │ │ └── .gitignore │ ├── dirs.txt │ └── main.go ├── _handlemethods.go ├── list.go ├── main.go ├── money.go ├── product.go └── timestamp.go ├── 022-Animated-Bouncing-Ball-In-CLI-Project ├── 01-draw-the-board │ └── main.go ├── 02-add-a-buffer │ └── main.go ├── 03-animate │ └── main.go ├── 04-find-the-bug │ └── main.go ├── 05-width-and-height │ └── main.go ├── 06-previous-positions │ └── main.go ├── 07-single-dimensional │ └── main.go └── 08-no-slice │ └── main.go ├── 023-Strings-Runes-And-Bytes ├── 01-Basics-Of-Strings-Runes-And-Bytes │ └── main.go ├── 02-bytes-runes-strings-charset-table │ └── main.go ├── 03-bytes-runes-strings-examples │ └── main.go ├── 04-rune-decoding │ ├── 01 │ │ └── main.go │ └── 02 │ │ ├── benchmarks │ │ └── main.go │ │ └── main.go ├── 05-internals │ └── main.go ├── 07-convert │ └── main.go ├── 08-rune-manipulator │ └── main.go └── 09-print-the-runes │ └── main.go ├── 024-Spam-Maske-Project ├── 01-step-1 │ ├── main.go │ └── spam.txt ├── 02-step-2 │ ├── main.go │ └── spam.txt └── 03-step-2-no-append │ ├── main.go │ └── spam.txt ├── 025-Text-Wrapper-Project ├── main.go └── story.txt ├── 026-Maps-In-Go ├── 01-english-dict │ ├── 01-as-a-slice │ │ └── main.go │ └── 02-as-a-map │ │ └── main.go ├── 02-english-dict-map-populate │ └── main.go ├── 03-internals-cloning │ └── main.go ├── 04-Maps-Examples │ └── main.go ├── 05-populate │ └── main.go └── 06-Get-Students-By-Their-House-Names │ └── main.go ├── 027-Logs-Parser-Using-buffio.Scanner-Project ├── 01-scanning │ ├── main.go │ └── proverbs.txt ├── 02-map-as-sets │ ├── main.go │ └── shakespeare.txt ├── 03-project-log-parser │ ├── log.txt │ ├── log_err_missing.txt │ ├── log_err_negative.txt │ ├── log_err_str.txt │ └── main.go ├── 04-uppercaser │ ├── main.go │ └── shakespeare.txt ├── 05-unique-words │ ├── main.go │ └── shakespeare.txt ├── 06-unique-words-2 │ ├── main.go │ └── shakespeare.txt ├── 07-grep-Command-Clone-Project │ ├── main.go │ └── shakespeare.txt ├── 08-quit │ └── main.go └── 09-log-parser │ ├── log.txt │ ├── log_err_missing.txt │ ├── log_err_negative.txt │ ├── log_err_str.txt │ └── main.go ├── 028-Structs-In-Go ├── 01-intro │ └── main.go ├── 02-basics │ └── main.go ├── 03-compare-assign │ └── main.go ├── 04-embedding │ └── main.go ├── 05-project-log-parser-structs │ ├── log.txt │ ├── log_err_missing.txt │ ├── log_err_negative.txt │ ├── log_err_str.txt │ └── main.go ├── 06-JSON-encoding │ └── main.go ├── 07-decoding │ ├── main.go │ └── users.json ├── 08-decoding-2 │ ├── main.go │ └── users.json ├── 09-Command-Line-Game-Store-Project │ └── main.go ├── 10-Command-Line-Game-Store-Project-Add-Interface │ └── main.go ├── 11-Command-Line-Game-Store-Project-Query-By-Id │ └── main.go ├── 12-Command-Line-Game-Store-Project-Save-Command-Encode-JSON │ └── main.go └── 13-Command-Line-Game-Store-Project-Decode-JSON │ └── main.go ├── 029-OOP-Methods ├── book.go ├── game.go └── main.go ├── 030-OOP-Pointer-Receivers ├── book.go ├── game.go ├── huge.go └── main.go ├── 031-OOP-Attaching-Methods-To-DIfferent-Types ├── book.go ├── game.go ├── huge.go ├── list.go ├── main.go └── money.go ├── 032-OOP-Interfaces-In-Go ├── book.go ├── game.go ├── list.go ├── main.go ├── money.go ├── power │ ├── blender.go │ ├── kettle.go │ ├── main.go │ ├── mixer.go │ ├── player.go │ └── socket.go └── puzzle.go ├── 033-OOP-Type-Assertion ├── book.go ├── game.go ├── list.go ├── main.go ├── money.go ├── puzzle.go └── toy.go ├── 034-OOP-Empty-Interface ├── 01-Example-1 │ └── main.go ├── 02-Example-02 │ └── main.go └── 03-Example-03 │ ├── book.go │ ├── game.go │ ├── list.go │ ├── main.go │ ├── money.go │ ├── puzzle.go │ └── toy.go ├── 035-OOP-Type-Switch ├── book.go ├── game.go ├── list.go ├── main.go ├── money.go ├── puzzle.go └── toy.go ├── 036-OOP-Promoted-Methods ├── book.go ├── game.go ├── list.go ├── main.go ├── money.go ├── product.go ├── puzzle.go └── toy.go ├── 037-OOP-Store-App-Refactor ├── list.go ├── main.go ├── money.go ├── product.go └── timestamp.go ├── 038-OOP-Stringer ├── _handlemethods.go ├── list.go ├── main.go ├── money.go ├── product.go └── timestamp.go ├── 039-OOP-Store-App-Items-Sorting ├── list.go ├── main.go ├── money.go ├── product.go └── timestamp.go ├── 040-OOP-Marshaller ├── database.json ├── list.go ├── main.go ├── money.go ├── product.go └── timestamp.go ├── 041-IO ├── alice.txt └── main.go ├── 042-IO-Reusable-Streams └── main.go ├── 043-PNG-Detector ├── main.go └── some-file.unknown ├── 044-IO-Compose └── main.go ├── 045-Write-an-IO-Reader ├── main.go └── reader.go ├── 046-Testing-In-Go ├── main.go ├── reader.go └── reader_test.go ├── 047-Variadic-Functions-In-Go └── main.go ├── 048-Func-Values-And-Signatures └── main.go ├── 049-Func-To-Func └── main.go ├── 050-Closures-In-Go ├── 01-Example-01 │ └── main.go └── 02-Example-02 │ └── main.go ├── 051-Higher-Order-Functions-In-Go └── main.go ├── 052-Functional-Programming └── main.go ├── 053-Deferred-Functions-In-Go └── main.go ├── 054-Command-Line-Program ├── 01-Namaste │ └── main.go └── 02-With-CLI-Args-Help-Command │ └── main.go ├── 055-OOP-Pointer-Receivers-With-Interface ├── main.go └── shapes │ ├── rectangle.go │ ├── shape.go │ └── triangle.go ├── 056-OOP-Pointer-Receivers-With-Empty-Interface ├── main.go └── shapes │ ├── rectangle.go │ ├── shape.go │ └── triangle.go ├── 057-Social-Media-Post-Custom-Type ├── main.go └── socialmedia │ ├── moodstate_string.go │ └── socialmedia.go ├── 058-Goroutines ├── 01-Goroutines-Without-Delay │ └── main.go └── 02-Goroutines-With-Delay │ └── main.go ├── 059-Channels ├── 01-Example │ └── main.go ├── 02-Goroutines-With-Channels │ └── main.go ├── 03-Buffered-Channels │ └── main.go └── 04-Range-Over-Channels │ └── main.go ├── 060-Mutexes-And-Wait-Groups ├── 01-Race-Condition-Demo │ └── main.go ├── 02-Fixing-Race-Condition-Issue-By-Mutex │ └── main.go └── 03-Wait-Group │ └── main.go ├── 061-Concurrent-Pi-Computation-Using-Nilakantha-Series └── main.go ├── 062-Go-Vet-To-Catch-Errors └── main.go ├── 063-Unit-Testing-In-Go ├── checkusername_test.go └── validationkit.go ├── 064-HTTP-GET-Request └── main.go ├── 065-Web-Server ├── main.go └── validationkit │ ├── checkusername_test.go │ └── validationkit.go ├── 066-Web-Templates ├── main.go └── templates │ └── namaste.html ├── 067-Custom-Web-Template ├── main.go ├── static │ ├── css │ │ └── gopherface.css │ └── images │ │ └── gogopher.png └── templates │ └── socialmediapost.html ├── 068-MVC-Using-Gorilla-Mux ├── endpoints │ ├── createpost.go │ ├── deletepost.go │ ├── fetchposts.go │ └── updatepost.go ├── handlers │ ├── feed.go │ ├── find.go │ ├── foo.go │ ├── friends.go │ ├── home.go │ ├── login.go │ ├── logout.go │ ├── myprofile.go │ ├── panic.go │ ├── profile.go │ └── register.go ├── main.go ├── middleware │ ├── contextexample.go │ └── panicrecovery.go ├── models │ └── socialmedia │ │ ├── moodstate_string.go │ │ └── socialmedia.go └── templates │ └── index.html ├── 069-social-network-built-in-go-and-gopherjs ├── Dockerfile ├── certs │ ├── gopherfacecert.pem │ └── gopherfacekey.pem ├── client │ ├── client.go │ ├── common │ │ └── common.go │ └── handlers │ │ ├── feed.go │ │ ├── friends.go │ │ ├── handlers.go │ │ └── myprofile.go ├── common │ ├── asyncq │ │ ├── asyncq.go │ │ └── task.go │ ├── authenticate │ │ ├── authenticate.go │ │ ├── cookie.go │ │ └── session.go │ ├── common.go │ ├── datastore │ │ ├── datastore.go │ │ ├── mongodb.go │ │ ├── mysql.go │ │ └── redis.go │ └── utility │ │ ├── sha256.go │ │ └── uuid.go ├── config │ ├── gfdbdump.sql │ ├── gopherface-docker.service │ ├── gopherfacedb.sql │ └── nginx.conf ├── docker-compose.yml ├── endpoints │ ├── endpoints.go │ ├── fetchposts.go │ ├── findgophers.go │ ├── followgopher.go │ ├── friendslist.go │ ├── getgopherprofile.go │ ├── getuserprofile.go │ ├── savepost.go │ ├── saveuserprofile.go │ ├── saveuserprofileimage.go │ └── unfollowgopher.go ├── forms │ ├── myprofile.go │ └── smpost.go ├── gopherface.go ├── handlers │ ├── feed.go │ ├── find.go │ ├── foo.go │ ├── friends.go │ ├── handlers.go │ ├── home.go │ ├── login.go │ ├── logout.go │ ├── myprofile.go │ ├── panic.go │ ├── postpreview.go │ ├── profile.go │ ├── register.go │ ├── signup.go │ ├── templatebundle.go │ ├── uploadimage.go │ ├── uploadvideo.go │ └── utility.go ├── middleware │ ├── contextexample.go │ ├── gated.go │ └── panicrecovery.go ├── models │ ├── gopher.go │ ├── socialmedia │ │ ├── moodstate_string.go │ │ └── socialmedia.go │ ├── user.go │ └── userprofile.go ├── static │ ├── css │ │ ├── alertify.core.css │ │ ├── alertify.default.css │ │ ├── gopherface.css │ │ └── pure.css │ ├── images │ │ ├── .gitkeep │ │ └── gogopher.png │ ├── imageset │ │ ├── 3DGopher_blue.png │ │ ├── 3DGopher_green.png │ │ ├── 3DGopher_red.png │ │ ├── 3DGopher_yellow.png │ │ ├── Aerol.png │ │ ├── Case.png │ │ ├── Flatline.png │ │ ├── Jane.png │ │ ├── Linda.png │ │ ├── Marie.png │ │ ├── Molly.png │ │ ├── Riviera.png │ │ └── Wintermute.png │ ├── js │ │ ├── .gitkeep │ │ └── alertify.js │ ├── uploads │ │ ├── images │ │ │ ├── 0ef62347-cead-bfbf-6d23-7cdd84f8b080.png │ │ │ ├── 0ef62347-cead-bfbf-6d23-7cdd84f8b080_thumb.png │ │ │ ├── 2c2ef747-38b9-9968-8215-ce28099a8b63.png │ │ │ ├── 2c2ef747-38b9-9968-8215-ce28099a8b63_thumb.png │ │ │ ├── 38a52ac9-7704-60e7-b690-abfec7309162.png │ │ │ ├── 38a52ac9-7704-60e7-b690-abfec7309162_thumb.png │ │ │ ├── 3cc3af2b-9fb2-86b5-05b5-80e32a08b9d6.png │ │ │ ├── 3cc3af2b-9fb2-86b5-05b5-80e32a08b9d6_thumb.png │ │ │ ├── 5a4cd16c-93f1-5bff-cefb-5173e6d8f941.png │ │ │ ├── 5a4cd16c-93f1-5bff-cefb-5173e6d8f941_thumb.png │ │ │ ├── 605f6d17-d3f2-9090-ada7-27e72d1ebf72.png │ │ │ ├── 605f6d17-d3f2-9090-ada7-27e72d1ebf72_thumb.png │ │ │ ├── 6f3196b0-ccdc-c335-3984-f1e6b206e6a1.png │ │ │ ├── 6f3196b0-ccdc-c335-3984-f1e6b206e6a1_thumb.png │ │ │ ├── 8440908b-d565-e3ec-a16c-0b3560c806a2.png │ │ │ ├── 8440908b-d565-e3ec-a16c-0b3560c806a2_thumb.png │ │ │ ├── b2dcbd58-9489-132e-b393-9965aa40d146.png │ │ │ ├── b2dcbd58-9489-132e-b393-9965aa40d146_thumb.png │ │ │ ├── c3265e18-bf0c-fcd4-8581-d688c289e773.png │ │ │ ├── c3265e18-bf0c-fcd4-8581-d688c289e773_thumb.png │ │ │ ├── c868ac58-d7b6-f0b4-93f1-4d7249f55226.png │ │ │ ├── c868ac58-d7b6-f0b4-93f1-4d7249f55226_thumb.png │ │ │ ├── f79db6c9-3189-20c0-f0fc-bbe5e5f57335.png │ │ │ ├── f79db6c9-3189-20c0-f0fc-bbe5e5f57335_thumb.png │ │ │ └── readme.txt │ │ └── videos │ │ │ └── readme.txt │ └── videoset │ │ └── 3DGopher.mp4 ├── tasks │ └── imagetask.go ├── templates │ ├── feed_content.html │ ├── feed_page.html │ ├── footer.html │ ├── friends_content.html │ ├── friends_page.html │ ├── gatedheader.html │ ├── gopherprofile_content.html │ ├── gopherprofile_page.html │ ├── header.html │ ├── imagepreview.html │ ├── index.html │ ├── loginform.html │ ├── myprofile_content.html │ ├── myprofile_page.html │ ├── partials │ │ ├── feed_posts.html │ │ ├── friend_search_results.html │ │ └── friends_list.html │ ├── postform.html │ ├── signupconfirmation.html │ ├── signupform.html │ ├── socialmediapost.html │ ├── uploadimageform.html │ ├── uploadvideoform.html │ ├── videopreview.html │ └── webpage.html └── validationkit │ ├── checkusername_test.go │ └── validationkit.go ├── 070-Recap-Interface-And-Polymorphism └── main.go ├── 071-Text-Template ├── adi.anything ├── adi.txt └── main.go ├── 072-Templates-Parsing-Right-Way ├── main.go └── templates │ ├── one.adi │ ├── three.html │ └── two.adi ├── 073-Passing-Data-To-Templates ├── main.go └── templates │ └── adi.html ├── 074-Variables-In-Templates ├── main.go └── templates │ └── adi.html ├── 075-Passing-Composite-Data-Structure-Into-Templates ├── 01-passSlice.go ├── 02-passMap.go ├── 03-passStruct.go ├── 04-passSliceOfStruct.go ├── 05-passStructOfSliceofStruct.go ├── main.go └── templates │ ├── 01-slice.adi │ ├── 02-map.adi │ ├── 03-struct.adi │ ├── 04-slice-struct.adi │ └── 05-struct-slice-struct.adi ├── 076-Passing-Functions-Into-Template ├── main.go └── templates │ └── adi.gohtml ├── 077-Passing-Formatted-Time-Into-Templates ├── adi.gohtml └── main.go ├── 078-Pipelining ├── 01_pipeline-example │ ├── main.go │ └── tpl.gohtml └── 02_pipeline-example │ ├── main.go │ └── tpl.gohtml ├── 079-Predefined-Global-Functions ├── 01_index │ ├── 01 │ │ ├── main.go │ │ └── tpl.gohtml │ └── 02 │ │ ├── main.go │ │ └── tpl.gohtml ├── 02_and │ ├── main.go │ └── tpl.gohtml ├── 03_comparison │ ├── main.go │ ├── readme.txt │ └── tpl.gohtml └── README.md ├── 080-Template-Partials ├── 01-Partials │ ├── main.go │ └── templates │ │ ├── main.adi │ │ └── partials │ │ ├── footer.adi │ │ └── header.adi └── 02-Passing-Data-Into-Partial-Templates │ ├── main.go │ └── templates │ ├── main.adi │ └── partials │ ├── footer.adi │ └── header.adi ├── 081-Composition-And-Methods ├── 01-Composition │ ├── main.go │ └── tpl.gohtml ├── 02-Composition-Example │ ├── main.go │ └── tpl.gohtml ├── 03-Composition-Example │ ├── main.go │ ├── notes.txt │ └── tpl.gohtml ├── 04_method │ ├── main.go │ └── tpl.gohtml └── README.md ├── 082-Html-Templates-And-XSS ├── 01_text-template_no-escaping │ ├── index.html │ ├── main.go │ └── tpl.gohtml ├── 02_html-template_escaping │ ├── index.html │ ├── main.go │ └── tpl.gohtml └── README.md ├── 083-Servers-101 └── README.md ├── 084-bufio-scanner ├── 01-Scan-Lines │ └── main.go ├── 02-Scan-Words │ └── main.go └── 03-Scan-Characters │ └── main.go ├── 085-TCP-Server ├── 01-Write-To-Connection │ ├── README.md │ └── main.go ├── 02-Read-From-Connection-Goroutines │ ├── README.md │ └── main.go ├── 03-Read-Write-Connection │ ├── README.md │ └── main.go ├── 04-Read-Write-Connection-setDeadline │ ├── README.md │ └── main.go ├── 05-Client-Read-From-Connection-Dial-Read │ └── main.go ├── 06-Client-Write-To-Connection-Dial-Write │ └── main.go ├── 07-Building-TCP-Server │ └── main.go ├── 08-TCP-Server-Returns-URL-Of-GET-Request │ ├── README.md │ └── main.go ├── 09-Multiplexer-Mux-Servemux-Router-Server-HTTP │ ├── README.md │ └── main.go └── README.md ├── 086-ROT13-Server-Ceaser-Cipher └── main.go ├── 087-In-Memory-Key-Value-Database └── main.go ├── 088-nethttp-Package ├── 01-Handler │ └── main.go ├── 02-Listen-And-Serve │ └── main.go ├── 03-Request │ ├── 01-Parse-Form-Using-ParseForm │ │ ├── index.gohtml │ │ └── main.go │ ├── 02-Request-Method │ │ ├── index.gohtml │ │ └── main.go │ ├── 03-URL-Parsing │ │ ├── index.gohtml │ │ └── main.go │ ├── 04-Request-Headers │ │ ├── index.gohtml │ │ └── main.go │ └── 05-Host-ContentLength │ │ ├── index.gohtml │ │ └── main.go ├── 04-ResponseWriter │ └── main.go └── README.md ├── 089-nethttp-ServeMux-Routing ├── 01-Routing │ └── main.go ├── 02-NewServeMux │ └── main.go ├── 03-Default-ServeMux │ └── main.go ├── 04-HandleFunc │ ├── README.md │ └── main.go ├── 05-HandlerFunc │ ├── README.md │ └── main.go └── README.md ├── 090-Julien-Schimdt-Router ├── README.md ├── main.go └── templates │ ├── about.gohtml │ ├── apply.gohtml │ ├── applyProcess.gohtml │ ├── contact.gohtml │ └── index.gohtml ├── 091-Practice-Codes ├── 01-ListenAndServe-Using-Default-ServeMux │ ├── README.md │ └── main.go ├── 02-Parse-And-Serve-Template-With-Data │ ├── README.md │ ├── main.go │ └── something.gohtml ├── 03-http-Handle │ ├── README.md │ ├── main.go │ └── something.gohtml ├── 04-Basic-Server-Using-TCP │ ├── README.md │ └── main.go ├── 05-TCP-Server-Read-Operation │ ├── README.md │ └── main.go ├── 06-Breakout-Of-Reading-From-IO-Reader │ ├── README.md │ └── main.go ├── 07-Read-Functionality-Into-Serve-Func │ ├── README.md │ └── main.go ├── 08-Write-To-TCP-Connection │ ├── README.md │ └── main.go ├── 09-Status-Line-And-Response-Headers │ ├── README.md │ └── main.go ├── 10-Print-To-Terminal │ ├── README.md │ └── main.go ├── 11-Changing-ContentType-Response-Header │ ├── README.md │ └── main.go └── 12-Routing │ ├── README.md │ └── main.go ├── 092-Serving-Files-With-FileServer ├── 01-Not-Serving │ ├── 01-Example │ │ └── main.go │ └── 02-Example │ │ ├── main.go │ │ └── toby.jpg ├── 02-Serving │ ├── 01-io-Copy │ │ ├── main.go │ │ └── toby.jpg │ ├── 02-ServeContent │ │ ├── main.go │ │ └── toby.jpg │ └── 03-ServeFile │ │ ├── main.go │ │ └── toby.jpg ├── 03-Building-A-File-Server │ ├── 01-Serving-A-File-With-FileServer │ │ ├── main.go │ │ └── toby.jpg │ ├── 02-FileServer-And-StripPrefix │ │ ├── assets │ │ │ └── toby.jpg │ │ └── main.go │ └── 03-Static-File-Server │ │ ├── assets │ │ ├── css │ │ │ ├── main.css │ │ │ ├── mq_800-plus.css │ │ │ └── reset.css │ │ └── img │ │ │ ├── background-photo-mobile-devices.jpg │ │ │ ├── background-photo.jpg │ │ │ └── svg │ │ │ ├── briefcase.svg │ │ │ ├── gear.svg │ │ │ ├── home.svg │ │ │ ├── pencil.svg │ │ │ └── universal-access.svg │ │ ├── index.html │ │ └── main.go ├── 04-Practice-Codes │ ├── 01-http-ServeFile │ │ ├── README.md │ │ ├── dog.gohtml │ │ ├── dog.jpg │ │ └── main.go │ ├── 02-http-FileServer │ │ ├── README.md │ │ ├── css │ │ │ ├── main.css │ │ │ └── reset.css │ │ ├── index.html │ │ ├── main.go │ │ └── pic │ │ │ └── surf.jpg │ ├── 03-http-FileServer-Return-Type │ │ ├── README.md │ │ ├── main.go │ │ ├── public │ │ │ └── pics │ │ │ │ ├── dog.jpeg │ │ │ │ ├── dog1.jpeg │ │ │ │ └── dog2.jpeg │ │ └── templates │ │ │ └── index.gohtml │ ├── 04-FileServer-StripPrefix │ │ ├── README.md │ │ ├── main.go │ │ ├── public │ │ │ └── pics │ │ │ │ ├── dog.jpeg │ │ │ │ ├── dog1.jpeg │ │ │ │ └── dog2.jpeg │ │ └── templates │ │ │ └── index.gohtml │ ├── 05-FileServer-StripPrefix │ │ ├── README.md │ │ ├── main.go │ │ ├── public │ │ │ ├── css │ │ │ │ ├── main.css │ │ │ │ └── reset.css │ │ │ └── pic │ │ │ │ └── surf.jpg │ │ └── templates │ │ │ └── index.gohtml │ └── 06-ParseGlob-HandleFunc-applyProcess │ │ ├── README.md │ │ ├── main.go │ │ └── templates │ │ ├── about.gohtml │ │ ├── apply.gohtml │ │ ├── applyProcess.gohtml │ │ ├── contact.gohtml │ │ └── index.gohtml └── README.md ├── 093-logFatal-And-http-Error └── main.go ├── 094-http-NotFoundHandler └── main.go ├── 095-Deploying-To-Google-Cloud-AppEngine ├── 01-Example-Project-Not-For-Deployment │ ├── app.yaml │ ├── css │ │ └── main.css │ ├── img │ │ └── bird.jpg │ ├── index.html │ └── main.go ├── 02-Example-Project-For-Deployment │ ├── app.yaml │ ├── css │ │ ├── main.css │ │ ├── mq_800-plus.css │ │ └── reset.css │ ├── img │ │ ├── background-photo-mobile-devices.jpg │ │ ├── background-photo.jpg │ │ └── svg │ │ │ ├── briefcase.svg │ │ │ ├── gear.svg │ │ │ ├── home.svg │ │ │ ├── pencil.svg │ │ │ └── universal-access.svg │ ├── index.html │ └── main.go └── README.md ├── 096-Passing-Data-Query-String-Form-Submission ├── 01-URL-Query-String │ └── main.go ├── 02-HTML-Form-Submission │ └── main.go ├── 03-Form-Post │ └── main.go ├── 04-Form-Get │ └── main.go ├── 05-HTML-Form-With-Many-Fields │ ├── main.go │ └── templates │ │ ├── include-footer.gohtml │ │ ├── include-header.gohtml │ │ └── index.gohtml ├── 06-Enctype │ ├── 01-Default │ │ ├── main.go │ │ └── templates │ │ │ ├── include-footer.gohtml │ │ │ ├── include-header.gohtml │ │ │ └── index.gohtml │ ├── 02-Multipart-Form-Data │ │ ├── main.go │ │ └── templates │ │ │ ├── include-footer.gohtml │ │ │ ├── include-header.gohtml │ │ │ └── index.gohtml │ └── 03-Text-Plain │ │ ├── main.go │ │ └── templates │ │ ├── include-footer.gohtml │ │ ├── include-header.gohtml │ │ └── index.gohtml ├── README.md └── URL.png ├── 097-Creating-Uploading-Reading-File-On-Server ├── 01-Read-From-Uploaded-File │ ├── example.txt │ └── main.go └── 02-Store-Uploaded-File-Contents-Into-Another-File │ └── main.go ├── 098-Redirect ├── 01-SeeOther-303 │ ├── main.go │ └── templates │ │ └── index.gohtml ├── 02-TemporaryRedirect-307 │ ├── main.go │ └── templates │ │ └── index.gohtml ├── 03-MovedPermanently-301 │ └── main.go ├── 04-WriteHeader │ ├── main.go │ └── templates │ │ └── index.gohtml ├── README.html └── status-codes.html ├── 099-Cookies ├── 01-Set-Cookie-Read-Cookie │ └── main.go ├── 02-Multiple-Cookies │ └── main.go ├── 03-Website-Hit-Counter-Using-Cookie │ └── main.go ├── 04-Deleting-Cookie-With-MaxAge │ └── main.go ├── 05-Path │ ├── 01 │ │ └── main.go │ ├── 02 │ │ └── main.go │ └── 03-templates │ │ ├── 01 │ │ ├── main.go │ │ └── templates │ │ │ ├── bowzer.gohtml │ │ │ ├── bowzerpics.gohtml │ │ │ ├── cat.gohtml │ │ │ └── index.gohtml │ │ └── 02 │ │ ├── main.go │ │ └── templates │ │ ├── bowzer.gohtml │ │ ├── bowzerpics.gohtml │ │ ├── cat.gohtml │ │ └── index.gohtml └── README.md ├── 100-Sessions ├── 01-UUID │ └── main.go ├── 02-Session │ ├── main.go │ ├── session.jpg │ └── templates │ │ ├── bar.gohtml │ │ └── index.gohtml ├── 03-Signup │ ├── main.go │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ └── signup.gohtml ├── 04-Bcrypt │ ├── main.go │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ └── signup.gohtml ├── 05-Login │ ├── main.go │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ ├── login.gohtml │ │ └── signup.gohtml ├── 06-Logout │ ├── main.go │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ ├── login.gohtml │ │ └── signup.gohtml ├── 07-Permissions │ ├── main.go │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ ├── login.gohtml │ │ └── signup.gohtml ├── 08-Expire-Session │ ├── README.md │ ├── main.go │ ├── maps.png │ ├── norace.png │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ ├── login.gohtml │ │ └── signup.gohtml ├── 09-Middleware │ ├── README.md │ ├── main.go │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ ├── login.gohtml │ │ └── signup.gohtml ├── 10-Temp │ ├── README.md │ ├── main.go │ ├── maps.png │ ├── norace.png │ ├── notes.md │ ├── session.go │ └── templates │ │ ├── bar.gohtml │ │ ├── index.gohtml │ │ ├── login.gohtml │ │ └── signup.gohtml └── README.md ├── 101-Bcrypt └── main.go ├── 102-AWS ├── 01-About │ └── README.md ├── 02-Deploying-Namaste-Aditya-To-AWS │ ├── README.md │ ├── main.go │ └── namaste_aditya └── 03-Deploying-Session-Example-To-AWS │ ├── README.md │ ├── main.go │ ├── session.go │ └── templates │ ├── bar.gohtml │ ├── index.gohtml │ ├── login.gohtml │ └── signup.gohtml ├── 103-Concurrency-Waitgroups └── main.go ├── 104-Concurrency-Channels-Deadlock └── main.go ├── 105-Concurrency-Channels └── main.go ├── 106-Concurrency-Channels-Select-Statement └── main.go ├── 107-Concurrency-Worker-Pool-Pattern └── main.go ├── 108-RDS ├── 01-Connect-To-RDS │ ├── README.md │ └── main.go ├── 02-CRUD-App │ └── main.go └── README.md ├── 109-AWS-Scaling ├── 01-Architecture │ ├── 01.jpg │ ├── 02.jpg │ ├── 03.jpg │ ├── 04.jpg │ ├── 05.jpg │ └── 06.jpg ├── 02-Load-Balancer │ ├── README.md │ └── main.go ├── 03-AMI │ ├── README.md │ └── main.go ├── 04-Webservers-Accessing-RDS │ └── main.go └── 05-Auto-Scaling │ └── README.md ├── 110-Photo-Blog ├── 01-Starting │ ├── main.go │ └── templates │ │ └── index.gohtml ├── 02-Storing-User-Data-In-Cookie │ ├── main.go │ └── templates │ │ └── index.gohtml ├── 03-Appending-Multiple-Data-Into-Cookie │ ├── main.go │ └── templates │ │ └── index.gohtml ├── 04-Upload-Pictures-To-Server │ ├── main.go │ ├── public │ │ └── pics │ │ │ └── f382716c1600421f127c7414a072016434fcd43a.jpg │ └── templates │ │ └── index.gohtml └── 05-Display-Pictures │ ├── main.go │ ├── public │ └── pics │ │ └── f382716c1600421f127c7414a072016434fcd43a.jpg │ └── templates │ └── index.gohtml ├── 111-HMAC-Keyed-Hash-Message-Authentication ├── 01-Basic │ └── main.go └── 02-Web-Example │ └── main.go ├── 112-Base64 ├── 01-Custom-Encode-Standard │ └── main.go ├── 02-Standard-Encoding │ └── main.go ├── 03-Base64-Decode │ └── main.go └── README.md ├── 113-Web-Storage ├── 01-Local-Storage │ └── index.html ├── 02-Session-Storage │ └── index.html └── README.md ├── 114-Context ├── 01-What-Is-Context │ └── main.go ├── 02-Storing-Data-WithValue │ └── main.go ├── 03-WithTimeout │ └── main.go ├── 04-Context-With-Gen │ └── main.go ├── 05-WithCancel │ └── main.go └── README.md ├── 115-TLS-HTTPS ├── 01-ListenAndServeTLS │ └── main.go └── 02-LetsEncrypt │ └── main.go ├── 116-JSON ├── 01-Basics-Marshal-And-Encode │ └── main.go ├── 02-Unmarshal │ ├── 01-Simple-Example │ │ └── main.go │ ├── 02-Example │ │ └── main.go │ └── 03-Extract-Specific-Data-From-JSON │ │ └── main.go └── 03-Extras │ ├── 01 │ └── main.go │ ├── 02_object │ └── index.html │ ├── 03_array │ └── index.html │ ├── 04_stringify │ └── index.html │ ├── 05_stringify │ └── index.html │ ├── 06_unmarshal │ ├── index.html │ └── main.go │ ├── 07_unmarshal │ ├── index.html │ └── main.go │ ├── 08_unmarshal_tags │ ├── index.html │ └── main.go │ ├── 09_string │ ├── index.html │ └── main.go │ ├── 10_int │ ├── index.html │ └── main.go │ ├── 11_bool │ ├── index.html │ └── main.go │ ├── 12_null │ ├── index.html │ └── main.go │ ├── 13_marshal │ └── main.go │ ├── 14_marshal │ └── main.go │ ├── 15_marshal │ └── main.go │ └── 16_http_response_codes │ ├── index.html │ ├── instructions.txt │ └── main.go ├── 117-AJAX ├── 01 │ ├── data.txt │ ├── index.html │ └── test.html ├── 02 │ ├── 01 │ │ ├── main.go │ │ └── templates │ │ │ └── index.gohtml │ └── 02 │ │ ├── main.go │ │ └── templates │ │ └── index.gohtml └── 03 │ ├── main.go │ ├── notes.md │ ├── session.go │ ├── surfergirl │ └── templates │ ├── bar.gohtml │ ├── index.gohtml │ ├── login.gohtml │ └── signup.gohtml ├── 118-MongoDB-REST ├── 01-JulienSchmidt-Router │ ├── README.md │ └── main.go ├── 02-json │ ├── README.md │ ├── main.go │ └── models │ │ └── user.go ├── 03-post-delete │ ├── README.md │ ├── main.go │ └── models │ │ └── user.go ├── 04-mvc │ ├── README.md │ ├── controllers │ │ └── user.go │ ├── main.go │ └── models │ │ └── user.go ├── 05-mongodb │ ├── 01-update-user-controller │ │ ├── README.md │ │ ├── controllers │ │ │ └── user.go │ │ ├── main.go │ │ └── models │ │ │ └── user.go │ ├── 02-update-user-model │ │ ├── README.md │ │ ├── controllers │ │ │ └── user.go │ │ ├── main.go │ │ └── models │ │ │ └── user.go │ ├── 03-update-user-controllers-post │ │ ├── README.md │ │ ├── controllers │ │ │ └── user.go │ │ ├── main.go │ │ └── models │ │ │ └── user.go │ ├── 04-update-user-controllers-get │ │ ├── README.md │ │ ├── controllers │ │ │ └── user.go │ │ ├── main.go │ │ └── models │ │ │ └── user.go │ └── 05-update-user-controllers-delete │ │ ├── README.md │ │ ├── controllers │ │ └── user.go │ │ ├── main.go │ │ └── models │ │ └── user.go ├── 06-Storing-Data-In-Map-Instead-of-MongoDB │ ├── controllers │ │ └── user.go │ ├── main.go │ └── models │ │ └── user.go ├── 07-Storing-Data-In-JSON-File-Instead-of-MongoDB │ ├── README.md │ ├── controllers │ │ └── user.go │ ├── data │ ├── main.go │ └── models │ │ └── user.go └── 08-Refactor-Codes-Into-Packages │ ├── README.md │ ├── controllers │ ├── general.go │ └── user.go │ ├── main.go │ ├── models │ └── user.go │ ├── session │ └── session.go │ ├── templates │ ├── bar.gohtml │ ├── index.gohtml │ ├── login.gohtml │ └── signup.gohtml │ └── wildwest ├── 119-Bracket-Pairing-Matching └── main.go ├── 120-Functional-Options-Pattern ├── main.go └── server │ └── server.go ├── LICENSE ├── README.md ├── UBER-GO-STYLE-GUIDE.md ├── go.mod ├── go.sum └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Go Workspace - Custom created by Aditya 2 | 00-GoWorkSpace 3 | # 00-GoWorkSpace/cache 4 | # 00-GoWorkSpace/pkg 5 | # 00-GoWorkSpace/src 6 | 7 | # Binaries for programs and plugins 8 | *.exe 9 | *.exe~ 10 | *.dll 11 | *.so 12 | *.dylib 13 | 14 | # Test binary, built with `go test -c` 15 | *.test 16 | 17 | # Output of the go coverage tool, specifically when used with LiteIDE 18 | *.out 19 | 20 | # Dependency directories (remove the comment below to include it) 21 | # vendor/ 22 | -------------------------------------------------------------------------------- /001-Work-Environment-Setup/README.md: -------------------------------------------------------------------------------- 1 | # GO INSTALLATION GUIDES 2 | 3 | Detailed installation instructions: 4 | 5 | * [OS X](osx-installation.md) 6 | * [Windows](windows-installation.md) 7 | * [Linux (Ubuntu)](ubuntu-installation.md) 8 | -------------------------------------------------------------------------------- /003-Scopes/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // package scope 4 | // file scope 5 | 6 | import "fmt" 7 | 8 | const ok = true 9 | 10 | func main() { // block scope starts 11 | 12 | var namaste = "नमस्ते आदित्य" 13 | 14 | // namaste and ok are visible here 15 | fmt.Println(namaste, ok) 16 | 17 | } // block scope ends 18 | -------------------------------------------------------------------------------- /004-Print-Number-Of-CPU/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | ) 7 | 8 | func main() { 9 | fmt.Println(runtime.NumCPU()) 10 | } 11 | -------------------------------------------------------------------------------- /005-Exporting/goversion/cmd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aditya43/golang/005-Exporting/goversion" 7 | ) 8 | 9 | func main() { 10 | fmt.Println(goversion.Version()) 11 | } 12 | -------------------------------------------------------------------------------- /005-Exporting/goversion/goversion.go: -------------------------------------------------------------------------------- 1 | package goversion 2 | 3 | import "runtime" 4 | 5 | func Version() string { 6 | return runtime.Version() 7 | } 8 | -------------------------------------------------------------------------------- /005-Exporting/printer/cmd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/aditya43/golang/005-Exporting/printer" 4 | 5 | func main() { 6 | // printer.namaste() // Not available. This will throw error. 7 | printer.Namaste() 8 | } 9 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/01-declaration-syntax/01-syntax/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var speed int 7 | 8 | fmt.Println(speed) 9 | } 10 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/01-declaration-syntax/02-naming-rules/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // VARIABLE NAMING RULES 4 | 5 | func main() { 6 | // CORRECT DECLARATIONS 7 | var speed int 8 | var SpeeD int 9 | 10 | // underscore is allowed but not recommended 11 | var _speed int 12 | 13 | // Unicode letters are allowed 14 | var 速度 int 15 | 16 | // keep the compiler happy 17 | _, _, _, _ = speed, SpeeD, _speed, 速度 18 | } 19 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/02-example-declarations/01-int/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var nFiles int 7 | var counter int 8 | var nCPU int 9 | 10 | fmt.Println( 11 | nFiles, 12 | counter, 13 | nCPU, 14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/02-example-declarations/02-float64/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var heat float64 7 | var ratio float64 8 | var degree float64 9 | 10 | fmt.Println( 11 | heat, 12 | ratio, 13 | degree, 14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/02-example-declarations/03-bool/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var off bool 7 | var valid bool 8 | var closed bool 9 | 10 | fmt.Println( 11 | off, 12 | valid, 13 | closed, 14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/02-example-declarations/04-string/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var msg string 7 | var name string 8 | var text string 9 | 10 | fmt.Println( 11 | msg, 12 | name, 13 | text, 14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/04-unused-variables-and-blank-identifier/02-blank-identifier/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var speed int 5 | 6 | // let's assign the variable to the blank-identifier 7 | // so that Go compiler won't get grumpy 8 | _ = speed 9 | } 10 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/05-multiple-declarations/01-multiple/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var ( 7 | speed int 8 | heat float64 9 | 10 | off bool 11 | brand string 12 | ) 13 | 14 | fmt.Println(speed) 15 | fmt.Println(heat) 16 | fmt.Println(off) 17 | fmt.Printf("%q\n", brand) 18 | } 19 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/02-Declarations/05-multiple-declarations/02-parallel/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // this is equal to: 7 | // 8 | // var ( 9 | // speed int 10 | // velocity int 11 | // ) 12 | // 13 | // or: 14 | // 15 | // var speed int 16 | // var velocity int 17 | // 18 | var speed, velocity int 19 | 20 | fmt.Println(speed, velocity) 21 | } 22 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/03-Short-Declarations/03-multiple-short-declaration/01-declaration/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // the number of variables and values should be equal 7 | 8 | // -> `true` is being assigned to `safe` 9 | // -> `50` is being assigned to `speed` 10 | 11 | safe, speed := true, 50 12 | 13 | fmt.Println(safe, speed) 14 | } 15 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/04-Swapping-Variable-Values/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | firstName, lastName := "Aditya", "Hajare" 7 | fmt.Println("Before Swapping: ", firstName, lastName) 8 | 9 | firstName, lastName = lastName, firstName 10 | fmt.Println("After Swapping: ", firstName, lastName) 11 | } 12 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/05-Assignments/01-assignment/01-assignment/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var speed int 7 | fmt.Println(speed) 8 | 9 | speed = 100 10 | fmt.Println(speed) 11 | 12 | speed = speed - 25 13 | fmt.Println(speed) 14 | } 15 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/05-Assignments/01-overview/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var counter int 7 | 8 | fmt.Println("counter's name : counter") 9 | fmt.Println("counter's value:", counter) 10 | fmt.Printf("counter's type : %T\n", counter) 11 | 12 | counter = 10 // OK 13 | // counter = "ten" // NOT OK 14 | 15 | fmt.Println("counter's value:", counter) 16 | 17 | counter++ 18 | fmt.Println("counter's value:", counter) 19 | } 20 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/05-Assignments/05-multiple-assignment/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | var ( 10 | speed int 11 | now time.Time 12 | ) 13 | 14 | speed, now = 100, time.Now() 15 | 16 | fmt.Println(speed, now) 17 | 18 | // Try this alternative (formatted time). 19 | 20 | // fmt.Println(speed, now.Format(time.Kitchen)) 21 | } 22 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/05-Assignments/06-swapping/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var ( 7 | speed = 100 8 | prevSpeed = 50 9 | ) 10 | 11 | speed, prevSpeed = prevSpeed, speed 12 | 13 | fmt.Println(speed, prevSpeed) 14 | } 15 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/05-Assignments/07-path-project/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "path" 6 | ) 7 | 8 | func main() { 9 | var dir, file string 10 | 11 | dir, file = path.Split("project/assets/css/main.css") 12 | 13 | fmt.Println("dir :", dir) 14 | fmt.Println("file:", file) 15 | } 16 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/05-Assignments/08-path-project-discarding-shorthand/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "path" 6 | ) 7 | 8 | func main() { 9 | // 'project/assets/css/' is discarded. 10 | _, file := path.Split("project/assets/css/main.css") 11 | 12 | fmt.Println("file:", file) 13 | } 14 | -------------------------------------------------------------------------------- /006-Variables-And-Data-Types/07-Command-Line-Args-Greeter/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | // I didn't include any error detection here. 9 | // 10 | // So, if we don't pass any command line argument, this program will fail. 11 | // This is intentional. 12 | 13 | func main() { 14 | // fmt.Printf("%#v\n", os.Args) // To see whats inside 'os.Args' 15 | 16 | name := os.Args[1] 17 | 18 | fmt.Println("नमस्ते", name) 19 | } 20 | -------------------------------------------------------------------------------- /008-Printf/02-Escape-Sequences/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // without newline 7 | fmt.Println("AdityaHajare") 8 | 9 | // with newline: 10 | // \n = escape sequence 11 | // \ = escape character 12 | fmt.Println("Aditya\nHajare") 13 | 14 | // escape characters: 15 | // \\ = \ 16 | // \" = " 17 | fmt.Println("Aditya\\n\"nHajare\"") 18 | } 19 | -------------------------------------------------------------------------------- /008-Printf/03-Printing-Variable-Types/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var ( 7 | adiBool bool 8 | adiInt int 9 | adiFloat float64 10 | adiStr string 11 | adiPointer *string 12 | ) 13 | 14 | fmt.Printf("\nadiBool: %T", adiBool) 15 | fmt.Printf("\nadiInt: %T", adiInt) 16 | fmt.Printf("\nadiFloat: %T", adiFloat) 17 | fmt.Printf("\nadiStr: %T", adiStr) 18 | fmt.Printf("\nadiPointer: %T\n", adiPointer) 19 | } 20 | -------------------------------------------------------------------------------- /008-Printf/04-Argument-Indexing/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var ( 7 | firstName = "Aditya" 8 | age = 33 9 | isActive = true 10 | ) 11 | 12 | // Using Argument indexing in Printf. Argument indexing starts at 1 13 | fmt.Printf("\nName: %[3]v | Age: %[1]v | isActive: %[2]v\n", firstName, age, isActive) 14 | } 15 | -------------------------------------------------------------------------------- /008-Printf/printf cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/008-Printf/printf cheatsheet.pdf -------------------------------------------------------------------------------- /009-Numbers/01-arithmetic-operators/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var ( 7 | myAge = 30 8 | yourAge = 35 9 | average float64 10 | ) 11 | 12 | average = float64(myAge+yourAge) / 2 13 | 14 | fmt.Println(average) 15 | } 16 | -------------------------------------------------------------------------------- /009-Numbers/01-arithmetic-operators/03-float-inaccuracy/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | ratio := 1.0 / 10.0 7 | 8 | // After 10 operations the inaccuracy is clear 9 | for range [...]int{10: 0} { 10 | ratio += 1.0 / 10.0 11 | } 12 | 13 | fmt.Printf("%.60f", ratio) 14 | } 15 | -------------------------------------------------------------------------------- /009-Numbers/01-arithmetic-operators/03-float-inaccuracy/03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // When we use a float value with an integer 7 | // in a calculation, 8 | // the result always becomes a float. 9 | 10 | ratio := 3.0 / 2 11 | 12 | // OR: 13 | // ratio = 3 / 2.0 14 | 15 | // OR - if 3 is inside an int variable: 16 | // n := 3 17 | // ratio = float64(n) / 2 18 | 19 | fmt.Printf("%f", ratio) 20 | } 21 | -------------------------------------------------------------------------------- /009-Numbers/03-precedence/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println( 7 | 2+2*4/2, 8 | 2+((2*4)/2), // same as above 9 | ) 10 | 11 | fmt.Println( 12 | 1+4-2, 13 | (1+4)-2, // same as above 14 | ) 15 | 16 | fmt.Println( 17 | (2+2)*4/2, 18 | (2+2)*(4/2), // same as above 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /009-Numbers/03-precedence/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | n, m := 1, 5 7 | 8 | fmt.Println(2 + 1*m/n) 9 | fmt.Println(2 + ((1 * m) / n)) // same as above 10 | 11 | // let's change the precedence using parentheses 12 | fmt.Println(((2 + 1) * m) / n) 13 | } 14 | -------------------------------------------------------------------------------- /009-Numbers/03-precedence/04/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | celsius := 35. 7 | 8 | // Wrong formula : 9*celsius + 160 / 5 9 | // Correct formula: (9*celsius + 160) / 5 10 | fahrenheit := (9*celsius + 160) / 5 11 | 12 | fmt.Printf("%g ºC is %g ºF\n", celsius, fahrenheit) 13 | } 14 | -------------------------------------------------------------------------------- /009-Numbers/04-incdec-statement/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var n int 7 | 8 | // ALTERNATIVES: 9 | // n = n + 1 10 | // n += 1 11 | 12 | // BETTER: 13 | n++ 14 | 15 | fmt.Println(n) 16 | } 17 | -------------------------------------------------------------------------------- /009-Numbers/04-incdec-statement/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | n := 10 7 | 8 | // ALTERNATIVES: 9 | // n = n - 1 10 | // n -= 1 11 | 12 | // BETTER: 13 | n-- 14 | 15 | fmt.Println(n) 16 | } 17 | -------------------------------------------------------------------------------- /009-Numbers/06-Feets-To-Meters-Calculator/main.go: -------------------------------------------------------------------------------- 1 | // OS Package: strconv allows us to convert vasic values from/to a string value. 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "strconv" 9 | ) 10 | 11 | func main() { 12 | arg := os.Args[1] 13 | 14 | feets, _ := strconv.ParseFloat(arg, 64) 15 | 16 | meters := feets * 0.3048 17 | 18 | fmt.Printf("\n%g feets equals to %g meters\n", feets, meters) 19 | } 20 | -------------------------------------------------------------------------------- /009-Numbers/07-Celsius-To-Fahrenheit-Calculator/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | arg := os.Args[1] 11 | 12 | celsius, _ := strconv.ParseFloat(arg, 64) 13 | 14 | fahrenheit := (celsius * 1.8) + 32 15 | 16 | fmt.Printf("\n%g°C equals to %g°F\n", celsius, fahrenheit) 17 | } 18 | -------------------------------------------------------------------------------- /010-Strings/02-concatenation/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | name, last := "आदित्य", "Hajare" 7 | 8 | fmt.Println(name + " " + last) 9 | } 10 | -------------------------------------------------------------------------------- /010-Strings/02-concatenation/02-assignment-operation/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | name, last := "आदित्य", "Hajare" 7 | 8 | // assignment operation using string concat 9 | name += " Doe" 10 | 11 | // equals to this: 12 | // name = name + " Doe" 13 | 14 | fmt.Println(name + " " + last) 15 | } 16 | -------------------------------------------------------------------------------- /010-Strings/03-string-length/01-len/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | name := "carl" 7 | 8 | // strings are made up of bytes 9 | // len function counts the bytes in a string value 10 | fmt.Println(len(name)) 11 | } 12 | -------------------------------------------------------------------------------- /010-Strings/05-windows-path/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // this one uses a raw string literal 7 | 8 | // can We see how readable it is? 9 | // compared to the previous one? 10 | 11 | path := `c:\program files\duper super\fun.txt 12 | c:\program files\really\funny.png` 13 | 14 | fmt.Println(path) 15 | } 16 | -------------------------------------------------------------------------------- /010-Strings/06-print-json/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // this one uses a raw string literal 7 | 8 | // can we see how readable it is? 9 | // compared to the previous one? 10 | 11 | json := ` 12 | { 13 | "Items": [{ 14 | "Item": { 15 | "name": "Aditya Hajare" 16 | } 17 | }] 18 | }` 19 | 20 | fmt.Println(json) 21 | } 22 | -------------------------------------------------------------------------------- /010-Strings/07-raw-concat/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | name := os.Args[1] 10 | 11 | msg := `hi ` + name + `! 12 | how are you?` 13 | 14 | fmt.Println(msg) 15 | } 16 | -------------------------------------------------------------------------------- /010-Strings/08-count-the-chars/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "unicode/utf8" 7 | ) 8 | 9 | func main() { 10 | length := utf8.RuneCountInString(os.Args[1]) 11 | fmt.Println(length) 12 | } 13 | -------------------------------------------------------------------------------- /010-Strings/09-improved-banger/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | "unicode/utf8" 8 | ) 9 | 10 | func main() { 11 | msg := os.Args[1] 12 | l := utf8.RuneCountInString(msg) 13 | 14 | s := msg + strings.Repeat("!", l) 15 | 16 | fmt.Println(s) 17 | } 18 | -------------------------------------------------------------------------------- /010-Strings/10-tolowercase/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | fmt.Println(strings.ToLower(os.Args[1])) 11 | } 12 | -------------------------------------------------------------------------------- /010-Strings/11-trim-it/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func main() { 9 | msg := ` 10 | 11 | The weather looks good. 12 | I should go and play. 13 | 14 | 15 | 16 | ` 17 | 18 | fmt.Println(strings.TrimSpace(msg)) 19 | } 20 | -------------------------------------------------------------------------------- /010-Strings/12-right-trim-it/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "unicode/utf8" 7 | ) 8 | 9 | func main() { 10 | name := "आदित्य " 11 | 12 | name = strings.TrimRight(name, " ") 13 | l := utf8.RuneCountInString(name) 14 | 15 | fmt.Println(l) 16 | } 17 | -------------------------------------------------------------------------------- /011-Type-System-In-Go/02-bytes/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // byte is an integer number with 8 bits (1 byte) 7 | var b byte 8 | 9 | // all bits are empty or 0 10 | // this is the minimum number a byte can represent 11 | b = 0 12 | fmt.Printf("%08b = %d\n", b, b) 13 | 14 | // all bits are full or 1 15 | // this is the maximum number a byte can represent 16 | b = 255 17 | fmt.Printf("%08b = %d\n", b, b) 18 | } 19 | -------------------------------------------------------------------------------- /011-Type-System-In-Go/04-overflow/01-problem/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var ( 7 | width uint8 = 255 8 | height = 255 // int 9 | ) 10 | 11 | width++ 12 | 13 | if int(width) < height { 14 | fmt.Println("height is greater") 15 | } 16 | 17 | fmt.Printf("width: %d height: %d\n", width, height) 18 | } 19 | -------------------------------------------------------------------------------- /011-Type-System-In-Go/04-overflow/03-destructive/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // uint16 max value is 65535 7 | big := uint16(65535) 8 | 9 | // uint8 destroys its value 10 | // to its own max value which is 255 11 | // 12 | // 65535 - 255 is lost. 13 | small := uint8(big) 14 | 15 | // fmt.Printf("%b %d\n", big, big) 16 | // fmt.Printf("%b %[1]d\n", big) 17 | 18 | fmt.Printf("%016b %[1]d\n", big) 19 | fmt.Printf("%016b %[1]d\n", small) 20 | } 21 | -------------------------------------------------------------------------------- /011-Type-System-In-Go/05-defined-types/03-underlying-types/weights/weights.go: -------------------------------------------------------------------------------- 1 | package weights 2 | 3 | type ( 4 | // Gram underlying type is int64 5 | Gram int 6 | 7 | // Kilogram underlying type is int64 8 | Kilogram Gram 9 | 10 | // Ton underlying type is int64 11 | Ton Kilogram 12 | ) 13 | -------------------------------------------------------------------------------- /011-Type-System-In-Go/08-Type-Problem/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var ( 7 | width uint16 8 | height uint16 9 | ) 10 | 11 | width, height = 255, 265 12 | width += 10 13 | 14 | fmt.Printf("width: %d height: %d\n", width, height) 15 | fmt.Println("are they equal?", width == height) 16 | } 17 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/01-Syntax/01-magic-numbers/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // This program uses magic values 6 | 7 | func main() { 8 | cm := 100 9 | m := cm / 100 // 100 is a magic value 10 | fmt.Printf("%dcm is %dm\n", cm, m) 11 | 12 | cm = 200 13 | m = cm / 100 // 100 is a magic value 14 | fmt.Printf("%dcm is %dm\n", cm, m) 15 | } 16 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/01-Syntax/02-constants/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // This program uses a named constant 6 | // instead of a magic value 7 | 8 | func main() { 9 | const meters int = 100 10 | 11 | cm := 100 12 | m := cm / meters // using a named constant 13 | fmt.Printf("%dcm is %dm\n", cm, m) 14 | 15 | cm = 200 16 | m = cm / meters // using a named constant 17 | fmt.Printf("%dcm is %dm\n", cm, m) 18 | } 19 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/01-Syntax/03-safety/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // Go can't catch the same error at runtime 7 | // When we run this, there will be an error: 8 | // 9 | // panic: runtime error: integer divide by zero 10 | n, m := 1, 0 11 | fmt.Println(n / m) 12 | 13 | // Go will detect the division by zero error 14 | // at compile-time 15 | // 16 | // const n int = 1 17 | // const m int = 0 18 | // fmt.Println(n / m) 19 | } 20 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/01-Syntax/04-rules/01-immutability/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | const max int = 100 5 | 6 | // ERROR: cannot assign to max 7 | // constants are immutable (cannot change) 8 | // max = 100 9 | } 10 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/01-Syntax/04-rules/02-runtime-func/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | func main() { 9 | // math.Pow calculates the power of the given number 10 | fmt.Println(math.Pow10(2)) // 100 11 | fmt.Println(math.Pow10(3)) // 1000 12 | fmt.Println(math.Pow10(4)) // 10000 13 | 14 | // ERROR: math.Pow is not a constant 15 | // constants cannot use runtime constructs 16 | 17 | // const max int = math.Pow10(2) 18 | } 19 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/01-Syntax/04-rules/03-runtime-var/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | n := 2 5 | 6 | // ERROR: n is not a constant 7 | // const max int = n 8 | 9 | _ = n 10 | } 11 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/01-Syntax/04-rules/04-len/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // When argument to len is a constant, len can be used 7 | // while initializing a constant 8 | // 9 | // Here, "Hello" is a constant. 10 | 11 | const max int = len("Hello") 12 | 13 | fmt.Println(max) 14 | } 15 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/02-constant-types-and-expressions/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min int = 1 7 | const pi float64 = 3.14 8 | const version string = "2.0.1" 9 | const debug bool = true 10 | const A rune = 'A' 11 | 12 | fmt.Println(min, pi, version, debug, A) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/02-constant-types-and-expressions/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min = 1 7 | const pi = 3.14 8 | const version = "2.0.1" 9 | const debug = true 10 | const A = 'A' 11 | 12 | fmt.Println(min, pi, version, debug, A) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/02-constant-types-and-expressions/03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min = 1 + 1 7 | const pi = 3.14 * min 8 | const version = "2.0.1" + "-beta" 9 | const debug = !true 10 | const A rune = 'A' + 1 11 | 12 | fmt.Println(min, pi, version, debug, A) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/03-multiple-declaration/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // below declaration is the same as this one: 7 | 8 | // const ( 9 | // min int = 1 10 | // max int = 1000 11 | // ) 12 | 13 | const min, max int = 1, 1000 14 | 15 | fmt.Println(min, max) 16 | 17 | // print the types of min and max 18 | fmt.Printf("%T %T\n", min, max) 19 | } 20 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/03-multiple-declaration/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // constants repeat the previous type and expression 7 | const ( 8 | min int = 1 9 | max // int = 1 10 | ) 11 | 12 | fmt.Println(min, max) 13 | 14 | // print the types of min and max 15 | fmt.Printf("%T %T\n", min, max) 16 | } 17 | -------------------------------------------------------------------------------- /012-Constants/01-Declarations/03-multiple-declaration/03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // constants repeat the previous type and expression 7 | const ( 8 | min int = 1 + 1 9 | max // int = 1 + 1 10 | ) 11 | 12 | fmt.Println(min, max) 13 | 14 | // print the types of min and max 15 | fmt.Printf("%T %T\n", min, max) 16 | } 17 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/01-typeless-constants/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // min and pi are typeless constants 7 | const min = 1 + 1 8 | const pi = 3.14 * min 9 | 10 | fmt.Println(min, pi) 11 | } 12 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/02-typed-vs-typeless/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min int = 42 7 | 8 | var i int 9 | i = min // OK 10 | 11 | fmt.Println(i) 12 | } 13 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/02-typed-vs-typeless/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min int = 42 7 | 8 | var f float64 9 | 10 | // ERROR: Type Mismatch 11 | // f = min // NOT OK 12 | 13 | fmt.Println(f) 14 | } 15 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/02-typed-vs-typeless/03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min = 42 7 | 8 | var f float64 9 | 10 | f = min // OK when min is typeless 11 | 12 | fmt.Println(f) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/03-default-type/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min int32 = 1 7 | 8 | max := 5 + min 9 | // above line equals to this: 10 | // max := int32(5) + min 11 | 12 | fmt.Printf("Type of max: %T\n", max) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/03-default-type/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const min = 1 7 | 8 | max := 5 + min 9 | // above line equals to this: 10 | // max := int(5) + int(min) 11 | 12 | fmt.Printf("Type of max: %T\n", max) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/03-default-type/03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | i := 42 7 | f := 3.14 8 | b := true 9 | s := "Hello" 10 | r := 'A' 11 | 12 | fmt.Printf("i is %T\n", i) 13 | fmt.Printf("f is %T\n", f) 14 | fmt.Printf("b is %T\n", b) 15 | fmt.Printf("s is %T\n", s) 16 | 17 | // int32 = rune (type alias) 18 | fmt.Printf("r is %T\n", r) 19 | } 20 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/03-default-type/04/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | i := 42 + 3.14 // OK: 42 and 3.14 are typeless 7 | 8 | // above line equals to this: 9 | // i := float64(42 + 3.14) 10 | 11 | fmt.Printf("i is %T\n", i) 12 | } 13 | -------------------------------------------------------------------------------- /012-Constants/02-Typeless-Constants/03-default-type/05/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | // NOT OK 5 | // "Hello" string literal cannot be converted 6 | // into a bool value 7 | // f := true + "Hello" 8 | } 9 | -------------------------------------------------------------------------------- /012-Constants/04-IOTA/01-manually/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | monday = 0 8 | tuesday = 1 9 | wednesday = 2 10 | thursday = 3 11 | friday = 4 12 | saturday = 5 13 | sunday = 6 14 | ) 15 | 16 | fmt.Println(monday, tuesday, wednesday, thursday, friday, 17 | saturday, sunday) 18 | } 19 | -------------------------------------------------------------------------------- /012-Constants/04-IOTA/02-with-iota/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | monday = iota 8 | tuesday 9 | wednesday 10 | thursday 11 | friday 12 | saturday 13 | sunday 14 | ) 15 | 16 | fmt.Println(monday, tuesday, wednesday, thursday, friday, 17 | saturday, sunday) 18 | } 19 | -------------------------------------------------------------------------------- /012-Constants/04-IOTA/03-expressions/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | monday = iota + 1 8 | tuesday 9 | wednesday 10 | thursday 11 | friday 12 | saturday 13 | sunday 14 | ) 15 | 16 | fmt.Println(monday, tuesday, wednesday, thursday, friday, 17 | saturday, sunday) 18 | } 19 | -------------------------------------------------------------------------------- /012-Constants/04-IOTA/04-blank-identifier/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | EST = -5 8 | MST = -7 9 | PST = -8 10 | ) 11 | 12 | fmt.Println(EST, MST, PST) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/04-IOTA/04-blank-identifier/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | EST = -(5 + iota) // CORRECT: -5 8 | MST // INCORRECT: -6 9 | PST // INCORRECT: -7 10 | ) 11 | 12 | fmt.Println(EST, MST, PST) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/04-IOTA/04-blank-identifier/03/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | EST = -(5 + iota) // CORRECT: -5 8 | _ 9 | MST // CORRECT: -7 10 | PST // CORRECT: -8 11 | ) 12 | 13 | fmt.Println(EST, MST, PST) 14 | } 15 | -------------------------------------------------------------------------------- /012-Constants/05-minutes-in-weeks/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | minsPerDay = 60 * 24 8 | weekDays = 7 9 | ) 10 | 11 | fmt.Printf("There are %d minutes in %d weeks.\n", 12 | minsPerDay*weekDays*2, 2) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/06-remove-the-magic/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | hoursInDay = 24 8 | daysInWeek = 7 9 | hoursPerWeek = hoursInDay * daysInWeek 10 | ) 11 | 12 | fmt.Printf("There are %d hours in %d weeks.\n", 13 | hoursPerWeek*5, 5) 14 | } 15 | -------------------------------------------------------------------------------- /012-Constants/07-constant-length/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | home = "Milky Way Galaxy" 8 | length = len(home) 9 | ) 10 | 11 | fmt.Printf("There are %d characters inside %q\n", 12 | length, home) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/08-tau/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | pi = 3.14159265358979323846264 8 | tau = pi * 2 9 | ) 10 | 11 | fmt.Printf("tau = %g\n", tau) 12 | } 13 | -------------------------------------------------------------------------------- /012-Constants/09-area/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // Make them typeless 7 | const ( 8 | width = 25 9 | height = width * 2 10 | ) 11 | 12 | fmt.Printf("area = %d\n", width*height) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/11-iota-months/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | Nov = 11 - iota // 11 - 0 = 11 8 | Oct // 11 - 1 = 10 9 | Sep // 11 - 2 = 9 10 | ) 11 | 12 | fmt.Println(Sep, Oct, Nov) 13 | } 14 | -------------------------------------------------------------------------------- /012-Constants/12-iota-months-2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | _ = iota // 0 8 | Jan // 1 9 | Feb // 2 10 | Mar // 3 11 | ) 12 | 13 | fmt.Println(Jan, Feb, Mar) 14 | } 15 | -------------------------------------------------------------------------------- /012-Constants/13-iota-seasons/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | const ( 7 | Spring = (iota + 1) * 3 8 | Summer 9 | Fall 10 | Winter 11 | ) 12 | 13 | fmt.Println(Winter, Spring, Summer, Fall) 14 | } 15 | -------------------------------------------------------------------------------- /013-If-Statements/01-boolean-operators/02-comparison-and-assignability/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var speed int 5 | // speed = "100" // NOT OK 6 | 7 | var running bool 8 | // running = 50 // NOT OK 9 | 10 | var force float64 11 | // speed = force // NOT OK 12 | 13 | _, _, _ = speed, running, force 14 | } 15 | -------------------------------------------------------------------------------- /013-If-Statements/01-boolean-operators/02-comparison-and-assignability/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var speed int 5 | speed = 50 // OK 6 | 7 | var running bool 8 | running = true // OK 9 | 10 | var force float64 11 | speed = int(force) 12 | 13 | _, _, _ = speed, running, force 14 | } 15 | -------------------------------------------------------------------------------- /013-If-Statements/01-boolean-operators/03-logical-operators/01-and-operator/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // remove the comments and run 7 | // i've commented the lines it's because of the warnings 8 | 9 | // fmt.Println("true && true =", true && true) 10 | fmt.Println("true && false =", true && false) 11 | fmt.Println("false && true =", false && true) 12 | // fmt.Println("false && false =", false && false) 13 | } 14 | -------------------------------------------------------------------------------- /013-If-Statements/01-boolean-operators/03-logical-operators/02-or-operator/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // remove the comments and run 7 | // i've commented the lines it's because of the warnings 8 | 9 | // fmt.Println("true || true =", true || true) 10 | fmt.Println("true || false =", true || false) 11 | fmt.Println("false || true =", false || true) 12 | // fmt.Println("false || false =", false || false) 13 | } 14 | -------------------------------------------------------------------------------- /013-If-Statements/01-boolean-operators/03-logical-operators/03-not-operator/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println( 7 | "hi" == "hi" && 3 > 2, // true && true => true 8 | "hi" != "hi" || 3 > 2, // false || true => true 9 | !("hi" != "hi" || 3 > 2), // !(false || true) => false 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /013-If-Statements/01-boolean-operators/03-logical-operators/03-not-operator/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var on bool 9 | 10 | on = !on 11 | fmt.Println(on) 12 | 13 | on = !!on 14 | fmt.Println(on) 15 | } 16 | -------------------------------------------------------------------------------- /013-If-Statements/02-if-statement/01-if-branch/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | score, valid := 5, true 7 | 8 | if score > 3 && valid { 9 | fmt.Println("good") 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /013-If-Statements/02-if-statement/02-else-branch/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | score, valid := 3, true 7 | 8 | if score > 3 && valid { 9 | fmt.Println("good") 10 | } else { 11 | fmt.Println("low") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /013-If-Statements/02-if-statement/03-else-if-branch/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | score := 3 7 | 8 | if score > 3 { 9 | fmt.Println("good") 10 | } else if score == 3 { 11 | fmt.Println("on the edge") 12 | } else { 13 | fmt.Println("low") 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /013-If-Statements/02-if-statement/03-else-if-branch/02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | score := 2 7 | 8 | if score > 3 { 9 | fmt.Println("good") 10 | } else if score == 3 { 11 | fmt.Println("on the edge") 12 | } else if score == 2 { 13 | fmt.Println("meh...") 14 | } else { 15 | fmt.Println("low") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /014-Error-Handling/01-itoa/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func main() { 9 | // Itoa doesn't return any errors 10 | // So, we don't have to handle the errors for it 11 | 12 | s := strconv.Itoa(42) 13 | 14 | fmt.Println(s) 15 | } 16 | -------------------------------------------------------------------------------- /014-Error-Handling/02-atoi/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | // Atoi returns an error value 11 | // So, we should always check it 12 | 13 | n, err := strconv.Atoi(os.Args[1]) 14 | 15 | fmt.Println("Converted number :", n) 16 | fmt.Println("Returned error value:", err) 17 | } 18 | -------------------------------------------------------------------------------- /015-Short-If-Statement/01-without-short-if/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func main() { 9 | n, err := strconv.Atoi("42") 10 | 11 | if err == nil { 12 | fmt.Println("There was no error, n is", n) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /015-Short-If-Statement/02-with-short-if/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func main() { 9 | if n, err := strconv.Atoi("42"); err == nil { 10 | // n and err are available here 11 | fmt.Println("There was no error, n is", n) 12 | } 13 | 14 | // n and err are not available here 15 | // fmt.Println(n, err) 16 | } 17 | -------------------------------------------------------------------------------- /016-Switch-Statements/04-multiple-conditions/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | city := os.Args[1] 10 | 11 | switch city { 12 | case "Paris", "Lyon": 13 | fmt.Println("France") 14 | case "Tokyo": 15 | fmt.Println("Japan") 16 | } 17 | 18 | // if city == "Paris" || city == "Lyon" { 19 | // fmt.Println("France") 20 | // } else if city == "Tokyo" { 21 | // fmt.Println("Japan") 22 | // } 23 | } 24 | -------------------------------------------------------------------------------- /016-Switch-Statements/05-bool-expressions/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | i := 10 7 | 8 | switch { 9 | case i > 0: 10 | fmt.Println("positive") 11 | case i < 0: 12 | fmt.Println("negative") 13 | default: 14 | fmt.Println("zero") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /016-Switch-Statements/06-fallthrough/01-without/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | i := 142 7 | 8 | switch { 9 | case i > 100: 10 | fmt.Print("big positive number") 11 | case i > 0: 12 | fmt.Print("positive number") 13 | default: 14 | fmt.Print("number") 15 | } 16 | 17 | fmt.Println() 18 | } 19 | -------------------------------------------------------------------------------- /016-Switch-Statements/06-fallthrough/02-with/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | i := 142 7 | 8 | switch { 9 | case i > 100: 10 | fmt.Print("big ") 11 | fallthrough 12 | case i > 0: 13 | fmt.Print("positive ") 14 | fallthrough 15 | default: 16 | fmt.Print("number") 17 | } 18 | 19 | fmt.Println() 20 | } 21 | -------------------------------------------------------------------------------- /016-Switch-Statements/07-short-switch/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // i := 10 7 | 8 | // true is in a comment now 9 | // you can delete that part if you want 10 | // it's by default true anyway. 11 | switch i := 10; /* true */ { 12 | case i > 0: 13 | fmt.Println("positive") 14 | case i < 0: 15 | fmt.Println("negative") 16 | default: 17 | fmt.Println("zero") 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /017-Loops-In-Go/01-basics/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var sum int 9 | 10 | // sum += 1 11 | // sum += 2 12 | // sum += 3 13 | // sum += 4 14 | // sum += 5 15 | 16 | for i := 1; i <= 1000; i++ { 17 | sum += i 18 | } 19 | 20 | fmt.Println(sum) 21 | } 22 | -------------------------------------------------------------------------------- /017-Loops-In-Go/02-break/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var ( 9 | sum int 10 | i = 1 11 | ) 12 | 13 | for { 14 | if i > 5 { 15 | break 16 | } 17 | 18 | sum += i 19 | 20 | fmt.Println(i, "-->", sum) 21 | 22 | i++ 23 | } 24 | 25 | fmt.Println(sum) 26 | } 27 | -------------------------------------------------------------------------------- /017-Loops-In-Go/03-continue/01-a-before/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var ( 9 | sum int 10 | i = 1 11 | ) 12 | 13 | for { 14 | if i > 10 { 15 | break 16 | } 17 | 18 | if i%2 != 0 { 19 | // this continue creates an endless loop 20 | // since the code never increases the i 21 | continue 22 | } 23 | 24 | sum += i 25 | 26 | fmt.Println(i, "-->", sum) 27 | 28 | i++ 29 | } 30 | 31 | fmt.Println(sum) 32 | } 33 | -------------------------------------------------------------------------------- /017-Loops-In-Go/03-continue/01-b-after/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var ( 9 | sum int 10 | i = 1 11 | ) 12 | 13 | for { 14 | if i > 10 { 15 | break 16 | } 17 | 18 | if i%2 != 0 { 19 | // just by putting this here we solve the problem 20 | i++ 21 | continue 22 | } 23 | 24 | sum += i 25 | 26 | fmt.Println(i, "-->", sum) 27 | 28 | i++ 29 | } 30 | 31 | fmt.Println(sum) 32 | } 33 | -------------------------------------------------------------------------------- /017-Loops-In-Go/06-Lucky-Number-Game/01-randomization/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "time" 7 | ) 8 | 9 | func main() { 10 | // rand.Seed(10) 11 | // rand.Seed(100) 12 | 13 | // t := time.Now() 14 | // rand.Seed(t.UnixNano()) 15 | 16 | // ^-- same: 17 | 18 | rand.Seed(time.Now().UnixNano()) 19 | 20 | guess := 10 21 | 22 | for n := 0; n != guess; { 23 | n = rand.Intn(guess + 1) 24 | fmt.Printf("%d ", n) 25 | } 26 | fmt.Println() 27 | } 28 | -------------------------------------------------------------------------------- /017-Loops-In-Go/11-Goto-Statement/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | // cannot step over any variable declarations 9 | // ERROR: "i" variable is declared after the jump 10 | // 11 | // goto loop 12 | 13 | var i int 14 | 15 | loop: 16 | if i < 3 { 17 | fmt.Println("looping") 18 | i++ 19 | goto loop 20 | } 21 | fmt.Println("done") 22 | } 23 | -------------------------------------------------------------------------------- /017-Loops-In-Go/12-sum-the-numbers/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var sum int 9 | for i := 1; i <= 10; i++ { 10 | sum += i 11 | } 12 | fmt.Println("Sum:", sum) 13 | } 14 | -------------------------------------------------------------------------------- /017-Loops-In-Go/13-sum-the-numbers-verbose/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | const min, max = 1, 10 9 | 10 | var sum int 11 | for i := min; i <= max; i++ { 12 | sum += i 13 | 14 | fmt.Print(i) 15 | if i < max { 16 | fmt.Print(" + ") 17 | } 18 | } 19 | fmt.Printf(" = %d\n", sum) 20 | } 21 | -------------------------------------------------------------------------------- /017-Loops-In-Go/17-infinite-kill/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "time" 7 | ) 8 | 9 | func main() { 10 | for { 11 | var c string 12 | 13 | switch rand.Intn(4) { 14 | case 0: 15 | c = "\\" 16 | case 1: 17 | c = "/" 18 | case 2: 19 | c = "|" 20 | case 3: 21 | c = "-" 22 | } 23 | fmt.Printf("\r%s Please Wait. Processing....", c) 24 | time.Sleep(time.Millisecond * 250) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /018-Arrays-Composite-Types/08-Assigning-One-Array-To-Another/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | blue := [3]int{6, 9, 3} 7 | red := blue 8 | 9 | blue[0] = 10 10 | 11 | fmt.Printf("blue: %#v\n", blue) 12 | fmt.Printf("red : %#v\n", red) 13 | 14 | // UNASSIGNABLE: 15 | // blue := [3]int{6, 9, 3} 16 | // red := [2]int{3, 5} 17 | // red = blue 18 | } 19 | -------------------------------------------------------------------------------- /018-Arrays-Composite-Types/11-Rarely-Known-Features/01-unkeyed/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | rates := [3]float64{ 7 | 0.5, 8 | 2.5, 9 | 1.5, 10 | } 11 | 12 | fmt.Println(rates) 13 | } 14 | -------------------------------------------------------------------------------- /018-Arrays-Composite-Types/11-Rarely-Known-Features/02-keyed/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | rates := [3]float64{ 7 | 0: 0.5, // index: 0 8 | 1: 2.5, // index: 1 9 | 2: 1.5, // index: 2 10 | } 11 | 12 | fmt.Println(rates) 13 | 14 | // above array literal equals to this: 15 | // 16 | // rates := [3]float64{ 17 | // 0.5, 18 | // 2.5, 19 | // 1.5, 20 | // } 21 | } 22 | -------------------------------------------------------------------------------- /018-Arrays-Composite-Types/11-Rarely-Known-Features/03-keyed-order/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | rates := [3]float64{ 7 | 1: 2.5, // index: 1 8 | 0: 0.5, // index: 0 9 | 2: 1.5, // index: 2 10 | } 11 | 12 | fmt.Println(rates) 13 | 14 | // above array literal equals to this: 15 | // 16 | // rates := [3]float64{ 17 | // 0.5, 18 | // 2.5, 19 | // 1.5, 20 | // } 21 | } 22 | -------------------------------------------------------------------------------- /018-Arrays-Composite-Types/11-Rarely-Known-Features/04-keyed-auto-initialize/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | rates := [3]float64{ 7 | // index 0 empty 8 | // index 1 empty 9 | 2: 1.5, // index: 2 10 | } 11 | 12 | fmt.Println(rates) 13 | 14 | // above array literal equals to this: 15 | // 16 | // rates := [3]float64{ 17 | // 0., 18 | // 0., 19 | // 1.5, 20 | // } 21 | } 22 | -------------------------------------------------------------------------------- /018-Arrays-Composite-Types/11-Rarely-Known-Features/07-Xratio-Cryptocurrency-Exchange-Ratio/01-without-keys/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | rates := [...]float64{ 7 | 25.5, // ethereum 8 | 120.5, // wanchain 9 | } 10 | 11 | // uses magic values - not good 12 | fmt.Printf("1 BTC is %g ETH\n", rates[0]) 13 | fmt.Printf("1 BTC is %g WAN\n", rates[1]) 14 | } 15 | -------------------------------------------------------------------------------- /018-Arrays-Composite-Types/17-Simplifying-Complex-Code/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | names := [...]string{"Einstein", "Shepard", "Tesla"} 7 | books := [5]string{"Kafka's Revenge", "Stay Golden"} 8 | 9 | fmt.Printf("%q\n", names) 10 | fmt.Printf("%q\n", books) 11 | } 12 | -------------------------------------------------------------------------------- /020-Slices-In-Go/11-Slice-Internals-Append-Function/1-theory/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | s "github.com/inancgumus/prettyslice" 5 | ) 6 | 7 | func main() { 8 | s.PrintBacking = true 9 | 10 | ages := []int{35, 15} 11 | s.Show("ages", ages) 12 | 13 | ages = append(ages, 5) 14 | s.Show("append(ages, 5)", ages) 15 | } 16 | -------------------------------------------------------------------------------- /020-Slices-In-Go/11-Slice-Internals-Append-Function/4-example-growth/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | ages, oldCap := []int{1}, 1. 9 | 10 | for len(ages) < 5e5 { 11 | ages = append(ages, 1) 12 | 13 | c := float64(cap(ages)) 14 | if c != oldCap { 15 | fmt.Printf("len:%-10d cap:%-10g growth:%.2f\n", 16 | len(ages), c, c/oldCap) 17 | } 18 | oldCap = c 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /020-Slices-In-Go/13-Make-Function/1-theory/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | prettyslice "github.com/inancgumus/prettyslice" 5 | ) 6 | 7 | func main() { 8 | prettyslice.PrintBacking = true 9 | 10 | prettyslice.Show("make([]int, 3)", make([]int, 3)) 11 | prettyslice.Show("make([]int, 3, 5)", make([]int, 3, 5)) 12 | 13 | s := make([]int, 0, 5) 14 | prettyslice.Show("make([]int, 0, 5)", s) 15 | 16 | s = append(s, 42) 17 | prettyslice.Show("s = append(s, 42)", s) 18 | } 19 | -------------------------------------------------------------------------------- /020-Slices-In-Go/14-Copy-Function/01-usage/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | s "github.com/inancgumus/prettyslice" 7 | ) 8 | 9 | func main() { 10 | evens := []int{2, 4} 11 | odds := []int{3, 5, 7} 12 | 13 | s.Show("evens [before]", evens) 14 | s.Show("odds [before]", odds) 15 | 16 | N := copy(evens, odds) 17 | fmt.Printf("%d element(s) are copied.\n", N) 18 | 19 | s.Show("evens [after]", evens) 20 | s.Show("odds [after]", odds) 21 | } 22 | -------------------------------------------------------------------------------- /020-Slices-In-Go/22-append/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | png, header := []byte{'P', 'N', 'G'}, []byte{} 10 | 11 | header = append(header, png...) 12 | 13 | if bytes.Equal(png, header) { 14 | fmt.Println("They are equal") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /020-Slices-In-Go/24-append-3-fix/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | toppings := []string{"black olives", "green peppers"} 7 | 8 | var pizza []string 9 | pizza = append(pizza, toppings...) 10 | pizza = append(pizza, "onions", "extra cheese") 11 | 12 | fmt.Printf("toppings: %s\n", pizza) 13 | } 14 | -------------------------------------------------------------------------------- /020-Slices-In-Go/38-Limiting-The-Backing-Array-Sharing/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aditya43/golang/20-Slices-In-Go/38-Limiting-The-Backing-Array-Sharing/api" 7 | ) 8 | 9 | func main() { 10 | received := api.Read(0, 3) 11 | 12 | received = append(received, []int{1, 3}...) 13 | 14 | fmt.Println("api.temps :", api.All()) 15 | fmt.Println("main.received :", received) 16 | } 17 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/empty1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/empty1.txt -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/empty2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/empty2.txt -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/empty3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/empty3.txt -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/nonEmpty1.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 2 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/nonEmpty2.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 2 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/01-Fetch-Files/files/nonEmpty3.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 2 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/empty1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/empty1.txt -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/empty2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/empty2.txt -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/empty3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/empty3.txt -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/nonEmpty1.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 2 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/nonEmpty2.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 2 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/files/nonEmpty3.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 2 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/02-Write-To-A-File/out.txt: -------------------------------------------------------------------------------- 1 | empty1.txt 2 | empty2.txt 3 | empty3.txt 4 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dir/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !subdir1 3 | !subdir2 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dir/subdir1/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dir/subdir2/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dir2/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !subdir1 3 | !subdir2 4 | !subdir3 5 | !.gitignore 6 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dir2/subdir1/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dir2/subdir2/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dir2/subdir3/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/06-print-directories/dirs.txt: -------------------------------------------------------------------------------- 1 | dir/ 2 | subdir1/ 3 | subdir2/ 4 | 5 | dir2/ 6 | subdir1/ 7 | subdir2/ 8 | subdir3/ 9 | 10 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | // String() returns a string representation of money. 8 | // money is an fmt.Stringer. 9 | func (m money) String() string { 10 | return fmt.Sprintf("$%.2f", m) 11 | } 12 | -------------------------------------------------------------------------------- /021-Empty-Files-Finder-Program-IO/product.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type product struct { 8 | title string 9 | price money 10 | released timestamp 11 | } 12 | 13 | func (p *product) String() string { 14 | return fmt.Sprintf("%s: %s (%s)", p.title, p.price, p.released) 15 | } 16 | 17 | func (p *product) discount(ratio float64) { 18 | p.price *= money(1 - ratio) 19 | } 20 | -------------------------------------------------------------------------------- /023-Strings-Runes-And-Bytes/07-convert/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | words := []string{ 7 | "gopher", 8 | "programmer", 9 | "go language", 10 | "go standard library", 11 | } 12 | 13 | var bwords [][]byte 14 | for _, w := range words { 15 | bw := []byte(w) 16 | 17 | fmt.Println(bw) 18 | 19 | bwords = append(bwords, bw) 20 | } 21 | 22 | for _, w := range bwords { 23 | fmt.Println(string(w)) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /024-Spam-Maske-Project/01-step-1/spam.txt: -------------------------------------------------------------------------------- 1 | Hi guys, 2 | 3 | Here is my new spammy webpage http://www.mysuperpage.com <-- This is my website! 4 | 5 | Please click on the link now!!! 6 | 7 | When you click, I will be rich, thanks! -------------------------------------------------------------------------------- /024-Spam-Maske-Project/02-step-2/spam.txt: -------------------------------------------------------------------------------- 1 | Hi guys, 2 | 3 | Here is my new spammy webpage http://www.mysuperpage.com <-- This is my website! 4 | 5 | Please click on the link now!!! 6 | 7 | When you click, I will be rich, thanks! -------------------------------------------------------------------------------- /024-Spam-Maske-Project/03-step-2-no-append/spam.txt: -------------------------------------------------------------------------------- 1 | Hi guys, 2 | 3 | Here is my new spammy webpage http://www.mysuperpage.com <-- This is my website! 4 | 5 | Please click on the link now!!! 6 | 7 | When you click, I will be rich, thanks! -------------------------------------------------------------------------------- /025-Text-Wrapper-Project/story.txt: -------------------------------------------------------------------------------- 1 | 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. 2 | 3 | Bu 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. 4 | 5 | Gezegenin maymun soyundan gelen canlıları öyle ilkeldir ki dijital kol saatinin hâlâ çok etkileyici bir buluş olduğunu düşünürler. -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/01-scanning/proverbs.txt: -------------------------------------------------------------------------------- 1 | Go Proverbs 2 | Make the zero value useful 3 | Clear is better than clever 4 | Errors are values -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/03-project-log-parser/log.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org 4 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/03-project-log-parser/log_err_missing.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/03-project-log-parser/log_err_negative.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org -100 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/03-project-log-parser/log_err_str.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org FOUR 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/09-log-parser/log.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org 4 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/09-log-parser/log_err_missing.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/09-log-parser/log_err_negative.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org -100 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /027-Logs-Parser-Using-buffio.Scanner-Project/09-log-parser/log_err_str.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org FOUR 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /028-Structs-In-Go/05-project-log-parser-structs/log.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org 4 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /028-Structs-In-Go/05-project-log-parser-structs/log_err_missing.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /028-Structs-In-Go/05-project-log-parser-structs/log_err_negative.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org -100 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /028-Structs-In-Go/05-project-log-parser-structs/log_err_str.txt: -------------------------------------------------------------------------------- 1 | learngoprogramming.com 10 2 | learngoprogramming.com 10 3 | golang.org FOUR 4 | golang.org 6 5 | blog.golang.org 20 6 | blog.golang.org 10 -------------------------------------------------------------------------------- /028-Structs-In-Go/07-decoding/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "username": "aditya" 4 | }, 5 | { 6 | "username": "god", 7 | "perms": { 8 | "admin": true 9 | } 10 | }, 11 | { 12 | "username": "devil", 13 | "perms": { 14 | "write": true 15 | } 16 | } 17 | ] 18 | -------------------------------------------------------------------------------- /028-Structs-In-Go/08-decoding-2/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "username": "aditya", 4 | "devices": [ 5 | { "name": "laptop", "battery": 10 }, 6 | { "name": "phone", "battery": 30 } 7 | ] 8 | }, 9 | { 10 | "username": "god", 11 | "perms": { 12 | "admin": true 13 | }, 14 | "devices": [ 15 | { "name": "omniverse", "battery": 95 } 16 | ] 17 | }, 18 | { 19 | "username": "devil", 20 | "perms": { 21 | "write": true 22 | } 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /029-OOP-Methods/book.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type book struct { 6 | title string 7 | price float64 8 | } 9 | 10 | func (b book) print() { 11 | fmt.Printf("%-19s: $%.2f\n", b.title, b.price) 12 | } 13 | -------------------------------------------------------------------------------- /029-OOP-Methods/game.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type game struct { 6 | title string 7 | price float64 8 | } 9 | 10 | func (g game) print() { 11 | fmt.Printf("%-15s: $%.2f\n", g.title, g.price) 12 | } 13 | -------------------------------------------------------------------------------- /029-OOP-Methods/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | mobydick := book{title: "मृत्युंजय", price: 10} 5 | cod := game{title: "Call Of Duty", price: 50} 6 | battlefield := game{title: "Battlefield V", price: 80.342} 7 | 8 | mobydick.print() 9 | cod.print() 10 | battlefield.print() 11 | } 12 | -------------------------------------------------------------------------------- /030-OOP-Pointer-Receivers/book.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type book struct { 6 | title string 7 | price float64 8 | } 9 | 10 | func (b book) print() { 11 | fmt.Printf("%-15s: $%.2f\n", b.title, b.price) 12 | } 13 | -------------------------------------------------------------------------------- /031-OOP-Attaching-Methods-To-DIfferent-Types/book.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type book struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (b book) print() { 11 | fmt.Printf("%-15s: %s\n", b.title, b.price.string()) 12 | } 13 | -------------------------------------------------------------------------------- /031-OOP-Attaching-Methods-To-DIfferent-Types/game.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type game struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (g *game) print() { 11 | fmt.Printf("%-15s: %s\n", g.title, g.price.string()) 12 | } 13 | 14 | func (g *game) discount(ratio float64) { 15 | g.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /031-OOP-Attaching-Methods-To-DIfferent-Types/list.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // + you can attach methods to non-struct types. 6 | // + rule: you need to declare a new type in the same package. 7 | type list []*game 8 | 9 | func (l list) print() { 10 | // `list` acts like a `[]game` 11 | if len(l) == 0 { 12 | fmt.Println("Sorry. We're waiting for delivery 🚚.") 13 | return 14 | } 15 | 16 | for _, it := range l { 17 | it.print() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /031-OOP-Attaching-Methods-To-DIfferent-Types/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) string() string { 8 | // $xx.yy 9 | return fmt.Sprintf("$%.2f", m) 10 | } 11 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/book.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type book struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (b book) print() { 11 | fmt.Printf("%-15s: %s\n", b.title, b.price.string()) 12 | } 13 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/game.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type game struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (g *game) print() { 11 | fmt.Printf("%-15s: %s\n", g.title, g.price.string()) 12 | } 13 | 14 | func (g *game) discount(ratio float64) { 15 | g.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) string() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/power/blender.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Blender can be powered 8 | type Blender struct{} 9 | 10 | // Draw power to a Blender 11 | func (Blender) Draw(power int) { 12 | fmt.Printf("Blender is drawing %dkW of electrical power.\n", power) 13 | } 14 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/power/kettle.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Kettle can be powered 8 | type Kettle struct{} 9 | 10 | // Draw power to a Kettle 11 | func (Kettle) Draw(power int) { 12 | fmt.Printf("Kettle is drawing %dkW of electrical power.\n", power) 13 | } 14 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/power/mixer.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Mixer can be powered 8 | type Mixer struct{} 9 | 10 | // Draw power to a Mixer 11 | func (Mixer) Draw(power int) { 12 | fmt.Printf("Mixer is drawing %dkW of electrical power.\n", power) 13 | } 14 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/power/player.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Player can be powered 8 | type Player struct{} 9 | 10 | // Draw power to a Player 11 | func (Player) Draw(power int) { 12 | fmt.Printf("Player is drawing %dkW of electrical power.\n", power) 13 | } 14 | -------------------------------------------------------------------------------- /032-OOP-Interfaces-In-Go/puzzle.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type puzzle struct { 6 | title string 7 | price money 8 | } 9 | 10 | // if you remove this method, 11 | // you can no longer add it to the `store` in `main()`. 12 | func (p puzzle) print() { 13 | fmt.Printf("%-15s: %s\n", p.title, p.price.string()) 14 | } 15 | -------------------------------------------------------------------------------- /033-OOP-Type-Assertion/book.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type book struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (b book) print() { 11 | fmt.Printf("%-15s: %s\n", b.title, b.price.string()) 12 | } 13 | -------------------------------------------------------------------------------- /033-OOP-Type-Assertion/game.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type game struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (g *game) print() { 11 | fmt.Printf("%-15s: %s\n", g.title, g.price.string()) 12 | } 13 | 14 | func (g *game) discount(ratio float64) { 15 | g.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /033-OOP-Type-Assertion/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) string() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /033-OOP-Type-Assertion/puzzle.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type puzzle struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (p puzzle) print() { 11 | fmt.Printf("%-15s: %s\n", p.title, p.price.string()) 12 | } 13 | -------------------------------------------------------------------------------- /033-OOP-Type-Assertion/toy.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type toy struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (t *toy) print() { 11 | fmt.Printf("%-15s: %s\n", t.title, t.price.string()) 12 | } 13 | 14 | func (t *toy) discount(ratio float64) { 15 | t.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /034-OOP-Empty-Interface/03-Example-03/game.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type game struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (g *game) print() { 11 | fmt.Printf("%-15s: %s\n", g.title, g.price.string()) 12 | } 13 | 14 | func (g *game) discount(ratio float64) { 15 | g.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /034-OOP-Empty-Interface/03-Example-03/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) string() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /034-OOP-Empty-Interface/03-Example-03/puzzle.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type puzzle struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (p puzzle) print() { 11 | fmt.Printf("%-15s: %s\n", p.title, p.price.string()) 12 | } 13 | -------------------------------------------------------------------------------- /034-OOP-Empty-Interface/03-Example-03/toy.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type toy struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (t *toy) print() { 11 | fmt.Printf("%-15s: %s\n", t.title, t.price.string()) 12 | } 13 | 14 | func (t *toy) discount(ratio float64) { 15 | t.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /035-OOP-Type-Switch/game.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type game struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (g *game) print() { 11 | fmt.Printf("%-15s: %s\n", g.title, g.price.string()) 12 | } 13 | 14 | func (g *game) discount(ratio float64) { 15 | g.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /035-OOP-Type-Switch/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | store := list{ 5 | book{title: "moby dick", price: 10, published: 118281600}, 6 | book{title: "odyssey", price: 15, published: "733622400"}, 7 | book{title: "hobbit", price: 25}, 8 | puzzle{title: "rubik's cube", price: 5}, 9 | &game{title: "minecraft", price: 20}, 10 | &game{title: "tetris", price: 5}, 11 | &toy{title: "yoda", price: 150}, 12 | } 13 | 14 | store.discount(.5) 15 | store.print() 16 | } 17 | -------------------------------------------------------------------------------- /035-OOP-Type-Switch/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) string() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /035-OOP-Type-Switch/puzzle.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type puzzle struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (p puzzle) print() { 11 | fmt.Printf("%-15s: %s\n", p.title, p.price.string()) 12 | } 13 | -------------------------------------------------------------------------------- /035-OOP-Type-Switch/toy.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type toy struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (t *toy) print() { 11 | fmt.Printf("%-15s: %s\n", t.title, t.price.string()) 12 | } 13 | 14 | func (t *toy) discount(ratio float64) { 15 | t.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /036-OOP-Promoted-Methods/game.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type game struct { 4 | product 5 | } 6 | -------------------------------------------------------------------------------- /036-OOP-Promoted-Methods/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) string() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /036-OOP-Promoted-Methods/product.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type product struct { 6 | title string 7 | price money 8 | } 9 | 10 | func (p *product) print() { 11 | fmt.Printf("%-15s: %s\n", p.title, p.price.string()) 12 | } 13 | 14 | func (p *product) discount(ratio float64) { 15 | p.price *= money(1 - ratio) 16 | } 17 | -------------------------------------------------------------------------------- /036-OOP-Promoted-Methods/puzzle.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type puzzle struct { 4 | product 5 | } 6 | -------------------------------------------------------------------------------- /036-OOP-Promoted-Methods/toy.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type toy struct { 4 | product 5 | } 6 | -------------------------------------------------------------------------------- /037-OOP-Store-App-Refactor/list.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type list []*product 6 | 7 | func (l list) print() { 8 | if len(l) == 0 { 9 | fmt.Println("Sorry. We're waiting for delivery 🚚.") 10 | return 11 | } 12 | 13 | for _, p := range l { 14 | p.print() 15 | } 16 | } 17 | 18 | func (l list) discount(ratio float64) { 19 | for _, p := range l { 20 | p.discount(ratio) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /037-OOP-Store-App-Refactor/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) string() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /037-OOP-Store-App-Refactor/product.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type product struct { 8 | title string 9 | price money 10 | released timestamp 11 | } 12 | 13 | func (p *product) print() { 14 | fmt.Printf("%s: %s (%s)\n", p.title, p.price.string(), p.released.string()) 15 | } 16 | 17 | func (p *product) discount(ratio float64) { 18 | p.price *= money(1 - ratio) 19 | } 20 | -------------------------------------------------------------------------------- /038-OOP-Stringer/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | // String() returns a string representation of money. 8 | // money is an fmt.Stringer. 9 | func (m money) String() string { 10 | return fmt.Sprintf("$%.2f", m) 11 | } 12 | -------------------------------------------------------------------------------- /038-OOP-Stringer/product.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type product struct { 8 | title string 9 | price money 10 | released timestamp 11 | } 12 | 13 | func (p *product) String() string { 14 | return fmt.Sprintf("%s: %s (%s)", p.title, p.price, p.released) 15 | } 16 | 17 | func (p *product) discount(ratio float64) { 18 | p.price *= money(1 - ratio) 19 | } 20 | -------------------------------------------------------------------------------- /039-OOP-Store-App-Items-Sorting/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) String() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /039-OOP-Store-App-Items-Sorting/product.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type product struct { 8 | title string 9 | price money 10 | released timestamp 11 | } 12 | 13 | func (p *product) String() string { 14 | return fmt.Sprintf("%s: %s (%s)", p.title, p.price, p.released) 15 | } 16 | 17 | func (p *product) discount(ratio float64) { 18 | p.price *= money(1 - ratio) 19 | } 20 | -------------------------------------------------------------------------------- /040-OOP-Marshaller/database.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "title": "moby dick", 4 | "price": 10, 5 | "released": 118281600 6 | }, 7 | { 8 | "title": "odyssey", 9 | "price": 15, 10 | "released": 733622400 11 | }, 12 | { 13 | "title": "hobbit", 14 | "price": 25, 15 | "released": -62135596800 16 | } 17 | ] 18 | -------------------------------------------------------------------------------- /040-OOP-Marshaller/money.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type money float64 6 | 7 | func (m money) String() string { 8 | return fmt.Sprintf("$%.2f", m) 9 | } 10 | -------------------------------------------------------------------------------- /040-OOP-Marshaller/product.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type product struct { 8 | Title string `json:"title"` 9 | Price money `json:"price"` 10 | Released timestamp `json:"released"` 11 | } 12 | 13 | func (p *product) String() string { 14 | return fmt.Sprintf("%s: %s (%s)", p.Title, p.Price, p.Released) 15 | } 16 | 17 | func (p *product) discount(ratio float64) { 18 | p.Price *= money(1 - ratio) 19 | } 20 | -------------------------------------------------------------------------------- /043-PNG-Detector/some-file.unknown: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/043-PNG-Detector/some-file.unknown -------------------------------------------------------------------------------- /050-Closures-In-Go/02-Example-02/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | msg := "नमस्ते आदित्य!" 7 | 8 | // Closure function 9 | func(m string) { 10 | fmt.Println(m) 11 | }(msg) 12 | 13 | fmt.Println("Inside main() function") 14 | } 15 | -------------------------------------------------------------------------------- /055-OOP-Pointer-Receivers-With-Interface/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aditya43/golang/55-OOP-Pointer-Receivers-With-Interface/shapes" 7 | ) 8 | 9 | func main() { 10 | r := shapes.NewRectangle(9, 6) 11 | t := shapes.NewTriangle(3, 6) 12 | 13 | fmt.Println("Rectangle Area", shapes.ShapeArea(r)) 14 | fmt.Println("Trianlge Area", shapes.ShapeArea(t)) 15 | } 16 | -------------------------------------------------------------------------------- /055-OOP-Pointer-Receivers-With-Interface/shapes/rectangle.go: -------------------------------------------------------------------------------- 1 | package shapes 2 | 3 | type Rectangle struct { 4 | width float64 5 | height float64 6 | } 7 | 8 | func NewRectangle(w float64, h float64) *Rectangle { 9 | return &Rectangle{ 10 | width: w, 11 | height: h, 12 | } 13 | } 14 | 15 | func (r *Rectangle) Area() float64 { 16 | return r.width * r.height 17 | } 18 | -------------------------------------------------------------------------------- /055-OOP-Pointer-Receivers-With-Interface/shapes/shape.go: -------------------------------------------------------------------------------- 1 | package shapes 2 | 3 | type Shape interface { 4 | Area() float64 5 | } 6 | 7 | func ShapeArea(s Shape) float64 { 8 | return s.Area() 9 | } 10 | -------------------------------------------------------------------------------- /055-OOP-Pointer-Receivers-With-Interface/shapes/triangle.go: -------------------------------------------------------------------------------- 1 | package shapes 2 | 3 | type Triangle struct { 4 | base float64 5 | height float64 6 | } 7 | 8 | func NewTriangle(b float64, h float64) *Triangle { 9 | return &Triangle{ 10 | base: b, 11 | height: h, 12 | } 13 | } 14 | 15 | func (t *Triangle) Area() float64 { 16 | return (t.base * t.height) / 2 17 | } 18 | -------------------------------------------------------------------------------- /056-OOP-Pointer-Receivers-With-Empty-Interface/shapes/rectangle.go: -------------------------------------------------------------------------------- 1 | package shapes 2 | 3 | type Rectangle struct { 4 | width float64 5 | height float64 6 | } 7 | 8 | func NewRectangle(w float64, h float64) *Rectangle { 9 | return &Rectangle{ 10 | width: w, 11 | height: h, 12 | } 13 | } 14 | 15 | func (r *Rectangle) Area() float64 { 16 | return r.width * r.height 17 | } 18 | -------------------------------------------------------------------------------- /056-OOP-Pointer-Receivers-With-Empty-Interface/shapes/shape.go: -------------------------------------------------------------------------------- 1 | package shapes 2 | 3 | type Shape interface { 4 | Area() float64 5 | } 6 | 7 | func ShapeArea(s Shape) float64 { 8 | return s.Area() 9 | } 10 | -------------------------------------------------------------------------------- /056-OOP-Pointer-Receivers-With-Empty-Interface/shapes/triangle.go: -------------------------------------------------------------------------------- 1 | package shapes 2 | 3 | type Triangle struct { 4 | base float64 5 | height float64 6 | } 7 | 8 | func NewTriangle(b float64, h float64) *Triangle { 9 | return &Triangle{ 10 | base: b, 11 | height: h, 12 | } 13 | } 14 | 15 | func (t *Triangle) Area() float64 { 16 | return (t.base * t.height) / 2 17 | } 18 | -------------------------------------------------------------------------------- /058-Goroutines/01-Goroutines-Without-Delay/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func printGreetings(source string) { 8 | for i := 0; i < 9; i++ { 9 | fmt.Println("नमस्ते आदित्य!", i, source) 10 | } 11 | } 12 | 13 | func main() { 14 | go printGreetings("From Goroutine") 15 | printGreetings("From Main Function") 16 | } 17 | -------------------------------------------------------------------------------- /058-Goroutines/02-Goroutines-With-Delay/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func printGreetings(source string) { 9 | for i := 0; i < 9; i++ { 10 | fmt.Println("नमस्ते आदित्य!", i, source) 11 | } 12 | time.Sleep(time.Millisecond * 1) // Sleep for 1 millisecond 13 | } 14 | 15 | func main() { 16 | go printGreetings("From Goroutine") 17 | printGreetings("From Main Function") 18 | } 19 | -------------------------------------------------------------------------------- /059-Channels/02-Goroutines-With-Channels/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | var done chan bool = make(chan bool) 6 | 7 | func sayNamaste(source string) { 8 | for i := 0; i < 9; i++ { 9 | fmt.Println("नमस्ते आदित्य!", i, source) 10 | } 11 | 12 | if source == "Goroutine" { 13 | done <- true 14 | } 15 | } 16 | 17 | func main() { 18 | go sayNamaste("Goroutine") 19 | sayNamaste("main() Function") 20 | 21 | <-done 22 | } 23 | -------------------------------------------------------------------------------- /062-Go-Vet-To-Catch-Errors/main.go: -------------------------------------------------------------------------------- 1 | // Run this code with command: "go vet main.go" 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | fmt.Printf("String or number?: %s\n", 1) 8 | } 9 | -------------------------------------------------------------------------------- /066-Web-Templates/templates/namaste.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | नमस्ते 7 | 8 | 9 |

नमस्ते {{.Name}}!

10 | 11 | -------------------------------------------------------------------------------- /067-Custom-Web-Template/static/images/gogopher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/067-Custom-Web-Template/static/images/gogopher.png -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/endpoints/createpost.go: -------------------------------------------------------------------------------- 1 | package endpoints 2 | 3 | import "net/http" 4 | 5 | func CreatePostEndpoint(w http.ResponseWriter, r *http.Request) { 6 | 7 | // TODO: Implement the create post endpoint 8 | 9 | } 10 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/endpoints/deletepost.go: -------------------------------------------------------------------------------- 1 | package endpoints 2 | 3 | import "net/http" 4 | 5 | func DeletePostEndpoint(w http.ResponseWriter, r *http.Request) { 6 | 7 | // TODO: Implement the delete post endpoint 8 | 9 | } 10 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/endpoints/updatepost.go: -------------------------------------------------------------------------------- 1 | package endpoints 2 | 3 | import "net/http" 4 | 5 | func UpdatePostEndpoint(w http.ResponseWriter, r *http.Request) { 6 | 7 | // TODO: Implement the update post endpoint 8 | 9 | } 10 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/feed.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func FeedHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/find.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func FindHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/foo.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func FooHandler(w http.ResponseWriter, r *http.Request) { 8 | fooID := r.Context().Value("fooID").(string) 9 | _, _ = w.Write([]byte(fooID)) 10 | } 11 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/friends.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func FriendsHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/home.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | func HomeHandler(w http.ResponseWriter, r *http.Request) { 9 | 10 | fmt.Println("test") 11 | 12 | } 13 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/login.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func LoginHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/logout.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func LogoutHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/myprofile.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func MyProfileHandler(w http.ResponseWriter, r *http.Request) { 6 | _, _ = w.Write([]byte("profile")) 7 | } 8 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/panic.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func TriggerPanicHandler(w http.ResponseWriter, r *http.Request) { 8 | 9 | panic("Triggering a Panic!") 10 | } 11 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/profile.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gorilla/mux" 7 | ) 8 | 9 | func ProfileHandler(w http.ResponseWriter, r *http.Request) { 10 | 11 | vars := mux.Vars(r) 12 | username := vars["username"] 13 | _, _ = w.Write([]byte(username)) 14 | } 15 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/handlers/register.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func RegisterHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /068-MVC-Using-Gorilla-Mux/templates/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/068-MVC-Using-Gorilla-Mux/templates/index.html -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/client/common/common.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "go.isomorphicgo.org/go/isokit" 5 | "honnef.co/go/js/dom" 6 | ) 7 | 8 | type Env struct { 9 | TemplateSet *isokit.TemplateSet 10 | Window dom.Window 11 | Document dom.Document 12 | PrimaryContent dom.Element 13 | } 14 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/client/handlers/handlers.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "honnef.co/go/js/dom" 4 | 5 | var D = dom.GetWindow().Document().(dom.HTMLDocument) 6 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/common/asyncq/task.go: -------------------------------------------------------------------------------- 1 | package asyncq 2 | 3 | type Task interface { 4 | Perform() 5 | } 6 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/common/common.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "github.com/aditya43/golang/69-social-network-built-in-go-and-gopherjs/common/datastore" 5 | "go.isomorphicgo.org/go/isokit" 6 | ) 7 | 8 | type Env struct { 9 | DB datastore.Datastore 10 | TemplateSet *isokit.TemplateSet 11 | } 12 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/common/utility/sha256.go: -------------------------------------------------------------------------------- 1 | package utility 2 | 3 | import ( 4 | "crypto/sha256" 5 | "fmt" 6 | ) 7 | 8 | func SHA256OfString(input string) string { 9 | 10 | sum := sha256.Sum256([]byte(input)) 11 | return fmt.Sprintf("%x", sum) 12 | 13 | } 14 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/endpoints/endpoints.go: -------------------------------------------------------------------------------- 1 | package endpoints 2 | 3 | import "os" 4 | 5 | var WebAppRoot = os.Getenv("GOPHERFACE_APP_ROOT") 6 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/handlers/find.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func FindHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/handlers/foo.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func FooHandler(w http.ResponseWriter, r *http.Request) { 8 | fooID := r.Context().Value("fooID").(string) 9 | _, _ = w.Write([]byte(fooID)) 10 | } 11 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/handlers/handlers.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "os" 4 | 5 | var WebAppRoot = os.Getenv("GOPHERFACE_APP_ROOT") 6 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/handlers/home.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | func HomeHandler(w http.ResponseWriter, r *http.Request) { 9 | 10 | fmt.Println("home page handler reached") 11 | } 12 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/handlers/logout.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/aditya43/golang/69-social-network-built-in-go-and-gopherjs/common/authenticate" 7 | ) 8 | 9 | func LogoutHandler(w http.ResponseWriter, r *http.Request) { 10 | 11 | authenticate.ExpireUserSession(w, r) 12 | authenticate.ExpireSecureCookie(w, r) 13 | } 14 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/handlers/panic.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func TriggerPanicHandler(w http.ResponseWriter, r *http.Request) { 8 | 9 | panic("Triggering a Panic!") 10 | } 11 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/handlers/register.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import "net/http" 4 | 5 | func RegisterHandler(w http.ResponseWriter, r *http.Request) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/images/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/images/.gitkeep -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/images/gogopher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/images/gogopher.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_blue.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_green.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_red.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/3DGopher_yellow.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Aerol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Aerol.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Case.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Case.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Flatline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Flatline.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Jane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Jane.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Linda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Linda.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Marie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Marie.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Molly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Molly.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Riviera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Riviera.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/imageset/Wintermute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/imageset/Wintermute.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/js/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/js/.gitkeep -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/0ef62347-cead-bfbf-6d23-7cdd84f8b080.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/0ef62347-cead-bfbf-6d23-7cdd84f8b080.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/0ef62347-cead-bfbf-6d23-7cdd84f8b080_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/0ef62347-cead-bfbf-6d23-7cdd84f8b080_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/2c2ef747-38b9-9968-8215-ce28099a8b63.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/2c2ef747-38b9-9968-8215-ce28099a8b63.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/2c2ef747-38b9-9968-8215-ce28099a8b63_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/2c2ef747-38b9-9968-8215-ce28099a8b63_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/38a52ac9-7704-60e7-b690-abfec7309162.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/38a52ac9-7704-60e7-b690-abfec7309162.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/38a52ac9-7704-60e7-b690-abfec7309162_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/38a52ac9-7704-60e7-b690-abfec7309162_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/3cc3af2b-9fb2-86b5-05b5-80e32a08b9d6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/3cc3af2b-9fb2-86b5-05b5-80e32a08b9d6.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/3cc3af2b-9fb2-86b5-05b5-80e32a08b9d6_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/3cc3af2b-9fb2-86b5-05b5-80e32a08b9d6_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/5a4cd16c-93f1-5bff-cefb-5173e6d8f941.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/5a4cd16c-93f1-5bff-cefb-5173e6d8f941.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/5a4cd16c-93f1-5bff-cefb-5173e6d8f941_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/5a4cd16c-93f1-5bff-cefb-5173e6d8f941_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/605f6d17-d3f2-9090-ada7-27e72d1ebf72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/605f6d17-d3f2-9090-ada7-27e72d1ebf72.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/605f6d17-d3f2-9090-ada7-27e72d1ebf72_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/605f6d17-d3f2-9090-ada7-27e72d1ebf72_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/6f3196b0-ccdc-c335-3984-f1e6b206e6a1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/6f3196b0-ccdc-c335-3984-f1e6b206e6a1.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/6f3196b0-ccdc-c335-3984-f1e6b206e6a1_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/6f3196b0-ccdc-c335-3984-f1e6b206e6a1_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/8440908b-d565-e3ec-a16c-0b3560c806a2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/8440908b-d565-e3ec-a16c-0b3560c806a2.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/8440908b-d565-e3ec-a16c-0b3560c806a2_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/8440908b-d565-e3ec-a16c-0b3560c806a2_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/b2dcbd58-9489-132e-b393-9965aa40d146.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/b2dcbd58-9489-132e-b393-9965aa40d146.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/b2dcbd58-9489-132e-b393-9965aa40d146_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/b2dcbd58-9489-132e-b393-9965aa40d146_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/c3265e18-bf0c-fcd4-8581-d688c289e773.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/c3265e18-bf0c-fcd4-8581-d688c289e773.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/c3265e18-bf0c-fcd4-8581-d688c289e773_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/c3265e18-bf0c-fcd4-8581-d688c289e773_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/c868ac58-d7b6-f0b4-93f1-4d7249f55226.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/c868ac58-d7b6-f0b4-93f1-4d7249f55226.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/c868ac58-d7b6-f0b4-93f1-4d7249f55226_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/c868ac58-d7b6-f0b4-93f1-4d7249f55226_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/f79db6c9-3189-20c0-f0fc-bbe5e5f57335.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/f79db6c9-3189-20c0-f0fc-bbe5e5f57335.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/f79db6c9-3189-20c0-f0fc-bbe5e5f57335_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/uploads/images/f79db6c9-3189-20c0-f0fc-bbe5e5f57335_thumb.png -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/images/readme.txt: -------------------------------------------------------------------------------- 1 | This directory will store uploaded image files. 2 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/uploads/videos/readme.txt: -------------------------------------------------------------------------------- 1 | This directory will store uploaded video files. 2 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/static/videoset/3DGopher.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/static/videoset/3DGopher.mp4 -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/feed_page.html: -------------------------------------------------------------------------------- 1 | {{ define "pagecontent" }} 2 | {{template "feed_content" .}} 3 | {{end}} 4 | {{template "webpage" . }} 5 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/friends_page.html: -------------------------------------------------------------------------------- 1 | {{ define "pagecontent" }} 2 | {{template "friends_content" .}} 3 | {{end}} 4 | {{template "webpage" . }} 5 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/gopherprofile_page.html: -------------------------------------------------------------------------------- 1 | {{ define "pagecontent" }} 2 | {{template "gopherprofile_content" .}} 3 | {{end}} 4 | {{template "webpage" . }} 5 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | GopherFace - {{.PageTitle}} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/imagepreview.html: -------------------------------------------------------------------------------- 1 | {{template "gatedheader.html" .}} 2 |

{{.PageTitle}}

3 |
4 | 5 |
6 | 7 | 8 |
9 | 10 |
11 | 12 |
13 | 14 |
15 | 16 | {{template "footer.html" .}} 17 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/069-social-network-built-in-go-and-gopherjs/templates/index.html -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/myprofile_page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ define "pagecontent" }} 4 | {{template "myprofile_content" .}} 5 | {{end}} 6 | {{template "webpage" . }} 7 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/signupconfirmation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | GopherFace - Sign Up Confirmation 4 | 5 | 6 | 7 |

GopherFace - Sign Up Confirmation

8 | 9 | 10 |

Thank you {{.Fields.firstName}}!

11 |

We have received your form submission!

12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /069-social-network-built-in-go-and-gopherjs/templates/webpage.html: -------------------------------------------------------------------------------- 1 | {{ template "gatedheader" . }} 2 |
3 | {{ template "pagecontent" . }} 4 |
5 | {{ template "footer" . }} 6 | -------------------------------------------------------------------------------- /071-Text-Template/adi.anything: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | adi.anything Template 7 | 8 | 9 |

adi.anything Template

10 | 11 | -------------------------------------------------------------------------------- /071-Text-Template/adi.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | adi.txt Template 7 | 8 | 9 |

adi.txt Template

10 | 11 | -------------------------------------------------------------------------------- /072-Templates-Parsing-Right-Way/templates/one.adi: -------------------------------------------------------------------------------- 1 | one.adi -------------------------------------------------------------------------------- /072-Templates-Parsing-Right-Way/templates/three.html: -------------------------------------------------------------------------------- 1 | three.html -------------------------------------------------------------------------------- /072-Templates-Parsing-Right-Way/templates/two.adi: -------------------------------------------------------------------------------- 1 | two.adi -------------------------------------------------------------------------------- /073-Passing-Data-To-Templates/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "html/template" 5 | "log" 6 | "os" 7 | ) 8 | 9 | var tpl *template.Template 10 | 11 | func init() { 12 | tpl = template.Must(template.ParseGlob("templates/*")) 13 | } 14 | 15 | func main() { 16 | err := tpl.ExecuteTemplate(os.Stdout, "adi.html", "Aditya Hajare") 17 | 18 | if err != nil { 19 | log.Fatalln(err) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /073-Passing-Data-To-Templates/templates/adi.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Adi Template With Data 7 | 8 | 9 |

Passed Data: {{.}}

10 | 11 | -------------------------------------------------------------------------------- /074-Variables-In-Templates/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "html/template" 5 | "log" 6 | "os" 7 | ) 8 | 9 | var tpl *template.Template 10 | 11 | func init() { 12 | tpl = template.Must(template.ParseGlob("templates/*")) 13 | } 14 | 15 | func main() { 16 | err := tpl.ExecuteTemplate(os.Stdout, "adi.html", "Aditya Hajare") 17 | 18 | if err != nil { 19 | log.Fatalln(err) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /074-Variables-In-Templates/templates/adi.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Adi Template With Data 7 | 8 | 9 | {{$userName := .}} 10 |

Passed Data: {{$userName}}

11 | 12 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/01-passSlice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | func passSlice() { 9 | names := []string{"Aditya", "Nishi", "John", "Jane"} 10 | 11 | err := tpl.ExecuteTemplate(os.Stdout, "01-slice.adi", names) 12 | 13 | if err != nil { 14 | log.Fatalln(err) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/02-passMap.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | func passMap() { 9 | users := map[int]string{ 10 | 111: "Aditya", 11 | 222: "Nishi", 12 | 333: "John", 13 | 444: "Jane", 14 | } 15 | 16 | err := tpl.ExecuteTemplate(os.Stdout, "02-map.adi", users) 17 | 18 | if err != nil { 19 | log.Fatalln(err) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/03-passStruct.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | func passStruct() { 9 | type Person struct { 10 | Name string 11 | Age int 12 | } 13 | 14 | adi := Person{ 15 | "Aditya", 16 | 32, 17 | } 18 | 19 | err := tpl.ExecuteTemplate(os.Stdout, "03-struct.adi", adi) 20 | 21 | if err != nil { 22 | log.Fatalln(err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/04-passSliceOfStruct.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | func passSliceOfStruct() { 9 | type Person struct { 10 | Name string 11 | Age int 12 | } 13 | 14 | adi := Person{"Aditya", 32} 15 | nishi := Person{"Nishi", 26} 16 | 17 | users := []Person{adi, nishi} 18 | 19 | err := tpl.ExecuteTemplate(os.Stdout, "04-slice-struct.adi", users) 20 | 21 | if err != nil { 22 | log.Fatalln(err) 23 | } 24 | } -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "text/template" 4 | 5 | var tpl *template.Template 6 | 7 | func init() { 8 | tpl = template.Must(template.ParseGlob("templates/*")) 9 | } 10 | 11 | func main() { 12 | passSlice() 13 | passMap() 14 | passStruct() 15 | passSliceOfStruct() 16 | passStructOfSliceOfStruct() 17 | } 18 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/templates/01-slice.adi: -------------------------------------------------------------------------------- 1 | ------------------ 2 | Slice 3 | ------------------ 4 | {{range .}} 5 | {{.}} 6 | {{end}} 7 | ****************** 8 | {{range $index, $value := .}} 9 | Index: {{$index}} | Value: {{$value}} 10 | {{end}} 11 | ------------------ 12 | 13 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/templates/02-map.adi: -------------------------------------------------------------------------------- 1 | Map 2 | ------------------ 3 | {{range $index, $value := .}} 4 | Index: {{$index}} | Value: {{$value}} 5 | {{end}} 6 | ------------------ 7 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/templates/03-struct.adi: -------------------------------------------------------------------------------- 1 | Struct 2 | ------------------ 3 | Name: {{.Name}} 4 | Age: {{.Age}} 5 | ****************** 6 | {{$name := .Name}} 7 | {{$age := .Age}} 8 | Name: {{$name}} 9 | Age: {{$age}} 10 | 11 | 12 | ------------------ 13 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/templates/04-slice-struct.adi: -------------------------------------------------------------------------------- 1 | Slice Of Struct 2 | ------------------ 3 | {{range .}} 4 | Name: {{.Name}} 5 | Age: {{.Age}} 6 | {{end}} 7 | ------------------ 8 | -------------------------------------------------------------------------------- /075-Passing-Composite-Data-Structure-Into-Templates/templates/05-struct-slice-struct.adi: -------------------------------------------------------------------------------- 1 | Struct of Slice of Struct 2 | ------------------ 3 | {{range .People}} 4 | {{.}} 5 | {{end}} 6 | ****************** 7 | {{range .Cars}} 8 | {{.}} 9 | {{end}} 10 | ------------------ -------------------------------------------------------------------------------- /076-Passing-Functions-Into-Template/templates/adi.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Passing Functions Into Templates 6 | 7 | 8 | 9 | {{range .Wisdom}} 10 | {{uc .Name}} 11 | {{end}} 12 | 13 | {{range .Wisdom}} 14 | {{ft .Name}} 15 | {{end}} 16 | 17 | 18 | -------------------------------------------------------------------------------- /077-Passing-Formatted-Time-Into-Templates/adi.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Time Formatting 6 | 7 | 8 | Without date formatting: {{.}} 9 | 10 | With date formatting: {{fdateMDY .}} 11 | 12 | -------------------------------------------------------------------------------- /078-Pipelining/01_pipeline-example/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | functions 6 | 7 | 8 | 9 | {{.}} 10 | 11 | {{. | fdbl}} 12 | 13 | {{. | fdbl | fsq}} 14 | 15 | {{. | fdbl | fsq | fsqrt}} 16 | 17 | 18 | -------------------------------------------------------------------------------- /078-Pipelining/02_pipeline-example/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | functions 6 | 7 | 8 | 9 | {{ . | fdateMDY}} 10 | 11 | 12 | -------------------------------------------------------------------------------- /079-Predefined-Global-Functions/01_index/01/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "text/template" 7 | ) 8 | 9 | var tpl *template.Template 10 | 11 | func init() { 12 | tpl = template.Must(template.ParseFiles("tpl.gohtml")) 13 | } 14 | 15 | func main() { 16 | 17 | xs := []string{"zero", "one", "two", "three", "four", "five"} 18 | 19 | err := tpl.Execute(os.Stdout, xs) 20 | if err != nil { 21 | log.Fatalln(err) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /079-Predefined-Global-Functions/03_comparison/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "text/template" 7 | ) 8 | 9 | var tpl *template.Template 10 | 11 | func init() { 12 | tpl = template.Must(template.ParseFiles("tpl.gohtml")) 13 | } 14 | 15 | func main() { 16 | 17 | g1 := struct { 18 | Score1 int 19 | Score2 int 20 | }{ 21 | 7, 22 | 9, 23 | } 24 | 25 | err := tpl.Execute(os.Stdout, g1) 26 | if err != nil { 27 | log.Fatalln(err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /079-Predefined-Global-Functions/03_comparison/readme.txt: -------------------------------------------------------------------------------- 1 | eq 2 | Returns the boolean truth of arg1 == arg2 3 | 4 | ne 5 | Returns the boolean truth of arg1 != arg2 6 | 7 | lt 8 | Returns the boolean truth of arg1 < arg2 9 | 10 | le 11 | Returns the boolean truth of arg1 <= arg2 12 | 13 | gt 14 | Returns the boolean truth of arg1 > arg2 15 | 16 | ge 17 | Returns the boolean truth of arg1 >= arg2 18 | 19 | 20 | source: 21 | https://godoc.org/text/template#Functions -------------------------------------------------------------------------------- /080-Template-Partials/01-Partials/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "html/template" 5 | "log" 6 | "os" 7 | ) 8 | 9 | var tpl *template.Template 10 | 11 | func init() { 12 | tpl = template.Must(template.ParseGlob("templates/*.adi")) 13 | tpl, _ = tpl.ParseGlob("templates/partials/*.adi") 14 | } 15 | 16 | func main() { 17 | err := tpl.ExecuteTemplate(os.Stdout, "main.adi", nil) 18 | 19 | if err != nil { 20 | log.Fatalln(err) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /080-Template-Partials/01-Partials/templates/main.adi: -------------------------------------------------------------------------------- 1 | {{template "header"}} 2 | Inside Main template 3 | {{template "footer"}} -------------------------------------------------------------------------------- /080-Template-Partials/01-Partials/templates/partials/footer.adi: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 | Footer Template 3 | {{end}} -------------------------------------------------------------------------------- /080-Template-Partials/01-Partials/templates/partials/header.adi: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 | Header Template 3 | {{end}} -------------------------------------------------------------------------------- /080-Template-Partials/02-Passing-Data-Into-Partial-Templates/templates/main.adi: -------------------------------------------------------------------------------- 1 | {{template "header" .Name}} 2 | Inside Main template 3 | {{template "footer" .Age}} -------------------------------------------------------------------------------- /080-Template-Partials/02-Passing-Data-Into-Partial-Templates/templates/partials/footer.adi: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 | Footer Template | Age: {{.}} 3 | {{end}} -------------------------------------------------------------------------------- /080-Template-Partials/02-Passing-Data-Into-Partial-Templates/templates/partials/header.adi: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 | Header Template | Name: {{.}} 3 | {{end}} -------------------------------------------------------------------------------- /081-Composition-And-Methods/01-Composition/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Composition 6 | 7 | 8 | 9 |

{{.Name}}

10 |

{{.Age}}

11 | 12 | -------------------------------------------------------------------------------- /081-Composition-And-Methods/02-Composition-Example/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Composition 6 | 7 | 8 | 9 |

{{.Name}}

10 |

{{.Age}}

11 | {{if .LicenseToKill}} 12 |

License To Kill

13 | {{else}} 14 |

License To ill

15 | {{end}} 16 | 17 | -------------------------------------------------------------------------------- /081-Composition-And-Methods/03-Composition-Example/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 | {{.Fall.Term}}
10 | {{range .Fall.Courses}} 11 | {{.Number}} - {{.Name}} - {{.Units}}
12 | {{end}} 13 | 14 | 15 | {{.Spring.Term}}
16 | {{range .Spring.Courses}} 17 | {{.Number}} - {{.Name}} - {{.Units}}
18 | {{end}} 19 | 20 | 21 | -------------------------------------------------------------------------------- /081-Composition-And-Methods/04_method/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Composition 6 | 7 | 8 | 9 |

{{.Name}}

10 |

{{.Age}}

11 |

{{.SomeProcessing}}

12 |

{{.AgeDbl}}

13 |

{{.Age | .TakesArg}}

14 |

{{.AgeDbl | .TakesArg}}

15 | 16 | -------------------------------------------------------------------------------- /081-Composition-And-Methods/README.md: -------------------------------------------------------------------------------- 1 | # Passing data to templates 2 | 3 | These files use the [Composition Design Pattern](https://en.wikipedia.org/wiki/Composition_over_inheritance) . We should favor this design pattern over `Inheritance Design Pattern`. 4 | 5 | Read more about [Composition with Go](https://www.goinggo.net/2015/09/composition-with-go.html). -------------------------------------------------------------------------------- /082-Html-Templates-And-XSS/01_text-template_no-escaping/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Nothing Escaped 6 | 7 | 8 |

Nothing is escaped with text/template

9 | 10 | 11 | -------------------------------------------------------------------------------- /082-Html-Templates-And-XSS/01_text-template_no-escaping/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{ .Title }} 6 | 7 | 8 |

{{ .Heading}}

9 | {{ .Input }} 10 | 11 | -------------------------------------------------------------------------------- /082-Html-Templates-And-XSS/02_html-template_escaping/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Escaped 6 | 7 | 8 |

Danger is escaped with html/template

9 | <script>alert("Yow!");</script> 10 | 11 | -------------------------------------------------------------------------------- /082-Html-Templates-And-XSS/02_html-template_escaping/tpl.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{ .Title }} 6 | 7 | 8 |

{{ .Heading}}

9 | {{ .Input }} 10 | 11 | -------------------------------------------------------------------------------- /084-bufio-scanner/01-Scan-Lines/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | txt := "Hello\n How are you?\n Test 1\n Test 2\n" 11 | 12 | scanner := bufio.NewScanner(strings.NewReader(txt)) 13 | 14 | for scanner.Scan() { 15 | line := scanner.Text() 16 | fmt.Println(line) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /084-bufio-scanner/02-Scan-Words/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | txt := "Hello\n How are you?\n Test 1\n Test 2\n" 11 | 12 | scanner := bufio.NewScanner(strings.NewReader(txt)) 13 | 14 | scanner.Split(bufio.ScanWords) 15 | 16 | for scanner.Scan() { 17 | word := scanner.Text() 18 | fmt.Println(word) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /084-bufio-scanner/03-Scan-Characters/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | txt := "Hello\n How are you?\n Test 1\n Test 2\n" 11 | 12 | scanner := bufio.NewScanner(strings.NewReader(txt)) 13 | 14 | scanner.Split(bufio.ScanRunes) 15 | 16 | for scanner.Scan() { 17 | char := scanner.Text() 18 | fmt.Println(char) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /085-TCP-Server/01-Write-To-Connection/README.md: -------------------------------------------------------------------------------- 1 | start main.go (go run main.go) then go in another terminal window: 2 | telnet localhost 8080 -------------------------------------------------------------------------------- /085-TCP-Server/02-Read-From-Connection-Goroutines/README.md: -------------------------------------------------------------------------------- 1 | An open connection blocks. 2 | The reader is reading from the open connection. 3 | How does the reader know when it should stop reading? 4 | Instructions: run this file, then in our browser go to: 5 | http://localhost:8080/ -------------------------------------------------------------------------------- /085-TCP-Server/03-Read-Write-Connection/README.md: -------------------------------------------------------------------------------- 1 | An open connection blocks. 2 | The reader is reading from the open connection. 3 | How does the reader know when it should stop reading? 4 | Instructions: run this file, then in the browser go to: 5 | http://localhost:8080/ -------------------------------------------------------------------------------- /085-TCP-Server/04-Read-Write-Connection-setDeadline/README.md: -------------------------------------------------------------------------------- 1 | An open connection blocks. 2 | The reader is reading from the open connection. 3 | How does the reader know when it should stop reading? 4 | Instructions: run this file, then in the browser go to: 5 | http://localhost:8080/ -------------------------------------------------------------------------------- /085-TCP-Server/05-Client-Read-From-Connection-Dial-Read/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "net" 7 | ) 8 | 9 | func main() { 10 | conn, err := net.Dial("tcp", ":8080") 11 | 12 | if err != nil { 13 | panic(err) 14 | } 15 | 16 | defer conn.Close() 17 | 18 | bs, err := ioutil.ReadAll(conn) 19 | 20 | if err != nil { 21 | panic(err) 22 | } 23 | 24 | fmt.Println(string(bs)) 25 | } -------------------------------------------------------------------------------- /085-TCP-Server/06-Client-Write-To-Connection-Dial-Write/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net" 7 | ) 8 | 9 | func main() { 10 | conn, err := net.Dial("tcp", "localhost:8080") 11 | 12 | if err != nil { 13 | log.Fatalln(err) 14 | } 15 | 16 | defer conn.Close() 17 | 18 | fmt.Fprintln(conn, "Dialed!") 19 | } 20 | -------------------------------------------------------------------------------- /085-TCP-Server/08-TCP-Server-Returns-URL-Of-GET-Request/README.md: -------------------------------------------------------------------------------- 1 | run main.go 2 | 3 | in your browser, go to: 4 | http://localhost:8080/ -------------------------------------------------------------------------------- /085-TCP-Server/09-Multiplexer-Mux-Servemux-Router-Server-HTTP/README.md: -------------------------------------------------------------------------------- 1 | go run main.go 2 | 3 | in your browser, go to: 4 | http://localhost:8080/ -------------------------------------------------------------------------------- /088-nethttp-Package/01-Handler/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | type hotdog int 9 | 10 | func (m hotdog) ServeHTTP(w http.ResponseWriter, req *http.Request) { 11 | fmt.Println("Any code we want in this func") 12 | } 13 | 14 | func main() { 15 | var x hotdog 16 | _ = x 17 | } 18 | -------------------------------------------------------------------------------- /089-nethttp-ServeMux-Routing/01-Routing/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | ) 7 | 8 | type hotdog int 9 | 10 | func (m hotdog) ServeHTTP(w http.ResponseWriter, req *http.Request) { 11 | switch req.URL.Path { 12 | case "/dog": 13 | io.WriteString(w, "doggy doggy doggy") 14 | case "/cat": 15 | io.WriteString(w, "kitty kitty kitty") 16 | } 17 | } 18 | 19 | func main() { 20 | var d hotdog 21 | http.ListenAndServe(":8080", d) 22 | } 23 | -------------------------------------------------------------------------------- /089-nethttp-ServeMux-Routing/04-HandleFunc/README.md: -------------------------------------------------------------------------------- 1 | # HandleFunc 2 | 3 | [http.HandleFunc](https://godoc.org/net/http#HandleFunc) 4 | ``` Go 5 | func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) 6 | ``` -------------------------------------------------------------------------------- /090-Julien-Schimdt-Router/templates/about.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ABOUT 6 | 7 | 8 | 9 | ABOUT
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /090-Julien-Schimdt-Router/templates/apply.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | APPLY 6 | 7 | 8 | 9 | APPLY
10 | index
11 | about
12 | contact
13 | apply
14 |
15 | 16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /090-Julien-Schimdt-Router/templates/applyProcess.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | APPLY PROCESS 6 | 7 | 8 | 9 | APPLY PROCESS
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /090-Julien-Schimdt-Router/templates/contact.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CONTACT 6 | 7 | 8 | 9 | CONTACT
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /090-Julien-Schimdt-Router/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | INDEX 6 | 7 | 8 | 9 | INDEX
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /091-Practice-Codes/01-ListenAndServe-Using-Default-ServeMux/README.md: -------------------------------------------------------------------------------- 1 | ListenAndServe on port ":8080" using the default ServeMux. 2 | 3 | Use HandleFunc to add the following routes to the default ServeMux: 4 | 5 | "/" 6 | "/dog/" 7 | "/me/ 8 | 9 | Add a func for each of the routes. 10 | 11 | Have the "/me/" route print out your name. -------------------------------------------------------------------------------- /091-Practice-Codes/02-Parse-And-Serve-Template-With-Data/README.md: -------------------------------------------------------------------------------- 1 | 1. Take the previous program in the previous folder and change it so that: 2 | * a template is parsed and served 3 | * you pass data into the template -------------------------------------------------------------------------------- /091-Practice-Codes/02-Parse-And-Serve-Template-With-Data/something.gohtml: -------------------------------------------------------------------------------- 1 |

Hello, {{.}}

-------------------------------------------------------------------------------- /091-Practice-Codes/03-http-Handle/something.gohtml: -------------------------------------------------------------------------------- 1 |

Hello, {{.}}

-------------------------------------------------------------------------------- /091-Practice-Codes/07-Read-Functionality-Into-Serve-Func/README.md: -------------------------------------------------------------------------------- 1 | # Building upon the code from the previous problem: 2 | 3 | Extract the code you wrote to READ from the connection using bufio.NewScanner into its own function called "serve". 4 | 5 | Pass the connection of type net.Conn as an argument into this function. 6 | 7 | Add "go" in front of the call to "serve" to enable concurrency and multiple connections. -------------------------------------------------------------------------------- /091-Practice-Codes/08-Write-To-TCP-Connection/README.md: -------------------------------------------------------------------------------- 1 | Add code to WRITE to the connection. -------------------------------------------------------------------------------- /091-Practice-Codes/10-Print-To-Terminal/README.md: -------------------------------------------------------------------------------- 1 | # Building upon the code from the previous problem: 2 | 3 | Print to standard out (the terminal) the REQUEST method and the REQUEST URI from the REQUEST LINE. 4 | 5 | Add this data to your REPONSE so that this data is displayed in the browser. -------------------------------------------------------------------------------- /091-Practice-Codes/11-Changing-ContentType-Response-Header/README.md: -------------------------------------------------------------------------------- 1 | # Building upon the code from the previous problem: 2 | 3 | Change your RESPONSE HEADER "content-type" from "text/plain" to "text/html" 4 | 5 | Change the RESPONSE from "CHECK OUT THE RESPONSE BODY PAYLOAD" (and everything else it contained: request method, request URI) to an HTML PAGE that prints "HOLY COW THIS IS LOW LEVEL" in

tags. -------------------------------------------------------------------------------- /091-Practice-Codes/12-Routing/README.md: -------------------------------------------------------------------------------- 1 | # Building upon the code from the previous problem: 2 | 3 | Add code to respond to the following METHODS & ROUTES: 4 | GET / 5 | GET /apply 6 | POST /apply 7 | 8 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/01-Not-Serving/02-Example/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | ) 7 | 8 | func main() { 9 | http.HandleFunc("/", dog) 10 | _ = http.ListenAndServe(":8080", nil) 11 | } 12 | 13 | func dog(w http.ResponseWriter, req *http.Request) { 14 | w.Header().Set("Content-Type", "text/html; charset=utf-8") 15 | 16 | _, _ = io.WriteString(w, ` 17 | 18 | 19 | `) 20 | } 21 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/01-Not-Serving/02-Example/toby.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/01-Not-Serving/02-Example/toby.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/02-Serving/01-io-Copy/toby.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/02-Serving/01-io-Copy/toby.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/02-Serving/02-ServeContent/toby.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/02-Serving/02-ServeContent/toby.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/02-Serving/03-ServeFile/toby.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/02-Serving/03-ServeFile/toby.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/03-Building-A-File-Server/01-Serving-A-File-With-FileServer/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "net/http" 4 | 5 | func main() { 6 | http.Handle("/", http.FileServer(http.Dir("."))) 7 | _ = http.ListenAndServe(":8080", nil) 8 | } 9 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/03-Building-A-File-Server/01-Serving-A-File-With-FileServer/toby.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/03-Building-A-File-Server/01-Serving-A-File-With-FileServer/toby.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/03-Building-A-File-Server/02-FileServer-And-StripPrefix/assets/toby.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/03-Building-A-File-Server/02-FileServer-And-StripPrefix/assets/toby.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/03-Building-A-File-Server/03-Static-File-Server/assets/img/background-photo-mobile-devices.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/03-Building-A-File-Server/03-Static-File-Server/assets/img/background-photo-mobile-devices.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/03-Building-A-File-Server/03-Static-File-Server/assets/img/background-photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/03-Building-A-File-Server/03-Static-File-Server/assets/img/background-photo.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/03-Building-A-File-Server/03-Static-File-Server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | ) 7 | 8 | func main() { 9 | log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))) 10 | } 11 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/01-http-ServeFile/dog.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | FIDO 6 | 7 | 8 |

This is from dog

9 | a picture of a dog 10 | 11 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/01-http-ServeFile/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/01-http-ServeFile/dog.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/02-http-FileServer/README.md: -------------------------------------------------------------------------------- 1 | # Serve the files in the "starting-files" folder 2 | 3 | Use "http.FileServer" -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/02-http-FileServer/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | ) 7 | 8 | func main() { 9 | log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))) 10 | } 11 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/02-http-FileServer/pic/surf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/02-http-FileServer/pic/surf.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/README.md: -------------------------------------------------------------------------------- 1 | # Serve the files in the "starting-files" folder 2 | 3 | ## To get your images to serve, use only this: 4 | 5 | ``` Go 6 | fs := http.FileServer(http.Dir("public")) 7 | ``` 8 | 9 | Hint: look to see what type FileServer returns, then think it through. -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/public/pics/dog.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/public/pics/dog.jpeg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/public/pics/dog1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/public/pics/dog1.jpeg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/public/pics/dog2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/public/pics/dog2.jpeg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/03-http-FileServer-Return-Type/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

Pictures of dogs:

10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/README.md: -------------------------------------------------------------------------------- 1 | # Serve the files in the "starting-files" folder 2 | 3 | ## To get your images to serve, use: 4 | 5 | ``` Go 6 | func StripPrefix(prefix string, h Handler) Handler 7 | func FileServer(root FileSystem) Handler 8 | ``` 9 | 10 | Constraint: you are not allowed to change the route being used for images in the template file 11 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/public/pics/dog.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/public/pics/dog.jpeg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/public/pics/dog1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/public/pics/dog1.jpeg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/public/pics/dog2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/public/pics/dog2.jpeg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/04-FileServer-StripPrefix/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

Pictures of dogs redux:

10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/05-FileServer-StripPrefix/README.md: -------------------------------------------------------------------------------- 1 | # Serve the files in the "starting-files" folder 2 | 3 | ## To get your images to serve, use: 4 | 5 | ``` Go 6 | func StripPrefix(prefix string, h Handler) Handler 7 | func FileServer(root FileSystem) Handler 8 | ``` 9 | 10 | Constraint: you are not allowed to change the route being used for images in the template file 11 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/05-FileServer-StripPrefix/public/pic/surf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/092-Serving-Files-With-FileServer/04-Practice-Codes/05-FileServer-StripPrefix/public/pic/surf.jpg -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/06-ParseGlob-HandleFunc-applyProcess/templates/about.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ABOUT 6 | 7 | 8 | 9 | ABOUT
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/06-ParseGlob-HandleFunc-applyProcess/templates/applyProcess.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | APPLY PROCESS 6 | 7 | 8 | 9 | APPLY PROCESS
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/06-ParseGlob-HandleFunc-applyProcess/templates/contact.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CONTACT 6 | 7 | 8 | 9 | CONTACT
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /092-Serving-Files-With-FileServer/04-Practice-Codes/06-ParseGlob-HandleFunc-applyProcess/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | INDEX 6 | 7 | 8 | 9 | INDEX
10 | index
11 | about
12 | contact
13 | apply
14 | 15 | 16 | -------------------------------------------------------------------------------- /094-http-NotFoundHandler/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | ) 8 | 9 | func main() { 10 | http.HandleFunc("/", dog) 11 | http.Handle("/favicon.ico", http.NotFoundHandler()) 12 | 13 | log.Fatal(http.ListenAndServe(":8080", nil)) 14 | } 15 | 16 | func dog(res http.ResponseWriter, req *http.Request) { 17 | fmt.Println(req.URL) 18 | fmt.Fprintln(res, "In the terminal") 19 | } 20 | -------------------------------------------------------------------------------- /095-Deploying-To-Google-Cloud-AppEngine/01-Example-Project-Not-For-Deployment/app.yaml: -------------------------------------------------------------------------------- 1 | runtime: go113 2 | 3 | handlers: 4 | - url: /.* 5 | script: auto 6 | secure: always -------------------------------------------------------------------------------- /095-Deploying-To-Google-Cloud-AppEngine/01-Example-Project-Not-For-Deployment/img/bird.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/095-Deploying-To-Google-Cloud-AppEngine/01-Example-Project-Not-For-Deployment/img/bird.jpg -------------------------------------------------------------------------------- /095-Deploying-To-Google-Cloud-AppEngine/01-Example-Project-Not-For-Deployment/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func main() { 8 | http.Handle("/", http.FileServer(http.Dir("."))) 9 | http.ListenAndServe(":8080", nil) 10 | } 11 | -------------------------------------------------------------------------------- /095-Deploying-To-Google-Cloud-AppEngine/02-Example-Project-For-Deployment/app.yaml: -------------------------------------------------------------------------------- 1 | runtime: go113 2 | 3 | handlers: 4 | - url: /.* 5 | script: auto 6 | secure: always -------------------------------------------------------------------------------- /095-Deploying-To-Google-Cloud-AppEngine/02-Example-Project-For-Deployment/img/background-photo-mobile-devices.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/095-Deploying-To-Google-Cloud-AppEngine/02-Example-Project-For-Deployment/img/background-photo-mobile-devices.jpg -------------------------------------------------------------------------------- /095-Deploying-To-Google-Cloud-AppEngine/02-Example-Project-For-Deployment/img/background-photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/095-Deploying-To-Google-Cloud-AppEngine/02-Example-Project-For-Deployment/img/background-photo.jpg -------------------------------------------------------------------------------- /095-Deploying-To-Google-Cloud-AppEngine/02-Example-Project-For-Deployment/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func main() { 8 | http.Handle("/", http.FileServer(http.Dir("."))) 9 | http.ListenAndServe(":8080", nil) 10 | } 11 | -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/01-URL-Query-String/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "log" 6 | "net/http" 7 | ) 8 | 9 | func main() { 10 | http.HandleFunc("/", adi) 11 | http.Handle("/favicon.ico", http.NotFoundHandler()) 12 | 13 | log.Fatal(http.ListenAndServe(":8080", nil)) 14 | } 15 | 16 | func adi(res http.ResponseWriter, req *http.Request) { 17 | name := req.FormValue("uname") 18 | _, _ = io.WriteString(res, "नमस्ते "+name) 19 | } 20 | -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/05-HTML-Form-With-Many-Fields/templates/include-footer.gohtml: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 |

copyright Aditya

3 | 4 | 5 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/05-HTML-Form-With-Many-Fields/templates/include-header.gohtml: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/06-Enctype/01-Default/templates/include-footer.gohtml: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 | 3 | 4 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/06-Enctype/01-Default/templates/include-header.gohtml: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/06-Enctype/02-Multipart-Form-Data/templates/include-footer.gohtml: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 | 3 | 4 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/06-Enctype/02-Multipart-Form-Data/templates/include-header.gohtml: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/06-Enctype/03-Text-Plain/templates/include-footer.gohtml: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 | 3 | 4 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/06-Enctype/03-Text-Plain/templates/include-header.gohtml: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | {{end}} -------------------------------------------------------------------------------- /096-Passing-Data-Query-String-Form-Submission/URL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/096-Passing-Data-Query-String-Form-Submission/URL.png -------------------------------------------------------------------------------- /097-Creating-Uploading-Reading-File-On-Server/01-Read-From-Uploaded-File/example.txt: -------------------------------------------------------------------------------- 1 | Be crumbled. 2 | So wild flowers will come up where you are. 3 | You have been stony for too many years. 4 | Try something different. 5 | Surrender. 6 | -Rumi -------------------------------------------------------------------------------- /098-Redirect/01-SeeOther-303/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /098-Redirect/02-TemporaryRedirect-307/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /098-Redirect/04-WriteHeader/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /100-Sessions/02-Session/session.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/100-Sessions/02-Session/session.jpg -------------------------------------------------------------------------------- /100-Sessions/02-Session/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | FIRST {{.First}}
14 | LAST {{.Last}}
15 | {{end}} 16 | 17 | 18 | -------------------------------------------------------------------------------- /100-Sessions/03-Signup/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | FIRST {{.First}}
14 | LAST {{.Last}}
15 | {{end}} 16 | 17 | 18 | -------------------------------------------------------------------------------- /100-Sessions/03-Signup/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 | {{if .First}} 10 | USER NAME {{.UserName}}
11 | FIRST {{.First}}
12 | LAST {{.Last}}
13 | {{else}} 14 |

sign up

15 | {{end}} 16 | 17 |
18 |

Go to the bar

19 | 20 | -------------------------------------------------------------------------------- /100-Sessions/04-Bcrypt/notes.md: -------------------------------------------------------------------------------- 1 | You should never store a password without encrypting it. 2 | 3 | We will use ```bcrypt``` to encrypt our passwords. 4 | 5 | # Step 1: 6 | 7 | You will need to go get this package: 8 | 9 | ``` 10 | go get golang.org/x/crypto/bcrypt 11 | ``` 12 | 13 | # Step 2: 14 | Change your user struct's password field to the data type []byte 15 | 16 | # Step 3: 17 | Use bcrypt to encrypt your password before storing it. 18 | -------------------------------------------------------------------------------- /100-Sessions/04-Bcrypt/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 | {{end}} 17 | 18 | 19 | -------------------------------------------------------------------------------- /100-Sessions/04-Bcrypt/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 | {{if .First}} 10 | USER NAME {{.UserName}}
11 | PASSWORD {{.Password}}
12 | FIRST {{.First}}
13 | LAST {{.Last}}
14 | {{else}} 15 |

sign up

16 | {{end}} 17 | 18 |
19 |

Go to the bar

20 | 21 | -------------------------------------------------------------------------------- /100-Sessions/05-Login/notes.md: -------------------------------------------------------------------------------- 1 | # Step 1: 2 | Add a ```login.gohtml``` page. 3 | 4 | # Step 2: 5 | Handle the submission of a login form 6 | 7 | # Step 3: 8 | A fake user was added to dbUsers in func init -------------------------------------------------------------------------------- /100-Sessions/05-Login/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 | {{end}} 17 | 18 | 19 | -------------------------------------------------------------------------------- /100-Sessions/05-Login/templates/login.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 |

LOGIN

10 |
11 | 12 | 13 | 14 |
15 |

signup

16 | 17 | 18 | -------------------------------------------------------------------------------- /100-Sessions/06-Logout/notes.md: -------------------------------------------------------------------------------- 1 | # Step 1: 2 | 3 | Process a logout which occurs when someone goes to "/logout" 4 | -------------------------------------------------------------------------------- /100-Sessions/06-Logout/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /100-Sessions/06-Logout/templates/login.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 |

LOGIN

10 |
11 | 12 | 13 | 14 |
15 |

signup

16 | 17 | 18 | -------------------------------------------------------------------------------- /100-Sessions/07-Permissions/notes.md: -------------------------------------------------------------------------------- 1 | # Step 1: 2 | Added a field "Role" to the user struct 3 | 4 | # Step 2: 5 | Added a select drop-down to signup.gohtml 6 | 7 | # Step 3: 8 | Changed bar to only allow users with a role of "007" -------------------------------------------------------------------------------- /100-Sessions/07-Permissions/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /100-Sessions/07-Permissions/templates/login.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 |

LOGIN

10 |
11 | 12 | 13 | 14 |
15 |

signup

16 | 17 | 18 | -------------------------------------------------------------------------------- /100-Sessions/08-Expire-Session/maps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/100-Sessions/08-Expire-Session/maps.png -------------------------------------------------------------------------------- /100-Sessions/08-Expire-Session/norace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/100-Sessions/08-Expire-Session/norace.png -------------------------------------------------------------------------------- /100-Sessions/08-Expire-Session/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /100-Sessions/08-Expire-Session/templates/login.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 |

LOGIN

10 |
11 | 12 | 13 | 14 |
15 |

signup

16 | 17 | 18 | -------------------------------------------------------------------------------- /100-Sessions/09-Middleware/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /100-Sessions/09-Middleware/templates/login.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 |

LOGIN

10 |
11 | 12 | 13 | 14 |
15 |

signup

16 | 17 | 18 | -------------------------------------------------------------------------------- /100-Sessions/10-Temp/maps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/100-Sessions/10-Temp/maps.png -------------------------------------------------------------------------------- /100-Sessions/10-Temp/norace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/100-Sessions/10-Temp/norace.png -------------------------------------------------------------------------------- /100-Sessions/10-Temp/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /100-Sessions/10-Temp/templates/login.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 |

LOGIN

10 |
11 | 12 | 13 | 14 |
15 |

signup

16 | 17 | 18 | -------------------------------------------------------------------------------- /102-AWS/02-Deploying-Namaste-Aditya-To-AWS/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "log" 6 | "net/http" 7 | ) 8 | 9 | func main() { 10 | http.HandleFunc("/", index) 11 | log.Fatalln(http.ListenAndServe(":80", nil)) 12 | } 13 | 14 | func index(w http.ResponseWriter, req *http.Request) { 15 | _, _ = io.WriteString(w, "नमस्ते आदित्य on AWS.") 16 | } 17 | -------------------------------------------------------------------------------- /102-AWS/02-Deploying-Namaste-Aditya-To-AWS/namaste_aditya: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/102-AWS/02-Deploying-Namaste-Aditya-To-AWS/namaste_aditya -------------------------------------------------------------------------------- /102-AWS/03-Deploying-Session-Example-To-AWS/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /104-Concurrency-Channels-Deadlock/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | c := make(chan string, 2) // 2 = Buffer 7 | c <- "Aditya" 8 | c <- "Hajare" 9 | // c <- "Test123" // Since channel is already full, this will cause deadlock 10 | 11 | fmt.Println(<-c) 12 | fmt.Println(<-c) 13 | } 14 | -------------------------------------------------------------------------------- /108-RDS/README.md: -------------------------------------------------------------------------------- 1 | 1. install mysql 2 | 2. install workbench 3 | 3. create mysql db on aws 4 | 4. connect workbench to rds mysql db 5 | 5. https://www.youtube.com/watch?v=k68Y-XYapEI -------------------------------------------------------------------------------- /109-AWS-Scaling/01-Architecture/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/109-AWS-Scaling/01-Architecture/01.jpg -------------------------------------------------------------------------------- /109-AWS-Scaling/01-Architecture/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/109-AWS-Scaling/01-Architecture/02.jpg -------------------------------------------------------------------------------- /109-AWS-Scaling/01-Architecture/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/109-AWS-Scaling/01-Architecture/03.jpg -------------------------------------------------------------------------------- /109-AWS-Scaling/01-Architecture/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/109-AWS-Scaling/01-Architecture/04.jpg -------------------------------------------------------------------------------- /109-AWS-Scaling/01-Architecture/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/109-AWS-Scaling/01-Architecture/05.jpg -------------------------------------------------------------------------------- /109-AWS-Scaling/01-Architecture/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/109-AWS-Scaling/01-Architecture/06.jpg -------------------------------------------------------------------------------- /110-Photo-Blog/01-Starting/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | INDEX 6 | 7 | 8 | 9 | Hello from index 10 | 11 | 12 | -------------------------------------------------------------------------------- /110-Photo-Blog/02-Storing-User-Data-In-Cookie/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | INDEX 6 | 7 | 8 | 9 |

Cookie Value: {{.}}

10 | 11 | 12 | -------------------------------------------------------------------------------- /110-Photo-Blog/03-Appending-Multiple-Data-Into-Cookie/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | INDEX 6 | 7 | 8 | 9 |

Cookie Values:

10 | {{range .}} 11 |

{{.}}

12 | {{end}} 13 | 14 | 15 | -------------------------------------------------------------------------------- /110-Photo-Blog/04-Upload-Pictures-To-Server/public/pics/f382716c1600421f127c7414a072016434fcd43a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/110-Photo-Blog/04-Upload-Pictures-To-Server/public/pics/f382716c1600421f127c7414a072016434fcd43a.jpg -------------------------------------------------------------------------------- /110-Photo-Blog/04-Upload-Pictures-To-Server/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | INDEX 6 | 7 | 8 | 9 |

Cookie Values:

10 | {{range .}} 11 |

{{.}}

12 | {{end}} 13 | 14 |
15 | 16 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /110-Photo-Blog/05-Display-Pictures/public/pics/f382716c1600421f127c7414a072016434fcd43a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/110-Photo-Blog/05-Display-Pictures/public/pics/f382716c1600421f127c7414a072016434fcd43a.jpg -------------------------------------------------------------------------------- /110-Photo-Blog/05-Display-Pictures/templates/index.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | INDEX 6 | 7 | 8 | 9 |

Your Pictures:

10 | {{range .}} 11 | 12 | {{end}} 13 | 14 |
15 | 16 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /111-HMAC-Keyed-Hash-Message-Authentication/01-Basic/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/hmac" 5 | "crypto/sha256" 6 | "fmt" 7 | "io" 8 | ) 9 | 10 | func main() { 11 | c := getCode("aditya@example.com") 12 | fmt.Println(c) 13 | c = getCode("nishi@example.com") 14 | fmt.Println(c) 15 | } 16 | 17 | func getCode(s string) string { 18 | h := hmac.New(sha256.New, []byte("ourkey")) 19 | _, _ = io.WriteString(h, s) 20 | return fmt.Sprintf("%x", h.Sum(nil)) 21 | } 22 | -------------------------------------------------------------------------------- /113-Web-Storage/README.md: -------------------------------------------------------------------------------- 1 | # Web storage 2 | 3 | Use cookies for secure storage. 4 | 5 | Cookies have been around longer and have been built for secure storage. 6 | 7 | Web storage is the relative new comer. There are some articles that talk about it being compromised. 8 | 9 | ## Session storage 10 | Available only during the current session. Once the browser is closed, session storage is cleared off. 11 | 12 | ## Local storage 13 | Available until explicitly deleted -------------------------------------------------------------------------------- /114-Context/01-What-Is-Context/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | ) 8 | 9 | func main() { 10 | http.HandleFunc("/", foo) 11 | http.Handle("/favicon.ico", http.NotFoundHandler()) 12 | http.ListenAndServe(":8080", nil) 13 | } 14 | 15 | func foo(w http.ResponseWriter, req *http.Request) { 16 | ctx := req.Context() 17 | log.Println(ctx) 18 | fmt.Fprintln(w, ctx) 19 | } 20 | -------------------------------------------------------------------------------- /114-Context/README.md: -------------------------------------------------------------------------------- 1 | Context makes it possible to manage a chain of calls within the same call path by signaling context’s Done channel. 2 | 3 | source: https://rakyll.org/leakingctx/ -------------------------------------------------------------------------------- /116-JSON/03-Extras/09_string/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/09_string/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | ) 8 | 9 | func main() { 10 | var data string 11 | rcvd := `"Todd"` 12 | err := json.Unmarshal([]byte(rcvd), &data) 13 | if err != nil { 14 | log.Fatalln(err) 15 | } 16 | fmt.Println(data) 17 | } 18 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/10_int/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/10_int/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | ) 8 | 9 | func main() { 10 | var data int 11 | rcvd := `42` 12 | err := json.Unmarshal([]byte(rcvd), &data) 13 | if err != nil { 14 | log.Fatalln(err) 15 | } 16 | fmt.Println(data) 17 | } 18 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/11_bool/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/11_bool/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | ) 8 | 9 | func main() { 10 | var data bool 11 | rcvd := `true` 12 | err := json.Unmarshal([]byte(rcvd), &data) 13 | if err != nil { 14 | log.Fatalln(err) 15 | } 16 | fmt.Println(data) 17 | } 18 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/12_null/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/12_null/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | ) 8 | 9 | func main() { 10 | var a []string 11 | 12 | rcvd := `null` 13 | err := json.Unmarshal([]byte(rcvd), &a) 14 | if err != nil { 15 | log.Fatalln(err) 16 | } 17 | fmt.Println(a) 18 | fmt.Println(len(a)) 19 | fmt.Println(cap(a)) 20 | } 21 | -------------------------------------------------------------------------------- /116-JSON/03-Extras/13_marshal/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type model struct { 9 | State bool 10 | Pictures []string 11 | } 12 | 13 | func main() { 14 | m := model{} 15 | 16 | fmt.Println(m) 17 | 18 | bs, err := json.Marshal(m) 19 | if err != nil { 20 | fmt.Println("error: ", err) 21 | } 22 | 23 | fmt.Println(string(bs)) 24 | } 25 | -------------------------------------------------------------------------------- /117-AJAX/01/data.txt: -------------------------------------------------------------------------------- 1 | here is the data -------------------------------------------------------------------------------- /117-AJAX/01/test.html: -------------------------------------------------------------------------------- 1 | I'm a test. -------------------------------------------------------------------------------- /117-AJAX/03/surfergirl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/117-AJAX/03/surfergirl -------------------------------------------------------------------------------- /117-AJAX/03/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /117-AJAX/03/templates/login.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 |

LOGIN

10 |
11 | 12 | 13 | 14 |
15 |

signup

16 | 17 | 18 | -------------------------------------------------------------------------------- /118-MongoDB-REST/01-JulienSchmidt-Router/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | 8 | "github.com/julienschmidt/httprouter" 9 | ) 10 | 11 | func main() { 12 | r := httprouter.New() 13 | r.GET("/", index) 14 | log.Fatal(http.ListenAndServe(":8080", r)) 15 | } 16 | 17 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 18 | fmt.Fprint(w, "Index Page") 19 | } 20 | -------------------------------------------------------------------------------- /118-MongoDB-REST/02-json/README.md: -------------------------------------------------------------------------------- 1 | # Using Curl 2 | 3 | 1. Start your server 4 | 5 | 1. Enter this at the terminal 6 | ``` 7 | curl http://localhost:8080/user/1 8 | ``` -------------------------------------------------------------------------------- /118-MongoDB-REST/02-json/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type User struct { 4 | Name string `json:"name"` 5 | Gender string `json:"gender"` 6 | Age int `json:"age"` 7 | Id string `json:"id"` 8 | } 9 | -------------------------------------------------------------------------------- /118-MongoDB-REST/03-post-delete/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type User struct { 4 | Name string `json:"name"` 5 | Gender string `json:"gender"` 6 | Age int `json:"age"` 7 | Id string `json:"id"` 8 | } 9 | -------------------------------------------------------------------------------- /118-MongoDB-REST/04-mvc/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type User struct { 4 | Name string `json:"name"` 5 | Gender string `json:"gender"` 6 | Age int `json:"age"` 7 | Id string `json:"id"` 8 | } 9 | -------------------------------------------------------------------------------- /118-MongoDB-REST/05-mongodb/01-update-user-controller/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type User struct { 4 | Name string `json:"name"` 5 | Gender string `json:"gender"` 6 | Age int `json:"age"` 7 | Id string `json:"id"` 8 | } 9 | -------------------------------------------------------------------------------- /118-MongoDB-REST/05-mongodb/02-update-user-model/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "gopkg.in/mgo.v2/bson" 4 | 5 | type User struct { 6 | Name string `json:"name" bson:"name"` 7 | Gender string `json:"gender" bson:"gender"` 8 | Age int `json:"age" bson:"age"` 9 | Id bson.ObjectId `json:"id" bson:"_id"` 10 | } 11 | 12 | // Id was of type string before 13 | -------------------------------------------------------------------------------- /118-MongoDB-REST/05-mongodb/03-update-user-controllers-post/README.md: -------------------------------------------------------------------------------- 1 | # Don't run this code yet 2 | 3 | We create an ObjectId using the bson package. 4 | 5 | We do this in controllers/user.go in func CreateUser 6 | 7 | ``` 8 | // create bson ID 9 | u.Id = bson.NewObjectId() 10 | 11 | ``` 12 | 13 | Second, we store the user in mongodb. 14 | 15 | We do this in controllers/user.go in func CreateUser 16 | 17 | ``` 18 | uc.session.DB("go-web-dev-db").C("users").Insert(u) 19 | ``` -------------------------------------------------------------------------------- /118-MongoDB-REST/05-mongodb/03-update-user-controllers-post/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "gopkg.in/mgo.v2/bson" 4 | 5 | type User struct { 6 | Name string `json:"name" bson:"name"` 7 | Gender string `json:"gender" bson:"gender"` 8 | Age int `json:"age" bson:"age"` 9 | Id bson.ObjectId `json:"id" bson:"_id"` 10 | } 11 | -------------------------------------------------------------------------------- /118-MongoDB-REST/05-mongodb/04-update-user-controllers-get/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "gopkg.in/mgo.v2/bson" 4 | 5 | type User struct { 6 | Id bson.ObjectId `json:"id" bson:"_id"` 7 | Name string `json:"name" bson:"name"` 8 | Gender string `json:"gender" bson:"gender"` 9 | Age int `json:"age" bson:"age"` 10 | } 11 | -------------------------------------------------------------------------------- /118-MongoDB-REST/05-mongodb/05-update-user-controllers-delete/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "gopkg.in/mgo.v2/bson" 4 | 5 | type User struct { 6 | Id bson.ObjectId `json:"id" bson:"_id"` 7 | Name string `json:"name" bson:"name"` 8 | Gender string `json:"gender" bson:"gender"` 9 | Age int `json:"age" bson:"age"` 10 | } 11 | -------------------------------------------------------------------------------- /118-MongoDB-REST/06-Storing-Data-In-Map-Instead-of-MongoDB/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | // changed Id type to string 4 | type User struct { 5 | Id string `json:"id"` 6 | Name string `json:"name" ` 7 | Gender string `json:"gender"` 8 | Age int `json:"age"` 9 | } 10 | -------------------------------------------------------------------------------- /118-MongoDB-REST/07-Storing-Data-In-JSON-File-Instead-of-MongoDB/data: -------------------------------------------------------------------------------- 1 | {"ff69705b-0c6d-479d-ae12-71acf86587cf":{"id":"ff69705b-0c6d-479d-ae12-71acf86587cf","name":"Miss Moneypenny","gender":"female","age":27}} 2 | -------------------------------------------------------------------------------- /118-MongoDB-REST/08-Refactor-Codes-Into-Packages/README.md: -------------------------------------------------------------------------------- 1 | # Run this code 2 | 3 | at the terminal: 4 | 5 | go build -o wildwest 6 | ./wildwest -------------------------------------------------------------------------------- /118-MongoDB-REST/08-Refactor-Codes-Into-Packages/models/user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "time" 4 | 5 | // capitalize to export from package 6 | type User struct { 7 | UserName string 8 | Password []byte 9 | First string 10 | Last string 11 | Role string 12 | } 13 | 14 | // capitalize to export from package 15 | type Session struct { 16 | UserName string 17 | LastActivity time.Time 18 | } 19 | -------------------------------------------------------------------------------- /118-MongoDB-REST/08-Refactor-Codes-Into-Packages/templates/bar.gohtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BAR 6 | 7 | 8 | 9 |

Welcome to the bar. What can I get you to drink?

10 | 11 | {{if .First}} 12 | USER NAME {{.UserName}}
13 | PASSWORD {{.Password}}
14 | FIRST {{.First}}
15 | LAST {{.Last}}
16 |

log out

17 | {{end}} 18 | 19 | 20 | -------------------------------------------------------------------------------- /118-MongoDB-REST/08-Refactor-Codes-Into-Packages/wildwest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aditya43/golang-101/228c66878966ea4e75f7b661842661e1eb35ac09/118-MongoDB-REST/08-Refactor-Codes-Into-Packages/wildwest -------------------------------------------------------------------------------- /120-Functional-Options-Pattern/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/aditya43/golang-core/120-Functional-Options-Pattern/server" 7 | ) 8 | 9 | func main() { 10 | srv := server.New( 11 | server.WithHost("localhost"), 12 | server.WithMaxConn(100), 13 | server.WithPort(8080), 14 | server.WithTimeout(time.Minute), 15 | ) 16 | 17 | srv.Start() 18 | time.Sleep(time.Second) 19 | srv.Stop() 20 | } 21 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("नमस्ते आदित्य") 7 | } 8 | --------------------------------------------------------------------------------