GOSAMPLEShttps://gosamples.dev/Recent content on GOSAMPLESHugoen-us© GOSAMPLES. All rights reserved.Tue, 23 Dec 2025 00:00:00 +0000๐Ÿƒโ€โ™‚๏ธ What is 'go get' command in Gohttps://gosamples.dev/go-get/Tue, 23 May 2023 00:00:00 +0000https://gosamples.dev/go-get/๐Ÿ†• How to update all Go packages to the latest versionhttps://gosamples.dev/update-all-packages/Wed, 17 May 2023 00:00:00 +0000https://gosamples.dev/update-all-packages/๐Ÿ”— Join URL path elements in Gohttps://gosamples.dev/join-url-elements/Thu, 11 May 2023 00:00:00 +0000https://gosamples.dev/join-url-elements/๐Ÿงช Write end-to-end tests in Go using httptest.Serverhttps://gosamples.dev/e2e-httptest/Tue, 09 May 2023 00:00:00 +0000https://gosamples.dev/e2e-httptest/๐Ÿ  Get local IP address in Gohttps://gosamples.dev/local-ip-address/Thu, 04 May 2023 00:00:00 +0000https://gosamples.dev/local-ip-address/๐Ÿซถ The 'main()' function, 'main' package and 'main.go' file in Gohttps://gosamples.dev/main-function-package-file/Mon, 20 Mar 2023 00:00:00 +0000https://gosamples.dev/main-function-package-file/๐Ÿ†” Generate UUID in Gohttps://gosamples.dev/generate-uuid/Thu, 02 Mar 2023 00:00:00 +0000https://gosamples.dev/generate-uuid/๐Ÿ“ Convert date or time to string in Gohttps://gosamples.dev/time-to-string/Wed, 01 Mar 2023 00:00:00 +0000https://gosamples.dev/time-to-string/โœจ 5 different ways to loop over a time.Ticker in Gohttps://gosamples.dev/range-over-ticker/Mon, 27 Feb 2023 00:00:00 +0000https://gosamples.dev/range-over-ticker/๐Ÿ‘‘ Go Generics cheatsheethttps://gosamples.dev/generics-cheatsheet/Wed, 21 Dec 2022 00:00:00 +0000https://gosamples.dev/generics-cheatsheet/๐Ÿซ˜ Count the occurrences of an element in a slice in Gohttps://gosamples.dev/generics-count/Thu, 15 Dec 2022 00:00:00 +0000https://gosamples.dev/generics-count/โฑ๏ธ Set HTTP client timeout in Gohttps://gosamples.dev/http-client-timeout/Tue, 30 Aug 2022 00:00:00 +0000https://gosamples.dev/http-client-timeout/โฐ Handle HTTP timeout error in Gohttps://gosamples.dev/handle-http-timeout-error/Mon, 29 Aug 2022 00:00:00 +0000https://gosamples.dev/handle-http-timeout-error/โค๏ธโ€๐Ÿฉน Recover function in Gohttps://gosamples.dev/recover/Wed, 24 Aug 2022 00:00:00 +0000https://gosamples.dev/recover/๐Ÿพ How to compare strings in Gohttps://gosamples.dev/strings-compare/Tue, 02 Aug 2022 00:00:00 +0000https://gosamples.dev/strings-compare/๐Ÿ›‘ Exit an app in Gohttps://gosamples.dev/exit/Mon, 01 Aug 2022 00:00:00 +0000https://gosamples.dev/exit/How to check your Go versionhttps://gosamples.dev/check-go-version/Thu, 28 Jul 2022 00:00:00 +0000https://gosamples.dev/check-go-version/๐Ÿ” Repeat a string in Gohttps://gosamples.dev/repeat-string/Wed, 20 Jul 2022 00:00:00 +0000https://gosamples.dev/repeat-string/โŒš Unix time in Go [cheatsheet]https://gosamples.dev/unix-time/Mon, 18 Jul 2022 00:00:00 +0000https://gosamples.dev/unix-time/PostgreSQL in Go: Complete Tutorial with database/sql, pgx, and GORMhttps://gosamples.dev/postgresql-intro/Tue, 12 Jul 2022 00:00:00 +0000https://gosamples.dev/postgresql-intro/๐Ÿฅ‡ How to uppercase the first letter of each word in Gohttps://gosamples.dev/uppercase-first-letter/Wed, 25 May 2022 04:00:00 +0000https://gosamples.dev/uppercase-first-letter/๐Ÿ”  String to uppercase in Gohttps://gosamples.dev/string-to-uppercase/Wed, 25 May 2022 00:00:00 +0000https://gosamples.dev/string-to-uppercase/๐Ÿ˜ Best PostgreSQL database drivers and ORMs in Gohttps://gosamples.dev/list-postgresql-drivers/Tue, 24 May 2022 00:00:00 +0000https://gosamples.dev/list-postgresql-drivers/๐Ÿงฝ Remove non-alphanumeric characters from a string in Gohttps://gosamples.dev/remove-non-alphanumeric/Thu, 19 May 2022 00:00:00 +0000https://gosamples.dev/remove-non-alphanumeric/๐ŸงŠ Cube root in Gohttps://gosamples.dev/cube-root/Fri, 22 Apr 2022 03:00:00 +0000https://gosamples.dev/cube-root/๐ŸŸฆ Square root in Gohttps://gosamples.dev/square-root/Fri, 22 Apr 2022 02:00:00 +0000https://gosamples.dev/square-root/๐ŸŽฒ Generate a random string in Gohttps://gosamples.dev/random-string/Thu, 21 Apr 2022 00:00:00 +0000https://gosamples.dev/random-string/๐Ÿฐ The maximum and minimum value of the int types in Gohttps://gosamples.dev/int-min-max/Thu, 14 Apr 2022 04:00:00 +0000https://gosamples.dev/int-min-max/๐Ÿ“Š The maximum and minimum value of the float types in Gohttps://gosamples.dev/float64-min-max/Thu, 14 Apr 2022 02:00:00 +0000https://gosamples.dev/float64-min-max/๐Ÿฉ Get Pi constant in Gohttps://gosamples.dev/math-pi/Wed, 13 Apr 2022 06:00:00 +0000https://gosamples.dev/math-pi/โณ Time difference between two dates in Gohttps://gosamples.dev/difference-between-dates/Wed, 13 Apr 2022 00:00:00 +0000https://gosamples.dev/difference-between-dates/๐Ÿ‘€ Get a hostname (domain) from a URL in Gohttps://gosamples.dev/get-hostname-domain/Tue, 12 Apr 2022 00:00:00 +0000https://gosamples.dev/get-hostname-domain/๐Ÿ–– Calculate Median in Go using Genericshttps://gosamples.dev/calculate-median/Mon, 11 Apr 2022 00:00:00 +0000https://gosamples.dev/calculate-median/๐Ÿ‹๏ธโ€โ™‚๏ธ Calculate the power of a number x^y in Gohttps://gosamples.dev/calculate-power/Fri, 08 Apr 2022 00:00:00 +0000https://gosamples.dev/calculate-power/๐Ÿค Calculate arithmetic mean in Go using Genericshttps://gosamples.dev/calculate-mean/Fri, 08 Apr 2022 00:00:00 +0000https://gosamples.dev/calculate-mean/๐Ÿšง Remove non-printable characters from a string in Gohttps://gosamples.dev/remove-non-printable-characters/Wed, 06 Apr 2022 00:00:00 +0000https://gosamples.dev/remove-non-printable-characters/๐Ÿค Create a new file in Gohttps://gosamples.dev/create-file/Tue, 05 Apr 2022 06:00:00 +0000https://gosamples.dev/create-file/๐Ÿงน Delete or remove a file in Gohttps://gosamples.dev/delete-remove-file/Tue, 05 Apr 2022 00:00:00 +0000https://gosamples.dev/delete-remove-file/๐Ÿฆฅ Ternary operator in Gohttps://gosamples.dev/ternary-operator/Fri, 01 Apr 2022 00:00:00 +0000https://gosamples.dev/ternary-operator/โœŒ๏ธ 4 ways to create or print string with double quotes in Gohttps://gosamples.dev/string-double-quotes/Thu, 31 Mar 2022 00:00:00 +0000https://gosamples.dev/string-double-quotes/๐Ÿ—‘๏ธ Remove duplicates from any slice using Generics in Gohttps://gosamples.dev/generics-remove-duplicates-slice/Wed, 30 Mar 2022 00:00:00 +0000https://gosamples.dev/generics-remove-duplicates-slice/โŒจ๏ธ Read user input in Go [cheatsheet]https://gosamples.dev/read-user-input/Mon, 28 Mar 2022 00:00:00 +0000https://gosamples.dev/read-user-input/๐Ÿ•ฐ๏ธ Date and time format in Go cheatsheethttps://gosamples.dev/date-time-format-cheatsheet/Wed, 23 Mar 2022 00:00:00 +0000https://gosamples.dev/date-time-format-cheatsheet/๐Ÿ”‰ Reduce function using Generics in Gohttps://gosamples.dev/generics-reduce/Wed, 16 Mar 2022 13:00:00 +0000https://gosamples.dev/generics-reduce/๐Ÿฆพ Create a slice 'map' function using Generics in Gohttps://gosamples.dev/generics-map-function/Wed, 16 Mar 2022 12:00:00 +0000https://gosamples.dev/generics-map-function/๐Ÿ’‚ Filter a slice using Generics in Gohttps://gosamples.dev/generics-filter/Wed, 16 Mar 2022 11:00:00 +0000https://gosamples.dev/generics-filter/๐Ÿฉฐ Sort a slice of any type using Generics in Gohttps://gosamples.dev/generics-sort-slice/Wed, 16 Mar 2022 10:00:00 +0000https://gosamples.dev/generics-sort-slice/๐Ÿ”‘ Get a slice of keys from any map using Generics in Gohttps://gosamples.dev/generics-map-keys/Wed, 16 Mar 2022 06:00:00 +0000https://gosamples.dev/generics-map-keys/๐Ÿ” 'Slice contains' function using Generics in Gohttps://gosamples.dev/generics-slice-contains/Wed, 16 Mar 2022 05:00:00 +0000https://gosamples.dev/generics-slice-contains/โ˜ฏ๏ธ Min and max functions using Generics in Gohttps://gosamples.dev/generics-min-max/Wed, 16 Mar 2022 04:00:00 +0000https://gosamples.dev/generics-min-max/๐Ÿ“… YYYY-MM-DD date format in Gohttps://gosamples.dev/date-format-yyyy-mm-dd/Mon, 14 Mar 2022 00:00:00 +0000https://gosamples.dev/date-format-yyyy-mm-dd/๐ŸŒฏ Wrap and Unwrap errors in Gohttps://gosamples.dev/wrap-unwrap-errors/Sun, 13 Mar 2022 00:00:00 +0000https://gosamples.dev/wrap-unwrap-errors/๐ŸŽ  Round float to any precision in Gohttps://gosamples.dev/round-float/Thu, 10 Mar 2022 00:00:00 +0000https://gosamples.dev/round-float/๐Ÿ—๏ธ Check if a map contains a key in Gohttps://gosamples.dev/map-contains-key/Tue, 08 Mar 2022 00:00:00 +0000https://gosamples.dev/map-contains-key/๐Ÿ“’ Print a number with (comma) thousands separator in Gohttps://gosamples.dev/print-number-thousands-separator/Mon, 07 Mar 2022 00:00:00 +0000https://gosamples.dev/print-number-thousands-separator/๐Ÿœ Print HTTP request/response for debugging in Gohttps://gosamples.dev/print-http-request-response/Mon, 28 Feb 2022 00:00:00 +0000https://gosamples.dev/print-http-request-response/๐Ÿ‰ Do-while loop in Gohttps://gosamples.dev/do-while/Tue, 22 Feb 2022 00:00:00 +0000https://gosamples.dev/do-while/๐Ÿ’• Copy a map in Gohttps://gosamples.dev/copy-map/Wed, 16 Feb 2022 00:00:00 +0000https://gosamples.dev/copy-map/โ—€๏ธ Reverse sort a slice in Gohttps://gosamples.dev/sort-slice-reverse/Fri, 11 Feb 2022 00:00:00 +0000https://gosamples.dev/sort-slice-reverse/โœ‚๏ธ Remove duplicates from a slice in Gohttps://gosamples.dev/remove-duplicates-slice/Fri, 04 Feb 2022 00:00:00 +0000https://gosamples.dev/remove-duplicates-slice/โœ‹ Limit read bytes using io.LimitedReader in Gohttps://gosamples.dev/io-limited-reader/Wed, 26 Jan 2022 00:00:00 +0000https://gosamples.dev/io-limited-reader/โ™พ๏ธ Infinite loop in Gohttps://gosamples.dev/infinite-loop/Thu, 02 Dec 2021 00:00:00 +0000https://gosamples.dev/infinite-loop/๐Ÿ“” Convert a struct to io.Reader in Gohttps://gosamples.dev/struct-to-io-reader/Wed, 01 Dec 2021 00:00:00 +0000https://gosamples.dev/struct-to-io-reader/๐Ÿ“Ÿ Convert HTTP response io.ReadCloser to string in Gohttps://gosamples.dev/io-readcloser-to-string/Mon, 29 Nov 2021 00:00:00 +0000https://gosamples.dev/io-readcloser-to-string/๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ Copy a slice in Gohttps://gosamples.dev/copy-slice/Thu, 25 Nov 2021 00:00:00 +0000https://gosamples.dev/copy-slice/๐Ÿงฎ Sort a string slice containing numbers in Gohttps://gosamples.dev/sort-string-numbers/Tue, 23 Nov 2021 00:00:00 +0000https://gosamples.dev/sort-string-numbers/๐Ÿ—‚๏ธ Introductory tutorial to SQLite in Gohttps://gosamples.dev/sqlite-intro/Mon, 22 Nov 2021 00:00:00 +0000https://gosamples.dev/sqlite-intro/๐Ÿ”Ž Check if the slice contains the given value in Gohttps://gosamples.dev/slice-contains/Fri, 05 Nov 2021 00:00:00 +0000https://gosamples.dev/slice-contains/๐Ÿ’ Concatenate strings in Gohttps://gosamples.dev/concatenate-strings/Sun, 31 Oct 2021 00:00:00 +0000https://gosamples.dev/concatenate-strings/๐Ÿ”Œ Handle 'connection reset by peer' error in Gohttps://gosamples.dev/connection-reset-by-peer/Thu, 21 Oct 2021 00:00:00 +0000https://gosamples.dev/connection-reset-by-peer/๐Ÿ‘ˆ Decode Base64 to a string in Gohttps://gosamples.dev/decode-base64/Thu, 14 Oct 2021 00:00:00 +0000https://gosamples.dev/decode-base64/๐Ÿ‘‰ Encode a string to Base64 in Gohttps://gosamples.dev/encode-base64/Thu, 14 Oct 2021 00:00:00 +0000https://gosamples.dev/encode-base64/๐Ÿ–จ๏ธ Convert string to []byte or []byte to string in Gohttps://gosamples.dev/string-byte-slice/Wed, 13 Oct 2021 00:00:00 +0000https://gosamples.dev/string-byte-slice/๐Ÿง  Print the memory address of a variable in Gohttps://gosamples.dev/print-address/Tue, 12 Oct 2021 00:00:00 +0000https://gosamples.dev/print-address/๐ŸŸ๏ธ Capacity and length of a slice in Gohttps://gosamples.dev/capacity-and-length/Tue, 05 Oct 2021 00:00:00 +0000https://gosamples.dev/capacity-and-length/๐Ÿ•ต๏ธ Solve 'cannot take address of XXX' error in Gohttps://gosamples.dev/cannot-take-address/Mon, 04 Oct 2021 00:00:00 +0000https://gosamples.dev/cannot-take-address/๐Ÿ”Ÿ Convert string to bool in Gohttps://gosamples.dev/string-to-bool/Thu, 30 Sep 2021 00:00:00 +0000https://gosamples.dev/string-to-bool/๐Ÿ‘ฏ Remove duplicate spaces from a string in Gohttps://gosamples.dev/remove-duplicate-spaces/Wed, 29 Sep 2021 00:00:00 +0000https://gosamples.dev/remove-duplicate-spaces/๐Ÿช  Handle 'broken pipe' error in Gohttps://gosamples.dev/broken-pipe/Fri, 17 Sep 2021 00:00:00 +0000https://gosamples.dev/broken-pipe/๐Ÿ“š Convert byte slice to io.Reader in Gohttps://gosamples.dev/byte-slice-to-io-reader/Wed, 15 Sep 2021 00:00:00 +0000https://gosamples.dev/byte-slice-to-io-reader/๐Ÿ“ Create a directory in Gohttps://gosamples.dev/create-directory/Tue, 14 Sep 2021 00:00:00 +0000https://gosamples.dev/create-directory/๐Ÿ“Ž Convert JSON to CSV in Gohttps://gosamples.dev/json-to-csv/Mon, 13 Sep 2021 00:00:00 +0000https://gosamples.dev/json-to-csv/๐Ÿ—„๏ธ Unzip a file in Gohttps://gosamples.dev/unzip-file/Thu, 09 Sep 2021 00:00:00 +0000https://gosamples.dev/unzip-file/๐Ÿ–๏ธ Declare enum in Gohttps://gosamples.dev/enum/Tue, 07 Sep 2021 00:00:00 +0000https://gosamples.dev/enum/๐Ÿง iota in Go - how to use?https://gosamples.dev/iota/Mon, 06 Sep 2021 00:00:00 +0000https://gosamples.dev/iota/๐Ÿ’ก Empty slice vs nil slice in Gohttps://gosamples.dev/empty-vs-nil-slice/Thu, 02 Sep 2021 00:00:00 +0000https://gosamples.dev/empty-vs-nil-slice/๐Ÿ“ฐ String padding in Gohttps://gosamples.dev/string-padding/Fri, 27 Aug 2021 00:00:00 +0000https://gosamples.dev/string-padding/๐Ÿ—œ๏ธ Zip a file in Gohttps://gosamples.dev/zip-file/Wed, 25 Aug 2021 00:00:00 +0000https://gosamples.dev/zip-file/๐Ÿ• Compare two slices in Gohttps://gosamples.dev/compare-slices/Tue, 24 Aug 2021 00:00:00 +0000https://gosamples.dev/compare-slices/โŒ› Temporary file in Go - how to create?https://gosamples.dev/temp-file/Mon, 23 Aug 2021 00:00:00 +0000https://gosamples.dev/temp-file/๐Ÿ‘ฃ Print struct variables in Gohttps://gosamples.dev/print-struct-variables/Fri, 20 Aug 2021 00:00:00 +0000https://gosamples.dev/print-struct-variables/๐Ÿ“ก Handle Context Deadline Exceeded error in Gohttps://gosamples.dev/context-deadline-exceeded/Thu, 19 Aug 2021 00:00:00 +0000https://gosamples.dev/context-deadline-exceeded/๐Ÿ”„ Convert CSV to JSON in Gohttps://gosamples.dev/csv-to-json/Tue, 17 Aug 2021 00:00:00 +0000https://gosamples.dev/csv-to-json/๐Ÿ—’๏ธ Read a CSV file in Gohttps://gosamples.dev/read-csv/Mon, 16 Aug 2021 00:00:00 +0000https://gosamples.dev/read-csv/๐Ÿ“จ Validate an email address in Gohttps://gosamples.dev/validate-email/Fri, 13 Aug 2021 00:00:00 +0000https://gosamples.dev/validate-email/โš™๏ธ Convert interface to string in Gohttps://gosamples.dev/interface-to-string/Thu, 12 Aug 2021 00:00:00 +0000https://gosamples.dev/interface-to-string/โฒ๏ธ Measure execution time in Gohttps://gosamples.dev/measure-time/Tue, 10 Aug 2021 00:00:00 +0000https://gosamples.dev/measure-time/๐Ÿ“ List files in a directory in Gohttps://gosamples.dev/list-files/Mon, 09 Aug 2021 00:00:00 +0000https://gosamples.dev/list-files/๐Ÿ“‚ Check if a file exists in Gohttps://gosamples.dev/file-exists/Thu, 05 Aug 2021 00:00:00 +0000https://gosamples.dev/file-exists/๐Ÿ› Handle errors in Go with errors.Is() and errors.As()https://gosamples.dev/check-error-type/Wed, 04 Aug 2021 00:00:00 +0000https://gosamples.dev/check-error-type/๐Ÿ—ƒ๏ธ 3 ways to pretty print JSON in Gohttps://gosamples.dev/pretty-print-json/Tue, 03 Aug 2021 00:00:00 +0000https://gosamples.dev/pretty-print-json/๐Ÿ—บ๏ธ Convert map to JSON in Gohttps://gosamples.dev/map-to-json/Sun, 01 Aug 2021 00:00:00 +0000https://gosamples.dev/map-to-json/๐Ÿ”ข Convert int to string in Gohttps://gosamples.dev/convert-int-to-string/Fri, 23 Jul 2021 00:00:00 +0000https://gosamples.dev/convert-int-to-string/โœ’๏ธ Write to a CSV file in Gohttps://gosamples.dev/write-csv/Tue, 01 Jun 2021 00:00:00 +0000https://gosamples.dev/write-csv/๐Ÿ™Œ Case-insensitive string comparison in Gohttps://gosamples.dev/case-insensitive-string-comparison/Tue, 25 May 2021 00:00:00 +0000https://gosamples.dev/case-insensitive-string-comparison/๐Ÿ Check if a string starts with a substring in Gohttps://gosamples.dev/starts-with/Tue, 11 May 2021 00:00:00 +0000https://gosamples.dev/starts-with/โœ๏ธ Write to a file in Gohttps://gosamples.dev/write-file/Thu, 29 Apr 2021 00:00:00 +0000https://gosamples.dev/write-file/๐Ÿ“– Read a file in Gohttps://gosamples.dev/read-file/Tue, 27 Apr 2021 00:00:00 +0000https://gosamples.dev/read-file/Generate Random Numbers in Gohttps://gosamples.dev/random-numbers/Thu, 22 Apr 2021 00:00:00 +0000https://gosamples.dev/random-numbers/How to use environment variables in Go (get, set, expand)https://gosamples.dev/environment-variables/Wed, 21 Apr 2021 00:00:00 +0000https://gosamples.dev/environment-variables/How to write a while loop in Gohttps://gosamples.dev/while-loop/Tue, 20 Apr 2021 00:00:00 +0000https://gosamples.dev/while-loop/8 ways to split a string in Go with exampleshttps://gosamples.dev/split-string/Mon, 19 Apr 2021 00:00:00 +0000https://gosamples.dev/split-string/How to URL-decode in Go with net/url (parse, query, path)https://gosamples.dev/url-decode/Thu, 15 Apr 2021 00:00:00 +0000https://gosamples.dev/url-decode/How to URL-encode in Go with net/url (query, path, full URL)https://gosamples.dev/url-encode/Tue, 13 Apr 2021 00:00:00 +0000https://gosamples.dev/url-encode/How to use time.Sleep in Go (Golang) to pause executionhttps://gosamples.dev/sleep/Mon, 12 Apr 2021 00:00:00 +0000https://gosamples.dev/sleep/Print Type of Variable in Gohttps://gosamples.dev/print-type/Tue, 06 Apr 2021 00:00:00 +0000https://gosamples.dev/print-type/Foreach Loop in Go: Range, Iterate, and Modern Patternshttps://gosamples.dev/foreach/Fri, 26 Mar 2021 00:00:00 +0000https://gosamples.dev/foreach/Hello World in Go: Your First Programhttps://gosamples.dev/hello-world/Thu, 21 Jan 2021 00:00:00 +0000https://gosamples.dev/hello-world/