草庐IT

here-maps-rest

全部标签

rest - 在 API Rest golang 中发送 cookie

我在Golang工作,我正在构建一个API-Rest并且想知道,我可以使用restful设置cookies吗?我正在构建与用户身份验证相关的方法:登录、注销、注册等,现在我正在尝试使用生成的uuid在响应中设置cookie。我有这个:funcLogin(whttp.ResponseWriter,req*http.Request,pshttprouter.Params){...somecode....c:=&http.Cookie{Name:"session",Value:uuid.NewV4().String(),}http.SetCookie(w,c)w.Header().Set("

go - 替换 viper map 键而不替换整个 map

我在配置中使用viper。如何在不替换整个map的情况下替换key?packagemainimport("log""github.com/spf13/viper")typepersonstruct{FirststringLaststring}funcmain(){v:=viper.New()v.SetEnvPrefix("mememe")v.AutomaticEnv()bob:=person{First:"Bob",Last:"Smith",}john:=person{First:"John",Last:"Boothe",}v.SetDefault("people.bob",bob)v

forms - 通过 html 表单发送带有特定键的 map

我有一个看起来像这样的表格在我的Go应用程序中,我希望得到这样的map["mimetype":"text/plain",...]但我得到metadata["mimetype"]作为键这是我在Go中的逻辑forkey,values:=rangerq.Form{iflen(values)>0{value:=values[0]fmt.Println(key,value)}} 最佳答案 为什么不简单地更改表单输入名称以删除metadata[]部分?如果由于某种原因无法完成(例如,客户端Javascript依赖于这些名称),那么您可以使用如下

algorithm - 在 Go 中将 map 转换为树

我有一个非常具体的问题,我找不到解决方案。我有一个map[string]Metric,我想将它转换成树以便在前端使用。Metric接口(interface)看起来有一个Path()和一个Name()方法,name方法返回以句号分隔的路径的最后一部分(因此“my.awesome.metric”的路径将意味着该指标的名称为“metric”)树应按路径排序,并应包含IndexNode。这个结构看起来像这样:typeIndexNodestruct{NamestringPathstringChildren[]*IndexNode}所以像这样的map:{my.awesome.metric.down

php array_map不返回结果数组

我试图用低音替换数组值的间距,然后回忆起同一数组的所有值,但在空间中降低了。输入:$gFontsList=array("-1","AgencyFB","28","AharoniBold","BookshelfSymbol","100","BookshelfSymbol","111","BrowalliaNewBol");functiontoReplaceSpacing($gFontsListValues,$gFontsListIndex){if(gettype($gFontsListValues)==='string'){if(preg_match('//',$gFontsListValues

go - 命名查询无法解析 map

我有这段代码query:=`SELECTco_usernameasusername,co_passwordaspasswordFROMservers.coWHEREco_url=concat('https://',:co_url)`args:=map[string]interface{}{"co_url":in.Url,}rows,err:=collectorsConfig.Db.NamedQueryContext(ctx,query,args)iferr!=nil{msg:="Errorgettingcocredentialsforco'%s':%v"log.Error.Printf

rest - Golang 服务响应文件

如何在Go中更有效地从服务返回文件?例如,我收到这样一个文件这是我用来从服务接收文件的示例:func(b*BenefitListHandler)UploadAppend(whttp.ResponseWriter,r*http.Request){r.ParseMultipartForm(32在那之后,我很困惑如何从该请求发送另一个文件,如二进制文件,以减少时间和消耗。 最佳答案 查看有关问题的信息后,我得到了解决方案为了指定浏览器是一个文件,我将该header放入响应中:w.Header().Set("Content-Disposit

rest - 为什么 Go 包显示为未定义?

我无法理解以下代码的问题所在。VisualStudioCode编译器给我如下错误,因为包“util”未定义。'Error'message:'undefined:util.GetPortAndURL我将以下内容放在我的util.go文件的顶部packageutil我还在我的handlers.go文件中导入了包myproj/util,这是在其init方法中调用以下代码的文件。file,err:=ioutil.ReadFile("./creds.json")iferr!=nil{fmt.Printf("Fileerror:%v\n",err)//useabettererrorpatternh

json - 解码 map[string]interface{} 时出现 mgo 错误

我想在一个结构中存储一个任意的json对象:typeCstruct{Namestring`json:"name"bson:"name"`Configmap[string]interface{}`json:"config"bson:"config"`}当我存储任何深度嵌套的json对象时,这工作正常,但是当我检索它并且mgo尝试解码它时,我得到:Unmarshalcan'tdealwithstructvalues.Useapointer.我不确定指针应该是什么。如果我将其更改为:Config*map[string]interface{}错误发生在这里:https://github.com

rest - 从客户端向服务器发送数据 - REST webservice

我正在使用RESTfulWeb服务开发客户端-服务器应用程序。我想在客户端请求用户输入并将其发送到服务器并在我的程序的其余部分使用该名称,但我无法将该名称正确发送到服务器。下面是我的程序的一部分:客户:funcmain(){//gettinginputfmt.Println("Pleaseenteryourname:")reader:=bufio.NewReader(os.Stdin)myName,_:=reader.ReadString('\n')client:=&http.Client{CheckRedirect:nil,}reply,err:=http.NewRequest("G