草庐IT

树形结构

全部标签

go - 覆盖导入结构上的结构字段标签

我有一个第三方客户端库(Sarama)公开了aconfigurationstruct.我想直接从我的配置结构中引用该结构:typeMyConfigstruct{Saramasarama.Config}我正在使用go-yaml整理我的配置。使用go-yaml编码MyConfig会出现panic,因为sarama.Config包含类型为func的字段(Partitioner)并且yaml解析器不知道如何Marshalfunc。防止这种panic的一种方法是告诉go-yaml忽略这个字段(在该字段上使用标签yaml:"-")但是我无法在结构上设置标签我的代码中没有定义。有没有一种优雅的方法可

json - 有条件地将 JSON 解码为结构的简洁方法

我正在向JSONAPI发送请求,它要么返回错误...{"error":{"code":404,"message":"Documentnotfound.","status":"NOT_FOUND"}}或数据。{"name":"projectname","fields":{"userId":{"stringValue":"erw9384rjidfge"}},"createTime":"2018-06-28T00:52:25.638791Z","updateTime":"2018-06-28T00:52:25.638791Z"}下面是相应的结构体typeHttpErrorstruct{Cod

golang中具有嵌套结构的json对象

我有以下json对象,我试图用Go将其表示为typeJsonObjectstruct并将其传回其原始json中,以便我可以将json作为api端点返回。有什么建议/例子吗?[{"time":173000,"id":"VLSuEE5m1kmIhgE7ZhHDFe","height":"","DATASTRUCTURE":{},"language":"en","size":0,"url":"http://www.gstatic.com/play.m3u8","type":"vid","definitionid":"h264","reference":"PAN-EN","content":"

Golang Facebook 对结构的响应

您好,我是GO的新手,我正在尝试将json从facebookapi转换为结构。问题是对象的键是动态的:{"100555213756790":{"id":"100555213756790","about":"NoodleBar&Restaurant","metadata":{"fields":[{"name":"id","description":"asdasdasdasd","type":"numericstring"},//...,"101285033290986":{"id":"101285033290986","about":"SmartCityExpoWorldCongress

go - 重复 formData 到 Go 结构

我正在提交一个重复表单,其中生成的formData被解析为:"Name":{"John","Jake"},"Phone":{"999-999-999","12312-123-123"},但是,我想构造成{Name:"John",Phone:"999-999-999"},{Name:"Jake",Phone:"12312-123-123"}.有人告诉我gorilla/schema,很合适,但我在下面尝试了它,它产生了一个空slice。有什么我想念的吗?packagemainimport("fmt""github.com/gorilla/schema")typePersonstruct{N

go - 结构中的 map[string]string

为标题道歉,但这是一个奇怪的标题,超出了我的理解能力。我正在使用一个已经完成但还没有完成的go库:https://github.com/yfronto/go-statuspage-apistatuspage.ioAPI在发布事件时支持以下参数:incident[components][component_id]-Mapofstatuschangestoapplytoaffectedcomponents.一个例子是:"incident[components][ftgks51sfs2d]=degraded_performance"不幸的是,库中定义的结构doesn'tsupportthat

json - 动态 JSON 结构,API 结果 golang

我必须在GoLang中进行两次HTTPAPI调用,第一个API调用返回此json响应:{"status":200,"msg":"OK","result":{"id":"24","folderid":"4248"}}我的第一个响应的json结构是这样设置的:typeOnestruct{Statusint`json:"status"`Msgstring`json:"msg"`Resultstruct{IDstring`json:"id"`Folderidstring`json:"folderid"`}`json:"result"`}第二个电话就是问题所在。如您所见,第一个API调用返回一个

go - 填充包含 slice 的结构

我正在努力学习Go的基础知识。我正在尝试在golang中呈现一个模板,其中包含结构的预填充值。但是没有运气funcServeIndex(whttp.ResponseWriter,r*http.Request){p:=&Page{Title:"GoProjectCMS",Content:"Welcometoourhomepage",Posts:[]*Post{&Post{Title:"HelloWorld",Content:"Hello,WorldThanksforcomingtothissite",DatePublished:time.Now(),},&Post{Title:"APos

go - 在解码字段的 JSON 内容时打印结构字段标签?

在Go中,是否可以在我将JSON内容解码到结构字段时从结构字段中获取标签?这是我失败的尝试:packagemainimport("log""encoding/json")typePersonstruct{ProfileNameAltField`json:"profile_name"`}typeAltFieldstruct{Valstring}func(af*AltField)UnmarshalJSON(b[]byte)error{log.Println("Showtags")//log.Println(af.Tag)//Iwanttosee`json:"profile_name"`if

go - 当只读来自 HTTP 处理程序的共享结构时如何防止竞争条件

我需要从struct更新值并返回(只读)而不是从HTTP处理程序写入,以避免出现竞争条件我正在使用sync.Mutex这是一个基本示例:http://play.golang.org/p/21IimsdKP6epackagemainimport("encoding/json""log""net/http""sync""time")typeCounterstruct{countuintflagboolmusync.Mutexquitchanstruct{}timetime.Timewgsync.WaitGroup}func(c*Counter)Start(){c.count=1c.time