草庐IT

double-to-int

全部标签

pointers - 调用结构函数给出 "cannot refer to unexported field or method"

我有这样的结构:typeMyStructstruct{Idstring}和函数:func(m*MyStruct)id(){//doingsomethingwithidhere}我还有一个这样的结构:typeMyStruct2struct{m*MyStruct}现在我有一个函数:funcfoo(str*MyStruct2){str.m.id()}但是我在编译时遇到错误:str.m.idundefined(cannotrefertounexportedfieldormethodmypackage.(*MyStruct)."".id如何正确调用这个函数? 最佳答案

戈兰错误: reference to undefined identifier ‘syscall.TUNSETIFF’

因此,我一直在尝试使用gccgo构建法兰绒(https://github.com/coreos/flannel)。这是我在构建时遇到的错误:$./buildBuildingflanneld...#github.com/coreos/flannel/pkg/ipgopath/src/github.com/coreos/flannel/pkg/ip/tun.go:57:37:error:referencetoundefinedidentifier‘syscall.TUNSETIFF’err=ioctl(int(tun.Fd()),syscall.TUNSETIFF,uintptr(unsa

pointers - 我如何在 Go 中做一个文字 *int64?

我有一个带有*int64的结构类型field。typeSomeTypestruct{SomeField*int64}在我的代码中的某个时候,我想声明一个文字(比如,当我知道所说的值应该是0,或者指向0时,你知道我的意思)instance:=SomeType{SomeField:&0,}...除了这不起作用./main.go:xx:cannotuse&0(type*int)astype*int64infieldvalue所以我试试这个instance:=SomeType{SomeField:&int64(0),}...但这也不起作用./main.go:xx:cannottakethead

go - 编写 CLI : How to avoid showing the typed password on screen

这个问题在这里已经有了答案:getpasswdfunctionalityinGo?(11个答案)关闭7年前。我正在使用Go编写命令行工具,其中一个命令将查询用户的用户名和密码(并将其保存到主目录内的配置文件中)。目前我还不知道如何将键入的密码替换为“*”,甚至无法像许多命令行工具那样不键入任何内容。在使用golang时如何做到这一点?

go - 从 Golang 中的二进制文件中读取 int16

我目前正在开发一个从标准输入读取16位整数的Golang程序。我期望值介于3和~128之间,但是,当我打印出整数值时,它是完全随机的,从30,000+到-30,000。我通过执行以下操作在PHP中做同样的事情:这成功了。我正在处理的Go代码位于GitHub上:https://github.com/uniquoooo/dca/blob/decoding/main.go#L502-L536我正在使用bash管道(例如cattestfile|command)将内容通过管道传输到程序中。这是一些测试Golang代码:packagemainimport("bufio""fmt""encoding

json - Golang map : How to strip out empty fields automatically

给定以下结构...packagemodelsimport("time""gopkg.in/mgo.v2/bson""github.com/fatih/structs")typeUserstruct{Idbson.ObjectId`json:"id,omitempty"bson:"_id,omitempty"`Namestring`json:"name,omitempty"bson:"name,omitempty"`BirthDatetime.Time`json:"birth_date,omitempty"bson:"birth_date,omitempty"`}...我通过像这样解析H

戈朗 : Zip Package Modified Time Defaults to 30 November 1979, 00:00

如何将zip文件的修改时间更改为time.Now()?当我创建一个zip文件时,我得到的修改时间是1979年11月30日00:00。那么有没有简单的方法可以将修改时间设置为现在呢? 最佳答案 我发现这个函数可以满足我的需求:funcFileInfoHeader(fios.FileInfo)(*FileHeader,error)。这将获取一个输入数据文件并创建一个部分填充的FileHeader。 关于戈朗:ZipPackageModifiedTimeDefaultsto30November

arrays - 如何在 Go 中创建一个 map[string] [2]int?

这个问题在这里已经有了答案:Cannotassigntopairinamap(3个答案)关闭6年前。我想在Go中创建一个map[string][2]int。我试过this在Playground,但我遇到了错误。我该如何解决这个问题?fmt.Println("Hello,playground")m:=make(map[string][2]int)m["hi"]={2,3}m["heello"][1]=1m["hi"][0]=m["hi"][0]+1m["h"][1]=m["h"][1]+1fmt.Println(m)

Golang 中的正则表达式 : How to set character that makes the string not match?

我对正则表达式一窍不通(抱歉)。我试图制作一种非常简单的标记语言,匹配粗体和斜体,然后将它们转换为HTML。这是我使用的粗体示例:varbold=regexp.MustCompile("\\*([^\\*]+)\\*")它匹配两个星号之间的所有内容。现在,我希望它匹配*test*但不匹配\*test*。由于我对正则表达式知之甚少,但我正在尝试进行此实验,因此我想知道这样做的方法是什么。我到处搜索,但找不到完成这项工作的方法。 最佳答案 已更新Go不支持回顾。因此,解决方法可以是:(?:\A|(?:[^\\]+|\A)(\\{2})+

arrays - 如何在 Golang 中将字符串转换为 map[int]string

我在将字符串转换为map时遇到了问题。我有来自url的下一个数据map[start:0draw:1length:10_:1475090278299search[value]:search[regex]:falseorder[0][dir]:ascorder[0][column]:0columns[0][orderable]:truecolumns[0][searchable]:truecolumns[0][search][value]:columns[0][search][regex]:falsecolumns[0][data]:namecolumns[0][name]:columns