作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个库来简化流处理,该库公开了接口(interface),以便人们可以编写插件和中间件。这个问题是一些接口(interface)使用库中定义的具体类型,这迫使人们只为它的类型导入我的库。我在想是否将我所有的类型和接口(interface)保存在一个单独的包中并使用它自己的 go.mod 文件是一个好主意,这样人们就可以只导入类型包而不必拉入整个库。
package ziggurat
import "context"
type Handler interface {
HandleEvent(event Event) ProcessStatus
}
type Streams interface {
Consume(ctx context.Context, handler Handler) chan error
}
type StructuredLogger interface {
Info(message string, kvs ...map[string]interface{})
Debug(message string, kvs ...map[string]interface{})
Warn(message string, kvs ...map[string]interface{})
Error(message string, err error, kvs ...map[string]interface{})
Fatal(message string, err error, kvs ...map[string]interface{})
}
type Event interface {
Value() []byte
Context() context.Context
Header(key string) string
}
要实现 Handler 接口(interface),人们必须使用
Event
接口(interface),这需要他们拉入整个库。
最佳答案
Does it make sense to have multimodule golang repo just so people will not have to import my library just for it's types [?]
关于go - 拥有多模块 golang 存储库是否有意义,这样人们就不必仅仅因为它的类型而导入我的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65453883/
我是一名优秀的程序员,十分优秀!