草庐IT

内部网

全部标签

c - Go 语言使用 C 的内部结构

我希望能够在Go中将一个主机地址(让我们使用“www.google.be”)转换为sockaddr结构,然后在C代码中使用它。使用http://github.com/jbenet/go-sockaddr将主机地址转换为sockaddr_any结构并不难模块。我的代码有效,如下所示:ipAddr,_:=net.ResolveIPAddr("ip","www.google.be")sockAddr:=sockaddrnet.IPAddrToSockaddr(ipAddr)rawSockaddr,socklen,_:=sockaddr.SockaddrToAny(sockAddr)cStru

docker - docker 内部的 Golang 错误

在构建我的go应用程序时,我在docker中遇到了一个奇怪的错误:./main.go:31:9:cannotusedb(type*"github.com/khwerhahn/somerepo/vendor/github.com/jinzhu/gorm".DB)astype*"app/vendor/github.com/jinzhu/gorm".DBinargumenttoMigrateThecommand'/bin/sh-cgo-wrapperinstall'returnedanon-zerocode:2有人可以向我提示正确的方向吗,因为该应用程序在本地运行得很好。它就在docker容

go - 在 Golang 中将项目添加到结构内部的 map

我定义了这样的结构。typePagesstruct{Items[]map[string]string}在for循环中,我使用varitem=make(map[string]string)创建项目。完整代码pages:=Pages{}for_,partitionKey:=rangekeys{fields,err:=redis.Strings(conn.Do("hgetall",partitionKey))iferr==nil{varitem=make(map[string]string)item["id"]=strings.Replace(partitionKey,"pages:",""

go - 在golang中从另一个内部调用的模拟函数

我正在尝试stubos.Stat和ioutil.ReadFile(path)使用下面的代码或者如果你喜欢这里在goplayground[1]packagemainimport("fmt""io/ioutil""os""strings")funcAssignFileValueFrom(pathstring,val*string){var(tempValue[]byteerrerror)if_,err=os.Stat(path);err==nil{iferr!=nil{fmt.Println("Therewasaosstaterror:",err)}tempValue,err=ioutil

go - 如何访问 Structs 内部的 map ?不能获取 g.vertexes[base] 的地址

考虑以下问题。我有两个结构,Graph和Vertexpackagemainimport("github.com/shopspring/decimal")typeGraphstruct{vertexesmap[string]Vertex}typeVertexstruct{keystringedgesmap[string]decimal.Decimal}和Vertex的引用接收器func(v*Vertex)Edge(tstring,wdecimal.Decimal){v.edges[t]=w}我想在不同时间更新Graph结构内Vertex.edges映射的值。我最初尝试了这段来自Pytho

go - 作证模拟函数在函数内部返回

我想模拟一个函数的响应。但是这个函数位于或在另一个函数内部调用。假设我有这个功能//main.gofuncTheFunction()int{//Somecodeval:=ToMockResponse()returnval}funcToMockResponse()int{return123}现在在我的测试文件上//main_test.gofuncTestTheFunction(t*testing.T){mockInstance=new(randomMock)mockInstance.On("ToMockResponse").Return(456)returned:=TheFunction

go - 在 golang 中模拟内部函数

我想使用接口(interface)模拟函数,我能够模拟第一个函数callsomething在icza的大力帮助下,现在有点棘手了。我想测试函数vl1使用mockforfunctionfunction1,它是如何完成的。https://play.golang.org/p/w367IOjADFV主要包import("fmt""time""testing")typevInterfaceinterface{function1()bool}typemStructstruct{infostringtimetime.Time}func(s*mStruct)function1()bool{return

python - 将具有内部条件的循环从 python 转换为 golang

我正在将一些代码从python转换为go这里我想在golang中编写相同的代码:python:whileg_day_no>=g_days_in_month[i]+(i==1andleap):g_day_no-=g_days_in_month[i]+(i==1andleap)i+=1我的尝试:leap:=int32(1)vari=int32(0)forg_day_no>=(g_days_in_month[i]+(i==1&&leap)){g_day_no-=g_days_in_month[i]+(i==1&&leap)i+=1}但我在ide中有错误说:Invalidoperation:i

go - 为什么kubernetes内部使用字符串指针而不是字符串?

不仅是字符串指针,还有bool指针、int指针等参见:https://github.com/kubernetes/cli-runtime/blob/5c4694c3aa38d6f710b2e3b18598f9d83f1aae3b/pkg/genericclioptions/config_flags.go#L322-L336golang似乎无法从ConstantPool之类的东西中获益。语言packagemainimport("fmt")funcStringPtr(sstring)*string{return&s}funcmain(){fmt.Println(StringPtr(""))

go - 将内部 go struct 数组转换为 protobuf 生成的指针数组

我正在尝试将内部类型转换为protobuf生成的类型,但无法转换数组。我是新手,所以我不知道所有可以提供帮助的方法。但这是我的尝试。当运行这段代码时,我得到panic:runtimeerror:invalidmemoryaddressornilpointerdereference[signalSIGSEGV:segmentationviolationcode=0x1addr=0x8pc=0x86c724]以及许多其他字节数据。我想知道将内部结构转换为protobufs的最佳方法是什么。我认为我遇到的最大麻烦是protobuf生成的代码是指针。原型(prototype)定义message