草庐IT

golang-gin

全部标签

http - 如何使用 golang 发送帖子,用这个 curl 命令替换

错误是:streamerror:streamID1;REFUSED_STREAM但是curl命令没问题:curl-H"Content-type:application/json"-XPOST-d'{"skip_mobile":false,"selected_website":[],"basic_info":{"name":"王凯","id_card_num":"410881199210130778","cell_phone_num":"18817953402"}}'https://www.juxinli.com/orgApi/rest/v2/applications/yiqime我想知

json - 如何从 golang-map 中检索数据

我将我的json数据放在Unmarsha1上。我怎样才能检索像这样的数据log.Print(b["beat"]["name"])但是我怎样才能检索像这样的数据log.Print(b["beat"]["name"])-->获取数据失败我的代码如下:varbmap[string]interface{}data:=[]byte(`{"foo":1,"beat":{"@timestamp":"2016-10-27T12:02:00.352Z","name":"localhost.localdomain","version":"6.0.0-alpha1"}}`)err:=json.Unmarsh

bash - golang - 在空的 bash 窗口中打开文件

假设我有这段代码:packagemainimport("io/ioutil""fmt")funccheck(errerror){iferr!=nil{panic(err)}}funcmain(){file,err:=ioutil.ReadFile("test.txt")check(err)fmt.Print(string(file))}当使用gorun运行它时,我希望它被写入一个清除的bash窗口中。是否可以在不使用任何额外的开源存储库的情况下这样做?提前致谢。 最佳答案 如果清除终端确实是您程序职责的一部分,那么请查看此问题的答案

go - 如何将 interface{} 转换为 Golang 中的嵌套树

传入的接口(interface){}会被转换为[]map[string]接口(interface){}。原始数据类型是[]map[string]interface{}:[{"ID":1,"Name":"Root","ParentID":0,"Path":"Root"},{"ID":2,"Name":"Ball","ParentID":1,"Path":"Root/Ball"},{"ID":3,"Name":"Foot","ParentID":2,"Depth":2,"Path":"Root/Ball/Foot"}]希望得到json的类型:[{"ID":1,"Name":"Root","

macos - If 和 else 扰乱了 golang 中的变量作用域

我有以下golang代码:varcmd1*exec.Cmdmsg=receive_cmd();ifstrings.Contains(msg,"Log-In"){cmd1:=exec.Command("echo","Pleaselogin")}else{ifstrings.Contains(msg,"SignUp"){cmd1:=exec.Command("echo","PleaseSignUp")}}varoutbytes.Buffervarstderrbytes.Buffercmd1.Stdout=&outcmd1.Stderr=&stderrerr1:=cmd1.Run()ifer

dictionary - 如何在 golang 中遍历嵌套结构?

我是Golang的新手:这些是我定义的结构:typeNamemap[string]InfotypeInfostruct{Addressesstring`json:"addresses"`Hostmap[string]Server`json:"host"`}typeServerstruct{Ipaddressstring`json:"ip"`Statusstring`json:"status"`}varresultName解码Json后我得到:result=[user1:{192.168.98.0/26map[xx.user1.domain.com:{192.168.98.1good}x

http - 从外部世界连接到我自己的 golang 服务器

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎不是关于aspecificprogrammingproblem,asoftwarealgorithm,orsoftwaretoolsprimarilyusedbyprogrammers的.如果您认为这个问题是关于anotherStackExchangesite的主题,您可以发表评论,说明问题可能在哪里得到解答。关闭5年前。Improvethisquestion所以我用go编写了这段代码://firstserver-myfirstserverpackagemainimport("fmt""l

go - 我如何在文件开头的 golang 中删除 

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭5年前。ImprovethisquestionfuncTest_Read_Unicode(t*testing.T){s:="Οὐχὶταὐτὰ,παρίσταταίμοι,γιγνώσκεινὦ,ἄνδρες᾿Αθηναῖοι\n"+"ὅταντ᾿,εἰςτὰπράγματαἀποβλέψω,

sockets - Golang UDP 和 TCP 并排

是否可以在一个脚本中同时使用TCP和UDP?我需要我的一些包通过TCP发送和接收,一些通过UDP发送和接收funcmain(){////───TCP────────────────────────────────────────────────────────────────────////Listenforincomingconnections.l,err:=net.Listen("tcp","localhost"+":"+"3000")iferr!=nil{fmt.Println("Errorlistening:",err.Error())os.Exit(1)}//Closethe

session - Gorilla session 不会在 Golang 中持续存在

我在使用Gorillasession处理程序在Golang中持久保存session时遇到了问题。类似的问题(未解决!)已在其他堆栈溢出问题中提出(此处:Sessionsvariablesingolangnotsavedwhileusinggorillasessions和此处:cannotgetgorillasessionvaluebykey)。这非常可怕,因为看起来1)不仅仅是我2)目前似乎没有解决方案3)GorillaSessions包可能从根本上被破坏了。这里是更详细的问题:我可以在登录时设置session没有问题。但是,在我登录并向后端发出另一个请求后,session值不会持久化