草庐IT

test_slice

全部标签

function - StructScan 未知结构 slice [GO]

所以我想通过StructScan方法填充任何结构,然后将从数据库中获得的任何数据读取到我提供给测试函数的相关结构中。这个脚本不会给出任何编译错误(如果你实现了数据库连接等其他东西)但是StructScan方法仍然返回错误并告诉我它需要一个slice结构。如何创建我不知道其类型的结构片段?感谢您的任何建议。packagemainimport("database/sql""github.com/jmoiron/sqlx")vardb*sql.DBtypeAstruct{Namestring`db:"name"`}typeBstruct{Namestring`db:"name"}funcma

testing - 带 channel 的 Golang 测试不退出

下面的Golang测试永远不会退出。我怀疑这与channel死锁有关,但作为一个菜鸟,我不太确定。constuserName="xxxxxxxxxxxx"funcTestSynchroninze(t*testing.T){c,err:=channel.New(github.ChannelName,authToken)iferr!=nil{t.Fatalf("Couldnotcreatechannel:%s",err)return}state:=channel.NewState(nil)ctx:=context.Background()ctx=context.WithValue(ctx,

用于填充结构实例 slice 的 Goroutine

这是我第一天使用Go,我有一个关于goroutines和附加到实例slice的问题。想法是每辆卡车都有一个长度为1的cargo,其中包含一个名为“杂货”的项目。我几乎拥有它,但由于某种原因它正在失去卡车的属性,而且它似乎过早地终止了。https://play.golang.org/p/f0uIy5qg8dpackagemainimport"fmt"import"time"typeItemstruct{namestring}typeTruckstruct{Cargo[]Itemnamestring}funcUnloadTrucks(chchan*Truck){t:=

testing - Golang NewRequest 将 POST 参数传递给 API 进行测试

这是我的测试方法,它创建一个新请求并传递POST参数。url1:="/api/addprospect"data:=url.Values{}data.Add("customer_name","value")b:=bytes.NewBuffer([]byte(data.Encode()))request,err:=http.NewRequest("POST",serverHttp.URL+url1,b)res,err:=http.DefaultClient.Do(request)问题是POSTparam没有被url的函数处理程序获取。你能帮我设置正确的请求吗?谢谢

google-app-engine - 在 Datastore 中将 slice 设置为 noindex 没有任何效果

给定,typePersonstruct{Namestring`datastore:"name"`Pets[]Pet`datastore:"pets,noindex"`}typePetstruct{Ageint`datastore:"age"`}Datastore仍然索引Pets字段和Pet中的所有字段。 最佳答案 设置noindex只会影响新实体。之前保存的实体将保持索引状态,直到您覆盖它们。 关于google-app-engine-在Datastore中将slice设置为noindex

golang - 递归函数运行期间 slice 中指针的内容发生变化

funcgetAllCertainDivs(classNamestring,idNamestring,htmlTag*HtmlTag,matchingDivs*[]*HtmlTag){fmt.Println(htmlTag.Class)ifhtmlTag.XMLName.Local=="div"{ifhtmlTag.Class==className&&htmlTag.Id==idName{*matchingDivs=append(*matchingDivs,htmlTag)}}for_,tag:=rangehtmlTag.ChildTags{getAllCertainDivs(clas

go - 将数组/slice 作为 url 参数传递

我有一个简单的Web服务器,可以拦截地理空间map图block请求、交换像素并将图像传递到前端以提供服务。它工作得很好,但请求变得非常大。我想知道我是否可以传递数组或slice?我似乎无法找到任何搜索。例如:http://localhost:8002/tiles?url=url&r=0&g=250&b=0&a=230&replaceR=0&replaceG=127&replaceB=0&replaceA=0是我的典型要求。我想添加更多颜色进行交换,所以如果我可以通过类似的东西那就太好了:http://localhost:8002/tiles?url=url&rgba1=[0,250,0

go - 将 cgo 数组转换为 slice

目前我这样做是为了将CGOdouble组转换为float64slice:doubleSlc:=[6]C.double{}//FilldoubleSlcfloatSlc:=[]float64{float64(doubleSlc[0]),float64(doubleSlc[1]),float64(doubleSlc[2]),float64(doubleSlc[3]),float64(doubleSlc[4]),float64(doubleSlc[5])}做同样的事情有没有更简单的方法?我想这也可以看作是在Go中不同类型的slice/数组之间进行转换的通用方法。

testing - 针对 xml/字符串测试失败的自定义 testify 输出

我正在使用testify测试XML编码(marshal)处理,并使用strings.Contains检查我希望包含在XML中的行是否确实存在。但是,我想区分实际xml与所需xml。目前,我的代码看起来像这样:func(suite*BookSuite)TestXMLMarshal(){priceXML,priceErr:=xml.Marshal(PriceType{Price:10,Type:"IND"})suite.Nil(priceErr)linePresent:=strings.Contains(string(priceXML),``)iftrue!=linePresent{err

http - 去 Gin 框架 : Testing query and POST with cURL

我正在尝试theREADMEofginframework中的代码示例(“另一个例子:查询+发布表单”):packagemainimport("fmt""github.com/gin-gonic/gin")funcmain(){router:=gin.Default()router.POST("/post",func(c*gin.Context){id:=c.Query("id")page:=c.DefaultQuery("page","0")name:=c.PostForm("name")message:=c.PostForm("message")fmt.Printf("id:%s;p