Thursday, September 18, 2014

Go on Ubuntu


Intro

I have a strong Java background and have messed around with various other languages but never become fluent in any of them.  I guess because I didn't have to.  Perl crossed my path early in my career, then Ruby became popular and later python.
Now I'm looking at Go.  Actually it's the third time or so I'm doing that, and this time there seems to be a click.  What attracts me most is that it's fairly easy to pick up, and... it generates a single executable that can exist on its own without having to install a run-time environment.  I assume that's one of the reasons why it's so popular in the cloud community these days (yes, next to python of course).
Anyway, just a quick write-up so I don't forget how to quickly get started with Go after my next PC refresh.  There's nothing new here... just summarizing few key steps in one place.

The basics

Check the downloads section in the golang website for the latest and download it.

$ cd /tmp
$ wget --no-check-certificate https://storage.googleapis.com/golang/go1.3.1.linux-amd64.tar.gz
$ sudo tar -C /usr/local -xzf go1.3.1.linux-amd64.tar.gz

Create a workspace where you want to keep your Go projects

$ cd ~
$ mkdir -p ./workspace/go/src
$ mkdir -p ./workspace/go/bin

Add these lines to your ~/.bashrc file

export PATH=$PATH:/usr/local/go/bin
export GOROOT=$HOME/workspace/go
export PATH=$PATH:/$GOROOT/bin

Syntax highlighting and autocomplete in vi

Once there's good information on various tooling integration in /usr/local/go/misc.  I'm interested in vi.  Based on what's there in /usr/local/go/misc/readme.txt, here is the content of my /etc/vim/vimrc.local file.

" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to reload them.
if exists("g:did_load_filetypes")
  filetype off
  filetype plugin indent off
endif
set runtimepath+=/usr/local/go/misc/vim " replace $GOROOT with the output of: go env GOROOT
filetype plugin indent on
syntax on

" Reformat on exit/write of file.
autocmd FileType go autocmd BufWritePre <buffer> Fmt

" Close auto-complete window when exiting edit/insert mode.
autocmd InsertLeave * if pumvisible() == 0|pclose|endif

" Auto-complete braces
inoremap {      {}<Left>
inoremap {<CR>  {<CR>}<Esc>O
inoremap {     {
inoremap {}     {}

inoremap (      ()<Left>
inoremap (<CR>  (<CR>)<Esc>O
inoremap (     (
inoremap ()     ()

inoremap [      []<Left>
inoremap [<CR>  [<CR>]<Esc>O
inoremap [     [
inoremap []     []


And that's it.  You should now see syntax highlighting in vi.  Ctrl+x, ctrl+o opens up auto-complete.

Updated! Initial version of this post had some issues (<> tags where missing)

2 comments:

  1. AWS Training in Bangalore - Live Online & Classroom
    myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.

    IOT Training in Bangalore - Live Online & Classroom
    IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Reading data through the sensors and processing it with applications sitting in the cloud and thereafter passing the processed data to generate different kind of output is the motive of the complete curricula. Students are made to understand the type of input devices and communications among the devices in a wireless media.

    ReplyDelete
  2. Hadoop concepts, Applying modelling through R programming using Machine learning algorithms and illustrate impeccable Data Visualization by leveraging on 'R' capabilities.With companies across industries striving to bring their research and analysis (R&A) departments up to speed, the demand for qualified data scientists is rising.
    data science training in bangalore
    Big Data and Hadoop training Unlike traditional systems, Big Data and Hadoop enables multiple types of analytic workloads to run on the same data, at the same time, at massive scale on industry-standard hardware.myTectra Big Data and Hadoop training is designed to help you become a expert Hadoop developer. myTectra offers Big Data Hadoop Training in Bangalore using Class Room.
    hadoop training in bangalore
    Looking for best Machine Learning Training in Bangalore then join myTectra the leader in Machine Learning Training in Bangalore. Classroom & Online Training
    machine learning training in bangalore

    ReplyDelete