Embrace Go – A modern programming language

综合技术 2016-04-07

Let’s start with the Language Trend
in Github.com. There is no doubt, Java tops the chart amongst all compiled languages. Java 1.0 was released in 1995 and we haven’t had the need for another general-purpose programming language ever since.

Go, on the other hand recently announced
its latest release. If the success stories of few early adopters
are any indication, the language has a great future ahead.

You probably read and some of you probably tried the new language from Google, rightly named so – short and sweet. The language is getting popular
by the day and for good reasons. Obviously for the mass, it is not the language of choice yet. Having said that, there is a huge community and momentum
out there we cannot afford to ignore.

In this article, we’re going to go through everything you need to know in the Go ecosystem. If you like starting from “Hello World”, Start Here
, play with Playground
, read the FAQ
and Effective Go


  • Go offers a

    for Developers to experiment and share code – gotta love that.
  • Go is
    Open Source

    and Small
    – The complete spec
    is less than 40 pages.
  • Go is a Compiled
    ( Statically-Typed
    ) language.
  • Go supports GC
    and Concurrency
  • Go is Opinionated
    – leaves no room for ambiguity and interpretation. Checkout gofmt
    , golint
    and other productive commands
  • Go is a Modern
    language – Designed for the web and teams. Supports networked and multi-core computing.
  • It is


    – It has its origins
    in the C programming language.
  • Stay up-to-date with The Weekly Newsletter
    from Go.

Into the Weeds

In this section, we’ll deep-dive into some concepts that are important in the long run:

Zero Values

Zero values are the default values for various data types.


Function is a first-class
citizen in Go. A function in Go can take varargs
, and can return multiple types. It can be anonymous
and use defer
to do things later.

Structure, Method and Receiver

Go is not Object-Oriented but gives you features that gets you close enough. You may have already guessed it by now. Yes, a Structure
in Go allows you to capture both data and behavior.

The functions associated to a Structure are called Methods
and the runtime structure object is called a Receiver
. A receiver can be a pointer or a value object.


Read this thrice. Yes, three times.

An Interface
in Go is used to define behavior ( Method
) and really any type
can implement that behavior implicitly
. There is no implements keyword. In other words a type can take multiple forms by simply associating Method
(same signature) from different Interfaces.

Pointer vs. Value

There is a subtle (but huge) difference between these two and it is important to understand that distinction. Think about a link (URL) to a web-page as a Pointer
and the content of the page as Value

Functions (or Methods) interact with each other by (a) passing type/data and (b) receiving type/data. Either way it can be a Pointer
(Pass by Reference) or a Value
(Pass by Value).

With a Pointer
you can check against

as well as change the original data .
In contrast with a Value
you cannot check against
and you cannot change the original data. So use Pointer
to mutate and Value
for immutability.

Let’s try the same example as before, but this time we’ll change the Receiver to a Value
as opposed to a Pointer

Goroutine and Channel

Goroutines are threads. Channels are a typed conduit through which you can send and receive values with the channel operator, <-. The direction of arrow determines the flow (to or from).


Vendoring in Go is what we know as dependency management. Go lets you use specific versions from third-party vendors go into a specific

folder. So here is how you can accomplish this:

  1. For Go 1.5 or less, export GO15VENDOREXPERIMENT=1
  2. Get the package you need using a dependency management tool

More here

Server Side

Server side programming has never been so easy. Yes, you can write a simple (or complicated) http server in Go with ease. No Web-Server or App-Server is needed.

Obviously you cannot run this example in Playground. So, save this example to a go file (say server.go) and run from command-line.

> go run /server.go

This will start the server at port 8080. Now try this
from your browser.

Dockerizing Go Programs

Again it is fairly simple. Use this Dockerfile and try the server we build earlier.

# Get image from https://hub.docker.com/_/golang/
 FROM golang:1.6
 # Setup Vendor (if needed)
 # Copy your code to the image.
 COPY . /go/src/github.com/my-repo/server
 # Build & Install
 RUN cd /go/src && go install github.com/my-repo/server
 # Run the app
 ENTRYPOINT /go/bin/server
 # Expose port 8080.
 EXPOSE 8080

Next Steps and Resources

责编内容by:Washington Developer Blog (源链)。感谢您的支持!


A fast, hopefully accurate, fuzzy matching library... fuzzy Go library that provides fuzzy string matching optimized for filen...
Goism – Use Go instead of Emacs Lisp inside Emacs... goism Searching for Emacs Lisp alternative? Try hacking Emacs in Go! ...
Golang教程:(一)介绍和安装 H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVd...
Transcript of Russ Cox Interview on GoTime Erik St. Martin:Welcome back, everybody, to another episode of GoTime. Today's ...
Go 学习笔记(三)- 基础数据类型 Go 语言将数据类型分为四类:基础类型、复合类型、引用类型和接口类型。本章介绍基础数据类型,包括 整型,浮点,复数,布尔,字符串,常量。 整型 包括...