Skip to content

Go R1 Day 4

Day 4 of 100🔗

progress🔗

  • In the last week some more Pluralsight Go (Nigel's courses are always stellar)
  • I've done some odd work as had time in between last update, but nothing structured. Might continue with learn-go-with-tests but also came across exercism and might tackle that soon as well.
  • Setup new project in Visual Studio Codespaces
  • Used Serverless Framework to generate aws-go template project
  • Imported aws-go-sdk resources for AWS SSM Secrets Manager
  • Grabbed SSM Secrets manager output and used to create a POST request for authorization token
  • Used DumpRequest to pretty print output for debugging purpose
  • Hung my head in shame at my copy pasta project 😀
  • Realized half of the battle is just getting my lambda debugging effort running locally. Not exactly the easiest starter project.
  • Need to master different request types. PowerShell makes this easy with Invoke-RestMethod and object construction. I found that the Post method wasn't appropriate as I wanted to control custom headers. This required me to use a different approach, which I ended up doing with http.Client{}.
  • Not sure in a Go Playground sample to test and echo a post request. Thinking if no service that does this might try creating a Go routine to accept the request locally and echo for the purpose of a demo. Any suggestions welcome.
  • Identified i really need better understanding of the godoc libraries as would help a lot. Vscode intellisense even in codespaces isn't performing great, so I'm not getting that help that would really expedite discovery as a beginner. I might give my EAP Goland install a try and see if it helps.
  • Successfully included zap logging library
  • Successfully submitted request for authorization token and got response back into a struct, something that as a newbie I found a major win 🎉 using json.Unmarshal([]byte(body), ar) with ar referring to a pointer another win for me as new to pointers) being passed in like below:
// AuthResponse the authorization object returned by taco service when doing fancy things
type AuthResponse struct {
    MagicalToken string `json:"magical_token"`
    ExpiresIn    int    `json:"expires_in"`
}

func main() {
    var ar AuthResponse
    getToken(&ar) // pointer for the win ⚡️
}
func getToken(ar *AuthResponse) {
    json.Unmarshal([]byte(body), ar) // ❓ using bytes for json is new to me. gotta learn more
    sugar.Infow("Logging library with zap used to generate structured logs",
    "authResponse", ar,  // trailing quotes is the norm, also a new pattern for me
)
}