feat(channels): add feishu channel support with build tags
Introduced a stub implementation for the Feishu channel to allow compilation without the feishu tag, preventing dependency issues. Updated the NewFeishuChannel function signature to return a generic Channel type, accommodating both the stub and the actual implementation. This change resolves potential MaxInt64 overflow problems in specific environments.
This commit is contained in:
parent
4a39658e61
commit
f48e72599f
4 changed files with 28 additions and 3 deletions
BIN
picoclaw.exe~
Normal file
BIN
picoclaw.exe~
Normal file
Binary file not shown.
|
|
@ -1,3 +1,7 @@
|
||||||
|
// 飞书通道实现。通过 build tag 可选编译,规避 larksuite/oapi-sdk-go 的 math.MaxInt64 溢出问题。
|
||||||
|
// 旧实现:无 build tag,始终编译,导致依赖的 larksuite drive/v1 在部分环境编译失败。
|
||||||
|
//go:build feishu
|
||||||
|
|
||||||
package channels
|
package channels
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -28,7 +32,10 @@ type FeishuChannel struct {
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFeishuChannel(cfg config.FeishuConfig, bus *bus.MessageBus) (*FeishuChannel, error) {
|
// NewFeishuChannel 创建飞书通道。
|
||||||
|
// 旧签名: func NewFeishuChannel(cfg config.FeishuConfig, bus *bus.MessageBus) (*FeishuChannel, error)
|
||||||
|
// 改为 (Channel, error) 以便 feishu_stub.go 在未编译飞书时返回 nil 占位。
|
||||||
|
func NewFeishuChannel(cfg config.FeishuConfig, bus *bus.MessageBus) (Channel, error) {
|
||||||
base := NewBaseChannel("feishu", cfg, bus, cfg.AllowFrom)
|
base := NewBaseChannel("feishu", cfg, bus, cfg.AllowFrom)
|
||||||
|
|
||||||
return &FeishuChannel{
|
return &FeishuChannel{
|
||||||
|
|
|
||||||
16
pkg/channels/feishu_stub.go
Normal file
16
pkg/channels/feishu_stub.go
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
// 未启用飞书时的占位实现,使 manager 在无 -tags=feishu 时仍可编译。
|
||||||
|
// 旧方案:无此文件,feishu.go 始终参与编译,强制依赖 larksuite 导致 MaxInt64 溢出。
|
||||||
|
//go:build !feishu
|
||||||
|
|
||||||
|
package channels
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/bus"
|
||||||
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewFeishuChannel(cfg config.FeishuConfig, bus *bus.MessageBus) (Channel, error) {
|
||||||
|
return nil, fmt.Errorf("feishu support not compiled in, build with -tags=feishu")
|
||||||
|
}
|
||||||
|
|
@ -73,13 +73,15 @@ func (m *Manager) initChannels() error {
|
||||||
|
|
||||||
if m.config.Channels.Feishu.Enabled {
|
if m.config.Channels.Feishu.Enabled {
|
||||||
logger.DebugC("channels", "Attempting to initialize Feishu channel")
|
logger.DebugC("channels", "Attempting to initialize Feishu channel")
|
||||||
feishu, err := NewFeishuChannel(m.config.Channels.Feishu, m.bus)
|
// 旧: feishu, err := NewFeishuChannel(...); m.channels["feishu"] = feishu
|
||||||
|
// 改用 ch 以适配 NewFeishuChannel 返回 (Channel, error) 的接口
|
||||||
|
ch, err := NewFeishuChannel(m.config.Channels.Feishu, m.bus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorCF("channels", "Failed to initialize Feishu channel", map[string]interface{}{
|
logger.ErrorCF("channels", "Failed to initialize Feishu channel", map[string]interface{}{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
m.channels["feishu"] = feishu
|
m.channels["feishu"] = ch
|
||||||
logger.InfoC("channels", "Feishu channel enabled successfully")
|
logger.InfoC("channels", "Feishu channel enabled successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue