go开发环境配置

ylqmf · · 2547 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

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 }






有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:ylqmf

查看原文:go开发环境配置

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2547 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传