Try avoiding things like f *[]byte as slices and maps are already pointers by themselves. Also, it's a good practice to check whether entries exist in the map before converting them to types:
While it does seem redundant in personal/toy projects, I have seen some applications panic and crash due to such simple assumptions when someone later modifies the input map and misses some values :)
P.S. It would be a lot more robust if you parsed that yaml into a struct!
Thanks for the comment! I've been putting off dealing with checking on the front matter map for two posts. 😅 isNil() basically only exists for checking the map but I keep putting off implementing the full thing because I was working with "known good" files. But I kind of like the pattern in your example I will probably be using that. I think at some point it might go into a struct if I keep extending the code.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, good job :)
Try avoiding things like
f *[]byte
as slices and maps are already pointers by themselves. Also, it's a good practice to check whether entries exist in the map before converting them to types:Could be:
While it does seem redundant in personal/toy projects, I have seen some applications panic and crash due to such simple assumptions when someone later modifies the input map and misses some values :)
P.S. It would be a lot more robust if you parsed that yaml into a struct!
Thanks for the comment! I've been putting off dealing with checking on the front matter map for two posts. 😅
isNil()
basically only exists for checking the map but I keep putting off implementing the full thing because I was working with "known good" files. But I kind of like the pattern in your example I will probably be using that. I think at some point it might go into a struct if I keep extending the code.