gpt4 book ai didi

go - 拥有多模块 golang 存储库是否有意义,这样人们就不必仅仅因为它的类型而导入我的库

转载 作者:行者123 更新时间:2023-12-03 10:09:44 25 4
gpt4 key购买 nike

我正在编写一个库来简化流处理,该库公开了接口(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com