Golang Basics Part I

October 20, 2019 · View on GitHub

MIT Licensed Awesome       

Golang Basics Part I

Please complete the courses, tutorials and tasks listed below:

Theory

  1. As any young gopher we start by passing "Tour of Go"
  2. Go through 1-7 chapter at Golangbootcamp. Check your knowledge with exercizes at the end of 3,4,5,7 chapters.
  3. Read Introduction, Formatting, Commentary, Names, Semicolons, Control structures, Functions and Data chapters from Effective Go article written by go language developers.
  4. Read following important articles:

Learn Go Variables

Learn golang typed untyped constants

Go Blog: String

Understand go pointers in less than 800 words or your money back

Go slices usage and internals

If a map isn't a reference variable what is it

Types System

Types Conversations

Interface values are valueless

Interface semantics

Gotchas of defer

Panic & Recover

Understanding go panic output

Practical task

  1. In your kottans-backend folder create folder called digits.
  2. In digits folder create file called main.go.
  3. Given following string:
const digits =
`
 000
0   0
0   0
0   0
0   0
0   0
 000

  1
1 1
  1
  1
  1
  1
11111

 222
2   2
    2
   2
  2
 2
22222

 333
3   3
    3
  33
    3
3   3
 333

   4
  44
 4 4
4  4
44444
   4
   4

55555
5
5
5555
    5
5   5
 555

 666
6   6
6
6666
6   6
6   6
 666

77777
    7
    7
   7
  7
 7
 7

 888
8   8
8   8
 888
8   8
8   8
 888

 999
9   9
9   9
 9999
    9
9   9
 999
`

In main.go create write a program that satisfy following user stories:

  • As the user, I can take any unsigned integer (uint) value to use as argument in go run main.go <unsigned_integer> call.
  • Using uint as input I can get output value as ASCII art in my termanal window. For instance:

go run main.go 1234567890

***********************************************************
  1    222   333     4  55555  666  77777  888   999   000
1 1   2   2 3   3   44  5     6   6     7 8   8 9   9 0   0
  1       2     3  4 4  5     6         7 8   8 9   9 0   0
  1      2    33  4  4  5555  6666     7   888   9999 0   0
  1     2       3 44444     5 6   6   7   8   8     9 0   0
  1    2    3   3    4  5   5 6   6  7    8   8 9   9 0   0
11111 22222  333     4   555   666   7     888   999   000
***********************************************************
  • Note, that asterisk borders are mandatory
  • As the user, I can see error message in my terminal if my input is not valid (in case if given more than 1 argument or if 1 argument is not uint value).
  1. Optional story. Add possibily to set custom pixel symbol for your ASCII art via additional command line argument symbol. For instance:

go run main.go -symbol @ 1234567890

Will output:

***********************************************************
  @    @@@   @@@     @  @@@@@  @@@  @@@@@  @@@   @@@   @@@
@ @   @   @ @   @   @@  @     @   @     @ @   @ @   @ @   @
  @       @     @  @ @  @     @         @ @   @ @   @ @   @
  @      @    @@  @  @  @@@@  @@@@     @   @@@   @@@@ @   @
  @     @       @ @@@@@     @ @   @   @   @   @     @ @   @
  @    @    @   @    @  @   @ @   @  @    @   @ @   @ @   @
@@@@@ @@@@@  @@@     @   @@@   @@@   @     @@@   @@@   @@@
***********************************************************
  1. Useful links
  1. In your kottans-backend repo README.md:
    • add header ## Go basics 1
    • embed the link to your main.go source code file.
Code Submission

Save your program in a file. Follow instructions in this repo to submit your code.

  1. You did lot already! If you honestly finished all the previous steps then go ahead and share it with others – post a message in course channel: Go Basics 1 — #done and add the link to your repo. This step is important, as it helps mentors to track your progress!

Extra materials

  1. FreeCodeCamp Golang Course
  2. Go By Example
  3. An Introduction to Programming in Go;
  4. 50 оттенков Go

Done?

➡️ Go forward to Memory Management

⤴️ Back to Contents