草庐IT

上下级

全部标签

go - 如何导出入站请求结束后可以使用的上下文?

来自net/http包中的func(r*Request)Context()context.Context的文档:Forincomingserverrequests,thecontextiscanceledwhentheclient'sconnectioncloses,therequestiscanceled(withHTTP/2),orwhentheServeHTTPmethodreturns.如果我想在ServeHTTP方法返回后完成与请求相关的工作,例如发出通知,正确的做法是什么?我想根据值保留上下文链,但仅将上述方法最初返回的上下文传递给消息队列提交API不起作用,因为上下文可能

unit-testing - Uber Cadence 事件的单元测试上下文

我正在为使用UUID从联系人服务检索联系人的节奏事件功能编写单元测试。我想知道我应该将什么上下文传递给节奏事件。activity.Register(GetContactActivityFunc)funcGetContactActivityFunc(ctxcontext.Context,inputContactBbInput)(ContactBbOutput,error){...}这是测试函数。funcTestGetContactActivityFunc(t*testing.T){mockCSInterface:=&mocks.Interface{}csClient:=outbound.

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

logging - Logger.SetPrefix() 是否作为上下文粘在 channel /线程之间?

当我使用其他语言的日志包时,我总是强制执行某种类型的上下文Guid(UUID),每次调用记录器时都会记录下来。具体来说,这确实有助于在记录1000多个请求时跟踪哪组日志属于哪个Web请求或单个线程。我正在尝试使用Go附带的标准记录器来执行此操作。typeContextstruct{Log*log.Logger}//NewContextconstructsanewcontext.funcNewContext(r*http.Request)(*Context,error){id,err:=newUUID()iferr!=nil{log.Printf("ERRORinnewUUID():%s

struct - 在此上下文中, "make"函数对 map 做了什么

我是Go的新手,几天前一直在寻找有关表单的教程,现在我对自己有了更多的了解,我正在尝试创建我自己的错误处理程序,我可以将其与我的所有结构一起使用,有点像一个抽象类,但是我从教程中得到的例子让我有点难过。这是我用来测试make功能的小例子。我有点通过修补弄明白了,但我不明白它实际上在做什么,以及为什么它是必要的。typeErrorHandlerstruct{Errorsmap[string]string}typeFormstruct{ErrorHandler}funcmain(){form:=&Form{}iftrue{fmt.Printf("%p\n",&form.Errors)}el

go - 在 golang 中将元数据传递到上下文时出错

我正在处理特定的处理GRPC请求。我正在尝试根据以下代码示例将GRPC请求中的元数据传递到上下文中:https://github.com/go-kit/kit/blob/master/auth/jwt/transport.go#L47.(为了以防万一,contextKey的解释可以引用这里:https://medium.com/@matryer/context-keys-in-go-5312346a868d#.vn10llkse):下面是我的代码:typecontextKeystringfunc(ccontextKey)String()string{returnstring(c)}va

go - 如何在 http.HandleFunc 中设置上下文值?

我想在http.HandleFunc中设置上下文值。以下方法似乎有效。虽然我有点担心*r=*r.WithContext(ctx)。typecontextKeystringvarmyContext=contextKey("myContext")funcsetValue(r*http.Request,valstring){ctx:=context.WithValue(r.Context(),myContext,val)*r=*r.WithContext(ctx)}http.HandleFunc("/",func(whttp.ResponseWriter,r*http.Request){se

此上下文已知 javax.xml.bind.MarshalException 及其任何父类(super class)

我遇到了异常,正在寻找解决方案,我们将不胜感激。在其他一些消息中发现了同样的问题,但它们对我不起作用。请看下面的代码。javax.xml.bind.MarshalException-withlinkedexception:[com.sun.istack.SAXException2:classcom.mycompany.soma.ws.rest.v1.model.test.EmployeeConstructionnoranyofitssuperclassisknowntothiscontext.javax.xml.bind.JAXBException:classcom.mycompany

java - Spring xml + JUnit - xml 上下文文件在 src/test/resources 中不起作用但在 src/main/resources 中起作用

我遇到这样的junit测试问题。出于某种原因,spring上下文文件只有在我将它们放在maven项目的src/main/resources文件夹中时才有效。Intellij没有给我任何警告,但来自mvn和idebomb的junit测试运行程序。两种情况下的代码和输出如下:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration({"classpath:/test-applicationContext.xml"})publicclassDataSharingTest{AuthTokenServiceauthTokenServ

java - 我的 Spring Batch 上下文有什么问题?

这是SpringBatch的上下文:这是SpringBatch所说的:org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:Invalidcontentwasfoundstartingwithelement'b:tasklet'.Oneof'{"http://www.springframework.org/schema/batch":transaction-attributes,"http://www.springframework.org/schema/batch":no-rollback-exception-classes,"ht