新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

go语言gdb指令 go语言程序

Goe code在哪

GO语言中。Goecode是属于GO语言的指令,在GO语言中是表现最好的IDE,需要用户下载专门的GO语言编写软件后进入文件根目录即可找到Goecode指令。

网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了醴陵免费建站欢迎大家使用!

GO语言(十一):开始使用多模块工作区

本教程介绍 Go 中多模块工作区的基础知识。使用多模块工作区,您可以告诉 Go 命令您正在同时在多个模块中编写代码,并轻松地在这些模块中构建和运行代码。

在本教程中,您将在共享的多模块工作区中创建两个模块,对这些模块进行更改,并在构建中查看这些更改的结果。

本教程需要 go1.18 或更高版本。使用go.dev/dl中的链接确保您已在 Go 1.18 或更高版本中安装了 Go 。

首先,为您要编写的代码创建一个模块。

1、打开命令提示符并切换到您的主目录。

在 Linux 或 Mac 上:

在 Windows 上:

2、在命令提示符下,为您的代码创建一个名为工作区的目录。

3、初始化模块

我们的示例将创建一个hello依赖于 golang.org/x/example 模块的新模块。

创建你好模块:

使用 . 添加对 golang.org/x/example 模块的依赖项go get。

在 hello 目录下创建 hello.go,内容如下:

现在,运行 hello 程序:

在这一步中,我们将创建一个go.work文件来指定模块的工作区。

在workspace目录中,运行:

该go work init命令告诉为包含目录中模块的工作空间go创建一个文件 。go.work./hello

该go命令生成一个go.work如下所示的文件:

该go.work文件的语法与go.mod相同。

该go指令告诉 Go 应该使用哪个版本的 Go 来解释文件。它类似于文件中的go指令go.mod 。

该use指令告诉 Go在进行构建时hello目录中的模块应该是主模块。

所以在模块的任何子目录中workspace都会被激活。

2、运行工作区目录下的程序

在workspace目录中,运行:

Go 命令包括工作区中的所有模块作为主模块。这允许我们在模块中引用一个包,即使在模块之外。在模块或工作区之外运行go run命令会导致错误,因为该go命令不知道要使用哪些模块。

接下来,我们将golang.org/x/example模块的本地副本添加到工作区。然后,我们将向stringutil包中添加一个新函数,我们可以使用它来代替Reverse.

在这一步中,我们将下载包含该模块的 Git 存储库的副本golang.org/x/example,将其添加到工作区,然后向其中添加一个我们将从 hello 程序中使用的新函数。

1、克隆存储库

在工作区目录中,运行git命令来克隆存储库:

2、将模块添加到工作区

该go work use命令将一个新模块添加到 go.work 文件中。它现在看起来像这样:

该模块现在包括example.com/hello模块和 `golang.org/x/example 模块。

这将允许我们使用我们将在模块副本中编写的新代码,而不是使用命令stringutil下载的模块缓存中的模块版本。

3、添加新功能。

我们将向golang.org/x/example/stringutil包中添加一个新函数以将字符串大写。

将新文件夹添加到workspace/example/stringutil包含以下内容的目录:

4、修改hello程序以使用该功能。

修改workspace/hello/hello.go的内容以包含以下内容:

从工作区目录,运行

Go 命令在go.work文件指定的hello目录中查找命令行中指定的example.com/hello模块 ,同样使用go.work文件解析导入golang.org/x/example。

go.work可以用来代替添加replace 指令以跨多个模块工作。

由于这两个模块在同一个工作区中,因此很容易在一个模块中进行更改并在另一个模块中使用它。

现在,要正确发布这些模块,我们需要发布golang.org/x/example 模块,例如在v0.1.0. 这通常通过在模块的版本控制存储库上标记提交来完成。发布完成后,我们可以增加对 golang.org/x/example模块的要求hello/go.mod:

这样,该go命令可以正确解析工作区之外的模块。

eclipse配置go?

1.下载go的windows下的安装包:

也可以下载源代码,用MinGW编译。先配置好MinGW的环境,再运行all.bat即可。

MingW:

2.下载gocode,用于go的补全提示:

gocode 的github地址:

要安装git,在windows下,通常用msysgit。

再在cmd下安装:

go get -u github.com/nsf/gocode

也可以下载代码,直接用go build来编译,会生成gocode.exe。

3.在eclipse中安装插件:

4.配置插件:

(1).配置go的编译器

(2).配置gocode(可选),这里我用的是eclipse插件自带的gocode。

(3).配置gdb,做调试用(可选)

如果安装了MingW,可以在安装目录下找到gdb。

5.测试是否成功

新建一个go工程,再建立一个hello.go。如下图:

gdb调试如下(要在console中用输入命令来调试):

6.其它

2012年3月31日:

目前这个eclipse插件,只能把代码放在cmd包中才能运行。

貌似现在流行的是Sublime Text2 + gocode。Sublime Text也的确比较好用。

======================

Eclipse平台下配置Go语言开发环境(Win7)

《Go语言编程》中写到:“从功能和易用性等方面考虑, Eclipse+GoEclipse、LiteIDE这两个环境在所有IDE里面是表现最好的”,所以笔者打算采用Eclipse+GoEclipse开发环境。

Eclipse平台下配置Go语言开发环境步骤:

1、安装JDK和Eclipse

建议JDK1.6及以上版本。Eclipse3.6及以上版本。

2、安装GoEclipse插件

在Eclipse中点击菜单“Help”-》“Install New Software”打开如下对话框,添加go插件的安装地址:,

按提示一步一步操作即可,下载时可能会遇到网络问题,可使用goagent或其他代理。

3、安装并配置Go的编译器

下载地址:

下载时请注意版本,应选择windows-386的版本。

安装完后重启Eclipse,并通过菜单项“Window”-》“Preferences”-》“Go”打开Go语言的配置选项框。如下图:

选择Go的安装路径即可,如笔者的安装路径是F:\Work\Go

4、配置调试器(可选)

需要先安装MinGW,下载地址:

安装完之后,通过菜单项“Window”-》“Preferences”-》“Go”-》“Debugger”打开调试器的配置选项框。

将GDB路径配置为:MinGW安装目录下的gdb.exe文件即可。

5、配置代码自动补全(可选)

需要配置gocode,可使用goEclipse插件自带的版本,也可以自己下载:

笔者使用的是goEclipse插件自带的版本,配置方式如下:

通过菜单项“Window”-》“Preferences”-》“Go”-》“Gocode”打开配置选项框。

将Gocode的路径配置为:goEclipse的安装路径下的gocode.exe文件,如

F:\Work\eclipse\plugins\com.googlecode.goclipse.gocode_0.7.6.v450\tools\windows_386\gocode.exe

6、配置支持Import远程包(可选)

为了支持Import远程包,最好装个gowin-env。下载地址:。 如果下的是压缩包,请把它解压到C盘。例如,C:\gowin-env。里面有个Console.bat是以后使用go get的环境。举例:有个文件a.go,里面import (

"fmt"

"github.com/astaxie/beedb"

_ "github.com/ziutek/mymysql/godrv"

为了编译该a.go文件,需要启动Console.bat,然后在该命令行窗口,进入c:\go\src目录下,执行go getgithub.com/astaxie/beedb

Go get github.com/ziutek/mymysql/godrv .

Go 会自动下载该远程包并编译和安装这些包。

7、go install: no install location for directory *** outside GOPATH错误的处理

由于每一个Go程序都必须包含一个main包以及一个main()函数,因此如果没有main包就会导致上述错误。

What Doesn't Kill Me Makes Me Stronger

如何配置go语言集成开发环境 vim

1、编译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 -p0 vimgdb-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

安装

// 这里直接执行make的操作

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时,报 “Unable to read from GDB pseudo tty” 的错误,因为没有安装 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

vim +PluginInstall +qall

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

filetype plugin indent off

set runtimepath+=$GOROOT/misc/vim

filetype plugin indent on

syntax on

autocmd FileType go autocmd BufWritePre Fmt

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

vim +PluginInstall +qall

写一个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

vim +PluginInstall +qall

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

" ********************************************************************

" 这里省略了其它不相关的插件

" 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'

\ }


文章题目:go语言gdb指令 go语言程序
文章路径:http://www.wjwzjz.com/article/dojhioo.html
在线咨询
服务热线
服务热线:028-86922220
TOP