Giter Site home page Giter Site logo

working-with-go's Introduction

Working with Go

By Marcus Kazmierczak mkaz.com, @mkaz

Working with Go is a set of example programs in Go (golang) to get an experienced programmer familiar with Go. The Go language is often referred to as golang to help searches.

This initially started out as a full fledged book, but I found the real value was in all the examples; the text and descriptions were simple enough to include in the code as comments. Also I think the descriptions explain better in context of the code.

Install Go

Go is distributed as a binary on the major platforms, Linux, FreeBSD, Mac OS X and Windows. It is available for both 32-bit and 64-bit architectures. See the official Getting Started with Go page for downloads and more instructions.

Go is available in most Linux package environments as golang. I would recommend using at least Go 1.1 as the minimum version. So for Debian users, Go 1.0 is latest version in stable, so you may want to switch to Jessie/Unstable or install from source or alternate binary. Most Ubuntu versions have Go 1.2 in repository.

Clone and Go

Once you have Go installed, clone this repository

$ git clone https://github.com/mkaz/working-with-go

And then you can start working through the examples, in any order you want, but they are numbered and build upon themselves. I explain more in the first few and then assume you understand certain packages and structure.

To run the first program use:

$ go run 01-hello.go

If you want to build a program in Go and then run:

$ go build -o hello 01-hello.go
$ ./hello

Development Environment

Go is a light-weight, which makes it flexible for just about any set of developer tools. A full blown IDE, such as Eclipse, is rarely used. Most developers opt for their favorite text editor and the terminal to run. This is how I run on Linux, but I also split my time on a Mac.

On Mac, I use TextMate 2 which has a nice Go bundle. The bundle offers a couple of shortcuts, the two I use frequently are quick running of program ⌘R and the shortcut to reformat code ^⇧H.

If using vim, I recommend using vim-go package.

Go has two tools that can automatically format your source code to the Go coding standard, gofmt which comes with standard install and goimports which will format and auto adjust import statements as needed.

I recommend installing and configuring goimports to automatically run on save.

Install goimports:

$ go get code.google.com/p/go.tools/cmd/goimports

Setup vim to auto run goimports on save using vim-go:

let g:go_fmt_command = "goimports"

Contribute

Working with Go was started by Marcus Kazmierczak. Additions, corrections and any contributions are encouraged, please submit a pull request with your change or an issue for a bug or fix. Thanks to all the contributors!

Resources

This set of examples assumes a certain level of programming experience and is intended for someone learning the Go language and not someone new to programming altogether.

If you are starting out and want to learn how to program and choose Go as your first language, check out Learn Programming in Go

The official site has a Tour of Go which is an interactive walk through, another good introduction to the language.

License

Working with Go is licensed under a Creative Commons Attribution 4.0 International License.

working-with-go's People

Contributors

mkaz avatar larrylv avatar 0rac1e avatar siawyoung avatar mminer avatar whilei avatar svisser avatar ysagal avatar therebelrobot avatar

Watchers

James Cloos avatar CHANG-NING TSAI avatar  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.