diff --git a/command/kvexp/kv_export.go b/command/kvexp/kv_export.go index e2565180e9..f913f7a046 100644 --- a/command/kvexp/kv_export.go +++ b/command/kvexp/kv_export.go @@ -1,13 +1,13 @@ package kvexp import ( - "encoding/base64" "encoding/json" "flag" "fmt" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/command/flags" + "github.com/hashicorp/consul/command/kvimpexp" "github.com/mitchellh/cli" ) @@ -70,9 +70,9 @@ func (c *cmd) Run(args []string) int { return 1 } - exported := make([]*kvExportEntry, len(pairs)) + exported := make([]*kvimpexp.Entry, len(pairs)) for i, pair := range pairs { - exported[i] = toExportEntry(pair) + exported[i] = kvimpexp.ToEntry(pair) } marshaled, err := json.MarshalIndent(exported, "", "\t") @@ -103,17 +103,3 @@ func (c *cmd) Help() string { return flags.Usage(s, c.flags, c.http.ClientFlags(), c.http.ServerFlags()) } - -type kvExportEntry struct { - Key string `json:"key"` - Flags uint64 `json:"flags"` - Value string `json:"value"` -} - -func toExportEntry(pair *api.KVPair) *kvExportEntry { - return &kvExportEntry{ - Key: pair.Key, - Flags: pair.Flags, - Value: base64.StdEncoding.EncodeToString(pair.Value), - } -} diff --git a/command/kvimpexp/kvimpexp.go b/command/kvimpexp/kvimpexp.go new file mode 100644 index 0000000000..a865a31013 --- /dev/null +++ b/command/kvimpexp/kvimpexp.go @@ -0,0 +1,21 @@ +package kvimpexp + +import ( + "encoding/base64" + + "github.com/hashicorp/consul/api" +) + +type Entry struct { + Key string `json:"key"` + Flags uint64 `json:"flags"` + Value string `json:"value"` +} + +func ToEntry(pair *api.KVPair) *Entry { + return &Entry{ + Key: pair.Key, + Flags: pair.Flags, + Value: base64.StdEncoding.EncodeToString(pair.Value), + } +}