Show HN: Book about writing web apps in Go without a framework
github.com
github.com
It deals with a lot of stuff for you (static assets, SSL, logging, etc.) and lets you focus on developing your application rather than re-inventing the wheel.
Would be a good idea to add in a section on configuring that type of setup.
Waiting to see someone do some detailed benchmarks on Caddy before I commit to it for production stuff, because I'm too busy and too lazy to do them myself and I have a while left on my paid TLS certs.
I mention Caddy because it includes LetsEncrypt and HTTP/2 out of the box — and is written in Go.
Usually things like serving images, css, automatically compressing them, automatically compressing other traffic, domain redirects, ssl, etc. Helps keep your application focused although I realize it can be tempting to just do all that inside of go since it's somewhat good at it.
location / {
proxy_pass http://127.0.0.1:8088;
}
This of course proxies everything to your Go app; you'd probably want to let NGINX handle static assets as well.One random page that I jumped to: https://thewhitetulip.gitbooks.io/webapp-with-golang-anti-te...
> Go doesn't allow us to have functions as a part of structs
I don't know what this means. Functions can be fields in structs.
> These methods can only be called by an instance of the struct.
That's not true. Methods are just regular functions, with some syntactic sugar to make them look like methods from other programming languages. They are not dispatched on the receiver value, but rather based on the type.
In your example: you call the method using an instance of T right? that was what I was saying, we have to define methods outside the struct declaration and then call it using an object of struct.
(*t).F(nil)
I accept I have to modify the statement I made.
We can have methods which work on objects on structs but never a function like class's method
Also, as far as Go language is concerned, we do not really have to worry about the underlying database, the code, as others have rightly pointed out, is totally reusable
For example the Result type's LastInsertId() method doesnt work in a few cases for postgres that it does for others.
I'm going to read this because I've never done any work with Go, but I feel like I should learn it and websites/apps are in my domain.
Thanks for the work
Thank you for the appreciation!
But for programming books i prefer online
I get that you wrote the templates, you trust them, you don't want the HTML escaping, etc... but is that true of the content you display?
Also missing (in general, from Go instructionals on web apps that dare to stray into HTML) is internationalisation and localisation.
These will be the next topics to be added :-)
Also, I use visual studio code, so haven't really written import statements on my own! I'll use html/template, because no matter who wrote the templates, escaping them is a good idea
//If the password matches, return true
if password == passwordFromDB {
return true
}
//by default return false
return false
This could simply be put as: //If the password matches, return true
//by default return false
return password == passwordFromDB+1 to switch html/template
I think we can add a chapter on Redis then!
That was a goimport gotcha, I use visual studio code, so have never really written imports.
Stackoverflow is worse in some ways. I'm not sure you (or anyone or Harvard) can ever please HN, so unless that is the goal of your book, why bother?