Hello all. I was wondering what an experienced Go programmer would recommend to a novice that's looking into learning the language. I came across several websites, but I want input as to what you guys would think is best.
评论:
MarkPitman:
AlBusters:I really liked https://gobyexample.com/ when I was first learning go.
schoenobates:Sorry for not replying earlier. I spent 4 hours looking through these last night and it was amazing. Thank you!
tuxlinski:+1 - This in combination with the official docs is ace.
AlBusters:Start with Golang Book and after Effective Go
nathj07:I'll check it out once I make it out of gobyexample.
AlBusters:Work through the go tour https://tour.golang.org/welcome/1and read the language as well as the spec. Reading the standard library is super useful alongside the docs.
andygrunwald:Had not found this one before. Thanks!
AlBusters:I blogged about how i learned go: http://andygrunwald.com/blog/2015/06/20/resources-to-learn-golang/ Maybe helpful
yocoda:Will definitely check it out!
jbuberel:I like this golang talk by /u/enneff that walks you through building a chat program. The chat program goes from a command line interface, to using websockets, to having AI that simulates users. The talk shows the power of golang's type system.
AlBusters:See also:
Sk1LLb0X:Resources upon resources! Thank you!
AlBusters:if you're lazy and already know how to program http://learnxinyminutes.com/docs/go/
qxclpxzk:I had seen that site, actually. I need to check it out further.
If you are interested in web development, write a website or app with minimal third-party module usage. I mainly use Gorilla's mux and websocket modules in addition to github.com/lib/pq for my postgreSQL driver. Start with serving just a string, then a static page, and then start adding routes and experimenting with controller functions. I recommend this book on building web services.
You'll want to use html/template if you want to serve web pages. An example of a static template composed of other templates would be:
{{define "index-loggedout"}} <!DOCTYPE html> <html> <head> {{template "header"}} </head> <body> {{template "nav-loggedout"}} {{template "news"}} </body> </html> {{end}}
Making your own user authentication module is a good next step. It will get you comfortable with the different http methods (ie: GET, POST) and database interaction.
A minimal user.go I developed has the following functions:
- hashPassword(password) hashedPassword string
- addUser(name, password, email) success bool
- userExists(user) exists bool
- newSession(user) authKey string
- sessionIsValid(authKey) valid bool
- deleteSession(authKey) err error
- getNameByKey(authKey) userName string
powering the following endpoints:
- / (GET) -> logged out page || logged in page
- /login (POST) -> error string || set auth cookie
- /register (POST) -> error string || set auth cookie
- /logout (GET) -> delete auth key from session table
Where jQuery handles ajax form posting, displaying error messages (eg: incorrect login, user already exists, password too short, ...), and refreshing the page upon authentication.
A real web service will need additional functions like account recovery, email verification, and editing account info, but these are the essentials. Once you have your user authentication infrastructure set up, you are ready to build out your application.
PS: Make sure you adhere to security standards when handling user info. Most importantly: you may only transmit passwords or auth keys over SSL (https), and you may only store securely hashed passwords generated by libraries like pbkdf2. You can set up an http -> https redirection server with 3 lines of code right before you start your secure server.
go http.ListenAndServe(":8080", func (w http.ResponseWriter, r *http.request) {
http.Redirect(w, r, "https://your-website.com", http.StatusMovedPermanently)
})
tuxlinski: tv64738:Very nice! Just to complete, a few days ago I wrote a simply crud using MySQL driver to teach in an easier way. Github - Go MySQL Crud
:http://golang.org/doc/ walks you through quite a lot, just keep reading in order and write little programs as you go along.
QThellimist:[deleted]
shmup:may not be true for mobile users
True, but it's still worth letting OP know about the sidebar resources.
