From a2d27e85fea0414d3e0b750466f1449075be5906 Mon Sep 17 00:00:00 2001 From: Changwei Ge Date: Tue, 16 Aug 2022 13:08:15 +0800 Subject: [PATCH] use xid to generate nydusd's internal ID The original ID generation method spawns a string with lower case, upper case and undersocre, which is too complicated. Signed-off-by: Changwei Ge --- go.mod | 2 +- go.sum | 2 ++ pkg/daemon/idgen.go | 8 ++------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 49b2189833..f5f5de87fc 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/docker/cli v20.10.0-beta1.0.20201029214301-1d20b15adc38+incompatible github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da github.com/google/go-containerregistry v0.5.1 - github.com/google/uuid v1.2.0 github.com/hashicorp/go-retryablehttp v0.7.1 github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 @@ -20,6 +19,7 @@ require ( github.com/prometheus/client_golang v1.11.1 github.com/prometheus/client_model v0.2.0 github.com/prometheus/common v0.30.0 + github.com/rs/xid v1.4.0 github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.7.0 github.com/urfave/cli/v2 v2.3.0 diff --git a/go.sum b/go.sum index 173e4d2974..1034a57af1 100644 --- a/go.sum +++ b/go.sum @@ -614,6 +614,8 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= +github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= diff --git a/pkg/daemon/idgen.go b/pkg/daemon/idgen.go index 694c4ac1af..a6a53ffd36 100644 --- a/pkg/daemon/idgen.go +++ b/pkg/daemon/idgen.go @@ -7,13 +7,9 @@ package daemon import ( - "encoding/base64" - - "github.com/google/uuid" + "github.com/rs/xid" ) func newID() string { - id := uuid.New() - b := [16]byte(id) - return base64.RawURLEncoding.EncodeToString(b[:]) + return xid.New().String() }