go開發環境配置

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。remove golang
sudo apt-get autoremove golang
download golang 1.2.2
wget http://golang.org/dl/go1.2.2.linux-amd64.tar.gz
tar zxf go1.2.2.linux-amd64.tar.gz
mv go /home/work/app/go1.2.2


vim /home/tudou/.bashrc
export GOROOT=/home/work/app/go1.2.2
export PATH=$PATH:$GOROOT/bin


sudo apt-get autoremove vim
sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev ruby-dev mercurial
wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
./configure --prefix=/home/work/app/vim74 && sudo make -j 6 VIMRUNTIMEDIR=/home/work/app/vim74/share/vim/vim74 && sudo make install


vim /home/tudou/.bashrc
export PATH=$PATH:/home/work/app/vim74/bin

export GOPATH=/home/go

export GOBIN=$GOPATH/bin

export PATH=$PATH:$GOBIN


go get -u github.com/nsf/gocode

sudo mv /home/tudou/.vim/autoload/gocomplete.vim /home/work/app/vim74/share/vim/vim74/autoload

sudo mv /home/tudou/.vim/ftplugin/go /home/work/app/vim74/share/vim/vim74/ftplugin


cd 

/home/work/app/vim74/share/vim/vim74/plugin

wget http://www.vim.org/scripts/download_script.php?src_id=11533


vim /home/tudou/.vimrc

set enc=utf-8

set nobackup

set ignorecase

colo desert

"" 行號

set nu

"" 自動縮排

set autoindent

"" 設定軟定位字元寬度為4

set tabstop=4

set softtabstop=4

"" 設定縮排的空格書為4

set shiftwidth=4

set backspace=indent,eol,start

set completeopt=longest,menu

set rtp+=$GOROOT/misc/vim

filetype plugin indent on

syntax on

let g:SuperTabRetainCompletionType=2

let g:SuperTabDefaultCompletionType="<C-X><C-O>"



package main  2   3 import (  4     "fmt"  5     "database/sql"  6     _"github.com/go-sql-driver/mysql"  7     "strconv"  8     "math/rand"  9     "time" 10 ) 11  12 var( 13     a = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") 14     defaultRand = rand.New(rand.NewSource(time.Now().UnixNano())) 15     l=len(a)           16 )                      17                        18 func ranKey(count uint) string{ 19     var result []byte 20     for i:=uint(0); i<count; i++{ 21         result = append(result,a[defaultRand.Intn(l)]) 22     }    23     result[defaultRand.Intn(5)+(int(count)/2)]=byte(95) 24     return string(result) 25 } 26  27 func main(){ 28     fmt.Printf("hell world\n") 29     db,err := sql.Open("mysql", "tudou_w:chuliang@tcp(127.0.0.1:3306)/xm_tudou?charset=utf8") 30     if err != nil { 31         panic(err.Error()) 32         fmt.Println(err.Error()) 33     }else{ 34         fmt.Println("db is open") 35     } 36     defer db.Close() 37      38     rows,err := db.Query("select id,t_name from test_a") 39     if err != nil { 40         panic(err.Error()) 41         fmt.Println(err.Error()) 42     }else{ 43         fmt.Println("rows is open") 44     } 45     defer rows.Close() 46     var id int 47     var tname string 48     for rows.Next(){ 49         rerr := rows.Scan(&id,&tname) 50         if rerr == nil{ 51             fmt.Println("id:"+strconv.Itoa(id)+"    name:"+tname) 52         } 53     } 54     db.Close() 55      56     fmt.Println(ranKey(32)) 57 }





相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.