GithubHelp home page GithubHelp logo

go-lang-cheat-sheet's Introduction

Comments

// Line Comment /* Block Comment */

Data Types

bool (true / false)

uint8 (255 max) uint16 (65,535 max) uint32 (4.2 billion max) uint64 (18,446 trillion max) uint alias for uint32 uintptr byte aslias for uint8

int8 (127 max) int16 (32767 max) int32 (2.1 billion max) int64 (9,223 trillion max) int alias for int32 rune alias for int32

float32 ex: 0.123456 float64 ex: 0.1e-5

complex64 ex: 12.34i complex128 ex: 12.1e-5i

string

NaN Array Slice Struct Map func

#functions

func add(x int, y int) int { return x + y }

#unknown

<<

unbounded slices??

const ( Big = 1<<100 Small = Big>>99 )

Loops

// for i := 0; i < 10; i++ { fmt.Println($i) }

// Equiv i := 0; for i < 10 { fmt.Println($i) i++ }

// For Each Loops pow = []int{1, 2, 4, 8, 16, 32, 64, 128, 256} for i, v := range pow { fmt.Printf("%d: %d\n", i, v) }

// Switches switch i { case 0: // do something default: f(): // do something else }

Operators and assignment

= := += -= ++

  • Concat or addition, depending on context & Assign by reference (pointer)

Checkings

<

Common

fmt.Printf (debug) fmt.Prinln (print a line with values)

#maps m[key] = elem insert of update elem = m[key] retreive an element delete(m, key) delete an element elem, ok = m[key] test that a key is present

m := map[string]int { "item1" : 123, "item2" : 456, }

#slices p := []int{2, 3, 5, 7, 11, 13} sliced := p[2:4]

go-lang-cheat-sheet's People

Contributors

phayes avatar

Watchers

James Cloos avatar FatFat 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.