The go language is now relatively ripe for development. There is a lot of information on the Internet, this article does not repeat the installation, configuration, operation, grammar-related knowledge, because these are not more clear and convenient than the official website.
It's just a little bit of the go language and other languages are not the same place, to help you quickly avoid the pit and change thinking.
- Getting Started reference documentation:
- https://github.com/unknwon/go-web-foundation
- https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/preface.md
- https://github.com/unknwon/the-way-to-go_zh_cn/blob/master/ebook/ Directory.md
- basic configuration
- environment variables
- source ~/.bash.profile config environment variable
- go env View environment variables
- Installation configuration
- Package
- Functions in the same package are not duplicate
- Package name can be different from folder name, import with folder name, reference with package name
- Go get-u github.com/xxx/xxx Get External references
- dependency management
- GODEP oldest
- DEP official project, just starting
- glide new, full-featured https:// segmentfault.com/a/1190000013016957
- garbled: First execute chcp 65001
- glide permissions on Windows bug: https:// studygolang.com/topics/4905
- govendor new, full function
- govendor init
- govendor fetch github.com/xxx
- sync
- web development
- web frame:
- gin high efficiency;
- beego domestic projects, star many, too large
- ORM Framework:
- xorm domestic projects, documents all, response fast;
Li> gorm fewer documents, more star;
- Syntax conventions to understand
- Initial case-sensitive visibility: functions, variables, etc. that begin with capital letters are public by default, otherwise private
- Iota enumeration types
- Defer to release resources and improve code readability
- Goroutine Natural support concurrent programming
- Database development Examples
Package Daoimport ("Github.com/go-xorm/xorm" "FMT") Type UserInfostruct{UserIdstring' Xorm:"userId varchar"' Usernamestring' Xorm:"username varchar"'}func getweixinconfig () {varEngine *Xorm. Enginevarerr error engine, err= Xorm. Newengine ("MySQL","username:password@tcp (host:port)/user_db") ifErr! =Nil {fmt. PRINTLN (Err)} ERR1:=engine. Ping ()ifErr1! =Nil {fmt. Println (ERR1)} engine. Showsql (true) varusers []userinfo err2:= engine. Table ("user_db"). Select (the UserId, username"). Find (&users)ifErr2! =Nil {fmt. PRINTLN (Err)} FMT. Println (len (Users))}
- Gin Web Development Sample
Package Mainimport ("Github.com/gin-gonic/gin" "Awesome-go/src/dao" "OS" "io") Func main () {//output log to fileGin. Disableconsolecolor () LogFile, _:= OS. Create ("Log") gin. Defaultwriter=io. Multiwriter (logFile) Router:=Gin. Default () router. GET ("/get", Func (c *Gin. Context) {C.json ( $, Gin. h{"message":"OK", }) }) router. Run ()//listen and serve on 0.0.0.0:8080}