Merge pull request #550 from mymmrac/govet-linter
feat(linter): Fix govet linter
This commit is contained in:
commit
273a8a2318
17 changed files with 29 additions and 61 deletions
19
.github/workflows/pr.yml
vendored
19
.github/workflows/pr.yml
vendored
|
|
@ -24,25 +24,6 @@ jobs:
|
||||||
with:
|
with:
|
||||||
version: v2.10.1
|
version: v2.10.1
|
||||||
|
|
||||||
# TODO: Remove once linter is properly configured
|
|
||||||
vet:
|
|
||||||
name: Vet
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Run go generate
|
|
||||||
run: go generate ./...
|
|
||||||
|
|
||||||
- name: Run go vet
|
|
||||||
run: go vet ./...
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Tests
|
name: Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ linters:
|
||||||
- godox
|
- godox
|
||||||
- goprintffuncname
|
- goprintffuncname
|
||||||
- gosec
|
- gosec
|
||||||
- govet
|
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- lll
|
- lll
|
||||||
- maintidx
|
- maintidx
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func authLoginOpenAI(useDeviceCode bool) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := auth.SetCredential("openai", cred); err != nil {
|
if err = auth.SetCredential("openai", cred); err != nil {
|
||||||
fmt.Printf("Failed to save credentials: %v\n", err)
|
fmt.Printf("Failed to save credentials: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +188,7 @@ func authLoginGoogleAntigravity() {
|
||||||
fmt.Printf("Project: %s\n", projectID)
|
fmt.Printf("Project: %s\n", projectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := auth.SetCredential("google-antigravity", cred); err != nil {
|
if err = auth.SetCredential("google-antigravity", cred); err != nil {
|
||||||
fmt.Printf("Failed to save credentials: %v\n", err)
|
fmt.Printf("Failed to save credentials: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +265,7 @@ func authLoginPasteToken(provider string) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := auth.SetCredential(provider, cred); err != nil {
|
if err = auth.SetCredential(provider, cred); err != nil {
|
||||||
fmt.Printf("Failed to save credentials: %v\n", err)
|
fmt.Printf("Failed to save credentials: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,8 @@ func gatewayCmd() {
|
||||||
channel, chatID = "cli", "direct"
|
channel, chatID = "cli", "direct"
|
||||||
}
|
}
|
||||||
// Use ProcessHeartbeat - no session history, each heartbeat is independent
|
// Use ProcessHeartbeat - no session history, each heartbeat is independent
|
||||||
response, err := agentLoop.ProcessHeartbeat(context.Background(), prompt, channel, chatID)
|
var response string
|
||||||
|
response, err = agentLoop.ProcessHeartbeat(context.Background(), prompt, channel, chatID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tools.ErrorResult(fmt.Sprintf("Heartbeat error: %v", err))
|
return tools.ErrorResult(fmt.Sprintf("Heartbeat error: %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ func skillsInstallFromRegistry(cfg *config.Config, registryName, slug string) {
|
||||||
workspace := cfg.WorkspacePath()
|
workspace := cfg.WorkspacePath()
|
||||||
targetDir := filepath.Join(workspace, "skills", slug)
|
targetDir := filepath.Join(workspace, "skills", slug)
|
||||||
|
|
||||||
if _, err := os.Stat(targetDir); err == nil {
|
if _, err = os.Stat(targetDir); err == nil {
|
||||||
fmt.Printf("\u2717 Skill '%s' already installed at %s\n", slug, targetDir)
|
fmt.Printf("\u2717 Skill '%s' already installed at %s\n", slug, targetDir)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +126,7 @@ func skillsInstallFromRegistry(cfg *config.Config, registryName, slug string) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Join(workspace, "skills"), 0o755); err != nil {
|
if err = os.MkdirAll(filepath.Join(workspace, "skills"), 0o755); err != nil {
|
||||||
fmt.Printf("\u2717 Failed to create skills directory: %v\n", err)
|
fmt.Printf("\u2717 Failed to create skills directory: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -267,10 +267,10 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
|
||||||
|
|
||||||
transcribedText := ""
|
transcribedText := ""
|
||||||
if c.transcriber != nil && c.transcriber.IsAvailable() {
|
if c.transcriber != nil && c.transcriber.IsAvailable() {
|
||||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
transcriberCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
result, err := c.transcriber.Transcribe(ctx, voicePath)
|
result, err := c.transcriber.Transcribe(transcriberCtx, voicePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorCF("telegram", "Voice transcription failed", map[string]any{
|
logger.ErrorCF("telegram", "Voice transcription failed", map[string]any{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,7 @@ func (c *WeComBotChannel) handleMessageCallback(ctx context.Context, w http.Resp
|
||||||
AgentID string `xml:"AgentID"`
|
AgentID string `xml:"AgentID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := xml.Unmarshal(body, &encryptedMsg); err != nil {
|
if err = xml.Unmarshal(body, &encryptedMsg); err != nil {
|
||||||
logger.ErrorCF("wecom", "Failed to parse XML", map[string]any{
|
logger.ErrorCF("wecom", "Failed to parse XML", map[string]any{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,7 @@ func (c *WeComAppChannel) handleMessageCallback(ctx context.Context, w http.Resp
|
||||||
AgentID string `xml:"AgentID"`
|
AgentID string `xml:"AgentID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := xml.Unmarshal(body, &encryptedMsg); err != nil {
|
if err = xml.Unmarshal(body, &encryptedMsg); err != nil {
|
||||||
logger.ErrorCF("wecom_app", "Failed to parse XML", map[string]any{
|
logger.ErrorCF("wecom_app", "Failed to parse XML", map[string]any{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -852,19 +852,6 @@ func TestWeComAppMessageStructures(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("WeComImageMessage structure", func(t *testing.T) {
|
|
||||||
msg := WeComImageMessage{
|
|
||||||
ToUser: "user123",
|
|
||||||
MsgType: "image",
|
|
||||||
AgentID: 1000002,
|
|
||||||
}
|
|
||||||
msg.Image.MediaID = "media_123456"
|
|
||||||
|
|
||||||
if msg.Image.MediaID != "media_123456" {
|
|
||||||
t.Errorf("Image.MediaID = %q, want %q", msg.Image.MediaID, "media_123456")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("WeComAccessTokenResponse structure", func(t *testing.T) {
|
t.Run("WeComAccessTokenResponse structure", func(t *testing.T) {
|
||||||
jsonData := `{
|
jsonData := `{
|
||||||
"errcode": 0,
|
"errcode": 0,
|
||||||
|
|
|
||||||
|
|
@ -198,9 +198,7 @@ func TestWeComBotVerifySignature(t *testing.T) {
|
||||||
Token: "",
|
Token: "",
|
||||||
WebhookURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=test",
|
WebhookURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=test",
|
||||||
}
|
}
|
||||||
base := NewBaseChannel("wecom", cfgEmpty, msgBus, cfgEmpty.AllowFrom)
|
|
||||||
chEmpty := &WeComBotChannel{
|
chEmpty := &WeComBotChannel{
|
||||||
BaseChannel: base,
|
|
||||||
config: cfgEmpty,
|
config: cfgEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func Run(opts Options) (*Result, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(openclawHome); os.IsNotExist(err) {
|
if _, err = os.Stat(openclawHome); os.IsNotExist(err) {
|
||||||
return nil, fmt.Errorf("OpenClaw installation not found at %s", openclawHome)
|
return nil, fmt.Errorf("OpenClaw installation not found at %s", openclawHome)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,10 @@ func TestConvertKeysToSnake(t *testing.T) {
|
||||||
t.Fatal("expected map[string]interface{}")
|
t.Fatal("expected map[string]interface{}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := m["api_key"]; !ok {
|
if _, ok = m["api_key"]; !ok {
|
||||||
t.Error("expected key 'api_key' after conversion")
|
t.Error("expected key 'api_key' after conversion")
|
||||||
}
|
}
|
||||||
if _, ok := m["api_base"]; !ok {
|
if _, ok = m["api_base"]; !ok {
|
||||||
t.Error("expected key 'api_base' after conversion")
|
t.Error("expected key 'api_base' after conversion")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,10 +69,10 @@ func TestConvertKeysToSnake(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("expected nested map")
|
t.Fatal("expected nested map")
|
||||||
}
|
}
|
||||||
if _, ok := nested["max_tokens"]; !ok {
|
if _, ok = nested["max_tokens"]; !ok {
|
||||||
t.Error("expected key 'max_tokens' in nested map")
|
t.Error("expected key 'max_tokens' in nested map")
|
||||||
}
|
}
|
||||||
if _, ok := nested["allow_from"]; !ok {
|
if _, ok = nested["allow_from"]; !ok {
|
||||||
t.Error("expected key 'allow_from' in nested map")
|
t.Error("expected key 'allow_from' in nested map")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ func TestLoadOpenClawConfig(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(configPath, data, 0o644); err != nil {
|
if err = os.WriteFile(configPath, data, 0o644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ func ReadCodexCliCredentials() (accessToken, accountID string, expiresAt time.Ti
|
||||||
}
|
}
|
||||||
|
|
||||||
var auth CodexCliAuth
|
var auth CodexCliAuth
|
||||||
if err := json.Unmarshal(data, &auth); err != nil {
|
if err = json.Unmarshal(data, &auth); err != nil {
|
||||||
return "", "", time.Time{}, fmt.Errorf("parsing %s: %w", authPath, err)
|
return "", "", time.Time{}, fmt.Errorf("parsing %s: %w", authPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ func (t *EditFileTool) Execute(ctx context.Context, args map[string]any) *ToolRe
|
||||||
return ErrorResult(err.Error())
|
return ErrorResult(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(resolvedPath); os.IsNotExist(err) {
|
if _, err = os.Stat(resolvedPath); os.IsNotExist(err) {
|
||||||
return ErrorResult(fmt.Sprintf("file not found: %s", path))
|
return ErrorResult(fmt.Sprintf("file not found: %s", path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,19 @@ func validatePath(path, workspace string, restrict bool) (string, error) {
|
||||||
return "", fmt.Errorf("access denied: path is outside the workspace")
|
return "", fmt.Errorf("access denied: path is outside the workspace")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resolved string
|
||||||
workspaceReal := absWorkspace
|
workspaceReal := absWorkspace
|
||||||
if resolved, err := filepath.EvalSymlinks(absWorkspace); err == nil {
|
if resolved, err = filepath.EvalSymlinks(absWorkspace); err == nil {
|
||||||
workspaceReal = resolved
|
workspaceReal = resolved
|
||||||
}
|
}
|
||||||
|
|
||||||
if resolved, err := filepath.EvalSymlinks(absPath); err == nil {
|
if resolved, err = filepath.EvalSymlinks(absPath); err == nil {
|
||||||
if !isWithinWorkspace(resolved, workspaceReal) {
|
if !isWithinWorkspace(resolved, workspaceReal) {
|
||||||
return "", fmt.Errorf("access denied: symlink resolves outside workspace")
|
return "", fmt.Errorf("access denied: symlink resolves outside workspace")
|
||||||
}
|
}
|
||||||
} else if os.IsNotExist(err) {
|
} else if os.IsNotExist(err) {
|
||||||
if parentResolved, err := resolveExistingAncestor(filepath.Dir(absPath)); err == nil {
|
var parentResolved string
|
||||||
|
if parentResolved, err = resolveExistingAncestor(filepath.Dir(absPath)); err == nil {
|
||||||
if !isWithinWorkspace(parentResolved, workspaceReal) {
|
if !isWithinWorkspace(parentResolved, workspaceReal) {
|
||||||
return "", fmt.Errorf("access denied: symlink resolves outside workspace")
|
return "", fmt.Errorf("access denied: symlink resolves outside workspace")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ func (t *I2CTool) readDevice(args map[string]any) *ToolResult {
|
||||||
if reg < 0 || reg > 255 {
|
if reg < 0 || reg > 255 {
|
||||||
return ErrorResult("register must be between 0x00 and 0xFF")
|
return ErrorResult("register must be between 0x00 and 0xFF")
|
||||||
}
|
}
|
||||||
_, err := syscall.Write(fd, []byte{byte(reg)})
|
_, err = syscall.Write(fd, []byte{byte(reg)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrorResult(fmt.Sprintf("failed to write register 0x%02x: %v", reg, err))
|
return ErrorResult(fmt.Sprintf("failed to write register 0x%02x: %v", reg, err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,17 +79,17 @@ func (t *GroqTranscriber) Transcribe(ctx context.Context, audioFilePath string)
|
||||||
|
|
||||||
logger.DebugCF("voice", "File copied to request", map[string]any{"bytes_copied": copied})
|
logger.DebugCF("voice", "File copied to request", map[string]any{"bytes_copied": copied})
|
||||||
|
|
||||||
if err := writer.WriteField("model", "whisper-large-v3"); err != nil {
|
if err = writer.WriteField("model", "whisper-large-v3"); err != nil {
|
||||||
logger.ErrorCF("voice", "Failed to write model field", map[string]any{"error": err})
|
logger.ErrorCF("voice", "Failed to write model field", map[string]any{"error": err})
|
||||||
return nil, fmt.Errorf("failed to write model field: %w", err)
|
return nil, fmt.Errorf("failed to write model field: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writer.WriteField("response_format", "json"); err != nil {
|
if err = writer.WriteField("response_format", "json"); err != nil {
|
||||||
logger.ErrorCF("voice", "Failed to write response_format field", map[string]any{"error": err})
|
logger.ErrorCF("voice", "Failed to write response_format field", map[string]any{"error": err})
|
||||||
return nil, fmt.Errorf("failed to write response_format field: %w", err)
|
return nil, fmt.Errorf("failed to write response_format field: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writer.Close(); err != nil {
|
if err = writer.Close(); err != nil {
|
||||||
logger.ErrorCF("voice", "Failed to close multipart writer", map[string]any{"error": err})
|
logger.ErrorCF("voice", "Failed to close multipart writer", map[string]any{"error": err})
|
||||||
return nil, fmt.Errorf("failed to close multipart writer: %w", err)
|
return nil, fmt.Errorf("failed to close multipart writer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue