草庐IT

数据指标

全部标签

dictionary - 使用 Golang 将映射数据输入到结构中

这个问题在这里已经有了答案:JSONanddealingwithunexportedfields(2个答案)关闭8个月前。我想使用Golang将我的map数据放入另一个map数据。但是它有结构类型。这是我的代码。birth:=make(map[string]interface{})birth["docType"]="registerBirth"birth["agencyCd"]=string(args[0])birth["birthYmd"]=string(args[1])birth["lsTypeNm"]=string(args[2])birth["monthDiff"]=strin

unit-testing - 数据库连接get的单元测试策略

被测代码中有一个方法,它只是尝试获取数据库连接,如果无法连接则返回错误。它,以及涉及的结构体定义如下:typeDatabaseContextstruct{ContextDatabaseDatabaseSt}////GetInfoReturnsthecontext.//func(c*DatabaseContext)GetInfo()*Context{//return&c.Context//}//GetDBGetsthedatabaseconnectionfromtheconnectionstring.func(c*DatabaseContext)GetDB()(*sql.DB,*erro

go - 使用 gin 包从 Postman Form 获取数据后没有显示任何值

下面是我正在处理的代码。它在运行时显示一条成功消息,但不显示postman表单中定义的值。相反,它在命令提示符中显示空格。packagemainimport("fmt""github.com/gin-gonic/gin")funcsaveCustomer(c*gin.Context){fn:=c.PostForm("firstName")ln:=c.PostForm("lastName")em:=c.PostForm("email")phnno:=c.PostForm("phone_no")fmt.Printf("fn:%v;ln:%v;em:%v;phnno:%v;",fn,ln,e

unit-testing - 获取数据库连接的连接字符串

我正在尝试测试这个功能://OpenConnectionopensaconnectiontoaMySQLdatabaseby`connStr`//orreturnserror.If`connStr`isempty,errorisreturned.////Parameters://-`connStr`:theURLofthedatabasetoconnectto//-`interpolateParams`:shouldweinterpolateparameters?////Returns://-pointertothedatabaseconnection//-anyerrorsthath

templates - 多个文件的划分模板不提供数据

我的模板有1个文件(原始文件)按预期工作,现在当它变大时我开始将它分成3个文件并且只是将原始文件中的数据复制并粘贴到3个文件中,我能够看到模板已成功执行,但start和end模板中缺少数据,只有main模板从structData正确接收数据例如startTemple.txt{{define"start"}}...{{end}}main.txt(hereiincludebothtemplate){{template"start"}}...{{template"end"}}endTemplate.txt{{define"end"}}...{{end}}我使用以下t,err:=templat

unit-testing - 如何在 golang 中编写关于插入、获取、删除和更新数据的测试用例

我必须编写插入、获取、删除和更新数据的测试用例。在互联网上搜索时,我找到了一个代码并且它可以工作,但我不知道它是如何工作的。我的代码在下面给出,任何人都可以用简单的方式告诉我我将如何理解代码。packagemodelsimport("testing""gopkg.in/mgo.v2/bson""fmt")funcTestAddBlog(t*testing.T){typeargsstruct{queryinterface{}}tests:=[]struct{namestringargsargswantbool}{{"first",args{bson.M{"_id":4,"title":"

go - [][]*数据类型在golang中是什么意思

假设这是我的示例代码。运行时输出[[]][[][]][[][][]][[][][][]]。帮助我理解这段代码描述的内容以及编程术语中称为routingtable[][]*node的内容。它是节点的slice还是节点类型的二维数组。如果我听起来很蠢,请原谅我,但我只是想学习。packagemainimport"fmt"typenodestruct{idint}funcmain(){varroutingtable[][]*nodefori:=0;i 最佳答案 它只是意味着它包含4个空节点指针slice,这是您的代码的预期行为。它是一片片

csv - 需要在CSV中添加数据而不需要在数据中添加逗号

我有一堆IP范围或单个地址。我想出了如何遍历它们,我可以成功地将它们打印到控制台。但是,当我将相同的数据写入CSV时,它会神奇地在每个值后添加一个逗号(而不是将它们全部添加到由空格分隔的同一标题下)。我遵循所有规则(好吧,看起来,无论如何)在Go中附加数据,但我只是想不通为什么这不起作用。我假设Go中的CSV函数只看到一个空格,并认为它应该用逗号分隔。输入部分是循环遍历[]string类型的地址。因此,一个值可以是127.0.0.1-127.0.0.255或只是127.0.0.1。我只是希望它们在csv列Included中看起来像这样:127.0.0.1-127.0.0.255127.

go - 默认结构用作 golang 中 yaml 数据的目的地

我尝试改善我维护的cli的用户体验。一个主要目标是提供合理的默认值。它广泛使用yaml进行配置。可在此处找到配置的基本演示实现:https://github.com/unprofession-al/configuration/tree/bf5a89b3eee7338899b28c047f3795546ce3d2e6一般主要配置如下所示:typeConfigmap[string]ConfigSectiontypeConfigSectionstruct{InputInputConfig`yaml:"input"`OutputOutputConfig`yaml:"output"`}Confi

postgresql - 使用 GoLang 保存额外数据

所以我使用GoLang1.10.3和Echo框架,以Gorm和Postgres作为我的数据库。我有三个表/结构,Profile、Addresses和Profile_addresses结构如下,简介typeProfilestruct{gorm.ModelCompanystring`gorm:"size:255"json:"company"`AddedDatetime.Time`gorm:"type:date"json:"date_added"`ProfileAddresses[]ProfileAddress`gorm:"foreignkey:profile_fk"json:"addres