├── CNAME ├── docs ├── assets │ ├── main.scss │ ├── .DS_Store │ └── favicon │ │ ├── favicon.ico │ │ ├── apple-icon.png │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── favicon-96x96.png │ │ ├── ms-icon-144x144.png │ │ ├── ms-icon-150x150.png │ │ ├── ms-icon-310x310.png │ │ ├── ms-icon-70x70.png │ │ ├── apple-icon-57x57.png │ │ ├── apple-icon-60x60.png │ │ ├── apple-icon-72x72.png │ │ ├── apple-icon-76x76.png │ │ ├── android-icon-144x144.png │ │ ├── android-icon-192x192.png │ │ ├── android-icon-36x36.png │ │ ├── android-icon-48x48.png │ │ ├── android-icon-72x72.png │ │ ├── android-icon-96x96.png │ │ ├── apple-icon-114x114.png │ │ ├── apple-icon-120x120.png │ │ ├── apple-icon-144x144.png │ │ ├── apple-icon-152x152.png │ │ ├── apple-icon-180x180.png │ │ ├── apple-icon-precomposed.png │ │ ├── browserconfig.xml │ │ └── manifest.json ├── img │ ├── aws.png │ ├── azure.png │ ├── calico.png │ ├── google.png │ ├── velero.png │ ├── weave.png │ ├── kubicorn.jpg │ ├── kubicorn-trans.png │ ├── sangam-biradar.png │ ├── aws-example-apply.png │ ├── aws-ec2-post-create-screen-shot.png │ └── aws-iam-user-perm-screen-shot.png ├── .jekyll-metadata ├── present │ ├── lib │ │ └── fonts │ │ │ ├── asul │ │ │ ├── asul-bold.ttf │ │ │ ├── asul-bold.woff │ │ │ ├── asul-regular.ttf │ │ │ ├── asul-regular.woff │ │ │ └── asul.css │ │ │ ├── lato │ │ │ ├── lato-bold.ttf │ │ │ ├── lato-bold.woff │ │ │ ├── lato-italic.ttf │ │ │ ├── lato-italic.woff │ │ │ ├── lato-regular.ttf │ │ │ ├── lato-regular.woff │ │ │ ├── lato-bolditalic.ttf │ │ │ ├── lato-bolditalic.woff │ │ │ └── lato.css │ │ │ ├── league │ │ │ ├── league_gothic_license │ │ │ ├── league_gothic.ttf │ │ │ ├── league_gothic.woff │ │ │ └── league_gothic.css │ │ │ ├── oxygen │ │ │ ├── oxygen-bold.ttf │ │ │ ├── oxygen-bold.woff │ │ │ ├── oxygen-regular.ttf │ │ │ ├── oxygen-regular.woff │ │ │ └── oxygen.css │ │ │ ├── katex │ │ │ ├── KaTeX_Main-Bold.ttf │ │ │ ├── KaTeX_Main-Bold.woff │ │ │ ├── KaTeX_AMS-Regular.ttf │ │ │ ├── KaTeX_AMS-Regular.woff │ │ │ ├── KaTeX_Fraktur-Bold.ttf │ │ │ ├── KaTeX_Main-Italic.ttf │ │ │ ├── KaTeX_Main-Italic.woff │ │ │ ├── KaTeX_Main-Regular.ttf │ │ │ ├── KaTeX_Math-Italic.ttf │ │ │ ├── KaTeX_Math-Italic.woff │ │ │ ├── KaTeX_Math-Regular.ttf │ │ │ ├── KaTeX_Fraktur-Bold.woff │ │ │ ├── KaTeX_Fraktur-Regular.ttf │ │ │ ├── KaTeX_Main-BoldItalic.ttf │ │ │ ├── KaTeX_Main-Regular.woff │ │ │ ├── KaTeX_Math-BoldItalic.ttf │ │ │ ├── KaTeX_Math-Regular.woff │ │ │ ├── KaTeX_SansSerif-Bold.ttf │ │ │ ├── KaTeX_SansSerif-Bold.woff │ │ │ ├── KaTeX_Script-Regular.ttf │ │ │ ├── KaTeX_Script-Regular.woff │ │ │ ├── KaTeX_Size1-Regular.ttf │ │ │ ├── KaTeX_Size1-Regular.woff │ │ │ ├── KaTeX_Size2-Regular.ttf │ │ │ ├── KaTeX_Size2-Regular.woff │ │ │ ├── KaTeX_Size3-Regular.ttf │ │ │ ├── KaTeX_Size3-Regular.woff │ │ │ ├── KaTeX_Size4-Regular.ttf │ │ │ ├── KaTeX_Size4-Regular.woff │ │ │ ├── KaTeX_Caligraphic-Bold.ttf │ │ │ ├── KaTeX_Caligraphic-Bold.woff │ │ │ ├── KaTeX_Fraktur-Regular.woff │ │ │ ├── KaTeX_Main-BoldItalic.woff │ │ │ ├── KaTeX_Math-BoldItalic.woff │ │ │ ├── KaTeX_SansSerif-Italic.ttf │ │ │ ├── KaTeX_SansSerif-Italic.woff │ │ │ ├── KaTeX_SansSerif-Regular.ttf │ │ │ ├── KaTeX_Caligraphic-Regular.ttf │ │ │ ├── KaTeX_Caligraphic-Regular.woff │ │ │ ├── KaTeX_SansSerif-Regular.woff │ │ │ ├── KaTeX_Typewriter-Regular.ttf │ │ │ └── KaTeX_Typewriter-Regular.woff │ │ │ ├── opensans │ │ │ ├── opensans-bold.ttf │ │ │ ├── opensans-bold.woff │ │ │ ├── opensans-italic.ttf │ │ │ ├── opensans-italic.woff │ │ │ ├── opensans-regular.ttf │ │ │ ├── opensans-regular.woff │ │ │ ├── opensans-bolditalic.ttf │ │ │ ├── opensans-bolditalic.woff │ │ │ └── opensans.css │ │ │ ├── overpass │ │ │ ├── overpass-bold.ttf │ │ │ ├── overpass-bold.woff │ │ │ ├── overpass-light.ttf │ │ │ ├── overpass-light.woff │ │ │ ├── overpass-regular.ttf │ │ │ ├── overpass-regular.woff │ │ │ └── overpass.css │ │ │ ├── newscycle │ │ │ ├── newscycle-bold.ttf │ │ │ ├── newscycle-bold.woff │ │ │ ├── newscycle-regular.ttf │ │ │ ├── newscycle-regular.woff │ │ │ └── newscycle.css │ │ │ ├── overpass2 │ │ │ ├── overpass2-bold.ttf │ │ │ ├── overpass2-bold.woff │ │ │ ├── overpass2-italic.ttf │ │ │ ├── overpass2-italic.woff │ │ │ ├── overpass2-light.ttf │ │ │ ├── overpass2-light.woff │ │ │ ├── overpass2-regular.ttf │ │ │ ├── overpass2-regular.woff │ │ │ ├── overpass2-bolditalic.ttf │ │ │ ├── overpass2-bolditalic.woff │ │ │ ├── overpass2-extralight.ttf │ │ │ ├── overpass2-extralight.woff │ │ │ ├── overpass2-lightitalic.ttf │ │ │ ├── overpass2-lightitalic.woff │ │ │ ├── overpass2-extralightitalic.ttf │ │ │ ├── overpass2-extralightitalic.woff │ │ │ └── overpass2.css │ │ │ ├── quicksand │ │ │ ├── quicksand-bold.ttf │ │ │ ├── quicksand-bold.woff │ │ │ ├── quicksand-regular.ttf │ │ │ ├── quicksand-regular.woff │ │ │ └── quicksand.css │ │ │ ├── montserrat │ │ │ ├── montserrat-bold.ttf │ │ │ ├── montserrat-bold.woff │ │ │ ├── montserrat-regular.ttf │ │ │ ├── montserrat-regular.woff │ │ │ └── montserrat.css │ │ │ ├── cabinsketch │ │ │ ├── cabinsketch-bold.ttf │ │ │ ├── cabinsketch-bold.woff │ │ │ ├── cabinsketch-regular.ttf │ │ │ ├── cabinsketch-regular.woff │ │ │ └── cabinsketch.css │ │ │ ├── josefinsans │ │ │ ├── josefinsans-bold.ttf │ │ │ ├── josefinsans-bold.woff │ │ │ ├── josefinsans-italic.ttf │ │ │ ├── josefinsans-italic.woff │ │ │ ├── josefinsans-regular.ttf │ │ │ ├── josefinsans-regular.woff │ │ │ ├── josefinsans-bolditalic.ttf │ │ │ ├── josefinsans-bolditalic.woff │ │ │ └── josefinsans.css │ │ │ └── merriweathersans │ │ │ ├── merriweathersans-bold.ttf │ │ │ ├── merriweathersans-bold.woff │ │ │ ├── merriweathersans-regular.ttf │ │ │ ├── merriweathersans-regular.woff │ │ │ └── merriweathersans.css │ └── deck-21cb68 │ │ ├── 2c13db815f65b8ce51112e44f6e28442.png │ │ └── be0683a058d1d92dfd3dda65cb7a48f4.png ├── _includes │ ├── discord.html │ ├── icon-github.html │ ├── icon-twitter.html │ ├── google-analytics.html │ ├── disqus_comments.html │ ├── icon-twitter.svg │ ├── icon-github.svg │ ├── icon-discord.svg │ └── head.html ├── notes ├── index.md ├── _friends │ └── sangam.md ├── 404.html ├── _layouts │ ├── page.html │ ├── default.html │ └── post.html ├── _documentation │ ├── readme.md │ ├── 1.2-numeral-system-decimal.md │ ├── 3.5-structs.md │ ├── 2.9-loop-conditional-modulus.md │ ├── 1.8-variable-with-zero-value.md │ ├── 4.0-Defer.md │ ├── 2.6-loop-printing-ASCII.md │ ├── 4.3-prefix-suffix.md │ ├── 3.7-ponter-to-struct.md │ ├── 1.4-numeral-system-hexadecimal.md │ ├── 3.6-struct-literal.md │ ├── 3.8-conversion-not-casting.md │ ├── 2.8-conditional-if-else-if-Else.md │ ├── 1.3-numeral-system-binary.md │ ├── 4.2-pointer.md │ ├── 10.6-resolve-the-user-home-directory.md │ ├── 2.5-random-number-math-crypto.md │ ├── 4.1-stacking-defers.md │ ├── 3.2-conditional-logic-operators.md │ ├── 9.9-writing-the-file.md │ ├── 4.4-conversion-between-array-slice.md │ ├── 1.1-hello-world.md │ ├── 9.7-getting-file-information.md │ ├── 2.1-loop-init-condition-post.md │ ├── 1.7-short-variable-declarations.md │ ├── 9.1-writing-multiple-writers-at-once.md │ ├── 4.6-variadic-function.md │ ├── 8.2-taking-logarithms.md │ ├── 10.4-filtering-file-listings.md │ ├── 2.2-loop-nested-loops.md │ ├── 10.2-Changing-file-permissions.md │ ├── 6.5-aligning-text-with-tabwriter.md │ ├── 2.4-break-continue.md │ ├── 3.9-creating-own-type.md │ ├── 9.2-piping-between-writer-reader.md │ ├── 5.4-getting-the-current-process-pid.md │ ├── 9.8-creating-temporary-files.md │ ├── 7.2-converting-strings-to-numbers.md │ ├── 9.0-reading-writing-binary-data.md │ ├── 6.7-finding-the-substring-in-text-by-the-regex-pattern.md │ ├── 10.3-Creating-files-and-dir.md │ ├── 8.6-opening-a-file-by-name.md │ ├── 10.0-writing-the-file-from-multiple-goroutines.md │ ├── 8.0-operating-complex-numbers.md │ ├── 8.1-converting-between-degrees-radians.md │ ├── 5.6-calling_external_process.md │ ├── 5.0-retriving-go-version.md │ ├── 8.8-reading-writing-different-charset.md │ ├── 8.7-reading-the-file-into-string.md │ ├── 5.7-retrieving-child-process-information.md │ ├── 1.5-numeral-system-loop.md │ ├── 6.4-concatenating-a-string-with-writer.md │ ├── 8.5-writing-standard-output-error.md │ ├── 9.3-serializing-objects-binary-format.md │ ├── 7.4-rounding-floating-point-numbers.md │ ├── 5.3-retrieving-current-working-directory.md │ ├── 6.1-finding-the-substring-in-a-string.md │ ├── 7.7-Converting-binary-octal-decimal-hexadecimal.md │ ├── 2.0-deep-drive-on-constants.md │ ├── 7.1-indenting-a-text-document.md │ ├── 9.6-extracting-data-JSON-array.md │ ├── 5.1-accessing-program-arguments.md │ ├── 9.4-reading-writing-zip-files.md │ ├── 2.7-conditional-if-statement.md │ ├── 7.5-floating-point-arithmetics.md │ ├── 6.8-controlling-case.md │ ├── 7.9-generating-random-numbers.md │ ├── 8.3-generating-checksums.md │ ├── 10.1-listing-directory.md │ └── 6.0-file-configuration-with-functional-options.md ├── README.md ├── about.md ├── Gemfile ├── LICENSE.txt ├── .gitignore ├── _config.yml └── Gemfile.lock └── .gitignore /CNAME: -------------------------------------------------------------------------------- 1 | gopherlabs.kubedaily.com -------------------------------------------------------------------------------- /docs/assets/main.scss: -------------------------------------------------------------------------------- 1 | 2 | @import "minima"; 3 | -------------------------------------------------------------------------------- /docs/img/aws.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/aws.png -------------------------------------------------------------------------------- /docs/img/azure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/azure.png -------------------------------------------------------------------------------- /docs/img/calico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/calico.png -------------------------------------------------------------------------------- /docs/img/google.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/google.png -------------------------------------------------------------------------------- /docs/img/velero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/velero.png -------------------------------------------------------------------------------- /docs/img/weave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/weave.png -------------------------------------------------------------------------------- /docs/.jekyll-metadata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/.jekyll-metadata -------------------------------------------------------------------------------- /docs/assets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/.DS_Store -------------------------------------------------------------------------------- /docs/img/kubicorn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/kubicorn.jpg -------------------------------------------------------------------------------- /docs/img/kubicorn-trans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/kubicorn-trans.png -------------------------------------------------------------------------------- /docs/img/sangam-biradar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/sangam-biradar.png -------------------------------------------------------------------------------- /docs/assets/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/favicon.ico -------------------------------------------------------------------------------- /docs/img/aws-example-apply.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/aws-example-apply.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon.png -------------------------------------------------------------------------------- /docs/assets/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /docs/assets/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /docs/assets/favicon/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/favicon-96x96.png -------------------------------------------------------------------------------- /docs/assets/favicon/ms-icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/ms-icon-144x144.png -------------------------------------------------------------------------------- /docs/assets/favicon/ms-icon-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/ms-icon-150x150.png -------------------------------------------------------------------------------- /docs/assets/favicon/ms-icon-310x310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/ms-icon-310x310.png -------------------------------------------------------------------------------- /docs/assets/favicon/ms-icon-70x70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/ms-icon-70x70.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _state* 2 | .idea* 3 | .DS_Store 4 | bin/* 5 | .vscode 6 | .sass-cache/ 7 | _site/ 8 | docs/vendor 9 | docs/.bundle 10 | -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-57x57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-57x57.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-60x60.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-72x72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-72x72.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-76x76.png -------------------------------------------------------------------------------- /docs/present/lib/fonts/asul/asul-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/asul/asul-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-bold.ttf -------------------------------------------------------------------------------- /docs/assets/favicon/android-icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/android-icon-144x144.png -------------------------------------------------------------------------------- /docs/assets/favicon/android-icon-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/android-icon-192x192.png -------------------------------------------------------------------------------- /docs/assets/favicon/android-icon-36x36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/android-icon-36x36.png -------------------------------------------------------------------------------- /docs/assets/favicon/android-icon-48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/android-icon-48x48.png -------------------------------------------------------------------------------- /docs/assets/favicon/android-icon-72x72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/android-icon-72x72.png -------------------------------------------------------------------------------- /docs/assets/favicon/android-icon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/android-icon-96x96.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-114x114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-114x114.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-120x120.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-144x144.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-152x152.png -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-180x180.png -------------------------------------------------------------------------------- /docs/img/aws-ec2-post-create-screen-shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/aws-ec2-post-create-screen-shot.png -------------------------------------------------------------------------------- /docs/img/aws-iam-user-perm-screen-shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/img/aws-iam-user-perm-screen-shot.png -------------------------------------------------------------------------------- /docs/present/lib/fonts/asul/asul-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/asul/asul-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/asul/asul-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/asul/asul-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-italic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-italic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-regular.ttf -------------------------------------------------------------------------------- /docs/assets/favicon/apple-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/assets/favicon/apple-icon-precomposed.png -------------------------------------------------------------------------------- /docs/present/lib/fonts/asul/asul-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/asul/asul-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/league/league_gothic_license: -------------------------------------------------------------------------------- 1 | SIL Open Font License (OFL) 2 | http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL 3 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/oxygen/oxygen-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/oxygen/oxygen-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/oxygen/oxygen-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/oxygen/oxygen-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-Bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-Bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-bolditalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-bolditalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato-bolditalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/lato/lato-bolditalic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/league/league_gothic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/league/league_gothic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/league/league_gothic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/league/league_gothic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass/overpass-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass/overpass-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/oxygen/oxygen-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/oxygen/oxygen-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/oxygen/oxygen-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/oxygen/oxygen-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_AMS-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_AMS-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_AMS-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_AMS-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Fraktur-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Fraktur-Bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-Italic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-Italic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Math-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Math-Italic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Math-Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Math-Italic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Math-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Math-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/newscycle/newscycle-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/newscycle/newscycle-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-italic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass/overpass-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass/overpass-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass/overpass-light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass/overpass-light.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass/overpass-light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass/overpass-light.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/quicksand/quicksand-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/quicksand/quicksand-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Fraktur-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Fraktur-Bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Fraktur-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Fraktur-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-BoldItalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Math-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Math-BoldItalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Math-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Math-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_SansSerif-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_SansSerif-Bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_SansSerif-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_SansSerif-Bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Script-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Script-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Script-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Script-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size1-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size1-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size1-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size1-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size2-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size2-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size2-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size2-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size3-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size3-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size3-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size3-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size4-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size4-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Size4-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Size4-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/montserrat/montserrat-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/montserrat/montserrat-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/montserrat/montserrat-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/montserrat/montserrat-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/newscycle/newscycle-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/newscycle/newscycle-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/newscycle/newscycle-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/newscycle/newscycle-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-italic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass/overpass-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass/overpass-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass/overpass-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass/overpass-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-italic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-italic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-light.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-light.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/quicksand/quicksand-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/quicksand/quicksand-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/quicksand/quicksand-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/quicksand/quicksand-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/cabinsketch/cabinsketch-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/cabinsketch/cabinsketch-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/cabinsketch/cabinsketch-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/cabinsketch/cabinsketch-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Caligraphic-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Caligraphic-Bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Caligraphic-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Caligraphic-Bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Fraktur-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Fraktur-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Main-BoldItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Main-BoldItalic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Math-BoldItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Math-BoldItalic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_SansSerif-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_SansSerif-Italic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_SansSerif-Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_SansSerif-Italic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_SansSerif-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_SansSerif-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/montserrat/montserrat-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/montserrat/montserrat-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/newscycle/newscycle-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/newscycle/newscycle-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-bolditalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-bolditalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans-bolditalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/opensans/opensans-bolditalic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/quicksand/quicksand-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/quicksand/quicksand-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/cabinsketch/cabinsketch-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/cabinsketch/cabinsketch-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/cabinsketch/cabinsketch-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/cabinsketch/cabinsketch-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-italic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-italic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Caligraphic-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Caligraphic-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Caligraphic-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Caligraphic-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_SansSerif-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_SansSerif-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Typewriter-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Typewriter-Regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/katex/KaTeX_Typewriter-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/katex/KaTeX_Typewriter-Regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/montserrat/montserrat-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/montserrat/montserrat-regular.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-bolditalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-bolditalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-bolditalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-bolditalic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-extralight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-extralight.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-extralight.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-extralight.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-lightitalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-lightitalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-lightitalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-lightitalic.woff -------------------------------------------------------------------------------- /docs/present/deck-21cb68/2c13db815f65b8ce51112e44f6e28442.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/deck-21cb68/2c13db815f65b8ce51112e44f6e28442.png -------------------------------------------------------------------------------- /docs/present/deck-21cb68/be0683a058d1d92dfd3dda65cb7a48f4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/deck-21cb68/be0683a058d1d92dfd3dda65cb7a48f4.png -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-bolditalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-bolditalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans-bolditalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/josefinsans/josefinsans-bolditalic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-extralightitalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-extralightitalic.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2-extralightitalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/overpass2/overpass2-extralightitalic.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/merriweathersans/merriweathersans-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/merriweathersans/merriweathersans-bold.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/merriweathersans/merriweathersans-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/merriweathersans/merriweathersans-bold.woff -------------------------------------------------------------------------------- /docs/present/lib/fonts/merriweathersans/merriweathersans-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/merriweathersans/merriweathersans-regular.ttf -------------------------------------------------------------------------------- /docs/present/lib/fonts/merriweathersans/merriweathersans-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golangmastery/GopherLabs/HEAD/docs/present/lib/fonts/merriweathersans/merriweathersans-regular.woff -------------------------------------------------------------------------------- /docs/_includes/discord.html: -------------------------------------------------------------------------------- 1 | {% include discord.svg %}{{ include.username }} 2 | -------------------------------------------------------------------------------- /docs/_includes/icon-github.html: -------------------------------------------------------------------------------- 1 | {% include icon-github.svg %}{{ include.username }} 2 | -------------------------------------------------------------------------------- /docs/_includes/icon-twitter.html: -------------------------------------------------------------------------------- 1 | {% include icon-twitter.svg %}{{ include.username }} 2 | -------------------------------------------------------------------------------- /docs/notes: -------------------------------------------------------------------------------- 1 | _config.yml - E-mail address needed on line 17. 2 | 3 | Do we want the writer section on the documentation? 4 | 5 | Are we gonna have posts of some kind, or anything other than a main page and the documentation? 6 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | # You don't need to edit this file, it's empty on purpose. 3 | # Edit theme's home layout instead if you wanna make some changes 4 | # See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults 5 | layout: home 6 | --- 7 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/league/league_gothic.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'League Gothic'; 3 | src: url('league_gothic.woff') format('woff'), 4 | url('league_gothic.ttf') format('truetype'); 5 | 6 | font-weight: normal; 7 | font-style: normal; 8 | } -------------------------------------------------------------------------------- /docs/_friends/sangam.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Sangam Biradar 3 | logo: /img/sangam-biradar.png 4 | --- 5 | 6 | Sangam is working as Technical Advocate ,Tenable | Docker Community Leader Award Winner 2020 , Packt Author 7 | Okteto / Traefik Ambassador , Kubedaily & CloudNativeFolks Community 8 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 | 5 |
6 |
7 |

404

8 |

Page not found :(

9 |

The requested page could not be found.

10 |
11 |
12 | -------------------------------------------------------------------------------- /docs/_layouts/page.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 |
5 | 6 |
7 |

{{ page.title | escape }}

8 |
9 | 10 |
11 | {{ content }} 12 |
13 | 14 |
15 | -------------------------------------------------------------------------------- /docs/_documentation/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Ultimate Gopherlabs 4 | weight: 0 5 | doctype: Go101 6 | --- 7 | 8 | ## Introduction 9 | 10 | 11 | ## Glossary 12 | 13 | 14 | ## Project structure 15 | 16 | 17 | ## Website 18 | 19 | 20 | ## Why we are doing stuff this way? 21 | 22 | -------------------------------------------------------------------------------- /docs/assets/favicon/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | #ffffff -------------------------------------------------------------------------------- /docs/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {% include head.html %} 5 | 6 | 7 | 8 | {% include header.html %} 9 | 10 |
11 |
12 | {{ content }} 13 |
14 |
15 | 16 | {% include footer.html %} 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Gopherlabs Community 2 | 3 | [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fsangam14%2FGopherLabs&count_bg=%2379C83D&title_bg=%23555555&icon=go.svg&icon_color=%23E7E7E7&title=hits&edge_flat=true)](https://hits.seeyoufarm.com) 4 | 5 | 6 | ## Thanks to all the contributors ❤️ 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /docs/_includes/google-analytics.html: -------------------------------------------------------------------------------- 1 | 11 | 12 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/asul/asul.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Asul'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('asul-regular.woff') format('woff'), 8 | url('asul-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Asul'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('asul-bold.woff') format('woff'), 15 | url('asul-bold.ttf') format('truetype'); 16 | } 17 | -------------------------------------------------------------------------------- /docs/_documentation/1.2-numeral-system-decimal.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Numeral Systems - Decimal 4 | weight: 2 5 | doctype: Go101 6 | --- 7 | 8 | 1.Numeral systems - Decimal 9 | 10 | ``` 11 | 12 | package main 13 | 14 | import "fmt" 15 | 16 | func main() { 17 | fmt.Println(42) 18 | } 19 | 20 | ``` 21 | [Run](https://play.golang.org/p/79__Y2CzdPh){:.button.button--outline-success.button--pill} 22 | 23 | 24 | Output: 25 | 26 | ``` 27 | 42 28 | Program exited. 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/oxygen/oxygen.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Oxygen'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('oxygen-regular.woff') format('woff'), 8 | url('oxygen-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Oxygen'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('oxygen-bold.woff') format('woff'), 15 | url('oxygen-bold.ttf') format('truetype'); 16 | } 17 | -------------------------------------------------------------------------------- /docs/_documentation/3.5-structs.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Structs 4 | weight: 25 5 | doctype: Go101 6 | --- 7 | 8 | A struct is a collection of fields. 9 | 10 | 11 | we are creating xy struct with X and Y fiels. 12 | ``` 13 | type xy struct { 14 | X string 15 | Y string 16 | } 17 | ``` 18 | [Go Program](https://play.golang.org/p/ffvPEWNpNvW) 19 | ``` 20 | package main 21 | 22 | import "fmt" 23 | 24 | type xy struct { 25 | X string 26 | Y string 27 | } 28 | 29 | func main() { 30 | fmt.Println(xy{"x", "y"}) 31 | } 32 | ``` 33 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/newscycle/newscycle.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'News Cycle'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('newscycle-regular.woff') format('woff'), 8 | url('newscycle-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'News Cycle'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('newscycle-bold.woff') format('woff'), 15 | url('newscycle-bold.ttf') format('truetype'); 16 | } 17 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/quicksand/quicksand.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Quicksand'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('quicksand-regular.woff') format('woff'), 8 | url('quicksand-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Quicksand'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('quicksand-bold.woff') format('woff'), 15 | url('quicksand-bold.ttf') format('truetype'); 16 | } 17 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/montserrat/montserrat.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Montserrat'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('montserrat-regular.woff') format('woff'), 8 | url('montserrat-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Montserrat'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('montserrat-bold.woff') format('woff'), 15 | url('montserrat-bold.ttf') format('truetype'); 16 | } 17 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/cabinsketch/cabinsketch.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Cabin Sketch'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('cabinsketch-regular.woff') format('woff'), 8 | url('cabinsketch-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Cabin Sketch'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('cabinsketch-regular.woff') format('woff'), 15 | url('cabinsketch-regular.ttf') format('truetype'); 16 | } -------------------------------------------------------------------------------- /docs/_documentation/2.9-loop-conditional-modulus.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Loop, Conditional, Modulus 4 | weight: 19 5 | doctype: Go101 6 | --- 7 | 8 | Use the modulo operator `%` and a `for` loop and `if` statement to print out all the even numbers from 1 to 100 9 | 10 | ```go 11 | package main 12 | 13 | import ( 14 | "fmt" 15 | ) 16 | 17 | func main() { 18 | for i := 1; i <= 100; i++ { 19 | if i%2 == 0 { // try changing the number to 3, 4, etc. 20 | fmt.Println(i) 21 | } 22 | } 23 | } 24 | ``` 25 | 26 | [playground](https://play.golang.org/p/mhwuHNMCEF) 27 | -------------------------------------------------------------------------------- /docs/_documentation/1.8-variable-with-zero-value.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Variable with zero value 4 | weight: 8 5 | doctype: Go101 6 | --- 7 | 8 | 9 | ``` 10 | package main 11 | 12 | import "fmt" 13 | 14 | func main() { 15 | 16 | var a int 17 | var b string 18 | var c float64 19 | var d bool 20 | 21 | fmt.Printf("%v \n", a) 22 | fmt.Printf("%v \n", b) 23 | fmt.Printf("%v \n", c) 24 | fmt.Printf("%v \n", d) 25 | 26 | fmt.Println() 27 | } 28 | ``` 29 | 30 | in this above program declared variable with its type so it will give zero values and for bool it will return 31 | false 32 | -------------------------------------------------------------------------------- /docs/about.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: page 3 | title: About 4 | permalink: /about/ 5 | --- 6 | 7 | This is the base Jekyll theme. You can find out more info about customizing your Jekyll theme, as well as basic Jekyll usage documentation at [jekyllrb.com](https://jekyllrb.com/) 8 | 9 | You can find the source code for Minima at GitHub: 10 | [jekyll][jekyll-organization] / 11 | [minima](https://github.com/jekyll/minima) 12 | 13 | You can find the source code for Jekyll at GitHub: 14 | [jekyll][jekyll-organization] / 15 | [jekyll](https://github.com/jekyll/jekyll) 16 | 17 | 18 | [jekyll-organization]: https://github.com/jekyll 19 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/merriweathersans/merriweathersans.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Merriweather Sans'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('merriweathersans-regular.woff') format('woff'), 8 | url('merriweathersans-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Merriweather Sans'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('merriweathersans-bold.woff') format('woff'), 15 | url('merriweathersans-bold.ttf') format('truetype'); 16 | } 17 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass/overpass.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Overpass'; 3 | font-style: normal; 4 | font-weight: bold; 5 | src: url('overpass-bold.woff') format('woff'), 6 | url('overpass-bold.ttf') format('truetype'); 7 | } 8 | 9 | 10 | @font-face { 11 | font-family: 'Overpass'; 12 | font-style: normal; 13 | font-weight: 500; 14 | src: url('overpass-regular.woff') format('woff'), 15 | url('overpass-regular.ttf') format('truetype'); 16 | } 17 | 18 | 19 | @font-face { 20 | font-family: 'Overpass'; 21 | font-style: normal; 22 | font-weight: normal; 23 | src: url('overpass-light.woff') format('woff'), 24 | url('overpass-light.ttf') format('truetype'); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /docs/_documentation/4.0-Defer.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Defer 4 | weight: 30 5 | doctype: Go101 6 | --- 7 | 8 | A defer statement defers the execution of a function until the surrounding function returns. 9 | 10 | The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns. 11 | 12 | 13 | ``` 14 | package main 15 | 16 | import "fmt" 17 | 18 | func main() { 19 | defer fmt.Println("world") 20 | 21 | fmt.Println("hello") 22 | } 23 | ``` 24 | [Go Playground](https://play.golang.org/p/GBzCn3hH39K) 25 | 26 | output: 27 | 28 | ``` 29 | hello 30 | world 31 | 32 | ``` 33 | 34 | in this above program if you use ``` defer ``` keyword it will not execute until the surrounding function returns 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/_includes/disqus_comments.html: -------------------------------------------------------------------------------- 1 | {% if page.comments != false and jekyll.environment == "production" %} 2 | 3 |
4 | 19 | 20 | {% endif %} 21 | -------------------------------------------------------------------------------- /docs/_includes/icon-twitter.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/_documentation/2.6-loop-printing-ASCII.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Loop - Printing ASCII 4 | weight: 16 5 | doctype: Go101 6 | --- 7 | 8 | 9 | We previously learned how to print the different characters of a string with format printing. Refer to the docmentation for a refresher on the [fmt](https://golang.org/pkg/fmt/) package. 10 | 11 | Loop through the numbers `33` through `122`, and print them out as numbers and text strings. 12 | 13 | *Hint*: Refer to the [ASCII](https://en.wikipedia.org/wiki/ASCII) coding scheme to see the decimal and glyph representations. 14 | 15 | ```go 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | ) 21 | 22 | func main() { 23 | for i := 33; i < 122; i++ { 24 | fmt.Printf("%v\t%#U\n", i, i) 25 | } 26 | } 27 | ``` 28 | 29 | [playground](https://play.golang.org/p/y4OzIKta2M) 30 | -------------------------------------------------------------------------------- /docs/_documentation/4.3-prefix-suffix.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Prefix Suffix 4 | weight: 33 5 | doctype: Go101 6 | --- 7 | 8 | 9 | 10 | HasPrefix tests whether the string s begins with prefix:
11 | ```strings.HasPrefix(s, prefix string) bool```
12 | HasSuffix tests whether the string s end with suffix:
13 | ``` strings.HasSuffix(s, suffix string) bool``` 14 | ``` 15 | package main 16 | import ( 17 | "fmt" 18 | "strings" 19 | ) 20 | func main() { 21 | var str string = "This is an example of a string" 22 | fmt.Printf("T/F? Does the string \"%s\" have prefix %s? ", str, "Th") 23 | fmt.Printf("%t\n", strings.HasPrefix(str, "Th")) 24 | } 25 | ``` 26 | 27 | Output: ```T/F? Does the string “This is an example of a string” have prefix Th? True``` 28 | 29 | 30 | 31 | [Go Playground](https://play.golang.org/p/ZQW-WzSkzLS) 32 | -------------------------------------------------------------------------------- /docs/_documentation/3.7-ponter-to-struct.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Pointer to struct 4 | weight: 27 5 | doctype: Go101 6 | --- 7 | 8 | # Struct fields can be accessed through a struct pointer. 9 | 10 | To access the field ``` X ```of a struct when we have the struct pointer ```p ```we could write``` (*p).X```. 11 | However, that notation is cumbersome, so the language permits us instead to write just ```p.X```, without the explicit dereference. 12 | 13 | ``` 14 | func main() { 15 | z := xy{1, 2} 16 | p := &z 17 | p.X = 20 18 | fmt.Println(z) 19 | } 20 | 21 | ``` 22 | [Go Program](https://play.golang.org/p/k0TOI-Ur2CN) 23 | ``` 24 | package main 25 | 26 | import "fmt" 27 | 28 | type xy struct { 29 | X int 30 | Y int 31 | } 32 | 33 | func main() { 34 | z := xy{1, 2} 35 | p := &z 36 | p.X = 20 37 | fmt.Println(z) 38 | } 39 | 40 | 41 | 42 | ``` 43 | -------------------------------------------------------------------------------- /docs/assets/favicon/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "App", 3 | "icons": [ 4 | { 5 | "src": "\/android-icon-36x36.png", 6 | "sizes": "36x36", 7 | "type": "image\/png", 8 | "density": "0.75" 9 | }, 10 | { 11 | "src": "\/android-icon-48x48.png", 12 | "sizes": "48x48", 13 | "type": "image\/png", 14 | "density": "1.0" 15 | }, 16 | { 17 | "src": "\/android-icon-72x72.png", 18 | "sizes": "72x72", 19 | "type": "image\/png", 20 | "density": "1.5" 21 | }, 22 | { 23 | "src": "\/android-icon-96x96.png", 24 | "sizes": "96x96", 25 | "type": "image\/png", 26 | "density": "2.0" 27 | }, 28 | { 29 | "src": "\/android-icon-144x144.png", 30 | "sizes": "144x144", 31 | "type": "image\/png", 32 | "density": "3.0" 33 | }, 34 | { 35 | "src": "\/android-icon-192x192.png", 36 | "sizes": "192x192", 37 | "type": "image\/png", 38 | "density": "4.0" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /docs/present/lib/fonts/lato/lato.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Lato'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('lato-regular.woff') format('woff'), 8 | url('lato-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Lato'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('lato-bold.woff') format('woff'), 15 | url('lato-bold.ttf') format('truetype'); 16 | } 17 | @font-face { 18 | font-family: 'Lato'; 19 | font-style: italic; 20 | font-weight: 400; 21 | src: url('lato-italic.woff') format('woff'), 22 | url('lato-italic.ttf') format('truetype'); 23 | } 24 | @font-face { 25 | font-family: 'Lato'; 26 | font-style: italic; 27 | font-weight: 700; 28 | src: url('lato-bolditalic.woff') format('woff'), 29 | url('lato-bolditalic.ttf') format('truetype'); 30 | } 31 | -------------------------------------------------------------------------------- /docs/_includes/icon-github.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/_layouts/post.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 |
5 | 6 |
7 |

{{ page.title | escape }}

8 | 16 |
17 | 18 |
19 | {{ content }} 20 |
21 | 22 | {% if site.disqus.shortname %} 23 | {% include disqus_comments.html %} 24 | {% endif %} 25 |
26 | -------------------------------------------------------------------------------- /docs/_documentation/1.4-numeral-system-hexadecimal.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Numeral systems - hexadecimal 4 | weight: 4 5 | doctype: Go101 6 | --- 7 | 8 | ``` 9 | package main 10 | 11 | import "fmt" 12 | 13 | func main() { 14 | // fmt.Printf("%d - %b - %x \n", 42, 42, 42) 15 | // fmt.Printf("%d - %b - %#x \n", 42, 42, 42) 16 | // fmt.Printf("%d - %b - %#X \n", 42, 42, 42) 17 | fmt.Printf("%d \t %b \t %#X \n", 42, 42, 42) 18 | } 19 | 20 | ``` 21 | [Run](ttps://play.golang.org/p/4vWR8_1Df3S){:.button.button--outline-success.button--pill} 22 | 23 | 24 | output: 25 | ``` 26 | 42 101010 0X2A 27 | ``` 28 | in above program the annotation verb %x formats a number in hexadecimal Ex:- which represent 0X2A ( base 16 format) 29 | 30 | integer to hexadecimal cheatsheet: 31 | 32 | 33 | %x base 16, with lower-case letters for a-f 34 | %x base 16, with upper-case letters for a-f 35 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/opensans/opensans.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Open Sans'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('opensans-regular.woff') format('woff'), 8 | url('opensans-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Open Sans'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('opensans-bold.woff') format('woff'), 15 | url('opensans-bold.ttf') format('truetype'); 16 | } 17 | @font-face { 18 | font-family: 'Open Sans'; 19 | font-style: italic; 20 | font-weight: 400; 21 | src: url('opensans-italic.woff') format('woff'), 22 | url('opensans-italic.ttf') format('truetype'); 23 | } 24 | @font-face { 25 | font-family: 'Open Sans'; 26 | font-style: italic; 27 | font-weight: 700; 28 | src: url('opensans-bolditalic.woff') format('woff'), 29 | url('opensans-bolditalic.ttf') format('truetype'); 30 | } 31 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/josefinsans/josefinsans.css: -------------------------------------------------------------------------------- 1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on May 10, 2013 */ 2 | 3 | @font-face { 4 | font-family: 'Josefin Sans'; 5 | font-style: normal; 6 | font-weight: 400; 7 | src: url('josefinsans-regular.woff') format('woff'), 8 | url('josefinsans-regular.ttf') format('truetype'); 9 | } 10 | @font-face { 11 | font-family: 'Josefin Sans'; 12 | font-style: normal; 13 | font-weight: 700; 14 | src: url('josefinsans-bold.woff') format('woff'), 15 | url('josefinsans-bold.ttf') format('truetype'); 16 | } 17 | @font-face { 18 | font-family: 'Josefin Sans'; 19 | font-style: italic; 20 | font-weight: 400; 21 | src: url('josefinsans-italic.woff') format('woff'), 22 | url('josefinsans-italic.ttf') format('truetype'); 23 | } 24 | @font-face { 25 | font-family: 'Josefin Sans'; 26 | font-style: italic; 27 | font-weight: 700; 28 | src: url('josefinsans-bolditalic.woff') format('woff'), 29 | url('josefinsans-bolditalic.ttf') format('truetype'); 30 | } 31 | -------------------------------------------------------------------------------- /docs/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # Hello! This is where you manage which Jekyll version is used to run. 4 | # When you want to use a different version, change it below, save the 5 | # file and run `bundle install`. Run Jekyll with `bundle exec`, like so: 6 | # 7 | # bundle exec jekyll serve 8 | # 9 | # This will help ensure the proper Jekyll version is running. 10 | # Happy Jekylling! 11 | gem "jekyll", "~> 3.8.4" 12 | 13 | # This is the default theme for new Jekyll sites. You may change this to anything you like. 14 | gem "minima", "~> 2.0" 15 | 16 | # If you want to use GitHub Pages, remove the "gem "jekyll"" above and 17 | # uncomment the line below. To upgrade, run `bundle update github-pages`. 18 | # gem "github-pages", group: :jekyll_plugins 19 | 20 | # If you have any plugins, put them here! 21 | group :jekyll_plugins do 22 | gem "jekyll-feed", "~> 0.6" 23 | end 24 | 25 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 26 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 27 | 28 | -------------------------------------------------------------------------------- /docs/_documentation/3.6-struct-literal.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Struct Literal 4 | weight: 26 5 | doctype: Go101 6 | --- 7 | 8 | 9 | A struct literal denotes a newly allocated struct value by listing the values of its fields. 10 | You can list just a subset of fields by using the Name: syntax. (And the order of named fields is irrelevant.) 11 | The special prefix & returns a pointer to the struct value. 12 | 13 | ``` 14 | var ( 15 | z1 = xy{1, 2} // has type xy. z1={1,2} 16 | z2 = xy{X: 1} // Y:0 is implicit z2={1,0} 17 | z3 = xy{} // X:0 and Y:0 z3={0,0} 18 | p = &xy{1, 2} // has type *xy p={1,2} 19 | ) 20 | ``` 21 | 22 | [Go Playground](https://play.golang.org/p/P5whnHh57Zn) 23 | ``` 24 | package main 25 | 26 | import "fmt" 27 | 28 | type xy struct { 29 | X, Y int 30 | } 31 | 32 | var ( 33 | z1 = xy{1, 2} // has type xy 34 | z2 = xy{X: 1} // Y:0 is implicit 35 | z3 = xy{} // X:0 and Y:0 36 | p = &xy{1, 2} // has type *xy 37 | ) 38 | 39 | func main() { 40 | fmt.Println(z1, p, z2, z3) 41 | } 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /docs/_includes/icon-discord.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_documentation/3.8-conversion-not-casting.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Conversion, Not Casting 4 | weight: 28 5 | doctype: Go101 6 | --- 7 | 8 | 9 | Conversion means we take the value of one type and _convert_ it to another type. 10 | 11 | Let's try it out in the [Go playground](https://play.golang.org/p/zMIh3Eur7K) 12 | ```go 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | ) 18 | 19 | var a int 20 | type hotdog int 21 | var b hotdog 22 | 23 | func main() { 24 | a = 42 25 | b = hotdog(a) // we can convert the value of a to a value of type hotdog 26 | fmt.Println(a) 27 | fmt.Printf("%T\n", a) 28 | fmt.Println(b) 29 | fmt.Printf("%T\n", b) 30 | } 31 | ``` 32 | In other programming languages, this is called _casting_. We don't call it casting in Go, we call it _conversion_. If you go to [Effective Go](https://golang.org/doc/effective_go.html) and search for "cast" you won't find any results, but if you search for "[conversion](https://golang.org/doc/effective_go.html#conversions)" you will. 33 | 34 | That's the end of this section! 35 | 36 | -------------------------------------------------------------------------------- /docs/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Parker Moore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/_documentation/2.8-conditional-if-else-if-Else.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Conditional - If, Else if, Else 4 | weight: 18 5 | doctype: Go101 6 | --- 7 | 8 | 9 | # Conditional - If, Else if, Else 10 | 11 | Here's an example of using `if` and `else` 12 | 13 | ```go 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | ) 19 | 20 | func main() { 21 | x := 42 22 | 23 | if x == 40 { 24 | fmt.Println("Our value was 40") 25 | } else { 26 | fmt.Println("Our value was not 40") 27 | } 28 | } 29 | ``` 30 | 31 | [playground](https://play.golang.org/p/o2LQFJxWNR) 32 | 33 | We can also use `else if` as many times as we want within the `if` statement. 34 | 35 | ```go 36 | package main 37 | 38 | import ( 39 | "fmt" 40 | ) 41 | 42 | func main() { 43 | x := 42 44 | if x == 40 { 45 | fmt.Println("Our value was 40") 46 | } else if x == 41 { 47 | fmt.Println("Our value was 41") 48 | } else if x == 42 { 49 | fmt.Println("Our value was 42") 50 | } else if x == 43 { 51 | fmt.Println("Our value was 43") 52 | } else { 53 | fmt.Println("Our value was not 40") 54 | } 55 | } 56 | ``` 57 | 58 | [playground](https://play.golang.org/p/a3jbqR2vXp) 59 | -------------------------------------------------------------------------------- /docs/_documentation/1.3-numeral-system-binary.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Numeral Systems - Binary 4 | weight: 3 5 | doctype: Go101 6 | --- 7 | 8 | 9 | ``` 10 | package main 11 | 12 | import "fmt" 13 | 14 | func main() { 15 | fmt.Printf("%d - %b \n", 42, 42) 16 | } 17 | ``` 18 | [Run](https://play.golang.org/p/8oA-JOz0flp){:.button.button--outline-success.button--pill} 19 | 20 | 21 | Output: 22 | 23 | 42 - 101010 24 | 25 | Program exited. 26 | 27 | 28 | 29 | in above program the annotation verb %b formats a number in binary Ex:- which represent 101010 ( base 2 format) 30 | and the annotation verb %d formats a number in Base 10 Ex:which represent 42 ( base 10 format) 31 | 32 | Integer cheatsheet for fmt 33 | 34 | ``` 35 | %b base 2 36 | %c the character represented by the corresponding Unicode code point 37 | %d base 10 38 | %o base 8 39 | %q a single-quoted character literal safely escaped with Go syntax. 40 | %x base 16, with lower-case letters for a-f 41 | %X base 16, with upper-case letters for A-F 42 | %U Unicode format: U+1234; same as "U+%04 43 | ``` 44 | -------------------------------------------------------------------------------- /docs/_documentation/4.2-pointer.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Pointer 4 | weight: 32 5 | doctype: Go101 6 | --- 7 | 8 | 9 | Go has pointers. A pointer holds the memory address of a value. 10 | 11 | The type``` *T``` is a pointer to a ```T``` value. Its zero value is nil. 12 | 13 | ```var p *int``` 14 | The & operator generates a pointer to its operand. 15 | ``` 16 | i := 42 17 | p = &i 18 | ``` 19 | The ```*``` operator denotes the pointer's underlying value. 20 | ``` 21 | fmt.Println(*p) // read i through the pointer p 22 | *p = 21 // set i through the pointer p 23 | 24 | ``` 25 | This is known as "dereferencing" or "indirecting". 26 | 27 | Unlike C, Go has no pointer arithmetic. 28 | 29 | ``` 30 | package main 31 | 32 | import "fmt" 33 | 34 | func main() { 35 | i, j := 42, 2701 36 | 37 | p := &i // point to i 38 | fmt.Println(*p) // read i through the pointer 39 | *p = 21 // set i through the pointer 40 | fmt.Println(i) // see the new value of i 41 | 42 | p = &j // point to j 43 | *p = *p / 37 // divide j through the pointer 44 | fmt.Println(j) // see the new value of j 45 | } 46 | ``` 47 | [Go Playground](https://play.golang.org/p/6ex5tqolgF5) 48 | -------------------------------------------------------------------------------- /docs/_documentation/10.6-resolve-the-user-home-directory.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Resolving the user home directory 4 | weight: 96 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - It could be beneficial for the program to know the user's home directory, for example, in case you need to store a custom user configuration or any other data related to the user. 10 | This recipe will describe how you can find out the current user's home directory. 11 | 12 | ## Create the home.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "log" 19 | "os/user" 20 | ) 21 | 22 | func main() { 23 | usr, err := user.Current() 24 | if err != nil { 25 | log.Fatal(err) 26 | } 27 | fmt.Println("The user home directory: " + usr.HomeDir) 28 | } 29 | 30 | 31 | ``` 32 | output 33 | ```sangam:golang-daily sangam$ go run home.go 34 | The user home directory: /Users/sangam 35 | sangam:golang-daily sangam$ 36 | 37 | ``` 38 | ## How it works... 39 | 40 | - The os/user package contains the Current function, which provides the os.User type pointer. The User contains the HomeDir property, which contains the path of the current user's home directory. 41 | -------------------------------------------------------------------------------- /docs/_documentation/2.5-random-number-math-crypto.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Generate Random number with math/crypto/rand in Go 4 | weight: 15 5 | doctype: Go101 6 | --- 7 | 8 | # Generate Random number with math/crypto/rand in Go - Programming in GO 9 | 10 | Random number is useful in many application. One such example is salting password to make in more secure. 11 | In this tutorial, we will learn how to generate random number in Go with math/rand library. 12 | 13 | 14 | ``` 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "math/rand" 20 | "time" 21 | ) 22 | 23 | 24 | func main() { 25 | rand.Seed(time.Now().UnixNano()) 26 | fmt.Println(rand.Intn(100)) 27 | } 28 | 29 | ``` 30 | Run : 31 | ``` 32 | go run math-rand.go 33 | ``` 34 | 35 | Random number is useful in many applications. From salting password to enabling secure transactions. 36 | 37 | In this tutorial, we will learn how to generate random number in Go with crypto/rand library. 38 | 39 | 40 | 41 | ``` 42 | package main 43 | 44 | import "encoding/binary" 45 | import "crypto/rand" 46 | 47 | func main() { 48 | var n int32 49 | binary.Read(rand.Reader, binary.LittleEndian, &n) 50 | println(n) 51 | } 52 | 53 | ``` 54 | Run : 55 | ``` 56 | go run crytpo-rand.go 57 | ``` 58 | -------------------------------------------------------------------------------- /docs/_documentation/4.1-stacking-defers.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Stacking defers 4 | weight: 31 5 | doctype: Go101 6 | --- 7 | 8 | Deferred function calls are pushed onto a stack. When a function returns, 9 | its deferred calls are executed in last-in-first-out order. 10 | 11 | lets write a program to count numbers from ```1``` to ```9``` 12 | ``` 13 | package main 14 | 15 | import "fmt" 16 | 17 | func main() { 18 | fmt.Println("counting") 19 | 20 | for i := 0; i < 10; i++ { 21 | fmt.Println(i) 22 | } 23 | 24 | fmt.Println("done") 25 | } 26 | ``` 27 | [Go Playground](https://play.golang.org/p/aOJHy5FgZXF) 28 | 29 | Stacking defers - use defer ``` defer fmt.Println(i). ``` because of defer its give you output of last result in first thats 30 | known as last-in-first out manner 31 | ``` 32 | package main 33 | 34 | import "fmt" 35 | 36 | func main() { 37 | fmt.Println("counting") 38 | 39 | for i := 0; i < 10; i++ { 40 | defer fmt.Println(i) 41 | } 42 | 43 | fmt.Println("done") 44 | } 45 | ``` 46 | [Go Playground](https://play.golang.org/p/aioV0JViI9Z) 47 | 48 | Important: 49 | ``` 50 | for i := 0; i < 10; i++ { 51 | defer fmt.Println(i) 52 | } 53 | ``` 54 | 55 | 56 | output: 57 | ``` 58 | counting 59 | done 60 | 9 61 | 8 62 | 7 63 | 6 64 | 5 65 | 4 66 | 3 67 | 2 68 | 1 69 | 0 70 | ``` 71 | -------------------------------------------------------------------------------- /docs/_documentation/3.2-conditional-logic-operators.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Conditional Logic Operators 4 | weight: 22 5 | doctype: Go101 6 | --- 7 | 8 | Try to think through the following conditionals before trying them out the playgroud. Will they evaluate to true or false? 9 | 10 | ```go 11 | package main 12 | 13 | import ( 14 | "fmt" 15 | ) 16 | 17 | func main() { 18 | fmt.Println(true && true) 19 | fmt.Println(true && false) 20 | fmt.Println(true || true) 21 | fmt.Println(true || false) 22 | fmt.Println(!true) 23 | } 24 | ``` 25 | 26 | [playground](https://play.golang.org/p/ukFrlC66uv) 27 | 28 | `&&` will return `true` if both sides evaluate to `true`, otherwise it will return `false`. 29 | 30 | `||` will return `true` if either side evaluates to `true`. 31 | 32 | `!` returns the opposite 33 | 34 | Try [some examples](https://play.golang.org/p/cZEfXSIIDO) for yourself. 35 | 36 | ```go 37 | package main 38 | 39 | import ( 40 | "fmt" 41 | ) 42 | 43 | func main() { 44 | fmt.Printf("true && true\t %v\n", true && true) 45 | fmt.Printf("true && false\t %v\n", true && false) 46 | fmt.Printf("true || true\t %v\n", true || true) 47 | fmt.Printf("true || false\t %v\n", true || false) 48 | fmt.Printf("!true\t\t\t %v\n", !true) 49 | } 50 | ``` 51 | 52 | [playground](https://play.golang.org/p/zRs5hDVmY2C) 53 | -------------------------------------------------------------------------------- /docs/_documentation/9.9-writing-the-file.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: writing the file 4 | weight: 89 5 | doctype: Go101 6 | --- 7 | 8 | - Writing a file is an essential task for every programmer; 9 | Go supports multiple ways on how you can do this. This recipe will show a few of them. 10 | 11 | ## Create the writefile.go file with the following content: 12 | ``` 13 | package main 14 | 15 | import ( 16 | "io" 17 | "os" 18 | "strings" 19 | ) 20 | 21 | func main() { 22 | 23 | f, err := os.Create("sample.file") 24 | if err != nil { 25 | panic(err) 26 | } 27 | defer f.Close() 28 | 29 | _, err = f.WriteString("Go is awesome!\n") 30 | if err != nil { 31 | panic(err) 32 | } 33 | 34 | _, err = io.Copy(f, strings.NewReader("Yeah! Go is great.\n")) 35 | if err != nil { 36 | panic(err) 37 | } 38 | } 39 | 40 | 41 | 42 | ``` 43 | output: 44 | ``` 45 | sangam:golang-daily sangam$ go run writefile.go 46 | ``` 47 | ## Check the content of the created sample.file: 48 | ``` 49 | sangam:golang-daily sangam$ cat sample.file 50 | Go is awesome! 51 | Yeah! Go is great. 52 | sangam:golang-daily sangam$ 53 | 54 | ``` 55 | ## How it works... 56 | 57 | - The os.File type implements the Writer interface, so writing to the file could be done by any option that uses the Writer interface. The preceding example uses the WriteString method of the os.File type. 58 | The io.WriteString method can also be used in general. 59 | 60 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | ### Jekyll ### 2 | _site 3 | .jekyll-metadata 4 | *-cache/ 5 | 6 | 7 | ### NPM ### 8 | /node_modules/ 9 | 10 | 11 | ### Atom ### 12 | .ftpconfig 13 | .sftpconfig 14 | 15 | 16 | ### WordPress ### 17 | wp-config.php 18 | wp-config-local.php 19 | wp-content/advanced-cache.php 20 | wp-content/backup-db/ 21 | wp-content/backups/ 22 | wp-content/blogs.dir/ 23 | wp-content/cache/ 24 | wp-content/upgrade/ 25 | wp-content/uploads/ 26 | wp-content/wp-cache-config.php 27 | wp-content/plugins/hello.php 28 | 29 | 30 | ### Apache ### 31 | .htaccess 32 | 33 | 34 | ### Compiled Source ## 35 | *.com 36 | *.class 37 | *.dll 38 | *.exe 39 | *.o 40 | *.so 41 | 42 | 43 | ### Compressed Packages ### 44 | *.7z 45 | *.dmg 46 | *.gz 47 | *.iso 48 | *.jar 49 | *.rar 50 | *.tar 51 | *.zip 52 | 53 | 54 | ### Logs and Databases ### 55 | *.log 56 | *.sql 57 | *.sqlite 58 | 59 | 60 | ### Linux ### 61 | *~ 62 | .fuse_hidden* 63 | .Trash-* 64 | .nfs* 65 | 66 | 67 | ### MacOS ### 68 | *.DS_Store 69 | .AppleDouble 70 | .LSOverride 71 | Icon 72 | ._* 73 | .DocumentRevisions-V100 74 | .fseventsd 75 | .Spotlight-V100 76 | .TemporaryItems 77 | .Trashes 78 | .VolumeIcon.icns 79 | .com.apple.timemachine.donotpresent 80 | .AppleDB 81 | .AppleDesktop 82 | Network Trash Folder 83 | Temporary Items 84 | .apdisk 85 | 86 | 87 | ### Windows ### 88 | Thumbs.db 89 | ehthumbs.db 90 | ehthumbs_vista.db 91 | Desktop.ini 92 | $RECYCLE.BIN/ 93 | *.cab 94 | *.msi 95 | *.msm 96 | *.msp 97 | *.lnk -------------------------------------------------------------------------------- /docs/_documentation/4.4-conversion-between-array-slice.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Conversion between array and slice 4 | weight: 34 5 | doctype: Go101 6 | --- 7 | 8 | In `Go`, array is a fixed length of continuous memory with specified type, while slice is just a reference which points to an underlying array. Since they are different types, they can't assign value each other directly. See the following example: 9 | 10 | package main 11 | 12 | import "fmt" 13 | 14 | func main() { 15 | s := []int{1, 2, 3} 16 | var a [3]int 17 | 18 | fmt.Println(copy(a, s)) 19 | } 20 | Because `copy` only accepts slice argument, we can use the `[:]` to create a slice from array. Check next code: 21 | 22 | package main 23 | 24 | import "fmt" 25 | 26 | func main() { 27 | s := []int{1, 2, 3} 28 | var a [3]int 29 | 30 | fmt.Println(copy(a[:2], s)) 31 | fmt.Println(a) 32 | } 33 | 34 | The running output is: 35 | 36 | 2 37 | [1 2 0] 38 | 39 | The above example is copying value from slice to array, and the opposite operation is similar: 40 | 41 | package main 42 | 43 | import "fmt" 44 | 45 | func main() { 46 | a := [...]int{1, 2, 3} 47 | s := make([]int, 3) 48 | 49 | fmt.Println(copy(s, a[:2])) 50 | fmt.Println(s) 51 | } 52 | 53 | The execution result is: 54 | 55 | 2 56 | [1 2 0] 57 | 58 | References: 59 | [Arrays, slices (and strings): The mechanics of 'append'](https://blog.golang.org/slices). 60 | -------------------------------------------------------------------------------- /docs/_documentation/1.1-hello-world.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Lets Start With First Hello world Program 4 | weight: 1 5 | doctype: Go101 6 | --- 7 | 8 | ## Lets Start With First Hello world Program 9 | 10 | ``` 11 | // visit :- gopherlabs.kubedaily.com 12 | package main 13 | 14 | // main package declaration 15 | import "fmt" 16 | 17 | // import librares 18 | func main() { 19 | // declare main function with func keyforword followed by main() 20 | fmt.Println("Hello World") 21 | // fmt is fromat 22 | } 23 | 24 | // output :- hello_world 25 | 26 | 27 | ``` 28 | [Run](https://play.golang.org/p/b5LpJFoesBI){:.button.button--outline-success.button--pill} 29 | 30 | 31 | 32 | 33 | 34 | - A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively. The main package must have package name main and declare a function main that takes no arguments and returns no value. 35 | 36 | func main() { … } 37 | 38 | - Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete. 39 | 40 | ----- 41 | 42 | - Go: Meaning of the 'fmt' package acronym 43 | - fmt is short for format. 44 | - Package fmt implements formatted I/O with functions analogous to C's printf and scanf. The format 'verbs' are derived from C's but are simpler. 45 | 46 | ----- 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /docs/_documentation/9.7-getting-file-information.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: getting file information 4 | weight: 87 5 | doctype: Go101 6 | --- 7 | 8 | If you need to discover basic information about the accessed file, 9 | Go's standard library provides a way on how you can do this. This recipe shows how you can access this information. 10 | 11 | 12 | ## Create the sample test.file with the content ```This is test file``` 13 | 14 | ## Create the fileinfo.go file with the following content: 15 | 16 | ``` 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | "os" 22 | ) 23 | 24 | func main() { 25 | 26 | f, err := os.Open("test.file") 27 | if err != nil { 28 | panic(err) 29 | } 30 | fi, err := f.Stat() 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | fmt.Printf("File name: %v\n", fi.Name()) 36 | fmt.Printf("Is Directory: %t\n", fi.IsDir()) 37 | fmt.Printf("Size: %d\n", fi.Size()) 38 | fmt.Printf("Mode: %v\n", fi.Mode()) 39 | 40 | } 41 | 42 | 43 | ``` 44 | output: 45 | ``` 46 | sangam:golang-daily sangam$ go run fileinfo.go 47 | File name: test.file 48 | Is Directory: false 49 | Size: 18 50 | Mode: -rw-r--r-- 51 | sangam:golang-daily sangam$ 52 | 53 | ``` 54 | ## How it works... 55 | 56 | The os.File type provides access to the FileInfo type via the Stat method. 57 | The FileInfo struct contains all the basic information about the file. 58 | -------------------------------------------------------------------------------- /docs/_documentation/2.1-loop-init-condition-post.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Loop Init, Condition, Post 4 | weight: 11 5 | doctype: Go101 6 | --- 7 | 8 | 9 | As you're learning Go, a good quick reference is [Go by Example](https://gobyexample.com/). 10 | 11 | For example, here's what it has for [for](https://gobyexample.com/for) 12 | 13 | ```go 14 | package main 15 | 16 | import "fmt" 17 | 18 | func main() { 19 | 20 | i := 1 21 | for i <= 3 { 22 | fmt.Println(i) 23 | i = i + 1 24 | } 25 | 26 | for j := 7; j <= 9; j++ { 27 | fmt.Println(j) 28 | } 29 | 30 | for n := 0; n <= 5; n++ { 31 | if n%2 == 0 { 32 | continue 33 | } 34 | fmt.Println(n) 35 | } 36 | } 37 | ``` 38 | 39 | **Note**: There is no `while` in Go. 40 | 41 | The way to create a loop is to start with `for`, and the first thing you put in is an init statement, a condition, and a post, e.g. 42 | 43 | ```go 44 | for init; condition; post { 45 | } 46 | ``` 47 | 48 | Let's try a loop with an init statment initializing a variable `i` with the value `0`, the condition that `i` is less than or equal to `100`, and the post of incrementing `i` by `1` (`i++`). Remember, we can always check the Go spec. In this case, [IncDec statements](https://golang.org/ref/spec#IncDec_statements) has information explaining the `++` and `--` operators. 49 | 50 | ```go 51 | package main 52 | 53 | import ( 54 | "fmt" 55 | ) 56 | 57 | func main() { 58 | // for init; condition; post {} 59 | for i := 0; i <= 100; i++ { 60 | fmt.Println(i) 61 | } 62 | } 63 | ``` 64 | 65 | [playground](https://play.golang.org/p/KGaFt09VB0) 66 | -------------------------------------------------------------------------------- /docs/_documentation/1.7-short-variable-declarations.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Short variable declarations 4 | weight: 7 5 | doctype: Go101 6 | --- 7 | 8 | 9 | Inside a function, the := short assignment statement can be used in place of a var declaration with implicit type. 10 | 11 | Outside a function, every statement begins with a keyword (var, func, and so on) and so the := construct is not available. 12 | 13 | 14 | ``` 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | a := 10 21 | b := "golang" 22 | c := 4.17 23 | d := true 24 | e := "Hello" 25 | f := `Do you like my hat?` 26 | g := 'M' 27 | fmt.Printf("%v \n", a) 28 | fmt.Printf("%v \n", b) 29 | fmt.Printf("%v \n", c) 30 | fmt.Printf("%v \n", d) 31 | fmt.Printf("%v \n", e) 32 | fmt.Printf("%v \n", f) 33 | fmt.Printf("%v \n", g) 34 | } 35 | 36 | ``` 37 | 38 | [Run](https://play.golang.org/p/4s_K8I_18ih) 39 | 40 | 41 | `%v` the value in a default format 42 | `%v` will give you the values of variable 43 | 44 | 45 | ```go 46 | package main 47 | 48 | import "fmt" 49 | 50 | func main() { 51 | 52 | a := 10 53 | b := "golang" 54 | c := 4.17 55 | d := true 56 | e := "Hello" 57 | f := `Do you like my hat?` 58 | g := 'M' 59 | 60 | fmt.Printf("%T \n", a) 61 | fmt.Printf("%T \n", b) 62 | fmt.Printf("%T \n", c) 63 | fmt.Printf("%T \n", d) 64 | fmt.Printf("%T \n", e) 65 | fmt.Printf("%T \n", f) 66 | fmt.Printf("%T \n", g) 67 | } 68 | ``` 69 | [RUN](https://play.golang.org/p/9jf7xEZL-s8)
70 | 71 | `%T` a Go-syntax representation of the type of the value 72 | in this above go program %T provide you the type of variable 73 | -------------------------------------------------------------------------------- /docs/_documentation/9.1-writing-multiple-writers-at-once.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: writing to multiple writers at once 4 | weight: 81 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - When you need to write the same output into more than one target, there is a helping hand available in the built-in package. 10 | This recipe shows how to implement writing simultaneously into multiple targets. 11 | 12 | # Create the multiwr.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import "io" 17 | import "bytes" 18 | import "os" 19 | import "fmt" 20 | 21 | func main() { 22 | 23 | buf := bytes.NewBuffer([]byte{}) 24 | f, err := os.OpenFile("sample.txt", os.O_CREATE|os.O_RDWR, 25 | os.ModePerm) 26 | if err != nil { 27 | panic(err) 28 | } 29 | wr := io.MultiWriter(buf, f) 30 | _, err = io.WriteString(wr, "Hello, Go is awesome!") 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | fmt.Println("Content of buffer: " + buf.String()) 36 | } 37 | 38 | 39 | 40 | ``` 41 | output: 42 | ``` 43 | sangam:golang-daily sangam$ go run multiwr.go 44 | Content of buffer: Hello, Go is awesome! 45 | sangam:golang-daily sangam$ 46 | 47 | ``` 48 | ## Check the content of the created file: sample.txt 49 | ``` 50 | Hello, Go is awesome! 51 | ``` 52 | ## How it works... 53 | 54 | - The io package contains the MultiWriter function with variadic parameters of Writers. 55 | - When the Write method on the Writer is called, then the data is written to all underlying Writers. 56 | -------------------------------------------------------------------------------- /docs/_documentation/4.6-variadic-function.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: variadic function 4 | weight: 36 5 | doctype: Go101 6 | --- 7 | 8 | # What is variadic function? 9 | 10 | variadic function is simple function which accepts many arguments.and those arguments store parameter as slicen type. 11 | 12 | ``` 13 | func f(elem ...Type) 14 | ``` 15 | 16 | A typical syntax of a variadic function looks like above. ... operator called as pack operator instructs go to store all arguments of type Type in elem parameter. With this syntax, go creates elem variable of the type []Type which is a slice. 17 | Hence, all arguments passed to this function is stored in a elem slice. 18 | 19 | 20 | ``` 21 | package main 22 | 23 | import "fmt" 24 | 25 | func getMultiples(factor int, args ...int) []int { 26 | multiples := make([]int, len(args)) 27 | 28 | for index, val := range args { 29 | multiples[index] = val * factor 30 | } 31 | 32 | return multiples 33 | } 34 | 35 | func main() { 36 | s := []int{10, 20, 30} 37 | 38 | // get multiples of 2, pass parameters from slice using `unpack` operator 39 | mult1 := getMultiples(2, s...) 40 | 41 | // get multiples of 3 42 | mult2 := getMultiples(3, 1, 2, 3, 4) 43 | 44 | fmt.Println(mult1) 45 | fmt.Println(mult2) 46 | } 47 | 48 | ``` 49 | try out -[Go Playground](https://play.golang.org/p/BgU6H9orhrn) 50 | 51 | in the above program `func getMultiples(factor int, args ...int) []int {` this is variadic fuction with two types 52 | variable in which one is factor with data type int and another is ( unpack operator ) which means n number of parameters. 53 | 54 | `mult1` and `mult2` is two shore declartion variable which execute `getmultiples` variadic function and first argument is factor 55 | 56 | -------------------------------------------------------------------------------- /docs/_documentation/8.2-taking-logarithms.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: taking logarithms 4 | weight: 72 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - Logarithms are used in scientific applications as well as in data visualizations and measurements. 10 | The built-in math package contains the commonly used bases of the logarithm. Using these, you are able to get all bases. 11 | 12 | ## Create the log.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "math" 19 | ) 20 | 21 | func main() { 22 | 23 | ln := math.Log(math.E) 24 | fmt.Printf("Ln(E) = %.4f\n", ln) 25 | 26 | log10 := math.Log10(-100) 27 | fmt.Printf("Log10(10) = %.4f\n", log10) 28 | 29 | log2 := math.Log2(2) 30 | fmt.Printf("Log2(2) = %.4f\n", log2) 31 | 32 | log_3_6 := Log(3, 6) 33 | fmt.Printf("Log3(6) = %.4f\n", log_3_6) 34 | 35 | } 36 | 37 | // Log computes the logarithm of 38 | // base > 1 and x greater 0 39 | func Log(base, x float64) float64 { 40 | return math.Log(x) / math.Log(base) 41 | } 42 | 43 | 44 | ``` 45 | output: 46 | ``` 47 | sangam:golang-daily sangam$ go run log.go 48 | Ln(E) = 1.0000 49 | Log10(10) = NaN 50 | Log2(2) = 1.0000 51 | Log3(6) = 1.6309 52 | ``` 53 | ## How it works... 54 | - The standard package, math, contains functions for all commonly used logarithms, 55 | and so you can easily get binary, decimal, and natural logarithms. See the Log function which counts any 56 | logarithm of y with base x through the helper-defined formula: 57 | ![img](https://raw.githubusercontent.com/collabnix/gopherlabs/master/img/log.jpg) 58 | 59 | - The internal implementation of the logarithm in standard lib is naturally based on approximation. 60 | This function can be seen in the $GOROOT/src/math/log.go file. 61 | 62 | -------------------------------------------------------------------------------- /docs/_documentation/10.4-filtering-file-listings.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Filtering file listings 4 | weight: 94 5 | doctype: Go101 6 | --- 7 | 8 | - you how to list the file paths, matching a given pattern. The list does not have to be from the same folder. 9 | 10 | ## Create the filter.go file with the following content: 11 | ``` 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "os" 18 | "path/filepath" 19 | ) 20 | 21 | func main() { 22 | 23 | for i := 1; i <= 6; i++ { 24 | _, err := os.Create(fmt.Sprintf("./test.file%d", i)) 25 | if err != nil { 26 | fmt.Println(err) 27 | } 28 | } 29 | 30 | m, err := filepath.Glob("./test.file[1-3]") 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | for _, val := range m { 36 | fmt.Println(val) 37 | } 38 | 39 | // Cleanup 40 | for i := 1; i <= 6; i++ { 41 | err := os.Remove(fmt.Sprintf("./test.file%d", i)) 42 | if err != nil { 43 | fmt.Println(err) 44 | } 45 | } 46 | } 47 | 48 | 49 | ``` 50 | output: 51 | ``` 52 | sangam:golang-daily sangam$ go run filter.go 53 | test.file1 54 | test.file2 55 | test.file3 56 | sangam:golang-daily sangam$ 57 | ``` 58 | 59 | ## How it works... 60 | 61 | - To get the filtered file list which corresponds to the given pattern, the Glob function from the filepath package can be used. For the pattern syntax, see the documentation of the filepath.Match function (https://golang.org/pkg/path/filepath/#Match). 62 | 63 | - Note that the returning result of filepath.Glob is the slice of strings with matching paths. 64 | -------------------------------------------------------------------------------- /docs/_documentation/2.2-loop-nested-loops.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Loop - Nested Loops 4 | weight: 12 5 | doctype: Go101 6 | --- 7 | 8 | Now, we're going to see a loop within a loop. There will be an _outer_ loop, and it will run however many times it runs, and inside that _outer_ loop will be an _inner_ loop, which will loop as many times as it loops _each time_ the outer loop loops. 9 | 10 | For example, if the outer loop loops 10 times, and the inner loop loops 5 times, the outer loop will loop once, then within that loop, the inner loop will loop 5 times, then the outer loop will loop its second time, and within that loop, the inner loop will loop 5 times, and so on... 11 | 12 | This is called nesting a loop; a loop within another loop. We can continue to nest loops within loops, but for now we'll stick with just one lopp within a loop. 13 | 14 | Let's give it a try. 15 | 16 | ```go 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | ) 22 | 23 | func main() { 24 | for i := 0; i <= 10; i++ { 25 | for j := 0; j < 3; j++ { 26 | fmt.Printf("Outer loop: %d\tInner loop: %d\n", i, j) 27 | } 28 | } 29 | } 30 | ``` 31 | 32 | [playground](https://play.golang.org/p/o0YaoYYAC8) 33 | 34 | Here we can see for each iteration of the outer loop, the inner loop prints out `0`, `1`, and `2`. 35 | 36 | Let's break this up and print `i` on the outer loop, and `j` on the inner loop. Try to do this with the output of the inner loop indented 37 | 38 | ```go 39 | package main 40 | 41 | import ( 42 | "fmt" 43 | ) 44 | 45 | func main() { 46 | for i := 0; i <= 10; i++ { 47 | fmt.Printf("Outer loop: %d\n", i) 48 | for j := 0; j < 3; j++ { 49 | fmt.Printf("\tInner loop: %d\n", j) 50 | } 51 | } 52 | } 53 | 54 | ``` 55 | [playground](https://play.golang.org/p/0Gd_NAXNyB) 56 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | # Welcome to Jekyll! 2 | # 3 | # This config file is meant for settings that affect your whole blog, values 4 | # which you are expected to set up once and rarely edit after that. If you find 5 | # yourself editing this file very often, consider using Jekyll's data files 6 | # feature for the data you need to update frequently. 7 | # 8 | # For technical reasons, this file is *NOT* reloaded automatically when you use 9 | # 'bundle exec jekyll serve'. If you change this file, please restart the server process. 10 | 11 | # Site settings 12 | # These are used to personalize your new site. If you look in the HTML files, 13 | # you will see them accessed via {{ site.title }}, {{ site.email }}, and so on. 14 | # You can create any custom variable you would like, and they will be accessible 15 | # in the templates via {{ site.myvariable }}. 16 | title: Gopherlabs - The Ultimate Workshop for Golang Developers 17 | email: your-email@example.com 18 | description: > # this means to ignore newlines until "baseurl:" 19 | Golang Workshop for beginners and experts 20 | baseurl: "/" # the subpath of your site, e.g. /blog 21 | url: "http://gopherlabs.kubedaily.com" # the base hostname & protocol for your site, e.g. http://example.com 22 | 23 | # Build settings 24 | markdown: kramdown 25 | theme: minima 26 | plugins: 27 | - jekyll-feed 28 | 29 | # Exclude from processing. 30 | # The following items will not be processed, by default. Create a custom list 31 | # to override the default setting. 32 | # exclude: 33 | # - Gemfile 34 | # - Gemfile.lock 35 | # - node_modules 36 | # - vendor/bundle/ 37 | # - vendor/cache/ 38 | # - vendor/gems/ 39 | # - vendor/ruby/ 40 | 41 | collections: 42 | documentation: 43 | output: true 44 | layout: documentation 45 | friends: 46 | output: false 47 | 48 | twitter_username: kubedaily 49 | -------------------------------------------------------------------------------- /docs/_documentation/10.2-Changing-file-permissions.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Changing file permissions 4 | weight: 92 5 | doctype: Go101 6 | --- 7 | 8 | 9 | how file permissions can be changed programmatically. 10 | 11 | ## Create the filechmod.go file with the following content: 12 | ``` 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "os" 18 | ) 19 | 20 | func main() { 21 | 22 | f, err := os.Create("test.file") 23 | if err != nil { 24 | panic(err) 25 | } 26 | defer f.Close() 27 | 28 | // Obtain current permissions 29 | fi, err := f.Stat() 30 | if err != nil { 31 | panic(err) 32 | } 33 | fmt.Printf("File permissions %v\n", fi.Mode()) 34 | 35 | // Change permissions 36 | err = f.Chmod(0777) 37 | if err != nil { 38 | panic(err) 39 | } 40 | fi, err = f.Stat() 41 | if err != nil { 42 | panic(err) 43 | } 44 | fmt.Printf("File permissions %v\n", fi.Mode()) 45 | 46 | } 47 | 48 | ``` 49 | output: 50 | 51 | ``` 52 | sangam:golang-daily sangam$ go run filechmod.go 53 | File permissions -rw-r--r-- 54 | File permissions -rwxrwxrwx 55 | sangam:golang-daily sangam$ 56 | 57 | ``` 58 | ## How it works... 59 | 60 | - The Chmod method of the File type in the os package can be used to change file permissions. The preceding example just creates the file and changes the permissions to 0777. 61 | 62 | - Just note that the fi.Mode() is called twice because it extracts the permissions (os.FileMode) for the current state of the file. 63 | 64 | - The shortest way to change the permissions is by using the os.Chmod function, which does the same, but you do not need to obtain the File type in the code. 65 | -------------------------------------------------------------------------------- /docs/_documentation/6.5-aligning-text-with-tabwriter.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Aligning text with tabwriter 4 | weight: 55 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - In certain cases, the output (usually data output) is done via tabbed text, which is formatted in well-arranged cells. This format could be achieved with the text/tabwriter package. The package provides the Writer filter, which transforms the text with the tab characters into properly formatted output text. 10 | 11 | ## Create the main.go file with the following content: 12 | 13 | ``` 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "os" 19 | "text/tabwriter" 20 | ) 21 | 22 | func main() { 23 | 24 | w := tabwriter.NewWriter(os.Stdout, 15, 0, 1, ' ', 25 | tabwriter.AlignRight) 26 | fmt.Fprintln(w, "username\tfirstname\tlastname\t") 27 | fmt.Fprintln(w, "sohlich\tRadomir\tSohlich\t") 28 | fmt.Fprintln(w, "novak\tJohn\tSmith\t") 29 | w.Flush() 30 | 31 | } 32 | 33 | 34 | 35 | ``` 36 | 37 | 38 | output: 39 | 40 | ``` 41 | sangam:golang-daily sangam$ go run main.go 42 | username firstname lastname 43 | sohlich Radomir Sohlich 44 | novak John Smith 45 | sangam:golang-daily sangam$ 46 | 47 | 48 | ``` 49 | 50 | ## How it works... 51 | 52 | - The NewWriter function call creates the Writer filter with configured parameters. All data written by this Writer is formatted according to the parameters. os.Stdout is used here for demonstration purposes. 53 | 54 | - The text/tabwriter package also provides a few more configuration options, such as the flag parameter. The most useful is tabwriter.AlignRight, which configures the writer to align the content to the right in each column. 55 | -------------------------------------------------------------------------------- /docs/_documentation/2.4-break-continue.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Loop - Break & Continue 4 | weight: 14 5 | doctype: Go101 6 | --- 7 | 8 | According to the Go Specification, `break` and `continue` are [keywords](https://golang.org/ref/spec#Keywords). 9 | 10 | ``` 11 | break default func interface select 12 | case defer go map struct 13 | chan else goto package switch 14 | const fallthrough if range type 15 | continue for import return var 16 | ``` 17 | 18 | `break` will _break out_ of a loop. It's a way to stop looping. 19 | 20 | `continue` will move on to the next iteration. Let's see it in action. 21 | 22 | *Aside* dividing and remainders 23 | 24 | ```go 25 | package main 26 | 27 | import ( 28 | "fmt" 29 | ) 30 | 31 | func main() { 32 | x := 83 / 40 33 | y := 83 % 40 34 | fmt.Println(x, y) 35 | } 36 | 37 | ``` 38 | 39 | [playground](https://play.golang.org/p/_BNQa7c8d8) 40 | 41 | *note*: `%` (modulo) is an [Arithmetic operator](https://golang.org/ref/spec#Arithmetic_operators) that gives the _remainder_. 42 | 43 | Back to `continue` in action. Let's say we want to iterate from `1` through to `100`, and print out only the even numbers, we can use `for`, `if`, and `continue` 44 | 45 | ```go 46 | package main 47 | 48 | import ( 49 | "fmt" 50 | ) 51 | 52 | func main() { 53 | x := 0 54 | for { 55 | x++ 56 | 57 | // break out of the loop (stop the loop) 58 | // if x is greater than 100 59 | if x > 100 { 60 | break 61 | } 62 | 63 | // continue to the next iteration if the 64 | // remainder of x divided by 2 is not 0 65 | // (if x is not even) 66 | if x%2 != 0 { 67 | continue 68 | } 69 | 70 | fmt.Println(x) 71 | 72 | } 73 | fmt.Println("done.") 74 | } 75 | ``` 76 | 77 | [playground](https://play.golang.org/p/aVd3OVLtop) 78 | -------------------------------------------------------------------------------- /docs/_documentation/3.9-creating-own-type.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Creating Your Own Type 4 | weight: 29 5 | doctype: Go101 6 | --- 7 | 8 | Some people say, "Go is all about 'type.'" Go is a static programming language, and at the heart of a static programming language is that once you declare that a variable is of a certain type, that's static; it doesn't change. 9 | 10 | 11 | Let's try creating our own type in the [Go playground](https://play.golang.org/p/9Gv-WWADVj). 12 | 13 | ```go 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | ) 19 | 20 | var a int 21 | type hotdog int 22 | var b hotdog 23 | 24 | func main() { 25 | a = 42 26 | b = 43 27 | fmt.Println(a) 28 | fmt.Printf("%T\n", a) 29 | fmt.Println(b) 30 | fmt.Printf("%T\n", b) 31 | } 32 | ``` 33 | This returns: 34 | ``` 35 | 42 36 | int 37 | 43 38 | main.hotdog 39 | ``` 40 | So we can see that the value of `a` is `42` and it is of type `int`, and the value of `b` is 43 and it is of type `hotdog` from the package `main`. 41 | 42 | We created a type `hotdog` with the line `type hotdog int`, we _declared_ a variable of type `hotdog` with `var b hotdog`, we _assigned a value_ to the variable with `b = 43` 43 | 44 | Go is a static programming language, so if I want to now do something like assign the value of `b` to `a`, with `a = b` the compiler will complain. We cannot take the value of something of type `hotdog` and assign it to something that is of type `int`. 45 | 46 | ```go 47 | package main 48 | 49 | import ( 50 | "fmt" 51 | ) 52 | 53 | var a int 54 | type hotdog int 55 | var b hotdog 56 | 57 | func main() { 58 | a = 42 59 | b = a // we cannot assign the value of a type int to a type hotdog 60 | fmt.Println(a) 61 | fmt.Printf("%T\n", a) 62 | fmt.Println(b) 63 | fmt.Printf("%T\n", b) 64 | } 65 | ``` 66 | returns 67 | `tmp/sandbox982815840/main.go:13: cannot use a (type int) as type hotdog in assignment` 68 | 69 | -------------------------------------------------------------------------------- /docs/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | addressable (2.8.0) 5 | public_suffix (>= 2.0.2, < 5.0) 6 | colorator (1.1.0) 7 | concurrent-ruby (1.0.5) 8 | em-websocket (0.5.1) 9 | eventmachine (>= 0.12.9) 10 | http_parser.rb (~> 0.6.0) 11 | eventmachine (1.2.7) 12 | ffi (1.9.25) 13 | forwardable-extended (2.6.0) 14 | http_parser.rb (0.6.0) 15 | i18n (0.9.5) 16 | concurrent-ruby (~> 1.0) 17 | jekyll (3.8.4) 18 | addressable (~> 2.4) 19 | colorator (~> 1.0) 20 | em-websocket (~> 0.5) 21 | i18n (~> 0.7) 22 | jekyll-sass-converter (~> 1.0) 23 | jekyll-watch (~> 2.0) 24 | kramdown (~> 2.3.1) 25 | liquid (~> 4.0) 26 | mercenary (~> 0.3.3) 27 | pathutil (~> 0.9) 28 | rouge (>= 1.7, < 4) 29 | safe_yaml (~> 1.0) 30 | jekyll-feed (0.9.2) 31 | jekyll (~> 3.3) 32 | jekyll-sass-converter (1.5.2) 33 | sass (~> 3.4) 34 | jekyll-watch (2.1.2) 35 | listen (~> 3.0) 36 | kramdown (2.3.1) 37 | rexml 38 | liquid (4.0.1) 39 | listen (3.1.5) 40 | rb-fsevent (~> 0.9, >= 0.9.4) 41 | rb-inotify (~> 0.9, >= 0.9.7) 42 | ruby_dep (~> 1.2) 43 | mercenary (0.3.6) 44 | minima (2.1.1) 45 | jekyll (~> 3.3) 46 | pathutil (0.16.2) 47 | forwardable-extended (~> 2.6) 48 | public_suffix (4.0.6) 49 | rb-fsevent (0.10.3) 50 | rb-inotify (0.9.10) 51 | ffi (>= 0.5.0, < 2) 52 | rexml (3.4.2) 53 | rouge (3.3.0) 54 | ruby_dep (1.5.0) 55 | safe_yaml (1.0.4) 56 | sass (3.6.0) 57 | sass-listen (~> 4.0.0) 58 | sass-listen (4.0.0) 59 | rb-fsevent (~> 0.9, >= 0.9.4) 60 | rb-inotify (~> 0.9, >= 0.9.7) 61 | 62 | PLATFORMS 63 | ruby 64 | 65 | DEPENDENCIES 66 | jekyll (~> 3.8.4) 67 | jekyll-feed (~> 0.6) 68 | minima (~> 2.0) 69 | tzinfo-data 70 | 71 | BUNDLED WITH 72 | 2.2.27 73 | -------------------------------------------------------------------------------- /docs/present/lib/fonts/overpass2/overpass2.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Overpass 2'; 3 | font-style: normal; 4 | font-weight: 700; 5 | src: url('overpass2-bold.woff') format('woff'), 6 | url('overpass2-bold.ttf') format('truetype'); 7 | } 8 | 9 | @font-face { 10 | font-family: 'Overpass 2'; 11 | font-style: italic; 12 | font-weight: 700; 13 | src: url('overpass2-bolditalic.woff') format('woff'), 14 | url('overpass2-bolditalic.ttf') format('truetype'); 15 | } 16 | 17 | @font-face { 18 | font-family: 'Overpass 2'; 19 | font-style: normal; 20 | font-weight: 500; 21 | src: url('overpass2-regular.woff') format('woff'), 22 | url('overpass2-regular.ttf') format('truetype'); 23 | } 24 | 25 | @font-face { 26 | font-family: 'Overpass 2'; 27 | font-style: italic; 28 | font-weight: 500; 29 | src: url('overpass2-italic.woff') format('woff'), 30 | url('overpass2-italic.ttf') format('truetype'); 31 | } 32 | 33 | @font-face { 34 | font-family: 'Overpass 2'; 35 | font-style: normal; 36 | font-weight: normal; 37 | src: url('overpass2-light.woff') format('woff'), 38 | url('overpass2-light.ttf') format('truetype'); 39 | } 40 | 41 | @font-face { 42 | font-family: 'Overpass 2'; 43 | font-style: italic; 44 | font-weight: normal; 45 | src: url('overpass2-lightitalic.woff') format('woff'), 46 | url('overpass2-lightitalic.ttf') format('truetype'); 47 | } 48 | 49 | @font-face { 50 | font-family: 'Overpass 2'; 51 | font-style: normal; 52 | font-weight: 300; 53 | src: url('overpass2-extralight.woff') format('woff'), 54 | url('overpass2-extralight.ttf') format('truetype'); 55 | } 56 | 57 | @font-face { 58 | font-family: 'Overpass 2'; 59 | font-style: italic; 60 | font-weight: 300; 61 | src: url('overpass2-extralightitalic.woff') format('woff'), 62 | url('overpass2-extralightitalic.ttf') format('truetype'); 63 | } -------------------------------------------------------------------------------- /docs/_documentation/9.2-piping-between-writer-reader.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: piping between writer and reader 4 | weight: 82 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - The pipes between processes are the easy way to use the output of the first process as the input of other processes. 10 | The same concept could be done in Go, for example, to pipe data from one socket to another socket, to create the tunneled connection. 11 | This recipe will show you how to create the pipe with use of the Go built-in library. 12 | 13 | ## Create the pipe.go file with the following content: 14 | ``` 15 | package main 16 | 17 | import ( 18 | "io" 19 | "log" 20 | "os" 21 | "os/exec" 22 | ) 23 | 24 | func main() { 25 | pReader, pWriter := io.Pipe() 26 | 27 | cmd := exec.Command("echo", "Hello Go!\nThis is example") 28 | cmd.Stdout = pWriter 29 | 30 | go func() { 31 | defer pReader.Close() 32 | if _, err := io.Copy(os.Stdout, pReader); err != nil { 33 | log.Fatal(err) 34 | } 35 | }() 36 | 37 | if err := cmd.Run(); err != nil { 38 | log.Fatal(err) 39 | } 40 | 41 | } 42 | 43 | ``` 44 | output: 45 | ``` 46 | sangam:golang-daily sangam$ go run pipe.go 47 | Hello Go! 48 | This is example 49 | sangam:golang-daily sangam$ 50 | 51 | ``` 52 | ## How it works... 53 | 54 | - The io.Pipe function creates the in-memory pipe and returns both ends of the pipe, the PipeReader on one side and PipeWriter on the other side. Each Write to PipeWriter is blocked until it is consumed by Read on the other end. 55 | 56 | - The example shows the piping output from the executed command to the standard output of the parent program. By assigning the pWriter to cmd.Stdout, the standard output of the child process is written to the pipe, and the io.Copy in goroutine consumes the written data, by copying the data to os.Stdout. 57 | -------------------------------------------------------------------------------- /docs/_documentation/5.4-getting-the-current-process-pid.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Getting the current process PID 4 | weight: 44 5 | doctype: Go101 6 | --- 7 | 8 | 9 | Getting to know the PID of the running process is useful. The PID could be used by OS utilities to find out the information about the process itself. It is also valuable to know the PID in case of process failure, so you can trace the process behavior across the system in system logs, such as /var/log/messages, /var/log/syslog. 10 | 11 | This program shows you how to use the os package to obtain a PID of the executed program, and use it with the operating system utility to obtain some more information. 12 | 13 | ``` 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "os" 19 | "os/exec" 20 | "strconv" 21 | ) 22 | 23 | func main() { 24 | 25 | pid := os.Getpid() 26 | fmt.Printf("Process PID: %d \n", pid) 27 | 28 | prc := exec.Command("ps", "-p", strconv.Itoa(pid), "-v") 29 | out, err := prc.Output() 30 | if err != nil { 31 | panic(err) 32 | } 33 | 34 | fmt.Println(string(out)) 35 | } 36 | ``` 37 | 38 | output: 39 | 40 | ``` 41 | Biradars-MacBook-Air-4:golang-daily sangam$ go run main.go 42 | Process PID: 48094 43 | PID STAT TIME SL RE PAGEIN VSZ RSS LIM TSIZ %CPU %MEM COMMAND 44 | 48094 S+ 0:00.01 0 0 0 4373552 2072 - 0 0.0 0.0 /var/folders/mg/_355pdvd741cz0z99ys9s66h0000gn/T/go-build581430461/b001/exe/main 45 | 46 | 47 | ``` 48 | 49 | ## How it works… 50 | 51 | - The function Getpid from the os package returns the PID of a process. The sample code shows how to get more information on the process from the operating system utility ps. 52 | 53 | - It could be useful to print the PID at the start of the application, so at the time of the crash, the cause could also be investigated by the retrieved PID. 54 | -------------------------------------------------------------------------------- /docs/_documentation/9.8-creating-temporary-files.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: creating temporary files 4 | weight: 88 5 | doctype: Go101 6 | --- 7 | 8 | - Temporary files are commonly used while running test cases or if your application needs to have a place to store short-term content such as user data uploads and currently processed data. 9 | This recipe will present the easiest way to create such a file or directory. 10 | 11 | ## Create the tempfile.go file with the following content: 12 | ``` 13 | package main 14 | 15 | import "io/ioutil" 16 | import "os" 17 | import "fmt" 18 | 19 | func main() { 20 | tFile, err := ioutil.TempFile("", "gopherlabs") 21 | if err != nil { 22 | panic(err) 23 | } 24 | // The called is responsible for handling 25 | // the clean up. 26 | defer os.Remove(tFile.Name()) 27 | 28 | fmt.Println(tFile.Name()) 29 | 30 | // TempDir returns 31 | // the path in string. 32 | tDir, err := ioutil.TempDir("", "gopherlabs") 33 | if err != nil { 34 | panic(err) 35 | } 36 | defer os.Remove(tDir) 37 | fmt.Println(tDir) 38 | 39 | } 40 | 41 | 42 | ``` 43 | output: 44 | ``` 45 | sangam:golang-daily sangam$ go run tempfile.go 46 | /var/folders/mg/_355pdvd741cz0z99ys9s66h0000gn/T/gopherlabs622911386 47 | /var/folders/mg/_355pdvd741cz0z99ys9s66h0000gn/T/gopherlabs447325745 48 | sangam:golang-daily sangam$ 49 | ``` 50 | ## How it works... 51 | 52 | - The ioutil package contains the functions TempFile and TempDir. The TempFile function consumes the directory and the file prefix. The os.File with the underlying temporary file is returned. Note that the caller is responsible for cleaning out the file. The previous example uses the os.Remove function to do that. 53 | 54 | - The TempDir function works the same way. The difference is that the string with the path to the directory is returned. 55 | -------------------------------------------------------------------------------- /docs/_documentation/7.2-converting-strings-to-numbers.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: converting strings to numbers 4 | weight: 62 5 | doctype: Go101 6 | --- 7 | 8 | Create the main.go file with the following content: 9 | 10 | ``` 11 | package main 12 | 13 | import ( 14 | "fmt" 15 | "strconv" 16 | ) 17 | 18 | const bin = "00001" 19 | const hex = "2f" 20 | const intString = "12" 21 | const floatString = "12.3" 22 | 23 | func main() { 24 | 25 | // Decimals 26 | res, err := strconv.Atoi(intString) 27 | if err != nil { 28 | panic(err) 29 | } 30 | fmt.Printf("Parsed integer: %d\n", res) 31 | 32 | // Parsing hexadecimals 33 | res64, err := strconv.ParseInt(hex, 16, 32) 34 | if err != nil { 35 | panic(err) 36 | } 37 | fmt.Printf("Parsed hexadecima: %d\n", res64) 38 | 39 | // Parsing binary values 40 | resBin, err := strconv.ParseInt(bin, 2, 32) 41 | if err != nil { 42 | panic(err) 43 | } 44 | fmt.Printf("Parsed bin: %d\n", resBin) 45 | 46 | // Parsing floating-points 47 | resFloat, err := strconv.ParseFloat(floatString, 32) 48 | if err != nil { 49 | panic(err) 50 | } 51 | fmt.Printf("Parsed float: %.5f\n", resFloat) 52 | 53 | } 54 | 55 | 56 | 57 | 58 | ``` 59 | 60 | output: 61 | ``` 62 | sangam:golang-daily sangam$ go run main.go 63 | Parsed integer: 12 64 | Parsed hexadecima: 47 65 | Parsed bin: 1 66 | Parsed float: 12.30000 67 | sangam:golang-daily sangam$ 68 | 69 | ``` 70 | 71 | ## How it works... 72 | 73 | - The dominant function in the preceding sample code is the ParseInt function of package strconv. The function is called with three arguments: input, the base of input, and bit size. The base determines how the number is parsed. Note that the hexadecimal has the base (second argument) of 16 and the binary has the base of 2. The function Atoi of package strconv is, in fact, the ParseInt function with the base of 10. 74 | 75 | - The ParseFloat function converts the string to a floating-point number. The second argument is the precision of bitSize. bitSize = 64 will result in float64. bitSize = 32 will result in float64, but it is convertible to float32 without changing its value. 76 | -------------------------------------------------------------------------------- /docs/_documentation/9.0-reading-writing-binary-data.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: reading and writing binary data 4 | weight: 80 5 | doctype: Go101 6 | --- 7 | 8 | 9 | 10 | - describes how to write and read any type in the binary form. 11 | 12 | ## Create the rwbinary.go file with the following content: 13 | 14 | ``` 15 | package main 16 | 17 | import ( 18 | "bytes" 19 | "encoding/binary" 20 | "fmt" 21 | ) 22 | 23 | func main() { 24 | // Writing binary values 25 | buf := bytes.NewBuffer([]byte{}) 26 | if err := binary.Write(buf, binary.BigEndian, 1.004); 27 | err != nil { 28 | panic(err) 29 | } 30 | if err := binary.Write(buf, binary.BigEndian, 31 | []byte("Hello")); err != nil { 32 | panic(err) 33 | } 34 | 35 | // Reading the written values 36 | var num float64 37 | if err := binary.Read(buf, binary.BigEndian, &num); 38 | err != nil { 39 | panic(err) 40 | } 41 | fmt.Printf("float64: %.3f\n", num) 42 | greeting := make([]byte, 5) 43 | if err := binary.Read(buf, binary.BigEndian, &greeting); 44 | err != nil { 45 | panic(err) 46 | } 47 | fmt.Printf("string: %s\n", string(greeting)) 48 | } 49 | 50 | ``` 51 | output: 52 | ``` 53 | sangam:golang-daily sangam$ go run rwbinary.go 54 | float64: 1.004 55 | string: Hello 56 | sangam:golang-daily sangam$ 57 | ``` 58 | ## How it works... 59 | 60 | - The binary data could be written with the use of the encoding/binary package. The function Write consumes the Writer where the data should be written, 61 | the byte order (BigEndian/LittleEndian) and finally, the value to be written into Writer. 62 | 63 | - To read the binary data analogically, the Read function could be used. 64 | Note that there is no magic in reading the data from the binary source. You need to be sure what data you are fetching from the Reader. If not, the data could be fetched into any type which fits the size. 65 | -------------------------------------------------------------------------------- /docs/_documentation/6.7-finding-the-substring-in-text-by-the-regex-pattern.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: finding the substring in text by the regex pattern 4 | weight: 57 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - There are always tasks such as validating the input, searching the document for any information, or even cleaning up a given string from unwanted escape characters. For these cases, regular expressions are usually used. 10 | 11 | - The Go standard library contains the regexp package, which covers the operations with regular expressions. 12 | 13 | ## Create the main.go file with the following content: 14 | 15 | ``` 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | "regexp" 21 | ) 22 | 23 | const refString = `[{ \"email\": \"email@example.com\" \"phone\": 555467890}, 24 | { \"email\": \"other@domain.com\" \"phone\": 555467890}]` 25 | 26 | func main() { 27 | 28 | // This pattern is simplified for brevity 29 | emailRegexp := regexp.MustCompile("[a-zA-Z0-9]{1,}@[a-zA-Z0-9]{1,}\\.[a-z]{1,}") 30 | first := emailRegexp.FindString(refString) 31 | fmt.Println("First: ") 32 | fmt.Println(first) 33 | 34 | all := emailRegexp.FindAllString(refString, -1) 35 | fmt.Println("All: ") 36 | for _, val := range all { 37 | fmt.Println(val) 38 | } 39 | 40 | } 41 | 42 | 43 | 44 | ``` 45 | output:- 46 | 47 | ``` 48 | sangam:golang-daily sangam$ go run main.go 49 | First: 50 | email@example.com 51 | All: 52 | email@example.com 53 | other@domain.com 54 | sangam:golang-daily sangam$ 55 | 56 | ``` 57 | 58 | ## How it works... 59 | 60 | - The FindString or FindAllString functions are the simplest ways to find the matching pattern in the given string. The only difference is that the FindString method of Regexp will return only the first occurrence. On the other hand, the FindAllString, as the name suggests, returns a slice of strings with all occurrences. 61 | 62 | - The Regexp type offers a rich set of FindXXX methods. This recipe describes only the String variations that are usually most useful. Note that the preceding code uses the MustCompile function of the regexp package, which panics if the compilation of the regular expression fails. 63 | -------------------------------------------------------------------------------- /docs/_documentation/10.3-Creating-files-and-dir.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Creating files and directories 4 | weight: 93 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - few general ways you can create files and directories in code. 10 | 11 | ## Create the create.go file with the following content: 12 | 13 | ``` 14 | package main 15 | 16 | import ( 17 | "os" 18 | ) 19 | 20 | func main() { 21 | 22 | f, err := os.Create("created.file") 23 | if err != nil { 24 | panic(err) 25 | } 26 | f.Close() 27 | 28 | f, err = os.OpenFile("created.byopen", os.O_CREATE|os.O_APPEND, 29 | os.ModePerm) 30 | if err != nil { 31 | panic(err) 32 | } 33 | f.Close() 34 | 35 | err = os.Mkdir("createdDir", 0777) 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | err = os.MkdirAll("sampleDir/path1/path2", 0777) 41 | if err != nil { 42 | panic(err) 43 | } 44 | 45 | } 46 | 47 | 48 | 49 | ``` 50 | 51 | output: 52 | 53 | ``` 54 | sangam:golang-daily sangam$ create.go 55 | sangam:golang-daily sangam$ tree 56 | . 57 | ├── binary 58 | ├── config.json 59 | ├── content.dat 60 | ├── created.byopen 61 | ├── created.file 62 | ├── createdDir 63 | ├── data.csv 64 | ├── data.xml 65 | ├── data.zip 66 | ├── example.txt 67 | ├── flatfile.txt 68 | ├── main.go 69 | ├── sample.file 70 | ├── sample.txt 71 | ├── sampleDir 72 | │   └── path1 73 | │   └── path2 74 | 75 | 76 | ``` 77 | ## How it works... 78 | 79 | - The previous example represents four ways you can create a file or directory. The os.Create function is the simplest way to create the file. By using this function, you will create the file with permissions such as 0666. 80 | 81 | - If you need to create the file with any other configuration of permissions, then the OpenFile function of the os package is the one to be used. 82 | 83 | - The directories can be created by using the Mkdir function of the os package. This way, a directory with given permissions is created. The second option is to use the MkdirAll function. This function also creates the directory, but if the given path contains non-exiting directories, 84 | then all directories in the path are created (it works the same as the -p option of Unix's mkdir utility). 85 | -------------------------------------------------------------------------------- /docs/_documentation/8.6-opening-a-file-by-name.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: opening a file by name 4 | weight: 76 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - File access is a very common operation used to store or read the data. 10 | This recipe illustrates how to open a file by its name and path, using the standard library. 11 | 12 | ## Create the directory temp and create the file file.txt in it. 13 | 14 | Edit the file.txt file and write This file content into the file. 15 | 16 | ## Create the openfile.go file with the following content: 17 | 18 | ``` 19 | package main 20 | 21 | import ( 22 | "fmt" 23 | "io" 24 | "io/ioutil" 25 | "os" 26 | ) 27 | 28 | func main() { 29 | 30 | f, err := os.Open("temp/file.txt") 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | c, err := ioutil.ReadAll(f) 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | fmt.Printf("### File content ###\n%s\n", string(c)) 41 | f.Close() 42 | 43 | f, err = os.OpenFile("temp/test.txt", os.O_CREATE|os.O_RDWR, 44 | os.ModePerm) 45 | if err != nil { 46 | panic(err) 47 | } 48 | io.WriteString(f, "Test string") 49 | f.Close() 50 | 51 | } 52 | 53 | 54 | ``` 55 | 56 | output: 57 | 58 | ``` 59 | sangam:golang-daily sangam$ go run openfile.go 60 | ### File content ### 61 | This file content 62 | 63 | sangam:golang-daily sangam$ 64 | 65 | ``` 66 | See the output there should also be a new file, test.txt, in the temp folder: 67 | 68 | 69 | ## How it works... 70 | 71 | - The os package offers a simple way of opening the file. The function Open opens the file by the path, just in read-only mode. Another function, OpenFile, is the more powerful one and consumes the path to the file, flags, and permissions. 72 | 73 | - The flag constants are defined in the os package and you can combine them with use of the binary OR operator |. The permissions are set by the os package constants (for example, os.ModePerm ) or by the number notation such as 0777 (permissions: -rwxrwxrwx). 74 | 75 | -------------------------------------------------------------------------------- /docs/_documentation/10.0-writing-the-file-from-multiple-goroutines.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: writing the file from multiple goroutines 4 | weight: 90 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - how to safely write to the file from multiple goroutines. 10 | 11 | Create the syncwrite.go file with the following content: 12 | ``` 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "io" 18 | "os" 19 | "sync" 20 | ) 21 | 22 | type SyncWriter struct { 23 | m sync.Mutex 24 | Writer io.Writer 25 | } 26 | 27 | func (w *SyncWriter) Write(b []byte) (n int, err error) { 28 | w.m.Lock() 29 | defer w.m.Unlock() 30 | return w.Writer.Write(b) 31 | } 32 | 33 | var data = []string{ 34 | "Hello!", 35 | "Ola!", 36 | "Ahoj!", 37 | } 38 | 39 | func main() { 40 | 41 | f, err := os.Create("sample.file") 42 | if err != nil { 43 | panic(err) 44 | } 45 | 46 | wr := &SyncWriter{sync.Mutex{}, f} 47 | wg := sync.WaitGroup{} 48 | for _, val := range data { 49 | wg.Add(1) 50 | go func(greetings string) { 51 | fmt.Fprintln(wr, greetings) 52 | wg.Done() 53 | }(val) 54 | } 55 | 56 | wg.Wait() 57 | } 58 | 59 | 60 | ``` 61 | 62 | ``` 63 | sangam:golang-daily sangam$ go run syncwrite.go 64 | sangam:golang-daily sangam$ cat sample.file 65 | Ahoj! 66 | Hello! 67 | Ola! 68 | sangam:golang-daily sangam$ 69 | 70 | ``` 71 | 72 | ## How it works... 73 | 74 | - Writing concurrently to a file is a problem that can end up with inconsistent file content. It is better to synchronize the writing to the file by using Mutex or any other synchronization primitive. This way, you ensure that only one goroutine at a time will be able to write to the file. 75 | 76 | - The preceding code creates a Writer with Mutex, which embeds the Writer (os.File, in this case), and for each Write call, internally locks the Mutex to provide exclusivity. After the write operation is complete, the Mutex primitive is unlocked naturally. 77 | -------------------------------------------------------------------------------- /docs/_documentation/8.0-operating-complex-numbers.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: operating complex numbers 4 | weight: 70 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - Complex numbers are usually used for scientific applications and calculations. Go implements complex numbers as the primitive type. 10 | - The specific operations on complex numbers are part of the math/cmplx package. 11 | 12 | ## Create the complex.go file with the following content: 13 | 14 | ``` 15 | 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | "math/cmplx" 21 | ) 22 | 23 | func main() { 24 | 25 | // complex numbers are 26 | // defined as real and imaginary 27 | // part defined by float64 28 | a := complex(2, 3) 29 | 30 | fmt.Printf("Real part: %f \n", real(a)) 31 | fmt.Printf("Complex part: %f \n", imag(a)) 32 | 33 | b := complex(6, 4) 34 | 35 | // All common 36 | // operators are useful 37 | c := a - b 38 | fmt.Printf("Difference : %v\n", c) 39 | c = a + b 40 | fmt.Printf("Sum : %v\n", c) 41 | c = a * b 42 | fmt.Printf("Product : %v\n", c) 43 | c = a / b 44 | fmt.Printf("Product : %v\n", c) 45 | 46 | conjugate := cmplx.Conj(a) 47 | fmt.Println("Complex number a's conjugate : ", conjugate) 48 | 49 | cos := cmplx.Cos(b) 50 | fmt.Println("Cosine of b : ", cos) 51 | 52 | } 53 | 54 | ``` 55 | 56 | output: 57 | ``` 58 | sangam:golang-daily sangam$ go run complex.go 59 | Real part: 2.000000 60 | Complex part: 3.000000 61 | Difference : (-4-1i) 62 | Sum : (8+7i) 63 | Product : (0+26i) 64 | Product : (0.46153846153846156+0.19230769230769232i) 65 | Complex number a's conjugate : (2-3i) 66 | Cosine of b : (26.220553750072888+7.625225809442885i) 67 | 68 | 69 | ``` 70 | 71 | ## How it works... 72 | 73 | - The basic operators are implemented for the primitive type complex. The other operations on complex numbers are provided by the math/cmplx package. In case high precision operations are needed, there is no big implementation. 74 | 75 | - On the other hand, the complex number could be implemented as real, and the imaginary part expressed by the big.Float type. 76 | -------------------------------------------------------------------------------- /docs/_documentation/8.1-converting-between-degrees-radians.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: converting between degrees and radians 4 | weight: 71 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - The trigonometric operations and geometric manipulation are usually done in radians; it is always useful to be able to convert these into degrees and vice versa. 10 | show you some tips on how to handle the conversion between these units. 11 | 12 | ## Create the radians.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "math" 19 | ) 20 | 21 | type Radian float64 22 | 23 | func (rad Radian) ToDegrees() Degree { 24 | return Degree(float64(rad) * (180.0 / math.Pi)) 25 | } 26 | 27 | func (rad Radian) Float64() float64 { 28 | return float64(rad) 29 | } 30 | 31 | type Degree float64 32 | 33 | func (deg Degree) ToRadians() Radian { 34 | return Radian(float64(deg) * (math.Pi / 180.0)) 35 | } 36 | 37 | func (deg Degree) Float64() float64 { 38 | return float64(deg) 39 | } 40 | 41 | func main() { 42 | 43 | val := radiansToDegrees(1) 44 | fmt.Printf("One radian is : %.4f degrees\n", val) 45 | 46 | val2 := degreesToRadians(val) 47 | fmt.Printf("%.4f degrees is %.4f rad\n", val, val2) 48 | 49 | // Conversion as part 50 | // of type methods 51 | val = Radian(1).ToDegrees().Float64() 52 | fmt.Printf("Degrees: %.4f degrees\n", val) 53 | 54 | val = Degree(val).ToRadians().Float64() 55 | fmt.Printf("Rad: %.4f radians\n", val) 56 | } 57 | 58 | func degreesToRadians(deg float64) float64 { 59 | return deg * (math.Pi / 180.0) 60 | } 61 | 62 | func radiansToDegrees(rad float64) float64 { 63 | return rad * (180.0 / math.Pi) 64 | } 65 | 66 | 67 | ``` 68 | output: 69 | ``` 70 | sangam:golang-daily sangam$ go run radians.go 71 | One radian is : 57.2958 degrees 72 | 57.2958 degrees is 1.0000 rad 73 | Degrees: 57.2958 degrees 74 | Rad: 1.0000 radians 75 | 76 | ``` 77 | 78 | ## How it works... 79 | 80 | - The Go standard library does not contain any package with a function converting radians to degrees and vice versa. But at least the Pi constant is a part of the math package, so the conversion could be done as shown in the sample code. 81 | 82 | - The preceding code also presents the approach of defining the custom type with additional methods. These are simplifying the conversion of values by handy API. 83 | -------------------------------------------------------------------------------- /docs/_documentation/5.6-calling_external_process.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: calling an external proces 4 | weight: 46 5 | doctype: Go101 6 | --- 7 | 8 | - The Go binary could also be used as a tool for various utilities and with use of go run as a replacement for the bash script. For these purposes, it is usual that the command-line utilities are called. 9 | 10 | - In this recipe, the basics of how to execute and handle the child process will be provided. 11 | 12 | # Create the run.go file with the following content: 13 | 14 | ``` 15 | package main 16 | 17 | import ( 18 | "bytes" 19 | "fmt" 20 | "os/exec" 21 | ) 22 | 23 | func main() { 24 | 25 | prc := exec.Command("ls", "-a") 26 | out := bytes.NewBuffer([]byte{}) 27 | prc.Stdout = out 28 | err := prc.Run() 29 | if err != nil { 30 | fmt.Println(err) 31 | } 32 | 33 | if prc.ProcessState.Success() { 34 | fmt.Println("Process run successfully with output:\n") 35 | fmt.Println(out.String()) 36 | } 37 | } 38 | ``` 39 | output: 40 | ``` 41 | Biradars-MacBook-Air-4:golang-daily sangam$ go run run.go 42 | Process run successfully with output: 43 | 44 | . 45 | .. 46 | binary 47 | main 48 | main.go 49 | run.go 50 | test 51 | util 52 | 53 | ``` 54 | 55 | ## How it works… 56 | 57 | - The Go standard library provides a simple way of calling the external process. This could be done by the Command function of the os/exec package. 58 | 59 | - The simplest way is to create the Cmd struct and call the Run function. The Run function executes the process and waits until it completes. If the command exited with an error, the err value is not null. 60 | 61 | - This is more suitable for calling the OS utils and tools, so the program does not hang too long. 62 | 63 | - The process could be executed asynchronously too. This is done by calling the Start method of the Cmd structure. In this case, the process is executed, but the main goroutine does not wait until it ends. The Wait method could be used to wait until the process ends. After the Wait method finishes, the resources of the process are released. 64 | 65 | - This approach is more suitable for executing long-running processes and services that the program depends on. 66 | -------------------------------------------------------------------------------- /docs/_documentation/5.0-retriving-go-version.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Retrieving the Golang version 4 | weight: 40 5 | doctype: Go101 6 | --- 7 | 8 | 9 | 10 | While building a program, it is a good practice to log the environment settings, build version, and runtime version, 11 | especially if your application is more complex. This helps you to analyze the problem, in case something goes wrong. 12 | 13 | Besides the build version and, for example, the environmental variables, the Go version by which the binary was compiled could be included in the log. The following recipe will show you how to include 14 | the Go runtime version into such program information. 15 | 16 | - Download and install Go on your machine. 17 | - Verify that your GOPATH and GOROOT environmental variables are set properly. 18 | - Open your Terminal and execute go version. If you get output with a version name, then Go is installed properly. 19 | - Create a repository in the GOPATH/src folder. 20 | 21 | ``` 22 | package main 23 | 24 | import ( 25 | "log" 26 | "runtime" 27 | ) 28 | 29 | const info = ` 30 | Application %s starting. 31 | The binary was build by GO: %s` 32 | 33 | func main() { 34 | log.Printf(info, "Example", runtime.Version()) 35 | } 36 | ``` 37 | output: 38 | ``` 39 | Biradars-MacBook-Air-4:golang-daily sangam$ go run main.go 40 | 2019/11/30 01:53:12 41 | Application Example starting. 42 | The binary was build by GO: go1.13.4 43 | 44 | ``` 45 | - How it works... 46 | 47 | - The runtime package contains a lot of useful functions. To find out the Go runtime version, the Version function could be used. The documentation states that the function returns the hash of the commit, and the date or tag at the time of the binary build. 48 | 49 | - The Version function, in fact, returns the `runtime/internal/sys` .The Version constant. The constant itself is located in the `$GOROOT/src/runtime/internal/sys/zversion.go` file. 50 | 51 | - This .go file is generated by the go dist tool and the version is resolved by the findgoversion function in the `go/src/cmd/dist/build.go` file, as explained next. 52 | 53 | - The $GOROOT/VERSION takes priority. If the file is empty or does not exist, the `$GOROOT/VERSION.cache` file is used. If the `$GOROOT/VERSION.cache` is also not found, the tool tries to resolve the version by using the Git information, but in this case, you need to initialize the Git repository for the Go source. -------------------------------------------------------------------------------- /docs/_documentation/8.8-reading-writing-different-charset.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Reading writing a different charset 4 | weight: 78 5 | doctype: Go101 6 | --- 7 | 8 | 9 | 10 | 11 | It is not an exception that the input from various sources could come in various charsets. 12 | Note that a lot of systems use the Windows operating system but there are others. 13 | Go, by default, expects that the strings used in the program are UTF-8 based. If they are not, 14 | then decoding from the given charset must be done to be able to work with the string. 15 | This recipe will show the reading and writing of the file in a charset other than UTF-8. 16 | 17 | ## Create the charset.go file with the following content: 18 | ``` 19 | package main 20 | 21 | import ( 22 | "fmt" 23 | "io/ioutil" 24 | "os" 25 | 26 | "golang.org/x/text/encoding/charmap" 27 | ) 28 | 29 | func main() { 30 | 31 | // Write the string 32 | // encoded to Windows-1252 33 | encoder := charmap.Windows1252.NewEncoder() 34 | s, e := encoder.String("This is sample text with runes Š") 35 | if e != nil { 36 | panic(e) 37 | } 38 | ioutil.WriteFile("example.txt", []byte(s), os.ModePerm) 39 | 40 | // Decode to UTF-8 41 | f, e := os.Open("example.txt") 42 | if e != nil { 43 | panic(e) 44 | } 45 | defer f.Close() 46 | decoder := charmap.Windows1252.NewDecoder() 47 | reader := decoder.Reader(f) 48 | b, err := ioutil.ReadAll(reader) 49 | if err != nil { 50 | panic(err) 51 | } 52 | fmt.Println(string(b)) 53 | } 54 | 55 | ``` 56 | output: 57 | 58 | ``` 59 | sangam:golang-daily sangam$ go run charset.go 60 | This is sample text with runes Š 61 | sangam:golang-daily sangam$ 62 | 63 | 64 | ``` 65 | 66 | ## How it works... 67 | 68 | - The golang.org/x/text/encoding/charmap package contains the Charmap type pointer constants that 69 | represent the widely used charsets. The Charmap type provides the methods for creating 70 | the encoder and decoder for the given charset. 71 | - The Encoder creates the encoding Writer which encodes the written bytes into the chosen charset. 72 | Similarly, the Decoder can create the decoding Reader, which decodes all read data from the chosen charset. 73 | -------------------------------------------------------------------------------- /docs/_documentation/8.7-reading-the-file-into-string.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: reading the file into a string 4 | weight: 77 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - In the previous recipes, we saw the reading from Stdin and the opening of the file. 10 | In this recipe, we will combine these two a little bit and show how to read the file into a string. 11 | 12 | ## Create the directory temp and create the file file.txt in it. 13 | Edit the file.txt file and write multiple lines into the file. 14 | 15 | ## Create the readfile.go file with the following content: 16 | ``` 17 | package main 18 | 19 | import "os" 20 | import "bufio" 21 | 22 | import "bytes" 23 | import "fmt" 24 | import "io/ioutil" 25 | 26 | func main() { 27 | 28 | fmt.Println("### Read as reader ###") 29 | f, err := os.Open("temp/file.txt") 30 | if err != nil { 31 | panic(err) 32 | } 33 | defer f.Close() 34 | 35 | // Read the 36 | // file with reader 37 | wr := bytes.Buffer{} 38 | sc := bufio.NewScanner(f) 39 | for sc.Scan() { 40 | wr.WriteString(sc.Text()) 41 | } 42 | fmt.Println(wr.String()) 43 | 44 | fmt.Println("### ReadFile ###") 45 | // for smaller files 46 | fContent, err := ioutil.ReadFile("temp/file.txt") 47 | if err != nil { 48 | panic(err) 49 | } 50 | fmt.Println(string(fContent)) 51 | 52 | } 53 | 54 | 55 | ``` 56 | ``` 57 | sangam:golang-daily sangam$ go run readfile.go 58 | ### Read as reader ### 59 | This file content 60 | ### ReadFile ### 61 | This file content 62 | 63 | ``` 64 | 65 | ## How it works... 66 | 67 | - The reading from the file is simple because the File type implements both the Reader and Writer interfaces. 68 | This way, all functions and approaches applicable to the Reader interface are applicable to the File type. 69 | The preceding example shows how to read the file with the use of Scanner and write the content to the bytes buffer (which is more performant than string concatenation). This way, you are able to control the volume of content read from a file. 70 | 71 | - The second approach with ioutil.ReadFile is simpler but should be used carefully, because it reads the whole file. Keep in mind that the file could be huge and it could threaten the stability of the application 72 | -------------------------------------------------------------------------------- /docs/_documentation/5.7-retrieving-child-process-information.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Retrieving child process information 4 | weight: 47 5 | doctype: Go101 6 | --- 7 | 8 | - The recipe Calling an external process describes how to call the child process, synchronously and asynchronously. Naturally, to handle the process behavior you need to find out more about the process. This recipe shows how to obtain the PID and elementary information about the child process after it terminates. 9 | 10 | - The information about the running process could be obtained only via the syscall package and it is highly platform-dependent. 11 | 12 | ## Getting ready 13 | 14 | - Test if the sleep (timeout for Windows) command exists in the Terminal. 15 | 16 | ## Create the main.go file with the following content: 17 | ``` 18 | 19 | package main 20 | 21 | import ( 22 | "fmt" 23 | "os/exec" 24 | "runtime" 25 | "time" 26 | ) 27 | 28 | func main() { 29 | 30 | var cmd string 31 | if runtime.GOOS == "windows" { 32 | cmd = "timeout" 33 | } else { 34 | cmd = "sleep" 35 | } 36 | 37 | proc := exec.Command(cmd, "1") 38 | proc.Start() 39 | 40 | // Wait function will 41 | // wait till the process ends. 42 | proc.Wait() 43 | 44 | // After the process terminates 45 | // the *os.ProcessState contains 46 | // simple information 47 | // about the process run 48 | fmt.Printf("PID: %d\n", proc.ProcessState.Pid()) 49 | fmt.Printf("Process took: %dms\n", 50 | proc.ProcessState.SystemTime()/time.Microsecond) 51 | fmt.Printf("Exited sucessfuly : %t\n", 52 | proc.ProcessState.Success()) 53 | } 54 | 55 | 56 | 57 | ``` 58 | 59 | output: 60 | ``` 61 | Biradars-MacBook-Air-4:golang-daily sangam$ go run main.go 62 | PID: 46936 63 | Process took: 1406ms 64 | Exited sucessfuly : true 65 | 66 | ``` 67 | ## How it works… 68 | 69 | - The os/exec standard library provides the way to execute the process. Using Command, the Cmd structure is returned. The Cmd provides the access to process the representation. When the process is running, you can only find out the PID. 70 | 71 | - There is only a little information that you can retrieve about the process. But by retrieving the PID of the process, you are able to call the utilities from the OS to get more information. 72 | 73 | 74 | ## Note 75 | 76 | Remember that it is possible to obtain the PID of the child process, even if it is running. On the other hand, the ProcessState structure of the os package is available, only after the process terminates. 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /docs/_documentation/1.5-numeral-system-loop.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Numeral Systems - Loop 4 | weight: 5 5 | doctype: Go101 6 | --- 7 | 8 | 9 | ## print decimal,binary,hexadecimal number from 10 to 15 using loop 10 | 11 | 4.Numeral systems - using loop 12 | 13 | 14 | package main 15 | 16 | import "fmt" 17 | 18 | func main() { 19 | for i := 1; i < 16; i++ { 20 | fmt.Printf("%d \t %b \t %x \n", i, i, i) 21 | } 22 | } 23 | 24 | [Run](https://play.golang.org/p/TxcV48laVMk){:.button.button--outline-success.button--pill} 25 | 26 | 27 | 28 | output: 29 | ``` 30 | 0 0 0 31 | 1 1 1 32 | 2 10 2 33 | 3 11 3 34 | 4 100 4 35 | 5 101 5 36 | 6 110 6 37 | 7 111 7 38 | 8 1000 8 39 | 9 1001 9 40 | 10 1010 a 41 | 11 1011 b 42 | 12 1100 c 43 | 13 1101 d 44 | 14 1110 e 45 | 15 1111 f 46 | 47 | ``` 48 | 49 | if your new to loop in GO so lets see some detailing of for loop in GO: 50 | 51 | for i := 1; i < 16; i++ { 52 | 53 | in above syntax of for its similar to other programming langaugae 54 | 55 | Go has only one looping construct, the for loop. 56 | 57 | The basic for loop has three components separated by semicolons: 58 | 59 | -the init statement: executed before the first iteration
60 | -the condition expression: evaluated before every iteration
61 | -the post statement: executed at the end of every iteration.
62 | The init statement will often be a short variable declaration, 63 | and the variables declared there are visible only in the scope of the for statement. 64 | 65 | The loop will stop iterating once the boolean condition evaluates to false. 66 | 67 | Note: Unlike other languages like C, Java, or JavaScript there are no parentheses surrounding 68 | the three components of the for statement and the braces { } are always required. 69 | 70 | 71 | as we seen decimal,binary and hexadecimal programs in Go , in this above program using loop you can print n number that convert 72 | number to any numeral system ( refer integer cheatsheet fmt) to convert number into different fmt format.quick suing simple Go 73 | program. 74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/_documentation/6.4-concatenating-a-string-with-writer.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Concatenating a string with writer 4 | weight: 54 5 | doctype: Go101 6 | --- 7 | 8 | - Besides the built-in + operator, there are more ways to concatenate the string. This recipe will describe the more performant way of concatenating strings with the bytes package and the built-in copy function. 9 | 10 | ## Create the concat_buffer.go file with the following content: 11 | ``` 12 | package main 13 | 14 | import ( 15 | "bytes" 16 | "fmt" 17 | ) 18 | 19 | func main() { 20 | strings := []string{"This ", "is ", "even ", 21 | "more ", "performant "} 22 | buffer := bytes.Buffer{} 23 | for _, val := range strings { 24 | buffer.WriteString(val) 25 | } 26 | 27 | fmt.Println(buffer.String()) 28 | } 29 | 30 | 31 | 32 | ``` 33 | 34 | output: 35 | 36 | ``` 37 | sangam:golang-daily sangam$ go run concat_buffer.go 38 | This is even more performant 39 | sangam:golang-daily sangam$ 40 | 41 | 42 | ``` 43 | ## Create the concat_copy.go file with the following content: 44 | 45 | ``` 46 | package main 47 | 48 | import ( 49 | "fmt" 50 | ) 51 | 52 | func main() { 53 | 54 | strings := []string{"This ", "is ", "even ", 55 | "more ", "performant "} 56 | 57 | bs := make([]byte, 100) 58 | bl := 0 59 | 60 | for _, val := range strings { 61 | bl += copy(bs[bl:], []byte(val)) 62 | } 63 | 64 | fmt.Println(string(bs[:])) 65 | 66 | } 67 | 68 | 69 | ``` 70 | 71 | output: 72 | 73 | ``` 74 | sangam:golang-daily sangam$ go run concat_copy.go 75 | This is even more performant 76 | sangam:golang-daily sangam$ 77 | ``` 78 | ## How it works... 79 | 80 | - The steps 1 - 5 cover the use of the bytes package Buffer as a performance-friendly solution to string concatenation. The Buffer structure implements the WriteString method, which could be used to effectively concatenate the strings into an underlying byte slice. 81 | 82 | - There is no need to use this improvement in all situations, just think about this in cases where the program is going to concatenate a big number of strings (for example, in-memory CSV exports and others). 83 | 84 | - The built-in copy function presented in steps 6 - 8 could be used to accomplish the string concatenation. This method requires some assumption about the final string length, or it could be done on the fly. However, if the capacity of the buffer, where the result is written, is smaller than the sum of the already written part and the string to be appended, the buffer must be expanded (usually by the allocation of a new slice with bigger capacity). 85 | -------------------------------------------------------------------------------- /docs/_documentation/8.5-writing-standard-output-error.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Writing standard output and error 4 | weight: 75 5 | doctype: Go101 6 | --- 7 | 8 | - each process has stdin, a stdout and stderr file descriptors. 9 | The standard approach is the use of stdout as a process output and stderr as process error output. 10 | As these are the file descriptors, the destination where the data is written could be anything, 11 | from the console to the socket.This recipe will show you how to write the stdout and stderr. 12 | 13 | ## Create the stdouterr.go file with the following content: 14 | ``` 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "io" 20 | "os" 21 | ) 22 | 23 | func main() { 24 | 25 | // Simply write string 26 | io.WriteString(os.Stdout, 27 | "This is string to standard output.\n") 28 | 29 | io.WriteString(os.Stderr, 30 | "This is string to standard error output.\n") 31 | 32 | // Stdout/err implements 33 | // writer interface 34 | buf := []byte{0xAF, 0xFF, 0xFE} 35 | for i := 0; i < 200; i++ { 36 | if _, e := os.Stdout.Write(buf); e != nil { 37 | panic(e) 38 | } 39 | } 40 | 41 | // The fmt package 42 | // could be used too 43 | fmt.Fprintln(os.Stdout, "\n") 44 | } 45 | 46 | 47 | ``` 48 | output: 49 | 50 | ``` 51 | sangam:golang-daily sangam$ go run stdouterr.go 52 | This is string to standard output. 53 | This is string to standard error output. 54 | ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 55 | 56 | sangam:golang-daily sangam$ 57 | 58 | ``` 59 | 60 | ## How it works... 61 | 62 | - As with the Stdin from the previous recipe, the Stdout and Stderr are the file descriptors. So these are implementing the Writer interface. 63 | 64 | - The preceding example shows a few ways of how to write into these via the io.WriteString function, with the use of the Writer API and by the fmt package and FprintXX functions. 65 | -------------------------------------------------------------------------------- /docs/_documentation/9.3-serializing-objects-binary-format.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: serializing objects to binary format 4 | weight: 83 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - Besides the well-known JSON and XML, Go also offers the binary format, gob. 10 | This recipe goes through the basic concept of how to use the gob package. 11 | 12 | ## Create the gob.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import ( 17 | "bytes" 18 | "encoding/gob" 19 | "fmt" 20 | ) 21 | 22 | type User struct { 23 | FirstName string 24 | LastName string 25 | Age int 26 | Active bool 27 | } 28 | 29 | func (u User) String() string { 30 | return fmt.Sprintf(`{"FirstName":%s,"LastName":%s, 31 | "Age":%d,"Active":%v }`, 32 | u.FirstName, u.LastName, u.Age, u.Active) 33 | } 34 | 35 | type SimpleUser struct { 36 | FirstName string 37 | LastName string 38 | } 39 | 40 | func (u SimpleUser) String() string { 41 | return fmt.Sprintf(`{"FirstName":%s,"LastName":%s}`, 42 | u.FirstName, u.LastName) 43 | } 44 | 45 | func main() { 46 | 47 | var buff bytes.Buffer 48 | 49 | // Encode value 50 | enc := gob.NewEncoder(&buff) 51 | user := User{ 52 | "sangam", 53 | "biradar", 54 | 24, 55 | true, 56 | } 57 | enc.Encode(user) 58 | fmt.Printf("%X\n", buff.Bytes()) 59 | 60 | // Decode value 61 | out := User{} 62 | dec := gob.NewDecoder(&buff) 63 | dec.Decode(&out) 64 | fmt.Println(out.String()) 65 | 66 | enc.Encode(user) 67 | out2 := SimpleUser{} 68 | dec.Decode(&out2) 69 | fmt.Println(out2.String()) 70 | 71 | } 72 | 73 | 74 | ``` 75 | output: 76 | 77 | ``` 78 | sangam:golang-daily sangam$ go run gob.go 79 | 40FF81030101045573657201FF82000104010946697273744E616D65010C0001084C6173744E616D65010C0001034167650104000106416374697665010200000018FF82010673616E67616D0107626972616461720130010100 80 | {"FirstName":sangam,"LastName":biradar, 81 | "Age":24,"Active":true } 82 | {"FirstName":sangam,"LastName":biradar} 83 | sangam:golang-daily sangam$ 84 | 85 | 86 | ``` 87 | 88 | ## How it works... 89 | 90 | - The gob serialization and deserialization need the Encoder and Decoder. 91 | The gob.NewEncoder function creates the Encoder with the underlying Writer. 92 | - Each call of the Encode method will serialize the object into a gob format. 93 | The gob format itself is the self-describing binary format. This means each serialized struct is preceded by its description. 94 | 95 | - To decode the data from the serialized form, the Decoder must be created by calling the gob.NewDecoder with the underlying Reader. The Decode then accepts the pointer to the structure where the data should be deserialized. 96 | -------------------------------------------------------------------------------- /docs/_documentation/7.4-rounding-floating-point-numbers.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: rounding floating-point numbers 4 | weight: 64 5 | doctype: Go101 6 | --- 7 | 8 | - The rounding of a floating-point number to an integer or to a particular precision has to be done properly. The most common error is to cast the floating-point type float64 to an integer type and consider it as well-handled. 9 | 10 | - An example could be casting the number 3.9999 to an integer and expect it to become an integer of value 4. The real result would be 3. At the time of writing this book, the current version of Go (1.9.2) does not contain the Round function. However, in version 1.10, 11 | the Round function was already implemented in the math package. 12 | 13 | # Create the round.go file with the following content: 14 | 15 | ``` 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | "math" 21 | ) 22 | 23 | var valA float64 = 3.55554444 24 | 25 | func main() { 26 | 27 | // Bad assumption on rounding 28 | // the number by casting it to 29 | // integer. 30 | intVal := int(valA) 31 | fmt.Printf("Bad rounding by casting to int: %v\n", intVal) 32 | 33 | fRound := Round(valA) 34 | fmt.Printf("Rounding by custom function: %v\n", fRound) 35 | 36 | } 37 | 38 | // Round returns the nearest integer. 39 | func Round(x float64) float64 { 40 | t := math.Trunc(x) 41 | if math.Abs(x-t) >= 0.5 { 42 | return t + math.Copysign(1, x) 43 | } 44 | return t 45 | } 46 | 47 | 48 | ``` 49 | ![Go playground](https://play.golang.org/p/j-f8JD-kRDY) 50 | 51 | ``` 52 | Bad rounding by casting to int: 3 53 | Rounding by custom function: 4 54 | ``` 55 | ## How it works... 56 | 57 | - Casting the float to integer actually just truncates the float value. Let's say the value 2 is represented as 1.999999; in this case, the output would be 1, which is not what you expected. 58 | 59 | - The proper way of rounding the float number is to use the function that would also consider the decimal part. The commonly used method of rounding is to half away from zero (also known as commercial rounding). Put simply, if the number contains the absolute value of the decimal part which is greater or equal to 0.5, the number is rounded up, otherwise, it is rounded down. 60 | 61 | - In the function Round, the function Trunc of package math truncates the decimal part of the number. Then, the decimal part of the number is extracted. If the value exceeds the limit of 0.5 than the value of 1 with the same sign as the integer value is added. 62 | -------------------------------------------------------------------------------- /docs/_documentation/5.3-retrieving-current-working-directory.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Retrieving the current working directory 4 | weight: 43 5 | doctype: Go101 6 | --- 7 | 8 | 9 | Another useful source of information for the application is the directory, where the program binary is located. With this information, the program can access the assets and files collocated with the binary file. 10 | 11 | Note: Go since version 1.8. This one is the preferred one. 12 | 13 | Create the main.go file with the following content: 14 | 15 | ``` 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | "os" 21 | "path/filepath" 22 | ) 23 | 24 | func main() { 25 | ex, err := os.Executable() 26 | if err != nil { 27 | panic(err) 28 | } 29 | 30 | // Path to executable file 31 | fmt.Println(ex) 32 | 33 | // Resolve the direcotry 34 | // of the executable 35 | exPath := filepath.Dir(ex) 36 | fmt.Println("Executable path :" + exPath) 37 | 38 | // Use EvalSymlinks to get 39 | // the real path. 40 | realPath, err := filepath.EvalSymlinks(exPath) 41 | if err != nil { 42 | panic(err) 43 | } 44 | fmt.Println("Symlink evaluated:" + realPath) 45 | } 46 | 47 | 48 | 49 | ``` 50 | 51 | output: 52 | ``` 53 | Biradars-MacBook-Air-4:golang-daily sangam$ go build -o binary 54 | Biradars-MacBook-Air-4:golang-daily sangam$ ./binary 55 | /Users/sangam/Documents/golang-daily/binary 56 | Executable path :/Users/sangam/Documents/golang-daily 57 | Symlink evaluated:/Users/sangam/Documents/golang-daily 58 | Biradars-MacBook-Air-4:golang-daily sangam$ 59 | 60 | ``` 61 | # How it works… 62 | 63 | - Since Go 1.8, the Executable function from the os package is the preferred way of resolving the path of the executable. The Executable function returns the absolute path of the binary that is executed (unless the error is returned). 64 | 65 | - To resolve the directory from the binary path, the Dir from the filepath package is applied. The only pitfall of this is that the result could be the symlink or the path it pointed to. 66 | 67 | - To overcome this unstable behavior, the EvalSymlinks from the filepath package could be applied to the resultant path. With this hack, the returned value would be the real path of the binary. 68 | 69 | - The information about the directory where the binary is located could be obtained with the use of the Executable function in the os library. 70 | 71 | - Note that if the code is run by the command go run, the actual executable is located in a temporary directory. 72 | 73 | -------------------------------------------------------------------------------- /docs/_documentation/6.1-finding-the-substring-in-a-string.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Finding the substring in a string 4 | weight: 51 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - Finding the substring in a string is one of the most common tasks for developers. Most of the mainstream languages implement this in a standard library. Go is not an exception. This recipe describes the way Go implements this. 10 | 11 | 12 | ## Create the main.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "strings" 19 | ) 20 | 21 | const refString = "Mary had a little lamb" 22 | 23 | func main() { 24 | 25 | lookFor := "lamb" 26 | contain := strings.Contains(refString, lookFor) 27 | fmt.Printf("The \"%s\" contains \"%s\": %t \n", refString, 28 | lookFor, contain) 29 | 30 | lookFor = "wolf" 31 | contain = strings.Contains(refString, lookFor) 32 | fmt.Printf("The \"%s\" contains \"%s\": %t \n", refString, 33 | lookFor, contain) 34 | 35 | startsWith := "Mary" 36 | starts := strings.HasPrefix(refString, startsWith) 37 | fmt.Printf("The \"%s\" starts with \"%s\": %t \n", refString, 38 | startsWith, starts) 39 | 40 | endWith := "lamb" 41 | ends := strings.HasSuffix(refString, endWith) 42 | fmt.Printf("The \"%s\" ends with \"%s\": %t \n", refString, 43 | endWith, ends) 44 | 45 | } 46 | ``` 47 | output:- 48 | ``` 49 | Biradars-MacBook-Air-4:Documents sangam$ cd golang-daily/ 50 | Biradars-MacBook-Air-4:golang-daily sangam$ go run main.go 51 | The "Mary had a little lamb" contains "lamb": true 52 | The "Mary had a little lamb" contains "wolf": false 53 | The "Mary had a little lamb" starts with "Mary": true 54 | The "Mary had a little lamb" ends with "lamb": true 55 | Biradars-MacBook-Air-4:golang-daily sangam$ 56 | ``` 57 | 58 | ## How it works... 59 | 60 | - The Go library strings contain functions to handle the string operations. This time the function Contains could be used. The Contains function simply checks whether the string has a given substring. In fact, the function Index is used in Contains function. 61 | 62 | - To check whether the string begins with the substring, the HasPrefix function is there. To check whether the string ends with the substring, the function HasSuffix will work. 63 | 64 | - In fact, the Contains function is implemented by use of the Index function from the same package. As you can guess, the actual implementation works like this: if the index of the given substring is greater than -1, the Contains function returns true. 65 | 66 | - The HasPrefix and HasSuffix functions work in a different way: the internal implementation just checks the length of both the string and substring, and if they are equal or the string is longer, the required part of the string is compared. 67 | -------------------------------------------------------------------------------- /docs/_documentation/7.7-Converting-binary-octal-decimal-hexadecimal.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Converting between binary, octal, decimal, and hexadecimal 4 | weight: 67 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - In some cases, the integer values can be represented by other than decimal representations. 10 | The conversion between these representations is easily done with the use of the strconv package 11 | 12 | ## Create the main.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "strconv" 19 | ) 20 | 21 | const bin = "10111" 22 | const hex = "1A" 23 | const oct = "12" 24 | const dec = "10" 25 | const floatNum = 16.123557 26 | 27 | func main() { 28 | 29 | // Converts binary value into hex 30 | v, _ := ConvertInt(bin, 2, 16) 31 | fmt.Printf("Binary value %s converted to hex: %s\n", bin, v) 32 | 33 | // Converts hex value into dec 34 | v, _ = ConvertInt(hex, 16, 10) 35 | fmt.Printf("Hex value %s converted to dec: %s\n", hex, v) 36 | 37 | // Converts oct value into hex 38 | v, _ = ConvertInt(oct, 8, 16) 39 | fmt.Printf("Oct value %s converted to hex: %s\n", oct, v) 40 | 41 | // Converts dec value into oct 42 | v, _ = ConvertInt(dec, 10, 8) 43 | fmt.Printf("Dec value %s converted to oct: %s\n", dec, v) 44 | 45 | //... analogically any other conversion 46 | // could be done. 47 | 48 | } 49 | 50 | // ConvertInt converts the given string value of base 51 | // to defined toBase. 52 | func ConvertInt(val string, base, toBase int) (string, error) { 53 | i, err := strconv.ParseInt(val, base, 64) 54 | if err != nil { 55 | return "", err 56 | } 57 | return strconv.FormatInt(i, toBase), nil 58 | } 59 | 60 | ``` 61 | output: 62 | ``` 63 | sangam:golang-daily sangam$ go run main.go 64 | Binary value 10111 converted to hex: 17 65 | Hex value 1A converted to dec: 26 66 | Oct value 12 converted to hex: a 67 | Dec value 10 converted to oct: 12 68 | sangam:golang-daily sangam$ 69 | ``` 70 | ## How it works... 71 | 72 | - The strconv package provides the functions ParseInt and FormatInt which are the, let's say, complementary functions. The function ParseInt is able to parse the integer number in any base representation. The function FormatInt, on the other hand, can format the integer into any given base. 73 | 74 | - Finally, it is possible to parse the string representation of the integer to the built-in int64 type and subsequently, format the string of the parsed integer into the given base representation. 75 | -------------------------------------------------------------------------------- /docs/_documentation/2.0-deep-drive-on-constants.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Deep Drive On Constants 4 | weight: 10 5 | doctype: Go101 6 | --- 7 | 8 | 9 | If you wanted to find out whether `const` was a keyword, how would you do so? 10 | 11 | ```go 12 | package main 13 | 14 | import ( 15 | "fmt" 16 | ) 17 | 18 | const 19 | 20 | func main() { 21 | fmt.Println("Hello, playground") 22 | } 23 | 24 | ``` 25 | 26 | [The Go Programming Language Specification](https://golang.org/ref/spec) is a great place to start. The [Keywords](https://golang.org/ref/spec#Keywords) section holds the answer. 27 | 28 | ``` 29 | break default func interface select 30 | case defer go map struct 31 | chan else goto package switch 32 | const fallthrough if range type 33 | continue for import return var 34 | ``` 35 | 36 | Make a few constants using the [Go playground](https://play.golang.org/p/et5Qf-Crsu). The Go compiler will figure out what type they are for you. 37 | ```go 38 | package main 39 | 40 | import ( 41 | "fmt" 42 | ) 43 | 44 | const a = 42 45 | const b = 42.78 46 | const c = "James Bond" 47 | 48 | func main() { 49 | fmt.Println(a) 50 | fmt.Println(b) 51 | fmt.Println(c) 52 | fmt.Printf("%T\n", a) 53 | fmt.Printf("%T\n", b) 54 | fmt.Printf("%T\n", c) 55 | } 56 | 57 | ``` 58 | 59 | An alternative way to declare several constants and assign values is using similar syntax to our `import` statement. 60 | 61 | ```go 62 | package main 63 | 64 | import ( 65 | "fmt" 66 | ) 67 | 68 | const ( 69 | a = 42 70 | b = 42.78 71 | c = "James Bond" 72 | ) 73 | 74 | func main() { 75 | fmt.Println(a) 76 | fmt.Println(b) 77 | fmt.Println(c) 78 | fmt.Printf("%T\n", a) 79 | fmt.Printf("%T\n", b) 80 | fmt.Printf("%T\n", c) 81 | } 82 | 83 | ``` 84 | [playground](https://play.golang.org/p/N3_-plSitG) 85 | 86 | If we want to specify the type of our constants, we can. Currently, they are untyped and are known as _constants of a kind_. That gives the compiler a bit of flexibility, because with constants of a kind, or constants which are untyped, the compiler decides which types to assign which values to. When it is typed, it doesn't have that flexibility. 87 | 88 | ```go 89 | package main 90 | 91 | import ( 92 | "fmt" 93 | ) 94 | 95 | const ( 96 | a int = 42 97 | b float32 = 42.78 98 | c string = "James Bond" 99 | ) 100 | 101 | func main() { 102 | fmt.Println(a) 103 | fmt.Println(b) 104 | fmt.Println(c) 105 | fmt.Printf("%T\n", a) 106 | fmt.Printf("%T\n", b) 107 | fmt.Printf("%T\n", c) 108 | } 109 | 110 | ``` 111 | [playground](https://play.golang.org/p/zs-UzDM_Q7) 112 | -------------------------------------------------------------------------------- /docs/_documentation/7.1-indenting-a-text-document.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: indenting a text document 4 | weight: 61 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - The previous recipe depicts how to do string padding and whitespace trimming. This one will guide you through the indentation and unindentation of a text document. Similar principles from the previous recipes will be used. 10 | 11 | 12 | ## Create the file main.go with the following content: 13 | 14 | ``` 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "strconv" 20 | "strings" 21 | "unicode" 22 | ) 23 | 24 | func main() { 25 | 26 | text := "Hi! Go is awesome." 27 | text = Indent(text, 6) 28 | fmt.Println(text) 29 | 30 | text = Unindent(text, 3) 31 | fmt.Println(text) 32 | 33 | text = Unindent(text, 10) 34 | fmt.Println(text) 35 | 36 | text = IndentByRune(text, 10, '.') 37 | fmt.Println(text) 38 | 39 | } 40 | 41 | // Indent indenting the input by given indent and rune 42 | func IndentByRune(input string, indent int, r rune) string { 43 | return strings.Repeat(string(r), indent) + input 44 | } 45 | 46 | // Indent indenting the input by given indent 47 | func Indent(input string, indent int) string { 48 | padding := indent + len(input) 49 | return fmt.Sprintf("% "+strconv.Itoa(padding)+"s", input) 50 | } 51 | 52 | // Unindent unindenting the input string. In case the 53 | // input is indented by less than "indent" spaces 54 | // the min of this both is removed. 55 | func Unindent(input string, indent int) string { 56 | 57 | count := 0 58 | for _, val := range input { 59 | if unicode.IsSpace(val) { 60 | count++ 61 | } 62 | if count == indent || !unicode.IsSpace(val) { 63 | break 64 | } 65 | } 66 | 67 | return input[count:] 68 | } 69 | 70 | ``` 71 | output: 72 | ``` 73 | sangam:golang-daily sangam$ go run main.go 74 | Hi! Go is awesome. 75 | Hi! Go is awesome. 76 | Hi! Go is awesome. 77 | ..........Hi! Go is awesome. 78 | sangam:golang-daily sangam$ 79 | ``` 80 | 81 | ## How it works... 82 | 83 | - The indentation is as simple as padding. In this case, the same formatting option is used. The more readable form of the indent implementation could use the Repeat function of the strings package. The IndentByRune function in the preceding code applies this approach. 84 | 85 | - Unindenting, in this case, means removing the given count of leading spaces. The implementation of Unindent in the preceding code removes the minimum number of leading spaces or given indentation. 86 | -------------------------------------------------------------------------------- /docs/_documentation/9.6-extracting-data-JSON-array.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: extracting data from an incomplete JSON array 4 | weight: 86 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - This recipe contains a very specific use case, where your program consumes the JSON from an unreliable source and the JSON contains an array of objects which has the beginning token 10 | [ but the number of items in the array is very large, and the end of the JSON could be corrupted. 11 | 12 | ## Create the json.go file with the following content: 13 | ``` 14 | package main 15 | 16 | import ( 17 | "encoding/json" 18 | "fmt" 19 | "strings" 20 | ) 21 | 22 | const js = ` 23 | [ 24 | { 25 | "name":"Axel", 26 | "lastname":"Fooley" 27 | }, 28 | { 29 | "name":"Tim", 30 | "lastname":"Burton" 31 | }, 32 | { 33 | "name":"Tim", 34 | "lastname":"Burton" 35 | ` 36 | 37 | type User struct { 38 | Name string `json:"name"` 39 | LastName string `json:"lastname"` 40 | } 41 | 42 | func main() { 43 | 44 | userSlice := make([]User, 0) 45 | r := strings.NewReader(js) 46 | dec := json.NewDecoder(r) 47 | for { 48 | tok, err := dec.Token() 49 | if err != nil { 50 | break 51 | } 52 | if tok == nil { 53 | break 54 | } 55 | switch tp := tok.(type) { 56 | case json.Delim: 57 | str := tp.String() 58 | if str == "[" || str == "{" { 59 | for dec.More() { 60 | u := User{} 61 | err := dec.Decode(&u) 62 | if err == nil { 63 | userSlice = append(userSlice, u) 64 | } else { 65 | break 66 | } 67 | } 68 | } 69 | } 70 | } 71 | 72 | fmt.Println(userSlice) 73 | } 74 | 75 | 76 | ``` 77 | output: 78 | ``` 79 | sangam:golang-daily sangam$ go run json.go 80 | [{Axel Fooley} {Tim Burton}] 81 | sangam:golang-daily sangam$ 82 | 83 | ``` 84 | 85 | ## How it works... 86 | 87 | - Besides the Unmarshall function, the json package also contains the Decoder API. With NewDecoder, the Decoder could be created. By calling the Token method on the decoder, the underlying Reader is read and returns the Token interface. This could hold multiple values. 88 | 89 | - One of these is the Delim type, which is a rune containing one of the {, [, ], } characters. Based on this, the beginning of the JSON array is detected. With the More method on the decoder, more objects to decode could be detected. 90 | -------------------------------------------------------------------------------- /docs/_documentation/5.1-accessing-program-arguments.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: accessing program arguments 4 | weight: 41 5 | doctype: Go101 6 | --- 7 | 8 | 9 | The most simple way to parameterize the program run is to use the command-line arguments as program parameters. 10 | 11 | Simply, the parameterized program call could look like this: ./parsecsv user.csv role.csv. In this case, parsecsv is the name of the executed binary and user.csv and role.csv are the arguments, that modify the program call (in this case it refers to files to be parsed). 12 | 13 | - How to do it... 14 | 15 | Create the main.go file with the following content: 16 | ``` 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | "os" 22 | ) 23 | 24 | func main() { 25 | 26 | args := os.Args 27 | 28 | // This call will print 29 | // all command line arguments. 30 | fmt.Println(args) 31 | 32 | // The first argument, zero item from slice, 33 | // is the name of the called binary. 34 | programName := args[0] 35 | fmt.Printf("The binary name is: %s \n", programName) 36 | 37 | // The rest of the arguments could be obtained 38 | // by omitting the first argument. 39 | otherArgs := args[1:] 40 | fmt.Println(otherArgs) 41 | 42 | for idx, arg := range otherArgs { 43 | fmt.Printf("Arg %d = %s \n", idx, arg) 44 | } 45 | } 46 | 47 | 48 | ``` 49 | 50 | output 51 | 52 | ``` 53 | Biradars-MacBook-Air-4:golang-daily sangam$ go build -o test 54 | Biradars-MacBook-Air-4:golang-daily sangam$ ./test arg1 arg2 55 | [./test arg1 arg2] 56 | The binary name is: ./test 57 | [arg1 arg2] 58 | Arg 0 = arg1 59 | Arg 1 = arg2 60 | Biradars-MacBook-Air-4:golang-daily sangam$ 61 | 62 | ``` 63 | - How it works... 64 | 65 | - The Go standard library offers a few ways to access the arguments of the program call. The most generic way is to access the arguments by the Args variable from the OS package. 66 | 67 | - This way you can get all the arguments from the command line in a string slice. The advantage of this approach is that the number of arguments is dynamic and this way you can, for example, pass the names of the files to be processed by the program. 68 | 69 | - The preceding example just echoes all the arguments that are passed to the program. Finally, let's say the binary is called test and the program run is executed by the Terminal command ./test arg1 arg2. 70 | 71 | - In detail, the os.Args[0] will return ./test. The os.Args[1:] returns the rest of the arguments without the binary name. In the real world, it is better to not rely on the number of arguments passed to the program, but always check the length of the argument array. Otherwise, naturally, if the argument on a given index is not within the range, the program panics. 72 | There's more… 73 | 74 | - If the arguments are defined as flags, -flag value, additional logic is needed to assign the value to the flag. In this case, there is a better way to parse these by using the flag package. This approach is part of the next recipe 75 | -------------------------------------------------------------------------------- /docs/_documentation/9.4-reading-writing-zip-files.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: reading and writing ZIP files 4 | weight: 84 5 | doctype: Go101 6 | --- 7 | 8 | 9 | 10 | - ZIP compression is a widely used compression format. It is usual to use the ZIP format for an application to upload a file set or, on the other hand, export zipped files as output. 11 | This recipe will show you how to handle ZIP files programmatically with the use of the standard library. 12 | 13 | ## Create the zip.go file with the following content: 14 | ``` 15 | package main 16 | 17 | import ( 18 | "archive/zip" 19 | "bytes" 20 | "fmt" 21 | "io" 22 | "io/ioutil" 23 | "log" 24 | "os" 25 | ) 26 | 27 | func main() { 28 | 29 | var buff bytes.Buffer 30 | 31 | // Compress content 32 | zipW := zip.NewWriter(&buff) 33 | f, err := zipW.Create("newfile.txt") 34 | if err != nil { 35 | panic(err) 36 | } 37 | _, err = f.Write([]byte("This is my file content")) 38 | if err != nil { 39 | panic(err) 40 | } 41 | err = zipW.Close() 42 | if err != nil { 43 | panic(err) 44 | } 45 | 46 | //Write output to file 47 | err = ioutil.WriteFile("data.zip", buff.Bytes(), os.ModePerm) 48 | if err != nil { 49 | panic(err) 50 | } 51 | 52 | // Decompress the content 53 | zipR, err := zip.OpenReader("data.zip") 54 | if err != nil { 55 | panic(err) 56 | } 57 | 58 | for _, file := range zipR.File { 59 | fmt.Println("File " + file.Name + " contains:") 60 | r, err := file.Open() 61 | if err != nil { 62 | log.Fatal(err) 63 | } 64 | _, err = io.Copy(os.Stdout, r) 65 | if err != nil { 66 | panic(err) 67 | } 68 | err = r.Close() 69 | if err != nil { 70 | panic(err) 71 | } 72 | fmt.Println() 73 | } 74 | 75 | } 76 | 77 | ``` 78 | output: 79 | ``` 80 | sangam:golang-daily sangam$ go run zip.go 81 | File newfile.txt contains: 82 | This is my file content 83 | sangam:golang-daily sangam$ 84 | 85 | ``` 86 | ## How it works... 87 | 88 | - The built-in package zip contains the NewWriter and NewReader functions to create the zip.Writer to compress, and the zip.Reader to decompress the zipped content. 89 | 90 | - Each record of the ZIP file is created with the Create method of the created zip.Writer . The returned Writer is then used to write the content body. 91 | 92 | - To decompress the files, the OpenReader function is used to create the ReadCloser of the records in the zipped file. The File field of the created ReaderCloser is the slice of zip.File pointers. 93 | The content of the file is obtained by calling the Open method and by reading the returned ReadCloser 94 | -------------------------------------------------------------------------------- /docs/_documentation/2.7-conditional-if-statement.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: Conditional - If Statement 4 | weight: 17 5 | doctype: Go101 6 | --- 7 | 8 | ## If Statements 9 | 10 | * `bool` 11 | - `true` 12 | - `false` 13 | * the _not_ operator 14 | - `!` 15 | * initialization statement 16 | * `if`/`else` 17 | * `if`/`else` 18 | * `if`/`else` 19 | * `if`/`else if`/.../`else` 20 | 21 | _If statements_ are conditional statements. Remember in control flow, we have sequence, we have iterative, and we also have conditional. Sequence is top to bottom, iterative is looping, and conditional is based upon a condition it will either do one thing or another. 22 | 23 | Let's start with some predeclared constants, `true` and `false` and not true `!true` and not false `!false` 24 | 25 | ```go 26 | package main 27 | 28 | import ( 29 | "fmt" 30 | ) 31 | 32 | func main() { 33 | if true { 34 | fmt.Println("001") 35 | } 36 | 37 | if false { 38 | fmt.Println("002") 39 | } 40 | 41 | if !true { 42 | fmt.Println("003") 43 | } 44 | 45 | if !false { 46 | fmt.Println("004") 47 | } 48 | } 49 | ``` 50 | 51 | [playground](https://play.golang.org/p/Aok8L_OVMo) 52 | 53 | Following through the example above, we see `if true` which will always be true, and will execute. `if false` will always be false, and will not execute. `if !true` is if _not_ true, which is the same as false, and will _not_ execute, while `if !false` is if _not_ false, which will execute. 54 | 55 | Let's try with some more examples using numbers and the not operator `!`: 56 | 57 | ```go 58 | package main 59 | 60 | import ( 61 | "fmt" 62 | ) 63 | 64 | func main() { 65 | if 2 == 2 { 66 | fmt.Println("001") 67 | } 68 | 69 | if 2 != 2 { 70 | fmt.Println("002") 71 | } 72 | 73 | if !(2 == 2) { 74 | fmt.Println("003") 75 | } 76 | 77 | if !(2 != 2) { 78 | fmt.Println("004") 79 | } 80 | } 81 | ``` 82 | 83 | [playground](https://play.golang.org/p/Q1QjvxZzFX) 84 | 85 | In Go, we mostly don't see [semicolons](https://golang.org/doc/effective_go.html#semicolons) at the end of statements in source. Though we do see them in initialization statments. 86 | 87 | So, if we want to have two statements on one line, we can use a semicolon. 88 | 89 | ```go 90 | package main 91 | 92 | import ( 93 | "fmt" 94 | ) 95 | 96 | func main() { 97 | fmt.Println("here's a statement"); fmt.Println("something else") 98 | } 99 | ``` 100 | 101 | If you run format, the formatter will put this over two lines. 102 | 103 | One usecase would be initialization of a variable and evaluation, for example `if x := 42; x == 2` will initialize the variable `x` with the value of `42` then will evaluation the expression `x == 2` which is `false` 104 | 105 | ```go 106 | package main 107 | 108 | import ( 109 | "fmt" 110 | ) 111 | 112 | func main() { 113 | if x := 42; x == 2 { 114 | fmt.Println("001") 115 | } 116 | fmt.Println("here's a statement") 117 | fmt.Println("something else") 118 | } 119 | ``` 120 | 121 | [playground](https://play.golang.org/p/araiTmOGMJ) 122 | -------------------------------------------------------------------------------- /docs/_documentation/7.5-floating-point-arithmetics.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: floating-point arithmetics 4 | weight: 65 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - As described in previous recipes, the representation of the floating-point numbers also complicates the arithmetic. For general purposes, the operations on the built-in float64 are sufficient. In case more precision is needed, the math/big package comes into play. This recipe will show you how to handle this. 10 | 11 | ``` 12 | package main 13 | 14 | import ( 15 | "fmt" 16 | "math/big" 17 | ) 18 | 19 | const ( 20 | PI = `3.1415926535897932384626433832795028841971693 21 | 993751058209749445923078164062862089986280348253 22 | 421170679821480865132823066470938446095505822317 23 | 253594081284811174502841027019385211055596446229 24 | 4895493038196` 25 | diameter = 3.0 26 | precision = 400 27 | ) 28 | 29 | func main() { 30 | 31 | pi, _ := new(big.Float).SetPrec(precision).SetString(PI) 32 | d := new(big.Float).SetPrec(precision).SetFloat64(diameter) 33 | 34 | circumference := new(big.Float).Mul(pi, d) 35 | 36 | pi64, _ := pi.Float64() 37 | fmt.Printf("Circumference big.Float = %.400f\n", 38 | circumference) 39 | fmt.Printf("Circumference float64 = %.400f\n", pi64*diameter) 40 | 41 | sum := new(big.Float).Add(pi, pi) 42 | fmt.Printf("Sum = %.400f\n", sum) 43 | 44 | diff := new(big.Float).Sub(pi, pi) 45 | fmt.Printf("Diff = %.400f\n", diff) 46 | 47 | quo := new(big.Float).Quo(pi, pi) 48 | fmt.Printf("Quocient = %.400f\n", quo) 49 | 50 | } 51 | 52 | ``` 53 | output: 54 | ``` 55 | sangam:golang-daily sangam$ go run main.go 56 | Circumference big.Float = 9.4247779607693797153879301498385086525915081981253174629248337769234492188586269958841044760263512039 57 | Circumference float64 = 9.4247779607693793479938904056325554847717285156250000000000000000000000000000000000000000000000000000 58 | Sum = 6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341360 59 | Diff = 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 60 | Quocient = 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 61 | ``` 62 | ## How it works... 63 | 64 | - The big package provides support for the arithmetic of floating-point numbers with high precision. The previous example illustrates the basic operations over the numbers. Note that the code compares the operation with the float64 type and the big.Float type. 65 | 66 | - By working with numbers with a high precision, it is crucial to use the big.Float type. When big.Float is converted back to the built-in float64 type, high precision is lost. 67 | 68 | 69 | The big package contains more operations of the Float type. See the documentation (https://golang.org/pkg/math/big/#Float) of this package for more details. 70 | -------------------------------------------------------------------------------- /docs/_documentation/6.8-controlling-case.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: controlling case 4 | weight: 58 5 | doctype: Go101 6 | --- 7 | 8 | 9 | 10 | - There are a lot of practical tasks where the modification of case is the most common approach. Let's pick a few of these: 11 | 12 | - Case-insensitive comparison 13 | - Beginning the sentence with an automatic first capital 14 | - Camel-case to snake-case conversion 15 | 16 | For these purposes, the strings package offers functions ToLower, ToUpper, ToTitle, and Title. 17 | 18 | ## How to do it... 19 | 20 | Create the main.go file with the following content: 21 | ``` 22 | package main 23 | 24 | import ( 25 | "fmt" 26 | "strings" 27 | "unicode" 28 | ) 29 | 30 | const email = "ExamPle@domain.com" 31 | const name = "isaac newton" 32 | const upc = "upc" 33 | const i = "i" 34 | 35 | const snakeCase = "first_name" 36 | 37 | func main() { 38 | 39 | // For comparing the user input 40 | // sometimes it is better to 41 | // compare the input in a same 42 | // case. 43 | input := "Example@domain.com" 44 | input = strings.ToLower(input) 45 | emailToCompare := strings.ToLower(email) 46 | matches := input == emailToCompare 47 | fmt.Printf("Email matches: %t\n", matches) 48 | 49 | upcCode := strings.ToUpper(upc) 50 | fmt.Println("UPPER case: " + upcCode) 51 | 52 | // This digraph has different upper case and 53 | // title case. 54 | str := "dz" 55 | fmt.Printf("%s in upper: %s and title: %s \n", str, 56 | strings.ToUpper(str), strings.ToTitle(str)) 57 | 58 | // Use of XXXSpecial function 59 | title := strings.ToTitle(i) 60 | titleTurk := strings.ToTitleSpecial(unicode.TurkishCase, i) 61 | if title != titleTurk { 62 | fmt.Printf("ToTitle is defferent: %#U vs. %#U \n", 63 | title[0], []rune(titleTurk)[0]) 64 | } 65 | 66 | // In some cases the input 67 | // needs to be corrected in case. 68 | correctNameCase := strings.Title(name) 69 | fmt.Println("Corrected name: " + correctNameCase) 70 | 71 | // Converting the snake case 72 | // to camel case with use of 73 | // Title and ToLower functions. 74 | firstNameCamel := toCamelCase(snakeCase) 75 | fmt.Println("Camel case: " + firstNameCamel) 76 | 77 | } 78 | 79 | func toCamelCase(input string) string { 80 | titleSpace := strings.Title(strings.Replace(input, "_", " ", -1)) 81 | camel := strings.Replace(titleSpace, " ", "", -1) 82 | return strings.ToLower(camel[:1]) + camel[1:] 83 | } 84 | 85 | 86 | 87 | ``` 88 | output: 89 | 90 | ``` 91 | sangam:golang-daily sangam$ go run main.go 92 | Email matches: true 93 | UPPER case: UPC 94 | dz in upper: DZ and title: Dz 95 | ToTitle is defferent: U+0049 'I' vs. U+0130 'İ' 96 | Corrected name: Isaac Newton 97 | Camel case: firstName 98 | sangam:golang-daily sangam$ 99 | 100 | ``` 101 | ## How it works... 102 | 103 | - Note that the title-case mapping in Unicode differs from the uppercase mapping. The difference is that the number of characters requires special handling. These are mainly ligatures and digraphs such as fl, dz, and lj, plus a number of polytonic Greek characters. For example, U+01C7 (LJ) maps to U+01C8 (Lj) rather than to U+01C9 (lj). 104 | 105 | 106 | -------------------------------------------------------------------------------- /docs/_documentation/7.9-generating-random-numbers.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: generating random numbers 4 | weight: 69 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - how to generate random numbers. This functionality is provided by the math/rand package. The random numbers generated by math/rand are considered cryptographically insecure because the sequences are repeatable with given seed. 10 | 11 | - To generate cryptographically secure numbers, the crypto/rand package should be used. These sequences are not repeatable. 12 | 13 | ## Create the rand.go file with the following content: 14 | ``` 15 | package main 16 | 17 | import ( 18 | crypto "crypto/rand" 19 | "fmt" 20 | "math/big" 21 | "math/rand" 22 | ) 23 | 24 | func main() { 25 | 26 | sec1 := rand.New(rand.NewSource(10)) 27 | sec2 := rand.New(rand.NewSource(10)) 28 | for i := 0; i < 5; i++ { 29 | rnd1 := sec1.Int() 30 | rnd2 := sec2.Int() 31 | if rnd1 != rnd2 { 32 | fmt.Println("Rand generated non-equal sequence") 33 | break 34 | } else { 35 | fmt.Printf("Math/Rand1: %d , Math/Rand2: %d\n", rnd1, rnd2) 36 | } 37 | } 38 | 39 | for i := 0; i < 5; i++ { 40 | safeNum := NewCryptoRand() 41 | safeNum2 := NewCryptoRand() 42 | if safeNum == safeNum2 { 43 | fmt.Println("Crypto generated equal numbers") 44 | break 45 | } else { 46 | fmt.Printf("Crypto/Rand1: %d , Crypto/Rand2: %d\n", 47 | safeNum, safeNum2) 48 | } 49 | } 50 | } 51 | 52 | func NewCryptoRand() int64 { 53 | safeNum, err := crypto.Int(crypto.Reader, big.NewInt(100234)) 54 | if err != nil { 55 | panic(err) 56 | } 57 | return safeNum.Int64() 58 | } 59 | 60 | ``` 61 | output: 62 | ``` 63 | sangam:golang-daily sangam$ go run rand.go 64 | Math/Rand1: 1512982403 , Math/Rand2: 1512982403 65 | Math/Rand1: 938371728 , Math/Rand2: 938371728 66 | Math/Rand1: 1727441275 , Math/Rand2: 1727441275 67 | Math/Rand1: 492959835 , Math/Rand2: 492959835 68 | Math/Rand1: 1031730807 , Math/Rand2: 1031730807 69 | Crypto/Rand1: 1156 , Crypto/Rand2: 75947 70 | Crypto/Rand1: 69204 , Crypto/Rand2: 426 71 | Crypto/Rand1: 14141 , Crypto/Rand2: 57210 72 | Crypto/Rand1: 62348 , Crypto/Rand2: 85520 73 | Crypto/Rand1: 77442 , Crypto/Rand2: 91391 74 | 75 | ``` 76 | 77 | ## How it works... 78 | 79 | - The previous code presents two possibilities on how to generate random numbers. The first option uses the math/rand package, which is cryptographically insecure, and allows us to generate the same sequence with the use of Source with the same seed number. This approach is usually used in tests. The reason for doing so is for the reproducibility of the sequence. 80 | 81 | - The second option, the cryptographically secure one, is the use of the crypto/rand package. The API uses the Reader to provide the instance of a cryptographically strong pseudo-random generator. The package itself has the default Reader which is usually based on the system-based random number generator. 82 | -------------------------------------------------------------------------------- /docs/_includes/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | {% if page.title %}{{ page.title | escape }}{% else %}{{ site.title | escape }}{% endif %} 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | {% if jekyll.environment == 'production' and site.google_analytics %} 16 | {% include google-analytics.html %} 17 | {% endif %} 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/_documentation/8.3-generating-checksums.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: generating checksums 4 | weight: 73 5 | doctype: Go101 6 | --- 7 | 8 | 9 | - The hash, or so-called checksum, is the easiest way to quickly compare any content. This recipe demonstrates how to create the checksum of the file content. For demonstration purposes, 10 | the MD5 hash function will be used. 11 | 12 | ## Create the content.dat file with the following content: 13 | ``` 14 | This is content to check 15 | ``` 16 | Create the checksum.go file with the following content: 17 | 18 | ``` 19 | package main 20 | 21 | import ( 22 | "crypto/md5" 23 | "fmt" 24 | "io" 25 | "os" 26 | ) 27 | 28 | var content = "This is content to check" 29 | 30 | func main() { 31 | 32 | checksum := MD5(content) 33 | checksum2 := FileMD5("content.dat") 34 | 35 | fmt.Printf("Checksum 1: %s\n", checksum) 36 | fmt.Printf("Checksum 2: %s\n", checksum2) 37 | if checksum == checksum2 { 38 | fmt.Println("Content matches!!!") 39 | } 40 | 41 | } 42 | 43 | // MD5 creates the md5 44 | // hash for given content encoded in 45 | // hex string 46 | func MD5(data string) string { 47 | h := md5.Sum([]byte(data)) 48 | return fmt.Sprintf("%x", h) 49 | } 50 | 51 | // FileMD5 creates hex encoded md5 hash 52 | // of file content 53 | func FileMD5(path string) string { 54 | h := md5.New() 55 | f, err := os.Open(path) 56 | if err != nil { 57 | panic(err) 58 | } 59 | defer f.Close() 60 | _, err = io.Copy(h, f) 61 | if err != nil { 62 | panic(err) 63 | } 64 | return fmt.Sprintf("%x", h.Sum(nil)) 65 | } 66 | 67 | 68 | ``` 69 | output: 70 | ``` 71 | sangam:golang-daily sangam$ go run checksum.go 72 | Checksum 1: e44f5ac2d500bde35ace3dcc34cc6bf1 73 | Checksum 2: 958ba356a2c98156d367a14b86226a1c 74 | sangam:golang-daily sangam$ 75 | ``` 76 | ## How it works... 77 | 78 | - The crypto package contains implementations of well-known hash functions. The MD5 hash function is located in the crypto/md5 package. Each hash function in the crypto package implements the Hash interface. Note that Hash contains the Write method. With the Write method, it can be utilized as a Writer. This can be seen in the FileMD5 function. 79 | The Sum method of Hash accepts the argument of byte slice, where the resulting hash should be placed. 80 | - Beware of this. The Sum method does not compute the hash of the argument, but computes the hash into an argument 81 | - On the other hand, md5.Sum, the package function, can be used to produce the hash directly. In this case, the argument of the Sum function is the one from the hash values computed. 82 | - Naturally, the crypto package implements the SHA variants and other hash functions as well. These are usually used in the same way. The hash functions can be accessed through the crypto package constant crypto.Hash (for example, crypto.MD5.New()), but this way, the package with the given function must be linked to a built binary as well (the blank import could be used, import _ "crypto/md5"), 83 | otherwise the call for New will panic. 84 | - The hash package itself contains the CRC checksums and more. 85 | -------------------------------------------------------------------------------- /docs/_documentation/10.1-listing-directory.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: listing a directory 4 | weight: 91 5 | doctype: Go101 6 | --- 7 | 8 | 9 | Create a directory named folder. 10 | ## Create the listdir.go file with the following content: 11 | 12 | ``` 13 | 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "io/ioutil" 19 | "os" 20 | "path/filepath" 21 | ) 22 | 23 | func main() { 24 | 25 | fmt.Println("List by ReadDir") 26 | listDirByReadDir(".") 27 | fmt.Println() 28 | fmt.Println("List by Walk") 29 | listDirByWalk(".") 30 | } 31 | 32 | func listDirByWalk(path string) { 33 | filepath.Walk(path, func(wPath string, info os.FileInfo, 34 | err error) error { 35 | 36 | // Walk the given dir 37 | // without printing out. 38 | if wPath == path { 39 | return nil 40 | } 41 | 42 | // If given path is folder 43 | // stop list recursively and print as folder. 44 | if info.IsDir() { 45 | fmt.Printf("[%s]\n", wPath) 46 | return filepath.SkipDir 47 | } 48 | 49 | // Print file name 50 | if wPath != path { 51 | fmt.Println(wPath) 52 | } 53 | return nil 54 | }) 55 | } 56 | 57 | func listDirByReadDir(path string) { 58 | lst, err := ioutil.ReadDir(path) 59 | if err != nil { 60 | panic(err) 61 | } 62 | for _, val := range lst { 63 | if val.IsDir() { 64 | fmt.Printf("[%s]\n", val.Name()) 65 | } else { 66 | fmt.Println(val.Name()) 67 | } 68 | } 69 | } 70 | 71 | ``` 72 | output: 73 | ``` 74 | sangam:golang-daily sangam$ go run main.go 75 | List by ReadDir 76 | .DS_Store 77 | binary 78 | config.json 79 | content.dat 80 | 81 | List by Walk 82 | .DS_Store 83 | binary 84 | config.json 85 | content.dat 86 | data.csv 87 | data.xml 88 | data.zip 89 | 90 | ``` 91 | 92 | ## How it works... 93 | 94 | - The folder listing the example above uses two approaches. The first, simpler one is implemented by using the listDirByReadDir function and utilizes the ReadDir function from the ioutil package. This function returns the slice of FileInfo structs that represent the actual directory content. Note that the ReadDir function does not read the folders recursively. In fact, the ReadDir function internally uses the Readdir method of the File type in the os package. 95 | 96 | - On the other hand, the more complicated listDirByWalk uses the filepath.Walk function which consumes the path to be 97 | walked and has a function that processes each file or folder in any given path. The main difference is that the Walk 98 | function reads the directory recursively. The core part of this approach is the WalkFunc type, where its function is to 99 | consume the results of the listing. Note that the function blocks the recursive call on underlying folders by returning 100 | the filepath.SkipDir error. The Walk function also processes the called path at first, so you need to handle this as 101 | well (in this case, we skip the printing and return nil because we need to process this folder recursively). 102 | -------------------------------------------------------------------------------- /docs/_documentation/6.0-file-configuration-with-functional-options.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: documentation 3 | title: file configuration with functional options 4 | weight: 50 5 | doctype: Go101 6 | --- 7 | 8 | - This recipe is not directly related to the Go standard library but includes how to handle an optional configuration for your application. The recipe will use the functional options pattern in a real case with a file configuration. 9 | 10 | 11 | ## Create the main.go file with the following content: 12 | 13 | ``` 14 | package main 15 | 16 | import ( 17 | "encoding/json" 18 | "fmt" 19 | "os" 20 | ) 21 | 22 | type Client struct { 23 | consulIP string 24 | connString string 25 | } 26 | 27 | func (c *Client) String() string { 28 | return fmt.Sprintf("ConsulIP: %s , Connection String: %s", 29 | c.consulIP, c.connString) 30 | } 31 | 32 | var defaultClient = Client{ 33 | consulIP: "localhost:9000", 34 | connString: "postgres://localhost:5432", 35 | } 36 | 37 | // ConfigFunc works as a type to be used 38 | // in functional options 39 | type ConfigFunc func(opt *Client) 40 | 41 | // FromFile func returns the ConfigFunc 42 | // type. So this way it could read the configuration 43 | // from the json. 44 | func FromFile(path string) ConfigFunc { 45 | return func(opt *Client) { 46 | f, err := os.Open(path) 47 | if err != nil { 48 | panic(err) 49 | } 50 | defer f.Close() 51 | decoder := json.NewDecoder(f) 52 | 53 | fop := struct { 54 | ConsulIP string `json:"consul_ip"` 55 | }{} 56 | err = decoder.Decode(&fop) 57 | if err != nil { 58 | panic(err) 59 | } 60 | opt.consulIP = fop.ConsulIP 61 | } 62 | } 63 | 64 | // FromEnv reads the configuration 65 | // from the environmental variables 66 | // and combines them with existing ones. 67 | func FromEnv() ConfigFunc { 68 | return func(opt *Client) { 69 | connStr, exist := os.LookupEnv("CONN_DB") 70 | if exist { 71 | opt.connString = connStr 72 | } 73 | } 74 | } 75 | 76 | func NewClient(opts ...ConfigFunc) *Client { 77 | 78 | client := defaultClient 79 | for _, val := range opts { 80 | val(&client) 81 | } 82 | return &client 83 | } 84 | 85 | func main() { 86 | client := NewClient(FromFile("config.json"), FromEnv()) 87 | fmt.Println(client.String()) 88 | } 89 | 90 | 91 | 92 | ``` 93 | In the same folder, create the file config.json with content: 94 | 95 | ``` 96 | { 97 | "consul_ip":"127.0.0.1" 98 | } 99 | 100 | ``` 101 | 102 | output : 103 | ``` 104 | Biradars-MacBook-Air-4:golang-daily sangam$ CONN_DB=oracle://local:5921 go run main.go 105 | ConsulIP: 127.0.0.1 , Connection String: oracle://local:5921 106 | Biradars-MacBook-Air-4:golang-daily sangam$ 107 | 108 | ``` 109 | 110 | ## How it works... 111 | 112 | - The core concept of the functional options pattern is that the configuration API contains the functional parameters. In this case, the NewClient function accepts a various number of ConfigFunc arguments, which are then applied one by one on the defaultClient struct. This way, the default configuration is modified with huge flexibility. 113 | 114 | - See the FromFile and FromEnv functions, which return the ConfigFunc, that is in fact, accessing the file or environmental variables. 115 | 116 | - Finally, you can check the output which applied both the configuration options and resulting Client struct that contains the values from the file and environmental variables. 117 | --------------------------------------------------------------------------------