Introduction to Go
for JavaScript Developers
Scott Ernst
/sernst/GoIntro
My Perspective
I'm not an expert Gopher
- I write Go for production work
- Still learning
Plan: Comparative Examples
- Syntax
- Hello World
- Existing Data Types
- Custom Data Types
- Reading JSON
- Concurrency
- Simple HTTP Server
(
vs
)
Not a battle for supremacy
!
Core Packages Only
Focusing on the Fundamentals
$ go get ...
$ npm install ...
require('path')
import "path"
Go is like C and Python had a kid
Good Looks
Pleasant Demeanor
Confidence
Athletic Ability
http://golang-for-python-programmers.readthedocs.org/en/latest/intro.html
"C for the 21st Century"
A Melting Pot of "Good Ideas"
• Statically typed
• Compiled
• C/Java syntax family
• Functional (closures & first class functions)
• Pointers (simplified compared to C)
• Concurrency
Go In A Nutshell
And Now
The Examples
/sernst/GoIntro
Hello World
Example:
-
Define functions
-
Pass variables
-
Print to console
-
Explicit type conversions
Variables & Functions
Example:
-
Define variables
-
Uninitialized "zero" values
-
Functions that return values
-
Closures
-
Functions as variables
Arrays & Slices
Example:
-
Define and populate arrays
-
Passing by copy versus by reference
-
Go slices like JavaScript arrays
Maps (Objects)
Example:
-
Define and populate maps/objects
-
Modifying by reference
Pointers
Example:
- * dereferencing operator
- & pointer creation operator
- Allow passing by reference
- Pointers share memory
Read JSON File
Example:
- Error handling
- File system utilities
Simple Web Server
Example:
- http package
- sending JSON data
Introduction to Go for JavaScript Developers
By sernst
Introduction to Go for JavaScript Developers
An introduction to the Go programming language for developers familiar with Node.js. Learn Golang with side-by-side examples in Go and Node.js.
- 1,499