草庐IT

has-many

全部标签

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

gorm golang one2many 同一张表

我正在尝试使用golanggorm在(我的)sql表中创建一个自引用。目前我的代码如下所示:typePersonstruct{gorm.ModelNamestringChildren[]*Person`gorm:"ForeignKey:ParentID"`ParentIDuint}funcmain(){/*codetogetdatabaseconnectionomitted*/p:=&Person{Name:"Sally"}db.Create(p)children:=[]*Person{{Name:"Jane",ParentID:p.ID},{Name:"Tom",ParentID:p

sockets - 转到套接字 : too many open files

当我从以下代码发送请求时:req,err:=http.NewRequest("GET","my_target:",nil)iferr!=nil{panic(err)}req.Close=trueclient:=http.DefaultClientresp,err:=client.Do(req)iferr!=nil{panic(err)}deferresp.Body.Close()平均每分钟发送10个请求几个小时后,我收到此错误:socket:toomanyopenfiles如何找到这个问题的原因?我不是关闭了http.Request吗?我认为req.Close=true可以完成这项工作

http - 去 - JSON-RPC - "too many colons"

我想调用HTTPJSON-RPCserverforBitcoin使用Go(不在GAE上),但我得到错误dialtcphttp://user:pass@127.0.0.1:8332:toomanycolonsinaddress或dialiphttp://user:pass@127.0.0.1:8332:lookuphttp://user:pass@127.0.0.1:8332:nosuchhost我尝试了各种networkconfigurations,但什么也做不了。当我在浏览器中输入地址时,我得到了服务器的响应:{"result":null,"error":{"code":-32700

去生成 : 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

mysql - 如何避免 "too many connections"

2019-04-2415:52:26.5269818ERRORoslo_messaging.rpc.server[req-857fec8a-7196-4425-85e4-389e2655a2c3-----]Exceptionduringmessagehandling:OperationalError:(pymysql.err.OperationalError)(1040,u'Toomanyconnections')(Backgroundonthiserrorat:http://sqlalche.me/e/e3q8)我用过"github.com/astaxie/beego/orm"mar

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")}但是我得到了错

unit-testing - 使用 testing.T 作为匿名结构字段 : "too many arguments in call to this.T.common.Fail"

我正在尝试解决KarateChopGo中的kata作为练习,并在我的测试用例中遇到了这个编译器错误:toomanyargumentsincalltothis.T.common.Fail我将testing.T包装到一个带有附加方法的结构中,作为一个匿名结构字段:packagemainimport("fmt""testing")typeassertionsstruct{*testing.T}func(thisassertions)assert_equal(expectedint,actualint){if(expected!=actual){this.Fail(fmt.Sprintf("F