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.
- The package in the
-
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
-
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 {}
-
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