Introduction to Golang syntax

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

Original link: http://blog.csdn.net/cnsword/article/details/17039073

Take a look at some of the knowledge of the go language, a lot of introductory tutorials on the Go language, and a tutorial on a point in-depth analysis, this article is not an introductory tutorial just to record some of the special points in the learning Golang process, of course these points are based on individuals (C,c++,python).

  1. Gopath is the path to the Go lookup package, Goroot is the Go installation directory, Gobin is the bin directory of Go Build
  2. Go is a strongly typed language, type declaration is behind
  3. Import. "FMT" open package content, import F "FMT" package Alias
  4. var p = fmt. Println defining function references
  5. Null is nil and NOT NULL or null
  6. No enumeration in Go
  7. Const, VAR, and import can be added () to handle multiple
  8. : = cannot declare global variables, only global variables can be declared by Var
  9. Rune = Uint,byte = int8
  10. A: = [...] Int{1, 2, 20:3}
  11. Switch type is more than C, the case can be any conditional statement after omitting the matching value
  12. Each file can have an init () function that is responsible for initialization, but cannot be explicitly called
  13. typedef can use type to implement
  14. function return value is behind
  15. Func can return multiple values, or it can be returned directly, and the return value is stored in the declared variable
  16. You can add func to any struct, including built-in types, but built-in types require type TypeName A_type into a local type
  17. The indeterminate parameters are implemented by the ... type, and are evaluated by the for rangs.
  18. If else for can be without parentheses, without a while statement
  19. Semicolons can be omitted
  20. Curly braces must be in the behavior
  21. Pointers are also used. Instead of->, the pointer is written so *int that the pointer cannot be calculated
  22. New is a function used to allocate memory to pointers, only 0 not initialized, new ([] int)
  23. Make can initialize slices, Map,chan. The return is not a pointer, is an initialized instance, make ([]int, 10, 100)
  24. No class, only struct, more interface, no concept of inheritance and virtual function
  25. No var before the struct variable
  26. There is no Func before the method in interface
  27. T interface{} defines an empty interface, an empty interface can correspond to any type and can be passed by T. (type) to the appropriate type, which applies only to NULL interfaces
  28. Interface generates a binding through InterfaceName (*struct)
  29. String is a built-in type
  30. No char type, using Byte, string directly
  31. The action string can be used with the strings package
  32. The panic corresponds to the catch,defer corresponding to the try, and the recovery operation requires Revcover
  33. Chan default is blocking non-blocking he oh sad select + default to implement, or with time timeout to achieve, close (channel) Close Chan
  34. Newtimer's time.c is performed only once, and Newticker's ticker.c can be looped, rang, with a for ticker. Stop () stops the loop
  35. Mutex, etc. in the sync bag
  36. Atomic operations in the Sync/atomic package
  37. The socket is in net package, net. Listen monitoring, net. Accept, net. Dail build LINK, Conn. Close closes
  38. Httpserver with Net/http bag
  39. System calls with OS package and Syscall package
  40. CGO Package for interaction with C
  41. Go own process to see the use of communication, the current go and other language programs between the process of communication needs to use C to achieve
  42. Include <stdio.h>
    Import "C"
    Import "unsafe"
    To introduce CGO.
  43. CGO requested memory requires manual release of C.free (unsafe. Pointer (Char))
  44. cloud9 Building a Go language development environment reference: HTTP://WWW.OSCHINA.NET/TRANSLATE/GO-UP-AND-RUNNING-ON-CLOUD-9

Introduction can look at the Hao brother's: http://coolshell.cn/articles/8460.html http://coolshell.cn/articles/8489.html


PS: Because of the powerful worship of Docker, decided to explore its source code implementation, so first from go to learn.

    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.