草庐IT

LOG_TYPE

全部标签

go - Go 中的 128 位 float - 相当于 C#'s "decimal"Type

简单的问题:是否有C#的decimal的等价物?输入Go标准库?我打算使用此类型与在某些端点返回小数的ODataAPI接口(interface),据我阅读,complex128不适合此行为(它的存储不同于花车) 最佳答案 标准库的math/big包括一个Floattype:AnonzerofiniteFloatrepresentsamulti-precisionfloatingpointnumber 关于go-Go中的128位float-相当于C#'s"decimal"Type,我们在S

arrays - 不能在赋值 : need type assertion 中使用字(类型接口(interface) {})作为类型字符串

我是Go的新手,出于某种原因我正在做的事情对我来说似乎不是很直接。这是我的代码:for_,column:=rangeresp.Values{for_,word:=rangecolumn{s:=make([]string,1)s[0]=wordfmt.Print(s,"\n")}}我得到了错误:不能在赋值中使用word(typeinterface{})作为类型字符串:需要类型断言resp.Values是一个数组数组,所有数组都填充有字符串。reflect.TypeOf(resp.Values)返回[][]interface{},reflect.TypeOf(resp.Values[0])

unix - log15 库将纪元时间从纳秒舍入到秒以进行日志记录

我希望我的golang项目中的日志记录具有毫秒级的精度,目前使用的是log15库问题是当我将它附加到Context时,它四舍五入到秒newTimeWithMilliseconds:=time.Unix(0,time.Now().UnixNano())returnlog.FuncHandler(func(r*log.Record){r.Ctx=append(r.Ctx,"time",newTimeWithMilliseconds)nextHandler.Log(r)})当我将它转换为字符串newTimeWithMilliseconds.String()时,它起作用了,我得到了"2018-

戈朗 : How to declare returned variables WITH TYPE?

在GO中,如何声明WITHTYPE函数的返回变量?例如我有这个代码dat,err:=ioutil.ReadFile("/tmp/dat")check(err)fmt.Print(string(dat))但我想要的是:vardat[]byte,errerror:=ioutil.ReadFile("/tmp/dat")check(err)fmt.Print(string(dat))然而,无论我如何尝试,我都只能得到这个输出syntaxerror:unexpectedcomma,expectingsemicolonornewlineor}我在没有IDE的情况下工作,随着变量数量的增加,必须将

正在测试 log.Fatalf?

我想在go代码中实现100%的测试覆盖率。我无法涵盖以下示例-任何人都可以帮助我吗?packageexampleimport("io/ioutil""log")funccheckIfReadable(filenamestring)(string,error){_,err:=ioutil.ReadFile(filename)iferr!=nil{log.Fatalf("Cannotreadthefile...howtoaddcoveragetestforthisline?!?")}return"",nil}funcmain(){checkIfReadable("dummy.txt")}一

go - 不能使用 p[idx + 1 :] (type []Person) as type Person in append

这个问题在这里已经有了答案:cannotusetype[]runeastyperuneinappend(1个回答)关闭2个月前。packagemainimport("fmt")typePersonstruct{namestringageint}funcmain(){p:=[]Person{{"Kate",20},{"Simon",30},{"John",28},{"Lake",19},}n:=[]string{"Simon","Kate","Lake",}foridx:=0;idx我有上面的代码来删除pslice中显示在nslice中的人。但是在编译的时候出现了如下错误:./main.

go - golang 中的类型不一致,不能将 <Type> 用作 <Type>

我正在用Go编写一个使用Logger对象类型的应用程序。在其中我使用了另一个使用相同记录器对象类型的应用程序:应用1:import"gitlab.sio.com/go/zlog"varlogger=zlog.New(append(opts,zlog.App(c.Name,typ,version),zlog.Env(c.Environment),)...)....router.GET("/get",GetHandler(logger))....funcGetHandler(logger*zlog.Logger){....mdl,_:=security.New(*logger)....}A

go - 关于 "cannot use time.Now() (type time.Time) as type "

使用以下类型定义获取“不能使用time.Now()(类型time.Time)作为字段值中的类型typetime”import("time")typetypetimetime.TimetypeFriendsstruct{NamestringBirthdaytypetime}John:=Friends{Name:"John",Birthday:time.Now()}如果我用直接类型形式(time.Time)替换typetime,就没有问题。GO的规则背后是什么??:> 最佳答案 time.Time和typetime是不同的类型(尽管它们

go - 调用 log.Fatalln 时是否调用延迟函数?

db,err:=sql.Open("postgres","…")iferr!=nil{log.Fatalln(err)}deferdb.Close()tpl,err:=template.ParseGlob("")iferr!=nil{log.Fatalln(err)}如果template.ParseGlob("")返回错误,db.Close()是否仍在调用? 最佳答案 不,延迟函数没有运行。这是对log.Fatal的描述:FatalisequivalenttoPrint()followedbyacalltoos.Exit(1).lo

google-app-engine - 无法使用 appengine/log 找到日志

我有这个代码://main.gopackagemagnumimport("net/http""google.golang.org/appengine""google.golang.org/appengine/log")funcinit(){http.HandleFunc("/tasks/backup",handler)}funchandler(whttp.ResponseWriter,r*http.Request){ctx:=appengine.NewContext(r)log.Debugf(ctx,"TestingcrontasksusingGo")}//cron.yamlcron: