Go-By-Example

  • This repository was created for educational purposes. It contains 100 different examples of using Golang.

Repo Structure


├── G01
├── G02
├── Gxx
├── G12                                 # Some repositories contains more than one sample of code for one task.
│   ├── 01                               # Each new solution is in separate catalog.
│       ├── main.go                 # And each solution is launched using the main.go file.
│   ├── 02                               # Second solution for G12
│       ├── main.go
├── G100
├── Gopkg.lock
├── Gopkg.toml
├── README.md

Examples

  • G01 - Swap two numbers without temporary variable.
  • G02 - Generate multiplication table 12 x 12.
  • G03 - Even/Odd numbers.
  • G04 - Compare two strings.
  • G05 - Get first element from slice and remove this element.
  • G06 - Get last element from slice and remove this element.
  • G07 - Concatenate two slices with int values.
  • G08 - Concatenate two slices with int and string values.
  • G09 - Get actual date and time in other timezones.
  • G10 - FizzBuzz with for loop.
  • G11 - FizzBuzz with switch loop.
  • G12 - Reverse string.
  • G13 - Is palindrome?
  • G14 - Create file, write string and read.
  • G15 - Read directory structure (files and other directories if exists).
  • G16 - Read directory structure (files and other directories if exists) with Readdir.
  • G17 - Count words from string.
  • G18 - Split string on white space.
  • G19 - Split slice of bytes (words).
  • G20 - Check if map contains a key.
  • G21 - Find element position in slice (for string and int).
  • G22 - Print index for any element from Array.
  • G23 - Print index for any element from Slice.
  • G24 - Compare two struct with 'DeepEqual'.
  • G25 - Compare two map with 'DeepEqual'.
  • G26 - Compare two slices with "DeadEqual".
  • G27 - Copy one map to another.
  • G28 - Remove duplicate elements from slice.
  • G29 - Get difference between two dates.
  • G30 - Find element in slice or map and move it to first position.
  • G31 - Convert struct to JSON.
  • G32 - Check if string is in a JSON format.
  • G33 - Read file char by char.
  • G34 - Append text fo file.
  • G35 - CRUD file - Create empty file. Add some information to file. Read file. Delete file.
  • G36 - Get system process information for this example. Try using os.Getpid().
  • G37 - Replace all numbers in string with 'x' char.
  • G38 - Delete element from map and return map length before and after deleting item.
  • G39 - Create CSV file with any data.
  • G40 - Execute any terminal command from go code. Try using exec.Command.
  • G41 - Check if string contain a specified word.
  • G42 - Split string into separate words
  • G43 - Replace one word type in a string.
  • G44 - Replace a few different words in string.
  • G45 - Read CSV file.
  • G46 - Convert string values (int, float, binary) to numeric values.
  • G47 - Convert binary, decimal, hexadecimal and octal from string values to numeric values.
  • G48 - Generate twenty random numbers with math/rand.
  • G49 - Generate random numbers with crypto/rand.
  • G50 - Generate string with random alphabetical characters.
  • G51 - Generate image.
  • G52 - Convert map to JSON.
  • G53 - Today's date.
  • G54 - Format date to string.
  • G55 - Extract name of day from date format ex. 2018-11-29.
  • G56 - Write to file with goroutines.
  • G57 - Creating custom error from error package in a very basic calculator.
  • G58 -
  • G59 - Create image: fill image with one color, set some pixels in other color and print all these information in output.
  • G60 - Create file.
  • G61 - Get file info (Name, Size, Modification date, if path
  • G62 - Rename file.
  • G63 - Delete file.
  • G64 - Check if file exists.
  • G65 - Change file permission.
  • G66 - Change file timestamp.
  • G67 - Copy file.
  • G68 - Hash content from file in MD5, SHA512, (...).
  • G69 - Generate slice of random numbers.
  • G70 - Create HTTP/GET request.
  • G71 - Connecting to PostgreSQL.
  • G72 - Execute query to database (PostgreSQL in this example).
  • G73 - Read query metadata.
  • G74 - Obtaining data from query result.
  • G75 - Create simple HTTP server.
  • G76 - Handling HTTP request.
  • G77 - Use static files.
  • G78 - Serve template.
  • G79 - Create http.Redirect.
  • G80 - Parse XML file.
  • G81 - Simple RESTful API.
  • G82 - Set, update and remove cookie.
  • G83 - MySQL
  • G84 - Validate user input.
  • G85 - Question game*
  • G86 - Request public JSON.
  • G87 - Create server with ECHO.
  • G88 - Query Params with ECHO.
  • G89 - Parsing request JSON with ECHO.
  • G90 - Mddleware with ECHO.
  • G91 - Custom middleware with ECHO.
  • G92 - Middleware authentication ECHO.
  • G92
  • G93 -
  • G94 -
  • G95 -
  • G96 -
  • G97 -
  • G98 -
  • G99 - Hash password with Bcrypt.
  • G100 - TCP server.
  • G101 - GET request.
  • G102 - IP parser.
  • G103 - Domain IP address resolver
  • G104 - Parse CIDR for IPv4.
  • G105 - Get CNAME.
  • G106 -
  • G107 -
  • G108 -
  • G109 -
  • G110 -