Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
Just to be picky, when I see Go code I can't help it sorry, ALL_UPPER is not idiomatic, even constants follow the normal naming conventions camel/pascal case (APIURL).
And a warning for the new gopher readers, be careful in production:
the default net/http instances does not timeout, including the default http.Defaultclient
you usually do not use ioutil.ReadAll, especially when you read the Requests (as a web server), if someone post you a 3GB payload it will try to read it all. To protect our code we can use Limiters like golang.org/pkg/net/http/#MaxBytesR...
Having a public web server inside our code is one of the biggest challenge, especially for the devs coming from an interpreted languge, at least for me. We do not have all the protection Nginx or Apache gave us, we have to be more careful. Using Throttlers, Limiters, Timeouts and such is a must!
Also when speaking about REST, I recommend using goswagger.io/, it handles everything for us, generating Server and Client code based on a Swagger config.
Thanks for the comments! I usually just defer to golint and try not think about it too much, the machine (or the authors of golint in this case) prefers all uppercase. main.go:12:6: var ApiURL should be APIURL. Yeah for a production webserver we'd definitly want to set up a timeout, typically I'd tend to deply behind Nginx anyway to take advantage of its caching. This example will probably change a bit over the next couple posts but it will likely not turn into a webserver (at least not yet) so I think ioutil.ReadAll and the http.DefaultClient should be fine for now. Though now you've given me another post I could mix in. ;)
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.
Nice!
Just to be picky, when I see Go code I can't help it sorry, ALL_UPPER is not idiomatic, even constants follow the normal naming conventions camel/pascal case (
APIURL
).And a warning for the new gopher readers, be careful in production:
net/http
instances does not timeout, including the defaulthttp.Defaultclient
ioutil.ReadAll
, especially when you read the Requests (as a web server), if someone post you a 3GB payload it will try to read it all. To protect our code we can use Limiters like golang.org/pkg/net/http/#MaxBytesR...Having a public web server inside our code is one of the biggest challenge, especially for the devs coming from an interpreted languge, at least for me. We do not have all the protection Nginx or Apache gave us, we have to be more careful. Using Throttlers, Limiters, Timeouts and such is a must!
Also when speaking about REST, I recommend using goswagger.io/, it handles everything for us, generating Server and Client code based on a Swagger config.
Thanks for the comments! I usually just defer to
golint
and try not think about it too much, the machine (or the authors of golint in this case) prefers all uppercase.main.go:12:6: var ApiURL should be APIURL
. Yeah for a production webserver we'd definitly want to set up a timeout, typically I'd tend to deply behind Nginx anyway to take advantage of its caching. This example will probably change a bit over the next couple posts but it will likely not turn into a webserver (at least not yet) so I thinkioutil.ReadAll
and thehttp.DefaultClient
should be fine for now. Though now you've given me another post I could mix in. ;)