草庐IT

strtk_parse_type

全部标签

parsing - 我如何在 Golang 中解析这个日期?

我在解析这个日期时遇到了一些问题(“美国东部时间4月19日,下午3:15”),有人可以帮我解决这方面的问题吗?这是我写的代码。d,err:=time.Parse("JAN02,3:04pET",date)提前致谢。 最佳答案 3个字母的月份常量是Jandate:="APR19,3:15pET"d,err:=time.Parse("Jan02,3:04pET",date)http://play.golang.org/p/LkeQOtc1Hd 关于parsing-我如何在Golang中解析这

parsing - 我如何解析 golang 中的非传统日期?

这个问题在这里已经有了答案:DateparsinginGo(1个回答)关闭6年前。我有这个日期,格式如下:25.04.2016我需要将其解析为Golang时间对象,以便将其存储在我的数据库中。这样做的最佳方法是什么?我找不到可以这样做的标准解析格式。

戈朗 : Type Assertion Error issue

我被下面代码片段中的类型断言相关错误困扰了。我不确定我错过了什么。我在以下位置进行类型断言itr=itr.(*DbIterator).Iteratorandkey:=itr.Key().(*Key).Sliceandvalue:=itr.Value().(*Value)。片。我想知道是否有更好的方法来做到这一点,而无需在代码库中到处使用类型断言或更好的设计模式来处理这种情况。该代码片段是更大代码库的一部分。我已经为这个问题提取了最相关的部分。非常感谢这方面的任何帮助。packagerocksdbimport("github.com/tecbot/gorocksdb")func(s*Ro

pointers - 转到错误 : "embedded type cannot be a pointer to interface"

以下代码给出了编译时错误:typeIFileinterface{Read()(nint,errerror)Write()(nint,errerror)}typeTestFilestruct{*IFile}错误:./test.go:18:embeddedtypecannotbeapointertointerface为什么我不能嵌入*IFile? 最佳答案 语言规范不允许。规范中的相关部分:Structtypes:Afielddeclaredwithatypebutnoexplicitfieldnameisananonymousfiel

go - undefined <type float32 has no field or method sum> 错误。如何解决?

这是我的程序。当我运行它时,它给出了以下错误-a.sumundefined(typefloat32hasnofieldormethodsum)packagemainimport("fmt")typeCalculationinterface{operation(input[]float32)}typeAdditionstruct{sumfloat32}func(aAddition)operation(input[]float32){a.sum=input[0]for_,a:=rangeinput[1:]{a.sum+=a}fmt.Println("Sum:",a.sum)}funcmai

Go AST/Types——如何判断错误?

有更好的方法吗?我需要知道v的类型是否是内置的“错误”类型。我觉得应该有一种更简洁的方法来做到这一点:import("go/ast""go/types")funcIsError(vast.Expr,infotypes.Info)bool{t:=info.Types[v]returnt.Type.String()=="error"&&t.Type.Underlying().String()=="interface{Error()string}"} 最佳答案 Typeassertion是检查变量类型的惯用方法。鉴于您正在处理一个AST表

Golang (v1.8) - 错误 : type *mux. Route has no field or method Method

我有一个配备了gorilla工具包的go/golang应用程序。我正在尝试使用gorilla/mux包进行路由。我的路线和错误信息如下。有什么指点吗?路线`r:=mux.NewRouter()r.HandleFunc("/",landing)r.HandleFunc("/contact",contact)r.HandleFunc("/faq",faq)r.HandleFunc("/register",accountsC.New).Method("GET")r.HandleFunc("/register",accountsC.Create).Method("POST")http.List

parsing - 从 Go 中的多行输出中提取日期

请查看下面的netuse命令的输出。现在我想从这段文本中提取到期日期。不幸的是,netuse命令无法输出为json、xml或任何解析格式。因此,我坚持使用此文本:(。我只对获取10-6-20176:57:20并将其转换为Golang日期格式感兴趣。问题:我不知道如何开始?首先找到包含“密码过期”的行?然后呢?UsernamejdoeFullNameJohnDoeCommentUser'scommentCountrycode(null)AccountactiveYesAccountexpiresNeverPasswordlastset1-5-20176:57:20Passwordexpi

parsing - 使用 "go/parser"检查表达式是否为自定义类型

情况编写一个代码生成器来检查结构的字段并使用结构标签添加验证函数问题这里我需要检查type字段是否为自定义类型即,以下不是自定义类型int,[]int,*int,[]Integer,map[string]PhoneNumber但以下是自定义类型Integer,PhoneNumber,*PhoneNumber我想我可以使用像下面这样的函数来查找完全匹配并可以添加映射,[]支持funcisBuiltInType(typstring)bool{switchtyp{case"bool","byte","complex128","complex64","error":case"float32",

oop - 需要帮助理解 Go 中的 `map[String]type` 行为

请看这段代码:packageactivityimport("fmt""strconv""time")typeActivitystruct{yearContributionsmap[string]weekContributions}typedayContributionsstruct{Datetime.TimeContributionint}typeweekContributionsstruct{NotationstringAllDays[]dayContributions}func(currentWeekContribution*weekContributions)addContrib