Go语言中文网 为您找到相关结果 85

golang flag 解析入参

首先一个例子: package main import ( "fmt" "flag" ) func main(){ data_path := flag.String("D","/home/manu/sample/","DB data path") log_file := flag.String("l","/home/manu/sample.log","log file") nowait_flag :=flag.Bool("W",false,"do not wait until operation completes") flag.Parse() var cmd string = flag.Arg(0); fmt.Printf("action : %s\n",cmd) fmt.Printf("...阅读全文

博文 2015-08-25 21:00:01 冷絮

go语言:flag的使用

go语言flag的使用 package main import ( "flag" "fmt" ) var music_file *string = flag.String("file", "musicfile", "Use -file ") func main() { flag.Parse() fmt.Println(*music_file) } 例如文件为flagTest.go go run flagTest.go -file "../music/sun.mp3" 即可指定file参数的值。 如果直接使用go run flagTest.go -file则会提示你-file的使用说明.-file="musicfile": Use -file 如...阅读全文

博文 2014-10-21 23:00:00 x369201170

golang中的string

一个字符串是一个不可改变的字节序列。字符串可以包含任意的数据,但是通常是用来包含人类可读的文本。 len()返回字符串字节数目(不是rune数)。 通过索引可以访问某个字节值,索引大于等于0小于len(str)。越界会panic。索引不是不是对应的字符而是对应的字节,因为有有非ASCII的UTF8字符有多个字节。 s := "hello, world" fmt.Println(len(s)) // "12" 英文字符占一个字节 fmt.Println(s[0], s[7]) // "104 119" ('h' and 'w') 字符串截取与链接 fmt.Println(s[:5]) // "hello" fmt.Println(s[7:]) // "world" fmt.Println(s[...阅读全文

博文 2019-07-02 23:32:41 XITEHIP

Intellij IDEA ,按Ctrl+左键,不能进入类或方法的【解决办法】,提示Cannot find declaration to go to

Intellij IDEA ,按Ctrl+左键,不能进入类或方法的【解决办法】,提示Cannot find declaration to go to 2017年8月4日 朱宏亮%1 $ S Intellij IDEA ,按Ctrl+左键,不能进入类或方法的【解决办法】,提示Cannot find declaration to go to 如图,,按住Ctrl+鼠标单击的时候,系统提示Cannot find declaration to go to。 原因:导入项目的时候使用的是Open而不是Import Project。 解决方法:关闭当前项目,如图点击Import PrOject,导入项目即可 标签:Cannot find declaration to go to、Intelli...阅读全文

博文 2017-12-04 06:01:01 zy_zhengyang

mac 下如何安装godoc?

使用的环境mac 10.9.3, 使用brew install go go version go version go1.3.3 darwin/amd64, 安装完没有godoc 然后,安装go get code.google.com/p/go.tools/cmd/godoc 提示: ```package code.google.com/p/go.tools/cmd/godoc imports golang.rog/x/tools/blog: unrecognized import path "golang.org/x/tools/blog" package code.google.com/p/go.tools/cmd/godoc imports golang...阅读全文

GO语言基础环境搭建以及HelloWorld

Go语言(golang)是Google推出的一种全新的编程语言。关于其详细介绍请自行百度,直接介绍基础开发环境配置。 1、安装GO安装包。 官方下载地址应该是 https://code.google.com/p/go/downloads/list 不过如果你在被墙了的话应该是无法访问该地址,这里是用的版本是go1.3.windows-386.msi,可直接百度文件名下载安装即可。 2、配置环境变量。 这里同Java环境变量配置很相似,配置项稍多。具体如下: 新建 变量名:GOBIN 变量值 :D:\Program Files (x86)\Go\bin 新建 变量名:GOARCH 变量值:386 新建 变量名:GOOS 变量值:windows 新建 变量名: GOROOT 变量值:c:\go ...阅读全文

博文 2015-05-27 16:00:00 PrinceTerence

解决golang https请求提示x509: certificate signed by unknown authority

Golang https请求发生错误 ` x509: certificate signed by unknown authority ` ### 重点: 引入"crypto/tls" ````golang import ( "crypto/tls" "log" "net/http" ) func get(url string, headers map[string]string) *http.Response { tr := &http.Transport{ //解决x509: certificate signed by unknown authority TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } client := ...阅读全文

博文 2018-01-17 10:10:04 hfyarvin

golang windows环境下的配置安装

使用MSI文件,然后按照提示安装围棋工具。默认情况下,安装程序使用转到分布在c:\Go。安装程序应设置c:\Go\bin目录到Windows PATH环境变量。重新启动任何打开命令提示符,以使更改生效。 1.在官网 Go:https://golang.org/dl/ 下载 MSI文件,不过现在这个网站可能被墙了,所以如果不想使用最新版本可以不去翻墙,百度网盘里有很多安装文件 2.安装选择安装路径,安装过程中会自动配置环境变量 3.验证是否安装成功 安装后在控制台输入如下命令表示成功: 4.验证安装 创建一个名为test.go的go文件D:\goproject File: test.go import "fmt" func main() { fmt.Println("Hello, World!...阅读全文

sqlite连接(windows 7)

请问在windows下连接sqlite应该怎么做? 试了mattn/go-sqlite3..提示 # command-line-arguments D:\GOPATH\pkg\windows_386/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text) : __divdi3: not defined D:\GOPATH\pkg\windows_386/github.com/mattn/go-sqlite3.a(sqlite3_windows.)(.text) : __moddi3: not defined D:\GOPATH\pkg\windows_386/github.com/mattn/go-sq...阅读全文

golang坑

1.新建文件后再删除失败,提示文件正在被另一程序使用中(The process cannot access the file because it is being used by another process.) func main() { NewConfigIni() DeleteConfigTemp() } func DeleteConfigTemp() { path := "time.ini" err := os.Remove(path) //如果文件不存在时执行会报错 fmt.Println("删除ini err:", err) } func NewConfigIni() { os.Create("time.ini") } 修正: func NewConfigIni() { f,...阅读全文

博文 2014-10-04 19:27:22 陈好

Go学习笔记:flag库的使用

flag支持的语言格式如下: -flag // bool类型only -flag=x -flag x //not bool 类型 很自然,这个flag能够解析 -D /home/manu/DB_data,对应第二种类型,我们知道pg_ctl有-W选项,属于一个开关性质的bool型的选项 -W do not wait until operation completes 自然对应第一种类型,也可以解析。第二种也很好理解。 下面我给出一个例子,简单的解析这个pg_ctl的命令: manu@manu-hacks:~/code/go/self$ cat pg_ctl_parse.go package main import ( "fmt" "flag" ) func main(){ data_path...阅读全文

博文 2015-12-22 22:00:01 qdx411324962

Golang 安装和配置

1. Windows下的安装和基本配置 打开官网 https://golang.org/ ,点击红框中的 Download Go 图:Golang 主页 进入到下载页面,向下滚动到最新版本详细的下载列表。 图:下载页面 我先介绍Windows的安装:总共有红框中的四个文件。386 代表你的操作系统是32位使用这个,amd64 代表64位操作系统使用的(AMD首先生产了64位cpu,所以一般称为amd64)。(在 我的电脑 (windows10叫此电脑,英文版叫This PC),右键选择属性,里面就可以看见,如下图:) 操作系统位数查看 如图,我的操作系统是64位。 而 zip 和msi的区别,就是安装版和便携版(绿色版)的区别。zip解压就能使用,而msi需要点下一步,下一步,安装好,就可以...阅读全文

博文 2017-07-15 06:06:29 naturelover5

Golang 解决已安装guru,依然提示"could not find 'guru'. Run :GoInstallBinaries to fix it"的问题

【问题】已安装guru及其依赖,当“vim xxx.go”时,按下“ctrl +[”提示“could not find 'guru'. Run :GoInstallBinaries to fix it” 【解决】可按如下步骤操作: $ go get golang.org/x/tools/cmd/guru $ go build golang.org/x/tools/cmd/guru $ mv guru $(go env GOROOT)/bi...阅读全文

博文 2017-04-17 06:00:36 吃一堑消化不良

Go 使用swig使用C++11代码的问题

请问下有没有使用swig调用c++11代码的成功案例? 我这边按照 http://www.swig.org/Doc3.0/Go.html 一文的提示操作,在调用 go install 时会出现 “This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.” 的提示。 不知道这个问题要如何解决呢...阅读全文

Gogland EAP 4发布

上班第一天,就收到Gogland EAP 4在2月1日的升级提示,接口实现的改进非常明显,注意快捷键是“command+I”(而不是官网说的“ctrl+0”)感觉不错: ![gogland 163.12024.20.png](http://studygolang.qiniudn.com/170203/1430b0baadc377efd72a8d768af2b8b5.png) 除了按照提示升级,还可以直接官网下载: + [Mac OS X](http://download.jetbrains.com/go/gogland-163.12024.20.dmg ) + [Windows](http://download.jetbrains.com/go/gogland-163.12024...阅读全文

FreeBSD go get 安装 iconv-go提示无 iconv.h 文件

go get github.com/djimenez/iconv-go 提示:../../github.com/djimenez/iconv-go/converter.go:8:19: error: iconv.h: No such file or directory 复制iconv.h至系统include目录,创建 libiconv 软连接,如果没有libiconv, 先执行 pkg install libiconv cp /usr/local/include/iconv.h /usr/include/ ln -s /usr/local/lib/libiconv.so.3 /usr/lib/libiconv.s...阅读全文

博文 2014-10-04 19:26:25 JSK

go在windows下连接oracle数据库

一、系统环境 1. win7 64位 2. go 1.8 3. oracle SDK版本 12.1 4. mingw64位 5. go-oci8 二、安装步骤 1. 安装go1.8,参照网上的教程 2. 下载oracle 的sdk和运行库 3. 安装mingw64和pkg-config.exe,将pkg-config拷贝到mingw64的bin目录,pkg-config是编译go-oci8的时候需要用到的。 三、配置 1. 修改oci8.pc文件,存入mingw64的lib/pkgconfig目录 2. 修改PKG_CONFIG_PATH为E:\mingw-w64\mingw-w64\x86_64-4.9.2-posix-seh-rt_v3-r...阅读全文

Mac版Eclipse 编写go 提示"Resource donesnt have a corresponding Go paceage.”

刚接触go的小白.请大神给指点一下.提示"Resource donesnt have a corresponding Go paceage" ![145FDFF8-3919-4AAB-8192-FA03C1A4362D.png](http://studygolang.qiniudn.com/170215/ef64b87d0187ace500b32cc5bbfec746.png)![931CF5D3-202C-4EA9-A8C3-48ED591BD54E.png](http://studygolang.qiniudn.com/170215/ecf9701325a04854c3d17318fdd2c15c.png...阅读全文

windows安装go-sqlite3失败,提示找不到gcc

windows安装go-sqlite3失败,提示找不到gcc go get github.com/mattn/go-sqlite3时失败,提示exec: “gcc”: executable file not found in %PATH%,是因为没有安装gcc。 去http://tdm-gcc.tdragon.net/download下载一个,32位windows下载 tdm-gcc-4.8.1-3.exe,64位下载 tdm64-gcc-4.8.1-3.exe 注:为保证能够成功编译,建议安装所有的包。 $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split(...阅读全文

博文 2016-09-19 05:00:02 u013474104

gin - validator 参数校验

最近自己也在用gin框架做项目,然后在群里也有人问关于,参数验证的问题,今天有时间正好研究一下。 gin版本 : v1.6.2 基本验证 定义参数绑定结构体account_io.go package controller type Register struct { Mobile uint `json:"mobile" binding:"required"` Password string `json:"password" binding:"required,gte=6"` } 将相求参数与结构体绑定account.go package controller import ( "fmt" "mid-anding/pkg" "github.com/gin-gonic/gin" ) type A...阅读全文

博文 2020-05-01 17:32:40 shangyin

revel提示program too big to fit in memory

在使用revel new xxx新建项目的时候一直提示这个,内存是肯定够用的。 系统是win8.1 32位64位均不行 求解 = = PS:在编译revel的时候提示安装了NTVDM, (NT Virtual DOS Machine,Windows 16位虚拟机的一部分,该进程用于使16位的进程能够运行在32位的系统环境下),不知是不是误判定程序为16程序了...阅读全文

golang in windows emacs hightlight howto

windows emacs 语法高亮 1) .find ".emacs" file 打开emacs,然后在Options下随便挑个选项,点Save Options,看到下面的提示 Wrote [path]....".emacs" 2).copy el file copy %goroot%/misc/emacs/*.el [path]/.emacs.d/ 3).modify .emacs file add (setq load-path (cons (expand-file-name "~/.emacs.d/") load-path)) (require 'go-mode-load...阅读全文

博文 2014-10-04 19:26:08 idcenter

windows下安装golang使用protobuf

一、安装protobuf1.去github下载protobuf,网址是https://github.com/google/protobuf,按照readme的步骤来编译安装。2.确保你的电脑上安装了go的编译器以及相关工具,具体参考go编译器的安装方式,安装好了,所需的工具就有了3.安装git工具4.在命令提示行中输入go get github.com/golang/protobuf/protoc-gen-go,稍等片刻会生成protoc-gen-go.exe等相关工具,将该文件夹添加到环境变量Path中5.安装protobuf,输入go get github.com/golang/protobuf/proto6.找到protoc.exe将其添加到环境变量二、测试1.新建test.proto...阅读全文

博文 2018-10-13 12:34:39 大啸

go notepad++ 运行 命令

Notepad++有自己的环境变量 变量名称 含义 FULL_CURRENT_PATH 文件路径名称 CURRENT_DIRECTORY 文件目录 FILE_NAME 文件全名称 NAME_PART 文件名称 EXT_PART 文件扩展名 go语言的 cmd /c 8g $(FULL_CURRENT_PATH) & 8l -o $(CURRENT_DIRECTORY)\$(NAME_PART).exe $(CURRENT_DIRECTORY)\$(NAME_PART).8 & $(CURRENT_DIRECTORY)\$(NAME_PART) & rm -f $(CURRENT_DIRECTORY)\$(NAME_PART).8 & pause 直接 cmd /c go.exe run $(...阅读全文

博文 2014-10-04 19:26:16 悠米海

安装golang tour,提示错误

试图在自己机器上安装golang tour,出现了问题。Couldn't find tour files: could not find go-tour content; check $GOROOT and $GOPATH请教一下各位前辈如何解决。上网找了几天,没有找到答案。谢谢先~系统环境是这样的:export GOROOT=/usr/local/goexport GOPATH=/usr/local/GOPATHexport PATH=$PATH:$GOROOT/bin:$GOPATH/binexport GO111MODULE=on安装步骤:~# go get golang.org/x/tourgo: finding golang.org/x/tour latestgo: finding...阅读全文

博文 2019-06-17 16:29:24 keman1984

结构体成员赋值问题,比较疑惑。

```go package main import ( "fmt" ) type stu struct { a int64 b int64 } func Add(a, b int64) (int64, error) { return a + b, nil } func (p *stu) Add(a, b int64) (int64, error) { //var err error p.a, err:= Add(a, b)//此处为什么会提示错误,p.a已经存在,但err不存在。感觉应该可以啊 fmt.Println(p.a) if err != nil { fmt.Println(err.Error()) } ret...阅读全文

新手求解答 eclipse中运行go Application是出现Resource doesn't have a corresponding Go Package

刚刚接触go,对他还不是很了解。 我在eclipse中运行.go文件时出现Resource doesn't have a corresponding Go Package,按照网上的解答说是应为少了main文件夹,我就在src文件夹下创建了一个main文件夹,将.go文件放进去之后还是出现这个提示,是我创建的方式不对吗,还是因为其他原因? 我在命令提示符中可以运行成功。 ![image.png](https://static.studygolang.com/180314/08e7258a984b46aa81cfe08c9096fca0.png) ...阅读全文