diff --git a/Makefile b/Makefile index 869c73e2..0867c795 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,7 @@ build-linux-arm: CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -o chatgpt-dingtalk main.go lint: - env GOGC=25 golangci-lint run --fix -j 8 -v ./... \ No newline at end of file + env GOGC=25 golangci-lint run --fix -j 8 -v ./... + +goimports: + @bash ./scripts/goimports-reviser.sh diff --git a/config/config.go b/config/config.go index 1f83cbbf..cf15ebcb 100644 --- a/config/config.go +++ b/config/config.go @@ -10,8 +10,9 @@ import ( "sync" "time" - "github.com/eryajf/chatgpt-dingtalk/pkg/logger" "gopkg.in/yaml.v2" + + "github.com/eryajf/chatgpt-dingtalk/pkg/logger" ) type Credential struct { diff --git a/main.go b/main.go index 6e70cb07..a9cd5a3e 100644 --- a/main.go +++ b/main.go @@ -9,13 +9,14 @@ import ( "strings" "time" + "github.com/gin-gonic/gin" + "github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot" + "github.com/open-dingtalk/dingtalk-stream-sdk-go/client" + "github.com/eryajf/chatgpt-dingtalk/pkg/dingbot" "github.com/eryajf/chatgpt-dingtalk/pkg/logger" "github.com/eryajf/chatgpt-dingtalk/pkg/process" "github.com/eryajf/chatgpt-dingtalk/public" - "github.com/gin-gonic/gin" - "github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot" - "github.com/open-dingtalk/dingtalk-stream-sdk-go/client" ) func init() { diff --git a/pkg/cache/user_base.go b/pkg/cache/user_base.go index 9fe321a7..59a21900 100644 --- a/pkg/cache/user_base.go +++ b/pkg/cache/user_base.go @@ -3,8 +3,9 @@ package cache import ( "time" - "github.com/eryajf/chatgpt-dingtalk/config" "github.com/patrickmn/go-cache" + + "github.com/eryajf/chatgpt-dingtalk/config" ) // UserServiceInterface 用户业务接口 diff --git a/pkg/chatgpt/chatgpt.go b/pkg/chatgpt/chatgpt.go index aea1c90f..23fdd07e 100644 --- a/pkg/chatgpt/chatgpt.go +++ b/pkg/chatgpt/chatgpt.go @@ -6,8 +6,9 @@ import ( "net/url" "time" - "github.com/eryajf/chatgpt-dingtalk/public" openai "github.com/sashabaranov/go-openai" + + "github.com/eryajf/chatgpt-dingtalk/public" ) type ChatGPT struct { diff --git a/pkg/chatgpt/context.go b/pkg/chatgpt/context.go index 81058caa..f236f0bc 100644 --- a/pkg/chatgpt/context.go +++ b/pkg/chatgpt/context.go @@ -12,11 +12,11 @@ import ( "strings" "time" - "github.com/eryajf/chatgpt-dingtalk/pkg/dingbot" "github.com/pandodao/tokenizer-go" + openai "github.com/sashabaranov/go-openai" + "github.com/eryajf/chatgpt-dingtalk/pkg/dingbot" "github.com/eryajf/chatgpt-dingtalk/public" - openai "github.com/sashabaranov/go-openai" ) var ( diff --git a/pkg/chatgpt/export.go b/pkg/chatgpt/export.go index d839cef4..eb6c2f1a 100644 --- a/pkg/chatgpt/export.go +++ b/pkg/chatgpt/export.go @@ -5,6 +5,7 @@ import ( "time" "github.com/avast/retry-go" + "github.com/eryajf/chatgpt-dingtalk/pkg/logger" "github.com/eryajf/chatgpt-dingtalk/public" ) diff --git a/pkg/db/sqlite.go b/pkg/db/sqlite.go index 80efb5ea..72b627f2 100644 --- a/pkg/db/sqlite.go +++ b/pkg/db/sqlite.go @@ -3,9 +3,10 @@ package db import ( "os" - "github.com/eryajf/chatgpt-dingtalk/pkg/logger" "github.com/glebarez/sqlite" "gorm.io/gorm" + + "github.com/eryajf/chatgpt-dingtalk/pkg/logger" ) // 全局数据库对象 diff --git a/pkg/dingbot/client.go b/pkg/dingbot/client.go index 1a73f0e0..2dc15445 100644 --- a/pkg/dingbot/client.go +++ b/pkg/dingbot/client.go @@ -5,13 +5,14 @@ import ( "encoding/json" "errors" "fmt" - "github.com/eryajf/chatgpt-dingtalk/config" "io" "mime/multipart" "net/http" url2 "net/url" "sync" "time" + + "github.com/eryajf/chatgpt-dingtalk/config" ) // OpenAPI doc: https://open.dingtalk.com/document/isvapp/upload-media-files diff --git a/pkg/dingbot/client_test.go b/pkg/dingbot/client_test.go index da9f2d49..0a349d36 100644 --- a/pkg/dingbot/client_test.go +++ b/pkg/dingbot/client_test.go @@ -2,12 +2,13 @@ package dingbot import ( "bytes" - "github.com/eryajf/chatgpt-dingtalk/config" "image" "image/color" "image/png" "os" "testing" + + "github.com/eryajf/chatgpt-dingtalk/config" ) func TestUploadMedia_Pass_WithValidConfig(t *testing.T) { diff --git a/pkg/process/image.go b/pkg/process/image.go index d8513f42..ce533b55 100644 --- a/pkg/process/image.go +++ b/pkg/process/image.go @@ -3,13 +3,14 @@ package process import ( "context" "fmt" - "github.com/eryajf/chatgpt-dingtalk/public" "strings" + "github.com/solywsh/chatgpt" + "github.com/eryajf/chatgpt-dingtalk/pkg/db" "github.com/eryajf/chatgpt-dingtalk/pkg/dingbot" "github.com/eryajf/chatgpt-dingtalk/pkg/logger" - "github.com/solywsh/chatgpt" + "github.com/eryajf/chatgpt-dingtalk/public" ) // ImageGenerate openai生成图片 diff --git a/pkg/process/process_request.go b/pkg/process/process_request.go index 9e84eb86..dae2f73c 100644 --- a/pkg/process/process_request.go +++ b/pkg/process/process_request.go @@ -6,11 +6,12 @@ import ( "strings" "time" + "github.com/solywsh/chatgpt" + "github.com/eryajf/chatgpt-dingtalk/pkg/db" "github.com/eryajf/chatgpt-dingtalk/pkg/dingbot" "github.com/eryajf/chatgpt-dingtalk/pkg/logger" "github.com/eryajf/chatgpt-dingtalk/public" - "github.com/solywsh/chatgpt" ) // ProcessRequest 分析处理请求逻辑 diff --git a/public/public.go b/public/public.go index a9babcdc..9ab8f30b 100644 --- a/public/public.go +++ b/public/public.go @@ -1,11 +1,12 @@ package public import ( + "github.com/sashabaranov/go-openai" + "github.com/eryajf/chatgpt-dingtalk/config" "github.com/eryajf/chatgpt-dingtalk/pkg/cache" "github.com/eryajf/chatgpt-dingtalk/pkg/db" "github.com/eryajf/chatgpt-dingtalk/pkg/dingbot" - "github.com/sashabaranov/go-openai" ) var UserService cache.UserServiceInterface diff --git a/public/tools_test.go b/public/tools_test.go index 7b463823..50b248ac 100644 --- a/public/tools_test.go +++ b/public/tools_test.go @@ -1,8 +1,9 @@ package public import ( - "github.com/eryajf/chatgpt-dingtalk/config" "testing" + + "github.com/eryajf/chatgpt-dingtalk/config" ) func TestCheckRequestWithCredentials_Pass_WithNilConfig(t *testing.T) { diff --git a/scripts/goimports-reviser.sh b/scripts/goimports-reviser.sh new file mode 100755 index 00000000..f170ce2d --- /dev/null +++ b/scripts/goimports-reviser.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +go install github.com/incu6us/goimports-reviser/v2@latest + +PROJECT_NAME=github.com/eryajf/chatgpt-dingtalk + +find . -name '*.go' -print0 | while IFS= read -r -d '' file; do + goimports-reviser -file-path "$file" -project-name "$PROJECT_NAME" +done