go语言ctags go语言开发为什么难找工作

如何配置go语言集成开发环境 vim1、编译vimgdb
下载vimgdb73和vim73
mkdir -p ./tmp
cd tmp
tar zxvf ../vim-7.3.tar.gz
unzip ../vimgdb-for-vim7.3-master.zip
mv vimgdb-for-vim7.3-master vimgdb-for-vim7.3
patch -p0vimgdb-for-vim7.3/vim73.patch
cd vim73
安装依赖
sudo apt-get install build-essential
sudo apt-get build-dep vim-gtk
sudo apt-get install libncurses5-dev
安装
// 这里直接执行makego语言ctags的操作
make
sudo make install
安装vimgdb runtime
cd ../vimgdb-for-vim7.3
cp vimgdb_runtime~/.vim/bundle
打开vim
:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件
添加配置.vimrc
" vimgdb插件
run macros/gdb_mappings.vim
在vim中执行gdb时go语言ctags,报 “Unable to read from GDB pseudo tty” 的错误go语言ctags,因为没有安装 gdb ,所以安装gdb
sudo apt-get install gdb
2、安装vundle
set up vundle
$ git clone~/.vim/bundle/vundle
Configure Plugins
在.vimrc文件的开头添加下面的内容,有些不是必须的,可以注掉
set nocompatible" be iMproved, required
filetype off" required
" set the runtime path to include Vundle and initialize
set rtp =~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from
Plugin 'L9'
Plugin 'FuzzyFinder'
" scripts not on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin ''
" ...
filetype plugin indent on" required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" : PluginList- list configured plugins
" : PluginInstall(!)- install (update) plugins
" : PluginSearch(!) foo - search (or refresh cache first) for foo
" : PluginClean(!)- confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
Install Plugins
Launch vim and run
: PluginInstall
vimPluginInstallqall
3、官方vim-lang插件
Config vim file .vimrc,Add content bellow in bottom of the file
" 官方的插件
" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to
"reload them.
filetype off
【go语言ctags go语言开发为什么难找工作】filetype plugin indent off
set runtimepath =$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePreFmt
4、代码补全的插件gocode
配置go的环境变量,比如我的配置,GOPATH变量是必须要配置的,PATH中必须把GOPATH的bin也添加进去 , 否则没有自动提示,会提示找不到模式
export GOROOT=/usr/local/go
export GOPATH=/data/app/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Set up gocode
Then you need to get the appropriate version of the gocode, for 6g/8g/5g compiler you can do this:
go get -u github.com/nsf/gocode (-u flag for "update")
Configure vim in .vimrc file
Plugin 'nsf/gocode', {'rtp': 'vim/'}
Install Plugins
Launch vim and run
: PluginInstall
vimPluginInstallqall
写一个helloword程序,输入fmt后按C-xC-o如果能看到函数的声明展示出来 , 说明安装是正确的 。
4、代码跳转提示godef
Set up godef
go get -v code.google.com/p/rog-go/exp/cmd/godef
go install -v code.google.com/p/rog-go/exp/cmd/godef
git clone~/.vim/bundle/vim-godef
Configure vim in .vimrc file
Bundle 'dgryski/vim-godef'
Install Plugins
Launch vim and run
: PluginInstall
vimPluginInstallqall
5、代码结构提示gotags
Set up gotags
go get -u github.com/jstemmer/gotags
Put the following configuration in your vimrc:
Bundle 'majutsushi/tagbar'
nmap:TagbarToggle
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds': [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin': 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
命令模式下按在右边就会显示当前文件下的函数名,结构体名等等,光标放到相应的tag上,按回车可以快速跳到程序中的相应位置 。
再次按会关闭tag窗口 。
PS:本地的.vimrc的配置
" 插件管理器 vundle
set nocompatible" be iMproved, required
filetype off" required
" set the runtime path to include Vundle and initialize
set rtp =~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
" Plugin 'tpope/vim-fugitive'
" Plugin 'Lokaltog/vim-easymotion'
" Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from
" Plugin 'L9'
" Plugin 'FuzzyFinder'
" scripts not on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin ''
" ...
"
filetype plugin indent on" required
" To ignore plugin indent changes, instead use:
" filetype plugin on
"
" Brief help
" : PluginList- list configured plugins
" : PluginInstall(!) - install (update) plugins
" : PluginSearch(!) foo - search (or refresh cache first) for foo
" : PluginClean(!)- confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
syntax on
" ********************************************************************
" 这里省略go语言ctags了其它不相关的插件
" vimgdb插件
run macros/gdb_mappings.vim
" 官方的插件
" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to
"reload them.
filetype off
filetype plugin indent off
set runtimepath =$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePre buffer Fmt
" 代码补全的插件
Bundle 'Blackrush/vim-gocode'
" 代码跳转提示
Bundle 'dgryski/vim-godef'
" 代码结构提示
Bundle 'majutsushi/tagbar'
nmap F8 :TagbarToggleCR
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds': [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin': 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
【转】ctags使用详解ctags可以根据文件的扩展名以及文件名的形式确定该文件是何种语言 。用--list-maps查看默认情况下哪些扩展名对应哪些语言 。
查看c语言可以识别哪些语法元素 。
ctags识别很多元素,但未必全都记录,例如“函数声明”这一语法元素默认是不记录的 。可以控制ctags记录的语法元素的种类,例如,下面的命令要求记录c文件中的函数声明 , 包括各种外部和前向声明:
指定扫描那种语言的文件 。也可以指定文件的扩展名 。下面的例子要求也扫描扩展名为.inl的文件 。
有些头文件的扩展名不是.h或.hpp 。以下的命令指定.inc文件也是头文件 。
tag对语法元素的描述取决于语法元素的种类 。可以在命令行中指定显示哪些描述,以哪种格式显示等 。比如下面的命令 。
ctags在记录成员函数时,默认情况下tag的名字只包括该函数的名字,不包括类名,这样很多不同类但同名的函数所对应的tag名字都一样 。于是在VIM中使用函数名来定位时就会出现很多选择,很麻烦 。如果想用包括类名的函数全名进行定位,就得要求ctags记录全名 。
如下面的命令:
可以要求ctags不要扫描某些目录或文件,比如下面的命令:
以下命令是ctags的常用法 。
VIM 常用法 (一)
VIM 常用法 (二)
VIM 常用法 (三)
【转】ctags使用详解
Go 语言 channel 的阻塞问题Hello,大家好,又见面了!上一遍我们将 channel 相关基础以及使用场景 。这一篇,还需要再次进阶理解channel 阻塞问题 。以下创建一个chan类型为int,cap 为3 。
channel 内部其实是一个环形buf数据结构,是一种滑动窗口机制,当make完后 , 就分配在 Heap 上 。
上面,向 chan 发送一条“hello”数据:
如果 G1 发送数据超过指定cap时,会出现什么情况?
看下面实例:
以上会出现什么 , chan 缓冲区允许大小为1,如果再往chan仍数据 , 满了就会被阻塞,那么是如何实现阻塞的呢?当 chan 满时,会进入 gopark,此时 G1 进入一个 waiting 状态,然后会创建一个 sudog 对象 , 其实就sendq队列,把 200放进去 。等 buf 不满的时候,再唤醒放入buf里面 。
通过如下源码 , 你会更加清晰:
上面,从 chan 获取数据:
Go 语言核心思想:“Do not communicate by sharing memory; instead, share memory by communicating.” 你可以看看这本书名叫:Effective Go
如果接收者,接收一个空对象,也会发生什么情况?
代码示例:
也会报错如下:
上面,从 chan 取出数据,可是没有数据了 。此时,它会把 接收者 G2 阻塞掉,也是和G1发送者一样 , 也会执行 gopark 将状态改为 waiting,不一样的点就是 。
正常情况下 , 接收者G2作为取出数据是去 buf 读取数据的,但现在,buf 为空了,此时,接收者G2会将sudog导出来,因为现在G2已经被阻塞了嘛,会把G2给G,然后将t := -ch中变量t是在栈上的地址,放进去elem,也就是说,只存它的地址指针在sudog里面 。
最后,ch - 200当G1往 chan 添加200这个数据 , 正常情况是将数据添加到buf里面,然后唤醒 G2 是吧,而现在是将 G1 的添加200数据直接干到刚才G2阻塞的t这里变量里面 。
你会认为 , 这样真的可以吗?想一想,G2 本来就是已经阻塞了,然后我们直接这么干肯定没有什么毛病,而且效率提高了,不需要再次放入buf再取出 , 这个过程也是需要时间 。不然,不得往chan添加数据需要加锁、拷贝、解锁一序列操作,那肯定就慢了,我想Go语言是为了高效及内存使用率的考虑这样设计的 。(注意 , 一般都是在runtime里面完成,不然会出现象安全问题 。)
总结:
chan 类型的特点:chan 如果为空 , receiver 接收数据的时候就会阻塞等待,直到 chan 被关闭或者有新的数据到来 。有这种个机制,就可以实现 wait/notify 的设计模式 。
相关面试题:
关于go语言ctags和go语言开发为什么难找工作的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读