"Go introductory programming language and practical skills," Chapter 1 _ _ Go language understanding

  EDITORIAL:

  Earlier it was decided to study notes written in the form of articles, published in a blog on the passenger, in their own service on can also take a few times, but not what I want to feel, has been dragged. In fact it, nothing exciting is true, day after day, hoping to adhere to.

  First, install

    After installing the language and go three main environment variable needs to be set

    1. $ GOROOT: Go language on your computer's installation directory (like I was installed in the default C: \ Go down).

    2. $ GOPATH: working directory Go language, as I understand it is the future compiled files on which the bin directory. (I set him to D: \ Go)

    3. $ PATH: performing address .. you must know that it is wise what path. Here is the path to the executable file, I put him under win10 set to% GOROOT% \ bin:% GOPATH% \ bin.

  Second, some commands

    Enter go help can get a list of commands, such as input go help run details can be obtained using the run command. But it was good to see it to understand English, ha ha, otherwise it can only be used to view the online translation. Posted the following memo again, each command has a number of parameters, you need special look.      

      • build: compiler package and dependencies
      • clean: remove the object file
      • doc: documentation package or display symbols
      • env: Printing of environmental information go
      • bug: Start Error Reporting
      • fix: Run go tool fix
      • fmt: Run gofmt format
      • generate: from the processing source files generated go
      • get: Download and install the packages and dependencies
      • install: compile and install the package and dependencies
      • list: the packet list
      • run: Compile and run the program go
      • test: Run the test
      • tool: tools provided run go
      • version: Displays the version go
      • vet: Run go tool vet

 

    I find it particularly amazing is, go fmt can be forced to format the code, my mother no longer worried about the coding style inconsistencies there.

  Third, the directory structure

 

    GOROOT is the root of the Go language environment

      api api-- stored list of public variables, constants, functions, etc., for the GO language API to retrieve.

      bin-- store executable file.

      doc-- document storage standard library, use GODOC -HTTP =: 6060 command to start the Document Services, you can access to view 6060 by the local port.

      pkg-- for the construction of the installation, save all archive Go language standard library. pkg folder contains a subdirectory associated with the installation of Go platform, which we call "platform-specific directory." For example, the operating system for Linux 32bit binary packages, the name is linux_386 platform-directory; and in the operating system for Windows 64bit installation package, the platform-specific directory name was windows_amd64.

      src-- store all standard libraries, Go language tools, and the related underlying library (C language) source code. This is to see the contents inside when reading the source code.

    GOPATH are working directory Go language

      bin-- store go install command generates an executable file.

      pkg-- Go to store files generated by the compiler.

      src-- own code

        --test_1.com Project

        --test_2.com Project II.

          --hello-world directory a

            --main.go file a

  Fourth, go first language program

     The above is GOPATH / src / test_2.com / hello-world / main.go code is as follows:

main Package Penalty for  // package ownership, define the current package code belongs 

Import (    // import package, Go package required to import only used, if you import a code package and not used, then the compiler will complain when 
  " fmt "  
) 
FUNC main () 
{ 
  fmt.Println ( " the Hello Word " ) 
}

 

     

@ DESKTOP-LFKJ3FD MINGW64 phwxi /d/Go/src/code.local/hello- Word 
$ RUN main.go go // compile and run the program go. Performed directly output 
the Hello Word 

phwxi @ DESKTOP -LFKJ3FD MINGW64 /d/Go/src/code.local/hello- Word 
$ Go Build  // compiler to create an executable file 

phwxi @ DESKTOP -LFKJ3FD MINGW64 / d / Go / src / code .local / Hello- Word 
$ LS  // At this point look and found more than one executable file-Word.exe the Hello 
the Hello-Word.exe *   main.go 

phwxi @ DESKTOP -LFKJ3FD MINGW64 / d / Go / src / code. local / Hello- Word 
$ Go install  // installation package 

phwxi @ DESKTOP -LFKJ3FD MINGW64 /d/Go/src/code.local/hello- Word
LS $  // At this point in view the catalog, find the executable file already gone, moved down GOPATH / bin directory 
main.go 

phwxi @ DESKTOP -LFKJ3FD MINGW64 /d/Go/src/code.local/hello- Word 
$ the Hello -word  // execution file GOPATH / hello-word.exe file in the bin 
the Hello Word  // output hello word

 

    First go to this language has completed the execution again. Congratulations, congratulations.

 

Guess you like

Origin www.cnblogs.com/zigua/p/11575503.html