Giter Site home page Giter Site logo

go-notes's Introduction

GO Notes

Resources

Basics

  • Go is a statically typed, compiled programming language.
  • All source files in a directory must share the same package name.
  • When a package is imported, only entities whose names start with a capital letter can be used / accessed.
  • Variables can be defined by explicitly specifying a type.
  • You can also use an initializer, and the compiler will assign the variable type to match the type of the initializer.
  • Constants are defined using the const.
  • Go functions accept zero or more parameters.
    • Parameters must be explicitly typed, there is no type inference.
  • Values are returned from functions using the return keyword.

Comments

  • Go supports two types of comments:
    • Single line comments are preceded by //.
    • Multiline comments are inserted between /* and */.
  • They are used by the godoc command.
  • A documentation comment should be a complete sentence that starts with the name of the thing being described and ends with a period.
  • Comments should precede packages as well as exported identifiers.

Numbers

  • Go contains basic numeric types that can represent sets of either integer or floating-point values.
    • uint: the set of all unsigned integers.
    • int: the set of all integers.
    • float: the set of all floating-point numbers
    • complex: the set of all complex numbers.
    • byte: alias for uint8.
    • rune: alias for int32.

Arithmetic Operators

  • Arithmetic operations on different types in Go gives an error.
  • You can convert the type of a variable using a type conversion.
  • It's possible to use x++ or x--.

Booleans

  • Booleans in Go are represented by the bool type.
  • A bool is either true or false.
  • Go supports three boolean operators: ! (NOT), && (AND), and || (OR).
  • The preference order is !, &&, and ||.

Iteration

  • Go has only one looping construct: the for loop.
  • The for loop has three components: the initialization, the condition, and the post statement.
  • In Go there are no ( ) surrounding the three components of the for statement.
  • The braces { } are always required.

Strings

  • A string in Go is an immutable sequence of bytes.
  • A string literal is defined between double quotes.
  • Strings can be concatenated via the + operator.
  • Special characters need to be escaped with a leading backslash.

Conditionals

  • Conditionals in Go are similar to conditionals in other languages.
  • There are if, else if, and else statements.
  • If statements can also include a short initialization statement.

Packages

go-notes's People

Contributors

pmareke avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.