草庐IT

google_maps

全部标签

go http.Request.Conn.ActiveConn是一个map,那么会不会有并发map的问题呢?

去http.Request.Context.ActiveConn是一个map,会不会有并发map问题?如果有很多连接,我打印包含ActiveConn(map)的request.Context,会不会有并发读写map的问题?packagemainimport("fmt""net/http")funcmain(){http.HandleFunc("/",func(whttp.ResponseWriter,r*http.Request){fmt.Fprintf(w,"r.ctx:%#v,%+v",r.Context(),r.Context())})http.ListenAndServe(":

firebase - 在谷歌云功能中找不到包 "firebase.google.com/go"

我正在尝试运行一些示例代码,这些代码使用Firestore服务器中的云函数存储一些随机数据,但是,云函数部署命令拒绝构建命令://PackagepcontainsanHTTPCloudFunction.packagepimport(//...firebase"firebase.google.com/go""log""net/http""os")//Store1StoresdataonFireBasefuncStore1(whttp.ResponseWriter,r*http.Request){//Usetheapplicationdefaultcredentialsctx:=conte

根据 map[string]somestruct 调用 golang 调度方法

假设我有很多带有接收器的函数或方法,每个函数或方法都有不同类型的参数。我想使用表驱动方法来调度函数或方法调用。所以我将构建一个这样的表:typecommandstruct{namestringhandlerfunc(parameter...interface{})//Idon'tknowwhethertouse`...interface{}`iscorrect}table:=map[string]command{...}func(ccommand)foo(f1int,f2string){}func(ccommand)bar(b1bool,b2int,b3string){}//metho

google-app-engine - 如何使用结构数组实现 google datastore propertyloadsaver

当你有一个结构数组时,你如何为谷歌数据存储实现Load()和Save()?这显然是可能的,但如何实现呢?首先,当您允许数据​​存储本身使用Phone对象列表序列化一个Person时,您可以使用反射来查看它在内部创建了一个列表>*datastore.Entity对象:packagemainimport("fmt""reflect""cloud.google.com/go/datastore")typePhonestruct{TypestringNumberstring}typePersonstruct{NamestringPhone[]Phone}funcmain(){person:=P

go - 使用 google.protobuf.Timestamp 在 Go 中解析具有时区偏移的日期时间戳

我正在创建一个将使用GRPC和protobuf的Go应用程序。我的RPC服务应接收包含google.protobuf.Timestamp类型的消息,对其进行解析并最终将其保存在数据库中或对其执行更多操作。对于google.protobuf.Timestamp类型的有效输入,我感到很困惑。我希望对带有时区偏移量的日期时间戳使用以下格式。2019-02-15T13:00:00+01:00这是我正在使用的原型(prototype)文件。syntax="proto3"packageexample;import"google/protobuf/timestamp.proto"serviceTes

json - 在 map[string]interface{} 的值上键入 switch 到 []map[string]interface{}

问题我面临从json对象中删除不需要的数组的问题,例如。只有一个元素不是对象或数组的数组。(没有数组作为输入的根)例子在:{"name":[{"inner":["test"]}]}通缉令:{"name":[{"inner":"test"}]}方法我从对已解析的map[string]interface{}的值进行简单类型切换开始,并认识到它不会切换到case[]map[string]interface{}。(举个例子)这是我想出的实现。它适用于大多数场景,但不适用于数组中的内部对象。typejsonMapmap[string]interface{}typejsonMapList[]map

go - 如何将嵌套接口(interface)转换为 map slice 的 map ?

我有一个map数组的mapmap[string][]map[string]string,只是,当我获取数据时,它的格式是map[interface{}]map[interface{}][]map[interface{}]interface{},所以我只剩下做一堆嵌套的类型断言,这真的很笨拙,需要很长时间来编写,是难以读/写,并且可能容易出错,就像这样;ifkey=="identities"{idErrMessage:="Sorry,therewasaproblemwithanidentity"idArray,ok:=setting.(map[string]interface{})ifo

dictionary - 为什么 map 值变得不存在?

我正在使用映射将随机字符串键存储到*os.File对象。用户将上传一个文件,我想在全局map中保存对该文件的引用,以便稍后删除它。我有一个http处理程序来处理上传,最后,我将一个随secret钥从操作系统uuidgen映射到类型为*os.File的“logBu​​ndleFile”。vardb=map[string]*os.File{}funcuploadHandler(whttp.ResponseWriter,r*http.Request){r.ParseMultipartForm(5完成后,您将被重定向到此sessionHandler。它将检查正文中的ID是否有效,即是否映射到*

google-app-engine - 在 Google App Engine 上从 main.go 传递出去时上下文值发生变化

有一个问题,当我将context.Context传递给GoogleAppEngine上的另一个包后,我不知道为什么会发生更改。以下代码在AppEngine上运行时运行良好:packagemainimport("net/http""log""google.golang.org/appengine")funcmain(){http.HandleFunc("/",myHandler)appengine.Main()}funcmyHandler(whttp.ResponseWriter,r*http.Request){ctx:=r.Context()account,err:=appengine

dictionary - Golang 多个计时器与 map+channel+mutex

所以我正在使用map/channel/mutex实现多个计时器。为了取消计时器,我有一个存储取消信息的channel映射,下面是代码:vartimerCancelMap=make(map[string]chaninterface{})varmutexLockersync.MutexfunccancelTimer(timerIndexstring){mutexLocker.Lock()defermutexLocker.Unlock()timerCancelMap[timerIndex]=make(chaninterface{})timerCancelMap[timerIndex]现在这个