草庐IT

go-simplejson

全部标签

go - 为什么 time.Time 在 bson.Marshal 和 bson.Unmarshal 之后不相等?

为什么会输出false?我期待true...packagemainimport("fmt""time""gopkg.in/mgo.v2/bson")typeSstruct{Ttime.Time}funcmain(){t:=S{time.Now()}bytes,_:=bson.Marshal(t)vardtSbson.Unmarshal(bytes,&dt)fmt.Println(dt.T.Equal(t.T))}gorun上面会输出false,为什么Marshal/Unmarshal不保留原来的值? 最佳答案 Bson存储时间的精度

docker - go dep 不在 docker-compose 上运行

我的问题是docker-compose总是返回:golang_1|bash:dep:找不到命令这是我的docker-compose.yml:version:"3"services:postgres:image:postgresenvironment:POSTGRES_USER:mini_apiPOSTGRES_PASSWORD:p4ssw0rdPOSTGRES_DB:mini-apivolumes:-./db.sql:/docker-entrypoint-initdb.d/db.sqlports:-"5433:5432"golang:image:golang:1.11.0-stretc

go - golang 中的 math.Pow 是否适合这个公式?

公式:C1*B+C2B^2+C3*G+C4*G*B+C5*G*B^2+C6*G^2+C7*G^2*B+C8*R+C9*R*B+C10*R*B^2+C11*R*G+C12*R*G*B+C13*R*G^2+C14*R^2+C15*R^2*B+C16*R^2*G+C17*1+C18*R^3+C19*G^3+C20*B^3开始:varC1=-0.0343varC2=0.4062...snippedC1*B+C2*math.Pow(B,2)+C3*G+C4*G*B+C5*G*math.Pow(B,2)+C6*G*math.Pow(G,2)+C7*math.Pow(G,2)*B+C8*R+C9*R

go - 通过引用传递接收者结构

我需要一个函数来返回一个由调用者传递给函数的结构。每次调用函数时,结构都会不同。我正在使用ORMpostgres驱动程序“github.com/go-pg/pg”。据我了解,ORM要求在调用.Query()之前定义结构,后者使用数据库中的数据填充结构。funcPgSql(userUser,statementstring)(output[]string,errerror){_,err=db.Query(&users,`SELECT*FROMstandard_lookupWHEREpkid_='STATE|AFKDZ'`)}结果将在用户结构中。但是,我需要在不同的包中定义这个结构并将其传递

go - 如何执行命令来执行sed

我有以下代码段不起作用。编译但不执行预期的操作。在bash上执行相同的命令。为什么?hash:="4ab32de"cmd="sed-i-e's/clt_[0-9a-z]*/clt_"+hash+"/g'/tmp/test.env"parts=strings.Fields(cmd)for_,part:=rangeparts{fmt.Printf("\n%s",part)}head=parts[0]out,err=exec.Command(head,parts[1:]...).Output()fmt.Printf("\nnewcmdis%s\n",cmd)fmt.Printf("out:%

go - Golang 中的结构声明

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion鉴于Go主要基于C,并且该语言中的结构定义如下:structPerson{...}为什么我们在Go中有额外的词?typePersonstruct{...}为什么我们需要同时提到类型和结构?似乎有点冗长。

go - 解码映射结构

首先我有一个结构:typetimesmap[time.Time]struct{}我需要为它编写Marshal/Unmarshal方法来转换json。我写过MarshalJSON方法,但不明白如何写UnmarshalJSON方法。func(tstimes)keys()[]time.Time{res:=make([]time.Time,0,len(ts))forkey:=rangets{res=append(res,key)}returnres}func(tstimes)MarshalJSON()([]byte,error){returnjson.Marshal(ts.keys())}fu

go - 如何修复此导入?

main_test.gopackagemain_testimport("log""os""testing"".")funcTestMain(m*testing.M){a=main.App{}a.Init(os.Getenv("TEST_DB_USERNAME"),os.Getenv("TEST_DB_PASSWORD"),os.Getenv("TEST_DB_NAME"))ensureTableExists()code:=m.Run()clearTable()os.Exit(code)}应用程序去packagemainimport("database/sql""fmt""log""gi

go - 为什么 "close"不是保留关键字?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestionclose()似乎是channel的保留关键字。让它成为一个内置的似乎有点强大,当它可能只是一个channel上的方法时,不是吗?比如在创建和关闭文件时?我想对于len()也可能有同样的要求?

regex - 使用 Go 从字符串中删除所有文章和其他字符串?

Go中是否有任何方法或正则表达式可以只删除字符串中使用的冠词?我试过下面的代码可以做到这一点,但它也会从我正在显示下面代码的字符串中删除其他单词:removalString:="Thisisastring"stringToRemove:=[]string{"a","an","the","is"}for_,wordToRemove:=rangestringToRemove{removalString=strings.Replace(removalString,wordToRemove,"",-1)}space:=regexp.MustCompile(`\s+`)trimedExtraSp