From 593b67e8c9286897a3757557da47b9a05ede6348 Mon Sep 17 00:00:00 2001 From: Breeze0806 <53822089+Breeze0806@users.noreply.github.com> Date: Tue, 5 Sep 2023 19:27:53 +0800 Subject: [PATCH] =?UTF-8?q?=20feat:=20=E4=BB=8D=E7=84=B6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?go=20generate=E8=BF=9B=E8=A1=8C=E6=9E=84=E5=BB=BA=20(#25)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Build.yml | 4 ++-- Makefile | 6 +----- README.md | 2 +- datax/README.md | 2 +- release.bat | 9 ++------- tools/datax/build/main.go | 14 ++++++-------- 6 files changed, 13 insertions(+), 24 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index fc095d3..18a8c85 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.16', '1.17' , '1.18', '1.19', '1.20'] + go: [ '1.16', '1.17' , '1.18', '1.19', '1.20', '1.21'] name: Go ${{ matrix.go }} sample steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup go uses: actions/setup-go@v4 with: diff --git a/Makefile b/Makefile index a01403c..51cbc4c 100644 --- a/Makefile +++ b/Makefile @@ -58,11 +58,7 @@ cover: .PHONY: release release: -ifdef IGNORE_PACKAGES - @go run tools/datax/build/main.go -i ${IGNORE_PACKAGES} -else - @go run tools/datax/build/main.go -endif + @go generate ./... @cd cmd/datax && go build && cd ../.. @go run tools/datax/release/main.go .PHONY: doc diff --git a/README.md b/README.md index 2f5613f..cc3b61e 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ readerPlugin(reader)—> Framework(Exchanger+Transformer) ->writerPlugin(riter) ##### build ```bash -go run tools/datax/build/main.go +go generate ./... ``` 发布命令,用于将由开发者开发的reader和writer插件注册到程序中的代码 diff --git a/datax/README.md b/datax/README.md index b4d9894..766f5dc 100644 --- a/datax/README.md +++ b/datax/README.md @@ -460,7 +460,7 @@ go run tools/license/main.go golang静态编译的方式决定了go-etl框架不能用运行时动态加载插件的方式去获取插件,为此这里只能使用注册代码的方式,以下命令会生成将由开发者开发的reader和writer插件注册到程序中的代码。 ```bash -go run tools/datax/build/main.go +go generate ./... ``` 主要的原理如下会将对应go-etl/plugin插件中的reader和writer的resources的plugin.json生成plugin.go,同时在go-etl目录下生成plugin.go用于导入这些插件, 具体在tools/go-etl/build实现,另外通过-i命令可以忽略编译数据源来源,可以忽略db2, 由于db2会使用odbc去访问数据库,并且需要在linux中被依赖,如果不需要用这个直接忽略。 diff --git a/release.bat b/release.bat index 9374918..a67bec6 100644 --- a/release.bat +++ b/release.bat @@ -1,12 +1,7 @@ set GO111MODULE=on -cd %GOPATH%\src\github.com\Breeze0806\go-etl go mod download -go mod vendor -if defined IGNORE_PACKAGES ( - go run tools\datax\build\main.go -i %IGNORE_PACKAGES% -) else ( - go run tools\datax\build\main.go -) +go mod vendor +go generate ./... cd cmd\datax go build cd ../.. diff --git a/tools/datax/build/main.go b/tools/datax/build/main.go index 1b02b5c..0c49d55 100644 --- a/tools/datax/build/main.go +++ b/tools/datax/build/main.go @@ -18,7 +18,6 @@ import ( "bufio" "bytes" "encoding/json" - "flag" "fmt" "io/ioutil" "os" @@ -29,6 +28,7 @@ import ( mylog "github.com/Breeze0806/go/log" ) +//go:generate go run main.go var log mylog.Logger = mylog.NewDefaultLogger(os.Stdout, mylog.ErrorLevel, "[datax]") const ( @@ -116,18 +116,16 @@ func init() { } } ` - sourcePath = "datax/" - programPath = "cmd/datax/version.go" + sourcePath = "../../../datax/" + programPath = "../../../cmd/datax/version.go" ) func main() { - ignore := flag.String("i", "", "ignore packages, use dot to split, like db2,oracle, it will ignore db2 and oracle data source") - - flag.Parse() + ignore := os.Getenv("IGNORE_PACKAGES") ignoreMap := make(map[string]struct{}) - if *ignore != "" { - packages := strings.Split(*ignore, ",") + if ignore != "" { + packages := strings.Split(ignore, ",") for _, v := range packages { ignoreMap[v] = struct{}{} }