Everything I learned | Week 19| Encora/Nearsoft Academy

Gibran Herrera
2 min readAug 17, 2021

Hi everyone! πŸ€—

This week I had a big transition within the Academy program, and this time I have to follow up the way I’m building myself which is very exciting.

β€” β€” β€” πŸ₯ Preparing Myself πŸ₯ β€” β€” β€”

I had the whole week to work on whatever I want and I was thrilled to start. This time I prepared myself to work with coding exercises beyond what Hacker Rank would provide me. I started with the gophercises course which gave me an insightful started point of two main things.

  • Struct Tags

Go has a particular way of defining how to validate and marshall structs, the tags, which are metadata within their fields.

type Contact struct { 
Email string `json:"email" valid:"required, email"`
Name string `json:"name" valid:"required,alpha"`
LastName string `json:"last_name" valid:"required,alpha"`
Company string `json:"company" valid:"optional"`
Phone string `json:"phone" valid:"numeric,optional"`}

In this case, the tags are defined within `` strings, for the JSON one it provides the key that is going to be associated, and for the validation one, it provides the options that are going to be checked to verify its validity.

These tags can also be checked by a user-created implementation using the reflect package

  • Flags

I always wonder how flags are created within CLI applications and this time I learned how to implement them in Go, which only requires a three-step process:

  1. Import the flags package
  2. Obtain the flag according to the type of value expected
  3. Parse the flags

And that’s all! Pretty easy right? Here is a code snippet that would help to visualize the process.

package mainimport "flags"func main() {
path string
timeLimit uint
flag.StringVar(&path, "path", "problems.csv", "Defines the CSV location")
flag.UintVar(&timeLimit, "time", 5, "Defines the time to complete the test")
flag.Parse()}

β€” β€” β€” β›° Final Thoughts β›° β€” β€” β€”

Coming back to the self-teaching process got me very excited as I have the freedom to explore what I’m curious about at the moment. Even though, it also has some disadvantages like not having a well-planned and defined process or being too distracted with new things. Nevertheless, this process always helps me to grow as much as I want.

Thank you for reading until here!

See you! πŸ‘‹πŸ½

--

--

Gibran Herrera

Software Engineer πŸ‘¨β€πŸ’» β€” Pythonist 🐍 β€” Linux lover 🐧 β€” Learning πŸ¦€πŸ‹