草庐IT

array_list_name

全部标签

arrays - Golang 数组指针

我想阐明Golang中的这种行为,为什么当您在数组上获取内存引用并更改此引用的值时,引用数组中没有任何变化。一个例子:vart[5]intprintType(t,"t")p:=&tprintType(p,"p")x:=*px[0]=4printType(x,"x")printType(p,"p")printType(t,"t")这段代码返回[t]Type:[5]intKind:arrayAdr:%!p([5]int=[00000])Value:([00000])[p]Type:*[5]intKind:ptrAdr:0xc4200142d0Value:(&[00000])[x]Type:

arrays - 如何在 GoLang 中将项目附加到 []os.FileInfo

我正在制作一个类似ioutil.ReadDir()的函数,但由于我想要文件夹和子文件夹中的所有文件而递归,而ioutil.ReadDir()只是在指定的文件夹中执行它,但我不知道如何附加项目到我创建的[]os.FileInfo数组。这是我的:funcGetFilesRecursively(searchDirectorystring)(foundFileList[]os.FileInfo,errorGeneratederror){fileList:=[]os.FileInfo{}allFilesAndFolders:=[]string{}//Getallthefilesanddirect

arrays - 从数组结构呈现 json 的问题

这个问题在这里已经有了答案:JSONanddealingwithunexportedfields(2个答案)关闭4年前。我用gorilla/mux和mysql数据库做一个简单的休息服务typeCarrostruct{Anoint`json:"ano"`Corstring`json:"cor"`Nomestring`json:"nome""`}typeRevendastruct{carro[]Carrorodastring}functest(whttp.ResponseWriter,r*http.Request){varlistas[]CarrocarA:=Carro{1975,"Ama

arrays - 如何将数据插入到结构中

typeOrdersstruct{data[]struct{hrefstring`json:"href"`order_idstring`json:"order_id"`}`json:"data"`}如何将数据插入订单结构中的数据数组结构?orders.data=append(orders.data,orders.data{href:r.Host+r.URL.Path+"/"+orderid,order_id:orderid})它出错了。怎么了? 最佳答案 先看appendbuilt-infunction.orders.data不是类

reactjs - AWS ELB 为 https ://domain_name:8000 but accessible via public_ip:8000 返回 404

我是在AWS上部署Web应用程序的初学者,我相信我遇到了与AWSforwardport8000fromelbtoport8000ofEC2类似的问题我有一个reactjs前端和golangapi在awsec2上运行,golangapi在端口8000上运行,可以通过我的public_ip:8000访问它,并给我消息说当我访问public_ip:8000时我的golangapi正在运行。我使用弹性IP创建了public_ip。我使用负载平衡器来获得HTTPS,因为我有一些只能与HTTPS一起使用的功能。然而,当我使用我的https://domain_name:8000时向我自己的API发送

arrays - 从另一个函数附加到数组?

我有这段代码,我在其中附加到一个函数中的结构数组。更改不会出现在其他函数中。typemystruct{arr[]int}funcNew_my()*my{m:=new(my)returnm}func(mmy)Dosomething(){m.arr=append(m.arr,1)m.arr=append(m.arr,2)m.arr=append(m.arr,3)}func(mmy)Dosomethingelse(){fmt.Println(m.arr)}funcmain(){m:=New_my()m.Dosomething()m.Dosomethingelse()}输出是:[]请解释一下发

arrays - golang 中的变量 getter 函数

在go中考虑以下堆栈实现:packagemainimport"fmt"vara[10]intvartopint=-1funcmain(){printStack()push(1)printStack()push(23)printStack()pop()push(2)printStack()println("Topelementis",getTop)}funcpush(xint){top+=1a[top]=x}funcpop(){top-=1}funcgetTop()int{returna[top]}funcprintStack(){fmt.Println(top+1,"Stack:",a

arrays - 数组数组中特定位置的类型?

我是Go的新手,我正在尝试构建一个具有这个一般方面的函数:mapOfResults=ThingDoer([["One",int,-1,true],["Flying",string,"",true],["Banana",bool,false,true]])但我什至无法计算出它的签名(在Go中签名甚至是正确的术语吗?它所有参数的定义等)。我说的是这个结构:funcThingDoer(configThisIsWhatICannotFigure)map[string]Results{//thebodyofmyfunction}如何定义此类参数的类型? 最佳答案

go - 如何在 go 中使用 os.Name()?

我正在尝试使用:https://golang.org/src/os/file.go?s=1472:1577#L35通过导入“os”包然后运行f,err:=os.Open("/tmp/dat3")check(err)name:=os.Name(f)我得到./main.go:29:undefined:os.Name为什么?我究竟做错了什么。(我当然知道我有打开文件的名称-但我很好奇为什么,我无法调用该函数) 最佳答案 因为Name是定义在File结构上的特殊函数(method)。意味着它采用File类型作为接收器,并且可以使用接收器实例

arrays - 在结构中写入数组(Golang)

我一直在使用Golang的“测试”包编写测试用例。我遇到过一种情况,我必须将数组和函数指针写入表中。我试过以下:typemyFunctionTypefunc([]float64,[]float64)float64vartestMatrix=[]struct{dataX[]float64dataY[]float64resultfloat64myFunctionmyFunctionType}{{{2,3},{8,7},1,doMagicOne},{2,3},{8,7},1,doMagicTwo},}但每次我最终都会遇到以下错误或其他问题:missingtypeincompositelite