Skip to content

Commit be61274

Browse files
committed
upgrade go version to 1.21
1 parent 4efc542 commit be61274

16 files changed

+40
-31
lines changed

.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Dockerfile
21
.git
32
.idea
43
.vscode
4+
/docker
55
/elasticdump
66
/elasticdump-linux-amd64
77
/elasticdumptest-*

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: all elasticdump docker-build img clean
22

33
DOCKER ?= docker
4-
GOLANG_VERSION ?= 1.18-alpine
4+
GOLANG_VERSION ?= 1.21-alpine
55
IMAGE ?= elasticdump
66
VERSION ?= latest
77
GOOS ?= linux
@@ -16,8 +16,8 @@ elasticdump:
1616

1717
docker-build:
1818
$(DOCKER) run --rm --name elasticdump-build -it \
19-
-v $(shell pwd):/go/src/xgh.io/elasticdump \
20-
--workdir /go/src/xgh.io/elasticdump \
19+
-v $(shell pwd):/build \
20+
--workdir /build \
2121
--user $(shell id -u):$(shell id -g) \
2222
--env XDG_CACHE_HOME=/tmp/.cache \
2323
--env GOOS=$(GOOS) \

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The ElasicSearch did not offer a dump tool, and the only tool provided at <https
88

99
## INSTALL
1010

11-
1. `go install xgh.io/elasticdump`
11+
1. `go install github.com/shinexia/elasticdump`
1212

1313
2. or download a prebuilt binary here: <https://github.com/shinexia/elasticdump/releases/>
1414

cmd/cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewElasticDumpCommand(in io.Reader, out, err io.Writer) *cobra.Command {
2525
│ a simple dump/load data/mapping from elasticsearch │
2626
│ │
2727
│ Please give us feedback at: │
28-
│ https://xgh.io/elasticdump/issues │
28+
│ https://github.com/shinexia/elasticdump/issues │
2929
└──────────────────────────────────────────────────────────┘
3030
3131
Example usage:

cmd/delete_index.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
"strings"
1212
"time"
1313

14+
"github.com/shinexia/elasticdump/pkg/helpers"
15+
1416
"github.com/elastic/go-elasticsearch/v7"
1517
"github.com/pkg/errors"
1618
"github.com/spf13/cobra"
1719
"k8s.io/klog"
18-
"xgh.io/elasticdump/pkg/helpers"
1920
)
2021

2122
func newCmdDeleteIndex(out io.Writer) *cobra.Command {

cmd/dump_data.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import (
1212
"strings"
1313
"time"
1414

15+
"github.com/shinexia/elasticdump/pkg/dumpdata"
16+
"github.com/shinexia/elasticdump/pkg/helpers"
17+
1518
"github.com/elastic/go-elasticsearch/v7/esapi"
1619
"github.com/spf13/cobra"
1720
"k8s.io/klog"
18-
"xgh.io/elasticdump/pkg/dumpdata"
19-
"xgh.io/elasticdump/pkg/helpers"
2021
)
2122

2223
func newCmdDumpData(out io.Writer) *cobra.Command {

cmd/dump_mapping.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ package cmd
88

99
import (
1010
"io"
11-
"io/ioutil"
1211
"os"
1312
"time"
1413

14+
"github.com/shinexia/elasticdump/pkg/helpers"
15+
1516
"github.com/elastic/go-elasticsearch/v7/esapi"
1617
"github.com/pkg/errors"
1718
"github.com/spf13/cobra"
1819
"k8s.io/klog"
19-
"xgh.io/elasticdump/pkg/helpers"
2020
)
2121

2222
func newCmdDumpMapping(out io.Writer) *cobra.Command {
@@ -52,7 +52,7 @@ func newCmdDumpMapping(out io.Writer) *cobra.Command {
5252
if err != nil {
5353
return errors.Cause(err)
5454
}
55-
body, err := ioutil.ReadAll(res.Body)
55+
body, err := io.ReadAll(res.Body)
5656
if res.IsError() || err != nil {
5757
return errors.Errorf("status: %d, body: %s", res.StatusCode, string(body))
5858
}

cmd/gen_test_data.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ package cmd
99
import (
1010
"io"
1111

12+
"github.com/shinexia/elasticdump/pkg/helpers"
13+
"github.com/shinexia/elasticdump/pkg/loaddata"
14+
1215
"github.com/spf13/cobra"
1316
"k8s.io/klog"
14-
"xgh.io/elasticdump/pkg/helpers"
15-
"xgh.io/elasticdump/pkg/loaddata"
1617
)
1718

1819
func newCmdTestGenData(out io.Writer) *cobra.Command {

cmd/load_data.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"io"
1111
"os"
1212

13+
"github.com/shinexia/elasticdump/pkg/helpers"
14+
"github.com/shinexia/elasticdump/pkg/loaddata"
15+
1316
"github.com/pkg/errors"
1417
"github.com/spf13/cobra"
1518
"k8s.io/klog"
16-
"xgh.io/elasticdump/pkg/helpers"
17-
"xgh.io/elasticdump/pkg/loaddata"
1819
)
1920

2021
func newCmdLoadData(out io.Writer) *cobra.Command {

cmd/load_mapping.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ package cmd
99
import (
1010
"bytes"
1111
"io"
12-
"io/ioutil"
12+
"os"
1313
"time"
1414

15+
"github.com/shinexia/elasticdump/pkg/helpers"
16+
"github.com/shinexia/elasticdump/pkg/mapping"
17+
1518
"github.com/pkg/errors"
1619
"github.com/spf13/cobra"
1720
"k8s.io/klog"
18-
"xgh.io/elasticdump/pkg/helpers"
19-
"xgh.io/elasticdump/pkg/mapping"
2021
)
2122

2223
func newCmdLoadMapping(out io.Writer) *cobra.Command {
@@ -58,7 +59,7 @@ func newCmdLoadMapping(out io.Writer) *cobra.Command {
5859
inputFile := extra.InputFile
5960
klog.V(5).Infof("reading file: %s\n", inputFile)
6061
startTime := time.Now()
61-
mappingData, err := ioutil.ReadFile(inputFile)
62+
mappingData, err := os.ReadFile(inputFile)
6263
if err != nil {
6364
return errors.Wrapf(err, "read file: %s failed", inputFile)
6465
}

docker/Dockerfile

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
#
33
# Licensed under the MIT License.
44

5-
ARG GOLANG_VERSION=1.18-alpine
5+
ARG GOLANG_VERSION=1.21-alpine
66
FROM golang:$GOLANG_VERSION as build
77

8-
WORKDIR /build
9-
COPY . .
8+
COPY ./ /build
109

1110
ARG GOPROXY=
1211
ENV GOPROXY=$GOPROXY
1312
ENV CGO_ENABLED=0
1413

1514
ARG LDFLAGS="-s -w"
16-
RUN go build -v -ldflags="$LDFLAGS" -buildvcs=false -o /build/elasticdump
15+
RUN cd /build && go build -v -ldflags="$LDFLAGS" -buildvcs=false -o /build/elasticdump
1716

1817
FROM alpine:latest
1918

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module xgh.io/elasticdump
1+
module github.com/shinexia/elasticdump
22

3-
go 1.19
3+
go 1.21
44

55
require (
66
github.com/elastic/go-elasticsearch/v7 v7.17.10

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"log"
1111
"os"
1212

13-
"xgh.io/elasticdump/cmd"
13+
"github.com/shinexia/elasticdump/cmd"
1414
)
1515

1616
func main() {

pkg/dumpdata/dumpdata.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"context"
1212
"encoding/json"
1313
"fmt"
14-
"io/ioutil"
14+
"io"
1515

1616
"github.com/elastic/go-elasticsearch/v7"
1717
"github.com/elastic/go-elasticsearch/v7/esapi"
@@ -36,12 +36,15 @@ func NewDumpDataOption() *DumpDataOption {
3636

3737
func DumpData(client *elasticsearch.Client, dumpOption *DumpDataOption, writeFunc WriteDataFunc, o ...func(*esapi.SearchRequest)) (int, error) {
3838
res, err := client.Search(o...)
39+
if err != nil {
40+
return 0, errors.Cause(err)
41+
}
3942
count := 0
4043
for {
44+
body, err := io.ReadAll(res.Body)
4145
if err != nil {
4246
return count, errors.Cause(err)
4347
}
44-
body, err := ioutil.ReadAll(res.Body)
4548
if res.IsError() {
4649
return count, errors.New(res.String())
4750
}
@@ -68,6 +71,9 @@ func DumpData(client *elasticsearch.Client, dumpOption *DumpDataOption, writeFun
6871
}
6972
scrollReq := []byte(fmt.Sprintf(`{"scroll": "%ds","scroll_id": "%s"}`, dumpOption.TimeoutSec, response.ScrollID))
7073
res, err = client.Scroll(client.Scroll.WithContext(context.Background()), client.Scroll.WithBody(bytes.NewReader(scrollReq)))
74+
if err != nil {
75+
return count, errors.Cause(err)
76+
}
7177
}
7278
return count, nil
7379
}
File renamed without changes.

pkg/loaddata/load.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"encoding/json"
1313
"fmt"
1414
"io"
15-
"io/ioutil"
1615
"strconv"
1716
"time"
1817

@@ -109,7 +108,7 @@ func LoadData(client *elasticsearch.Client, queue *DataQueue[*Hit], batch int, i
109108
if err != nil {
110109
return errors.WithStack(err)
111110
}
112-
body, err := ioutil.ReadAll(res.Body)
111+
body, err := io.ReadAll(res.Body)
113112
if res.IsError() || err != nil {
114113
return errors.Errorf("status: %d, body: %s", res.StatusCode, string(body))
115114
}

0 commit comments

Comments
 (0)