草庐IT

go - 卡夫卡 : client has run out of available brokers

更新:原来我在Docker中的端口有问题。不确定为什么会解决此现象。我相信我遇到了一个奇怪的错误。我正在使用Sarama库并能够成功创建消费者。funcmain(){config=sarama.NewConfig()config.ClientID="go-kafka-consumer"config.Consumer.Return.Errors=true//Createnewconsumermaster,err:=sarama.NewConsumer("localhost:9092",config)iferr!=nil{panic(err)}deferfunc(){iferr:=mast

google-app-engine - c.Infof undefined (type context.Context has no field or method Infof) google.golang.org/appengine/log 错误

在GoRuntime中,我使用方法c.Infof来记录消息,但编译失败并出现以下错误c.Infof未定义(类型context.Context没有字段或方法Infof)。错误清楚地表明从c:=appengine.NewContext(r)返回的应用引擎上下文是context.Context类型并且它上面没有方法c.Infof。但与此相反的是https://godoc.org/google.golang.org/appengine/log中的文档表明存在这种方法。还有一点需要注意,该方法存在于“appengine”(导入“appengine”)包返回的上下文中,而这似乎不存在于新包goog

sql - Golang 服务器 : send JSON with SQL query result that has variable number of columns

我正在使用Go服务器创建一个RESTfulAPI的小实现。我正在从URL中提取查询参数(我知道这不安全,稍后我会尝试解决这个问题,但如果您对这个主题有任何建议,它们会很有帮助)。我在3个sring变量中保存了表名、所需的列和一些条件。我正在使用这个查询:rows,_:=db.Query(fmt.Sprintf("SELECT%sFROM%sWHERE%s",columns,table,conditions))我想将查询结果作为JSON发送回我的前端。我有可变数量的未知列,所以我不能用“标准”方式来做。我能想到的一种解决方案是从查询结果和rows.Columns()中“手动”构建一个JS

去生成 : stringer: invalid operation: has no field or method String

我正在尝试使用stringercmd以便我可以为某些int类型生成String()方法。这是代码的样子//go:generatestringer-type=MyIntTypetypeMyIntTypeintconst(resourceMyIntType=iota)funcmyfunc(){print(resource.String())}我在执行gogenerate命令时遇到的错误是invalidoperation:resource(constant0oftypeMyIntType)hasnofieldormethodString这是有道理的,因为还没有String方法。如果strin

windows - "ConnectEx tcp: The semaphore timeout period has expired."是什么意思

我写了一个简单的go程序,它在windows上运行并测试远程端口是否处于事件状态:packagemainimport("fmt""net")funcmain(){conn,err:=net.Dial("tcp","192.168.23.191:3403")iferr!=nil{fmt.Println(err)}else{conn.Close()}}现在,远程端口已关闭。第一次运行,报错:dialtcp192.168.23.191:3403:ConnectExtcp:Theremotecomputerrefusedthenetworkconnection.然后我继续运行,报错改为:dia

Golang Gin "c.Param undefined (type *gin.Context has no field or method Param)"

我尝试使用作为Golang框架的Gin。https://github.com/gin-gonic/gin我从官方github上复制了示例代码。就像这样。packagemainimport("github.com/gin-gonic/gin""net/http")funcmain(){router:=gin.Default()router.GET("/user/:name",func(c*gin.Context){name:=c.Param("name")c.String(http.StatusOK,"Hello%s",name)})router.Run(":8080")}但是我得到了错

go-golang编译错误: type has no method

如何解决?https://play.golang.org/p/aOrqmDM91J:28:Cache.Segmentundefined(typeCachehasnomethodSegment):29:Cache.Segmentundefined(typeCachehasnomethodSegment)packagemainimport"fmt"typeSlotstruct{Key[]stringVal[]string}typeCachestruct{Segment[3615]Slot}funcNewCache(sint)*Cache{num:=3615Cacheobj:=new(Cac

deployment - Golang 执行 : stat: no such file or directory after file has been moved there

我有一个脚本,用于使用“os/exec”包进行部署。我使用的命令之一如下:cpInit=exec.Command("cp","initScripts/nginx","/etc/init.d/nginx")还有一个:startNginx=exec.Command("/etc/init.d/nginx","start")最初我使用err:=cpInit.Run()运行第一个命令,但后来当我运行第二个命令时出现错误:exec:"/etc/init.d/nginx":stat/etc/init.d/nginx:nosuchfileordirectory但是当程序退出时/etc/init.d/n

pointers - 戈朗 Cgo : panic: runtime error: cgo argument has Go pointer to Go pointer

我正在使用一个C库,与下面不同,我无法控制它。我需要将指向也包含指针的数组的指针传递给C函数。packagemain/*#includetypedefint*pInt;voidfoo(pIntp[]){printf("foo()\n");}*/import"C"import"unsafe"funcmain(){variC.intvarp1C.pInt=(*C.int)(unsafe.Pointer(&i))varp2C.pInt=(*C.int)(unsafe.Pointer(&i))varps[]C.pInt=[]C.pInt{p1,p2}C.foo(unsafe.Pointer(&

unit-testing - 使用 Gomock 测试返回错误 : Expected call has already been called the max number of times

我正在使用Gomockhttps://godoc.org/github.com/golang/mock和模仿这个测试的源代码是:packagesqsimport("fmt""log""os""runtime""github.com/aws/aws-sdk-go/aws/session""github.com/aws/aws-sdk-go/aws""github.com/aws/aws-sdk-go/service/sqs""github.com/aws/aws-sdk-go/service/sqs/sqsiface")varsess*session.Sessionvarsvc*sqs.