commands: move export entry struct to separate pkg

pull/3584/head
Frank Schroeder 7 years ago committed by Frank Schröder
parent 585b5b8d4e
commit cce364445e

@ -1,13 +1,13 @@
package kvexp package kvexp
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/command/flags" "github.com/hashicorp/consul/command/flags"
"github.com/hashicorp/consul/command/kvimpexp"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
@ -70,9 +70,9 @@ func (c *cmd) Run(args []string) int {
return 1 return 1
} }
exported := make([]*kvExportEntry, len(pairs)) exported := make([]*kvimpexp.Entry, len(pairs))
for i, pair := range pairs { for i, pair := range pairs {
exported[i] = toExportEntry(pair) exported[i] = kvimpexp.ToEntry(pair)
} }
marshaled, err := json.MarshalIndent(exported, "", "\t") 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()) 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),
}
}

@ -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),
}
}
Loading…
Cancel
Save