草庐IT

rev-parse

全部标签

parsing - 解析 Golang 变量

我正在尝试静态分析Go文件。为此,我需要解析以下格式的变量:shape.color=color.red我需要找到所有使用点符号访问的变量。例如,我需要知道shape变量具有color属性。并且还需要颜色变量具有红色属性。我正在尝试使用go/ast和go/parser包,但无法找到一种方法。注意如果它是类似于shape.color()的东西,即一种方法,那么它不应该被计算在内 最佳答案 啊!以下代码打印了所有使用点符号访问的变量!packagemainimport("fmt""go/ast""go/parser""go/token""

json - 戈朗 : how to parse json that get trait and data both?

我得到了一个dic数据{{"wordname":"wordmeaning"},{"wordname":"wordmeaning"},…}我想解析为单词的映射。我尝试使用interface{}编写代码,但我无法想象如何编写。感谢阅读。 最佳答案 如果您有办法将第一个和最后一个花括号更改为方括号,那么您可以执行以下操作:主要包import("encoding/json""fmt""log")funcmain(){varraw_list[]map[string]stringvarjsonText=[]byte(`[{"Cat":"smal

parsing - 如何在 Golang 中解析 IST 格式的日期?

time.Date(t.Year(),t.Month(),time.Now().Day(),10,0,0,0,time.UTC)我想在golang中以IST格式设置10:00:00AM的日期时间。 最佳答案 这取决于您手头时间的格式。Go在time包中准备了一些标准时间格式作为常量,但如果是自定义的,您可以指定自己的标准。关于时区,可以解析或输出特定时区的时间。下面是一个在IST中解析时间字符串并将其输出为UTC的示例。从你的问题中不清楚你的确切问题是什么,但我希望这会有所帮助://First,wecreateaninstanceo

arrays - Golang : Parsing two array of arrays in JSON, 使用相同的结构

这个问题在这里已经有了答案:Unmarshalingjsonintoatype(2个答案)HowtoUnmarshalthepairvaluesinannestedarraybyjsonforGolang(2个答案)UnmarshalJsondatainaspecificstruct(1个回答)关闭3年前。假设我有这个数据:{"code":10000,"msg":"Successfulrequestprocessing","asks":[["0.03434400","0.31100000"],["0.03436300","0.18900000"],[],"bids":[["0.0342

parsing - 将标志变量传递给程序导致奇怪的输出

sergiotapiaatMacbook-Airin~/Work/go/src/github.com/sergiotapia/gophersonmaster[!]$gobuild&&goinstall&&gophers-github_url=https://github.com/search?utf8=%E2%9C%93&q=location%3A%22San+Fransisco%22+location%3ACA+followers%3A%3E100&type=Users&ref=advsearch&l=[1]51873[2]51874[3]51875[4]51877[2]Doneq=

parsing - 如何将多个数据对象传递给 Golang 中的 HTML 模板

我将表的所有行作为json返回到变量pdata并将其解码为接口(interface)对象。我有一个用户结构的实例,我想将其与未编码的json数据一起传递给渲染函数,并使用html模板中的字段参数{{.fieldname}}访问它。ifuuid!=""{pdata,err:=getProduct()iferr!=nil{fmt.Println(err)}typePrdatastruct{Puidstring`json:"puid"`Pnamestring`json:"pname"`Quantitystring`json:"quantity"`Pricestring`json:"price

parsing - 为什么时间格式和解析给出不同的结果?

我正在获取当前时间并将其格式化并解析回来。当我将结果与当前时间进行比较时,它们不相等。这是一个Playground示例:https://play.golang.org/p/DDFzi1t8v_-t:=time.Now()formatted:=t.Format("2006-01-0215:04:05.000-0700")parsed,_:=time.Parse("2006-01-0215:04:05.000-0700",formatted)fmt.Println(parsed.Equal(t))这是在Playground上工作,但在我的本地计算机上不行,因为我的时区是+0300。下面是相

parsing - Golang ParseFloat 在示例中不准确

我一直在做一个项目,我必须将字符串转换为uint,以确保一些货币值匹配:total,err:=strconv.ParseFloat(paymentResp.Transactions[0].Amount.Total,64)iferr!=nil{returnctx.JSON(http.StatusBadRequest,err.Error())}ifo.TotalPrice!=uint(total*100){returnctx.JSON(http.StatusBadRequest,"Unabletoverifyamountpaid")}但是当我尝试对几个数字执行strconv.ParseFl

parsing - 如何正确解析时区代码

在下面的示例中,无论您为parseAndPrint函数选择的时区如何,结果始终为“[date]05:00:00+0000UTC”。这段代码有什么问题?时间应根据您选择的时区而变化。(GoPlayground服务器显然配置为UTC时区)。http://play.golang.org/p/wP207BWYEdpackagemainimport("fmt""time")funcmain(){now:=time.Now()parseAndPrint(now,"BRT")parseAndPrint(now,"EDT")parseAndPrint(now,"UTC")}funcparseAndPr

parsing - Golang yaml 生成双项

我想在yaml中生成以下内容:-bar:hello-bar:anotherpint:guiness-bar:secondpint:""在Golang中,但是制作以下示例,我得到以下输出:-bar:-bar:hello-bar:anotherpint:guiness-bar:-bar:secondpint:""似乎YAMLGolang解析器将结构的名称放在它生成的YAML中,如-bar:然后是它下面的成员数组。我不想要那个,因为它会破坏其他东西。packagemainimport("fmt""gopkg.in/yaml.v2""log")typebarstruct{Barstring}t