Golang Web Development Research

Source: Internet
Author: User

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
    • Goroot
    • Gopath
  • 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}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.