Everything I learned | Week 19| Encora/Nearsoft Academy
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:
- Import the flags package
- Obtain the flag according to the type of value expected
- 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 uintflag.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! ππ½