网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

go语言集成极光的简单介绍

LiteIDE使用

LiteIDE是一款开源,跨平台的轻量级Go语言集成开发环境。操作简单,提示迅速!当然不足之处也有很多,不过除了golad之外,个人觉得比vscode,eclipse等用的更舒心一点(ps:指的是编写golang,每个人的感受不一样,勿喷)

在榆树等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站建设、做网站 网站设计制作按需定制网站,公司网站建设,企业网站建设,品牌网站设计,成都营销网站建设,成都外贸网站建设公司,榆树网站建设费用合理。

目前本人使用的LiteIDE版本号是:x36.1

其中让我感受不是很好的两个点是:1.没有自动go lint检测,需要手动。2.更改键盘映射不能捕获按键的内容,需要自己粘贴复制比方说Ctrl+C之类的上去,如果不能接受这两点需要考虑考虑。当然也有可能是我玩的不够透彻,如果有人知道,请评论告知,感激不敬:)。

那么,接下来就让我们来学习一下LiteIDE这款国人开发的编辑器的简单用法:

当我们使用一款IDE的时候,首先当然是配置一下环境,其次是快捷键,界面布局之类的了。所以,我们先来

1.配置环境:

LiteIDE给我们提供了多种的环境,目的是为了让我们能将程序编译成不同的系统所能执行的文件,例如我目前使用的是windows64系统,而且我的服务器也是windows64,那我只需要选择system的环境就可以,这样在我执行编译执行后,编译器将会自动生成windows中可执行的.exe文件。

1.1配置管理GOPATH/Modules/GOPROXY

在我们项目是需要使用GOPATH或者是Modules的时候可以点击旁边的倒三角选项,on表示使用mod,off表示不使用,auto表示根据检测,有的话使用。

底下的GOPROXY可以设置代理,毕竟我们大中华的墙不设置代理还是很给力得。设置代理得另外一种方法是点击 工具-编辑当前环境,然后在里面输入代理,我一般用得是阿里云得代理:GOPROXY=,编辑当前环境得作用其实就跟我们在命令行中输入go env然后去设置是一个道理。

2.设置快捷键

点击查看-选项-LiteApp中点击键盘,然后就可以设置快捷键了,当然目前我这个版本需要粘贴复制进去

3.使用

3.1现在我们一般都是使用mod来管理,当然首先要设置GOPATH了。

将自己本地得GOPATH添加进去就可以了,如图所示可以添加多个。

3.2编辑器自动生成go.mod文件

点击M键,会弹出下拉菜单,选择go module init将会自动生成mod文件

3.3获取第三方包

可以使用M里面得go mod tidy也可以使用G键里面得Get按钮

目前记起来得就这么多,后续想起来后再添加。::)

Go语言的支持平台

LiteIDE是一款专门为Go语言开发的跨平台轻量级集成开发环境(IDE),由QT编写。

LiteIDE主要特点: 支持主流操作系统

Windows

Linux

MacOS X Go编译环境管理和切换

管理和切换多个Go编译环境

支持Go语言交叉编译 与Go标准一致的项目管理方式

基于GOPATH的包浏览器

基于GOPATH的编译系统

基于GOPATH的Api文档检索 Go语言的编辑支持

类浏览器和大纲显示

Gocode(代码自动完成工具)的完美支持

Go语言文档查看和Api快速检索

代码表达式信息显示F1

源代码定义跳转支持F2

Gdb断点和调试支持

gofmt自动格式化支持 其他特征

支持多国语言界面显示

完全插件体系结构

支持编辑器配色方案

基于Kate的语法显示支持

基于全文的单词自动完成

支持键盘快捷键绑定方案

Markdown文档编辑支持

实时预览和同步显示

自定义CSS显示

可导出HTML和PDF文档

批量转换/合并为HTML/PDF文档 Sublime Text 2(以下简称Sublime)+ GoSublime + gocode + MarGo的组合。

其优点有: 自动化提示代码。 保存的时候自动格式化代码,让您编写的代码更加美观,符合Go的标准。 支持项目管理 支持语法高亮 熟悉Java的读者应该对于idea不陌生,idea是通过一个插件来支持go语言的高亮语法,代码提示和重构实现。

如何配置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语言框架gin之集成swagger

1.先安装Go对应的开源Swagger相关的库

go get github.com/swaggo/swag/cmd/swag

go get github.com/swaggo/gin-swagger

go get github.com/swaggo/files

go get github.com/alecthomas/template

2.验证是否安装成功:swag -v

3.针对接口写入注解

// @Summary 获取多个标签

// @Tags 标签

// @Produce  json

// @Param name query string false "标签名称" maxlength(100)

// @Param state query int false "状态" Enums(0, 1) default(1)

// @Param page query int false "页码"

// @Param page_size query int false "每页数量"

// @Success 200 {object} model.TagSwagger "成功"

// @Failure 400 {object} errcode.Error "请求错误"

// @Failure 500 {object} errcode.Error "内部错误"

// @Router /api/v1/tags [get]

func (t Tag) List(c *gin.Context) {

}

// @Summary 新增标签

// @Tags 标签

// @Produce  json

// @Param name body string true "标签名称" minlength(3) maxlength(100)

// @Param state body int false "状态" Enums(0, 1) default(1)

// @Param created_by body string false "创建者" minlength(3) maxlength(100)

// @Success 200 {object} model.Tag "成功"

// @Failure 400 {object} errcode.Error "请求错误"

// @Failure 500 {object} errcode.Error "内部错误"

// @Router /api/v1/tags [post]

func (t Tag) Create(c *gin.Context) {

}

// @Summary 更新标签

// @Tags 标签

// @Produce  json

// @Param id path int true "标签ID"

// @Param name body string false "标签名称" minlength(3) maxlength(100)

// @Param state body int false "状态 (0为未删除、1为已删除)" Enums(0, 1) default(1)

// @Param modified_by body string true "修改者" minlength(3) maxlength(100)

// @Success 200 {array} model.Tag "成功"

// @Failure 400 {object} errcode.Error "请求错误"

// @Failure 500 {object} errcode.Error "内部错误"

// @Router /api/v1/tags/{id} [put]

func (t Tag) Update(c *gin.Context) {

}

4.针对整个项目进行注解,直接在main方法写入如下注解

//@title 项目名称

//@version 1.0

//@description 这里是描述

func main() {

5.生成执行 swag init

这时会在我项目的docs文件夹下面生成docs.go、swagger.json、swagger.yaml三个文件

6.要在routers中进行默认初始化和注册对应的路由:

r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

同时要引用 _"blog-service/docs" ,不然会报错

7.查看接口文档 :

8.ok,完成

Go语言的优势有哪些

1. 部署简单

Go

编译生成的是一个静态可执行文件,除了glibc外没有其他外部依赖。这让部署变得异常方便:目标机器上只需要一个基础的系统和必要的管理、监控工具,完全不需要操心应用所需的各种包、库的依赖关系,大大减轻了维护的负担。

2. 并发性好

Goroutine和channel使得编写高并发的服务端软件变得相当容易,很多情况下完全不需要考虑锁机制以及由此带来的各种问题。单个Go应用也能有效的利用多个CPU核,并行执行的性能好。

3. 良好的语言设计

从学术的角度讲Go语言其实非常平庸,不支持许多高级的语言特性;但从工程的角度讲,Go的设计是非常优秀的:规范足够简单灵活,有其他语言基础的程序员都能迅速上手。更重要的是

Go 自带完善的工具链,大大提高了团队协作的一致性。

4. 执行性能好

虽然不如 C 和 Java,但相比于其他编程语言,其执行性能还是很好的,适合编写一些瓶颈业务,内存占用也非常省。


分享文章:go语言集成极光的简单介绍
URL链接:http://bjjierui.cn/article/dodicsg.html

其他资讯