草庐IT

set_no_cache

全部标签

mongodb - Go 和 MongoDb 错误 : has no field or method

我是Golang的新手。在尝试从MongoDb查询结果中提取password时,出现以下错误:"./1.go:73:results.passwordundefined(type[]Personhasnofieldormethodpassword)"错误是由代码中的倒数第二行引起的。如何分离查询结果?代码:packagemainimport("fmt""html/template""log""net/http""reflect""gopkg.in/mgo.v2/bson""gopkg.in/mgo.v2")typeloginstruct{UserNamestringPasswordstr

sockets - 没有可用的缓冲区空间(tcp.cpp :69) when setting SNDBUF and RCVBUF ZeroMQ, golang,MacOSX

我在MacOSX上使用brew安装了zeromq:stable4.1.4,并编写了一个简单的PUB/SUB程序来测试zeromq。但是当我使用标志--bufsize>5运行示例程序时(使用大小>5MB的缓冲区)(去运行go_zmq_pubsub.go--bufsize=6);它抛出以下异常:没有可用的缓冲区空间(tcp.cpp:69)SIGABRT:中止PC=0x7fff9911c286m=0cgo执行时信号到达下面是我用来测试zeromq4.x的程序packagemainimport("fmt""flag""strconv""sync"log"github.com/Sirupsen/

algorithm - Go lang : search x digits from sets of numbers, 为什么需要很长时间才能执行?

我尝试制作从一组数字中找到x个数字的小程序,例如:我想从中找到89个数字strong>1-1000000000。这是我的代码:https://play.golang.org/p/93yh_urX16packagemainimport("fmt""strconv")varbucketstringfuncmain(){findDigits(89,1000000000)}funcfindDigits(digitsint,lengthint){fori:=1;i有谁知道,我犯了什么错误?我需要一些建议来改进这段代码。谢谢:) 最佳答案 Yo

testing - Go-lang测试,Benchmark上Parallel Setting是什么意思?

在https://golang.org/pkg/testing/描述了我们可以使用testing.B.RunParallel()函数在并行设置中运行基准测试。我尝试编写简单的测试代码:funcBenchmarkFunctionSome(b*testing.B){fori:=0;i然后我将其更改为使用RunParallel()funcBenchmarkFunctionSome(b*testing.B){b.RunParallel(func(pb*testing.PB){forpb.Next(){SomeFunction()}})}并且使用RunParallel()的比第一个基准测试慢。其

go - undefined <type float32 has no field or method sum> 错误。如何解决?

这是我的程序。当我运行它时,它给出了以下错误-a.sumundefined(typefloat32hasnofieldormethodsum)packagemainimport("fmt")typeCalculationinterface{operation(input[]float32)}typeAdditionstruct{sumfloat32}func(aAddition)operation(input[]float32){a.sum=input[0]for_,a:=rangeinput[1:]{a.sum+=a}fmt.Println("Sum:",a.sum)}funcmai

Golang (v1.8) - 错误 : type *mux. Route has no field or method Method

我有一个配备了gorilla工具包的go/golang应用程序。我正在尝试使用gorilla/mux包进行路由。我的路线和错误信息如下。有什么指点吗?路线`r:=mux.NewRouter()r.HandleFunc("/",landing)r.HandleFunc("/contact",contact)r.HandleFunc("/faq",faq)r.HandleFunc("/register",accountsC.New).Method("GET")r.HandleFunc("/register",accountsC.Create).Method("POST")http.List

Golang 重映射接口(interface) go-cache

我有如下结构:typePagestruct{titlestringurlstring}和结构图:varmostViewed=make(map[int]Page)使用go-cache,我用TTL时间存储map。c.Set("data",mostViewed,60*time.Minute)但是,一旦我恢复了“数据”key,我如何才能将它返回给map呢?a,_:=c.Get("data")fmt.Printf("%+v\n",a)out:map[17:{title:xxx,url:yyy}]我试过类似的东西:z:=map[int]Page{a}有什么线索吗?这就像“重新映射”映射的字符串。

cpu 的 golang no/debug/pprof/profile 端点,同时拥有其他一切

我对无法分析我的golang程序的问题感到非常困惑,我在/debug/pprof下有所有其他端点但没有用于CPU分析的/debug/pprof/profile有没有人偶然发现过这样的问题?gotoolpprofhttp://localhost:7778/debug/pprof/profileFetchingprofilefromhttp://localhost:7778/debug/pprof/profilePleasewait...(30s)serverresponse:404NotFound同时/debug/pprof/profiles:19block31goroutine10he

caching - channel 并发保证

我正在写一个并发安全的备忘录:packagemuimport("sync")//Funcrepresentsamemoizablefunction,operatingonastringkey,tousewithaMutypeFuncfunc(keystring)interface{}//Muisacachethatmemoizesresultsofanexpensivecomputation////Ithasatraditionalimplementationusingmutexes.typeMustruct{//guardsdonemusync.RWMutexdonemap[stri

git - 去获取 : Git settings are ignored

我尝试从mac上的私有(private)gitlab服务器获取存储库。我将git配置(~/.gitconfig)设置为使用ssh而不是https:[url"git@gitlab.mysite.com:"]insteadOf=https://gitlab.mysite.com/当我使用httpsurl克隆项目时,我得到了正确的替换$gitclonehttps://gitlab.mysite.com/group/project$cdproject$gitremote-vorigingit@gitlab.mysite.com:group/project(fetch)origingit@git