Go Language Notes

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Learning about Docker will have to learn the go language. Especially the interface type, it is not very convenient to feel. Update your understanding a little bit.

  1. The package in the
  2. Go language. The
    is directly in Java the gratitude of the class, and import takes effect directly on the class. However, in the go language, directories and packages will be used accordingly.
    Directory: Import is the imported directory.
    Packege: There can be multiple go files in a directory, but only one directory.
    In addition, the system default package has a specified path. @GOPATH/SRC, the imported packages start from this path. Look at the source of time or to pay attention to the point, or the compiler can not recognize the

     Import   "FMT"  //go The language comes with the package  FMT. Print () //How to use  import   "Google.golang.org/grpc"  grpc. NewServer () //Ghost know the specific NewServer method is in the above directory of the go file, so sometimes look at the third-party source code is very inconvenient, only the global search.  pb  "xcl"  //to wrap individual name under directory  PB. Userstatus_online  
  3. Simple syntax, just note that some things are similar to C + +, and some are similar to Python.

     definition: var  str string  var  str: = " hello " Method: //func keyword  //the method immediately following a defined struct  //method name  //parameter list  //return value, is the opposite, It still feels awkward.  func  (S *server) Logout (CTX context. Context, uid *PB. UserID) (*PB. Funcresponse, error) {return  param1, param2} struct: Similar to the C Language bar, and the concept of pointers. type  server struct  {}  
  4. Go get can download and install the remote code base, which is downloaded by default in the @gopath/src directory.

    go get google.golang.org/grpcexport PATH=$PATH:$GOPATH/bin //下载的第三方二进制文件,会默认在这个目录,使用的时候添加一下环境变量。

Reference:
[1] Go language primer

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.