在我的maven项目中,我有一个模块取决于另一个模块,它是测试代码/资源:
...
<scope>test</scope>
<type>test-jar</type>
...
Run Code Online (Sandbox Code Playgroud)
现在,两个模块都有自己的logback-test.xml,每个模块都有一个特定的配置,用于在该特定模块中运行测试.但是,正如预期的那样,在子模块中运行测试时,logback会抱怨路径中有多个logback-test.xml,并且使用它的默认日志记录配置执行此操作:
08:44:17,528 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
08:44:17,530 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:path/to/my/project/module2/logback-test.xml]
08:44:17,532 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs multiple times on the classpath.
08:44:17,533 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [file:/C:/path/to/my/project/module2/logback-test.xml]
08:44:17,533 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [file:/C:/path/to/my/project/module1/logback-test.xml]
08:44:17,636 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
08:44:17,647 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate …Run Code Online (Sandbox Code Playgroud) 假设我有代码,其中一个函数接受另一个作为参数:
type Person struct {
Name string
}
func personBuilder() * Person {
return &Person{Name: "John"}
}
func printRetrievedItem(callback func() interface {}){
fmt.Print(callback());
}
func doStuff(){
printRetrievedItem(personBuilder);
}
Run Code Online (Sandbox Code Playgroud)
这导致错误cannot use personBuilder (type func() *Person) as type func() interface {} in function argument。如果我将personBuilder返回类型更改为interface{},它可以工作,但在我正在处理的实际项目中,我希望有一个具体的类型来实现清晰的设计和 TDD 目的。
Go 是否支持这种方法签名泛化?如果您无法更改personBuilder部件(例如,您有很多返回不同类型结构的无参数函数,并且您想构建一个接受这些构建器中的任何一个作为参数的消费者函数),有什么解决方法?