Building a Web Server in Go: Handling User Input
austingwalters.com
austingwalters.com
usr.Password = codify.SHA(pass)
In modern code examples, please don't do things like just SHA plaintext passwords. Someone might copy it verbatim! Why not replace that with: import "code.google.com/p/go.crypto/bcrypt"
User := (... code pulling down the user account by username)
err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password))
if err != nil {
// invalid, password didn't match
}The reason is that if you are building a very dynamic web application in which the user's input or existing database values are used, for example, to determine a column name, table name, or even a database name, very strong whitelisting is required.
For the other cases, paramaterization can take care of it.
I'm not trying to start a Singleton debate but I like to avoid using them where possible, so I always wind up writing http.Handler factories moreso than raw handlers. This comment may be a bit outside of this blog post but I am curious if package-level vars and raw Handlers are more idiomatic in Go than using factories to produce handlers and prevent package-level vars.
Edit:
Calls in the original post that made me think of this are calls such as:
user.FindUser(usr.Email)
cookies.LoginCookie(usr.Email)
...which may very well be package functions instead of struct member functions.