An inspirational person

Joined January 2024
63 Photos and videos
Day 19 / 30 | #30DaysOfGo - Today I tackled JSON Unmarshaling—taking raw data from an external API and mapping it directly into a Go struct model. I also refactored my code from using memory buffers to direct streaming. Here is how it works. 🧵👇 #Golang #buildinpublic
1
3
35
🔄 Optimized with json.NewDecoder To make it production-ready, I refactored the fetch logic to use json.NewDecoder(resp.Body).Decode(&data). This bypasses the intermediate byte array, parsing the data stream directly from the pipe into my struct. Cleaner and memory-efficient.
1
2
🌐 Proxying the Data I took that optimized fetch logic, wrapped it in a clean helper function, and hooked it up to a local server endpoint (/external). Now, when a user hits my server, it safely calls the external API, handles errors, and returns a structured JSON response.
Day 18 / 30 | #30DaysOfGo - Switched things up today from building servers to acting as the client. I used http.Get to fetch data from an external API, check status codes, and read the response body. Here is what I picked up. 🧵👇 #Golang #buildinpublic
1
1
16
📦 Reading Data from the Pipe My instinct was to print the resp body directly, but that won't work 'cos the data flows thru a pipe (a stream). To actually read it, you have to use io.ReadAll(resp.Body) to pull the data out of the pipe into a byte array, then convert it to a str
1
2
io.ReadAll reads the entire response into your computer's RAM all at once. In those future cases where large files are involved, I will have to stream the data directly to a file or processor using io.Copy instead of saving it to a variable first!
Day 17 / 30 | #30DaysOfGo - I am officially building real REST API endpoints! Today, I combined HTTP routing, struct tags, and advanced streaming mechanics to decode incoming JSON request payloads safely. The backend architecture is coming together. 🧵 #GoFasterTogether #Golang
1
15
DRYing Code with JSON Helpers Writing w.Header().Set(...) and w.WriteHeader(...) for every single error or success response gets messy fast. I built a reusable writeJSON helper function using any (generics) to instantly serialize any data or error map back to the client!
1
5
🎯 Milestone Locked With method protection, payload decoding, input validation, and dynamic JSON error responses in place, this endpoint is fully production-ready. I'm keeping the momentum moving today to catch up on the next block. Let's Go! 🚀
3
Day 16 / 30 | #30DaysOfGo - How do Go web servers talk to modern frontend apps? JSON. Today, I mastered Struct Tags—the essential metadata tool that bridges the gap between Go data models and production-ready API payloads. 🧵👇 #GoFasterTogether #Golang #buildinpublic
1
1
32
📉 Dropping Bloat with omitempty Empty values (like an empty string "" or 0) can bloat an API payload. By adding ,omitempty to a tag, Go dynamically drops the key from the final output JSON string if it contains a zero-value. Clean and lightweight!
1
7
💾 From Go to JSON and Back I ran my struct through json.Marshal(), and the output matched my tags exactly. Sensitive data was stripped, and key cases transformed seamlessly.
4