commands: move export entry struct to separate pkg

This commit is contained in:
Frank Schroeder 2017-10-11 14:51:28 +02:00 committed by Frank Schröder
parent 215cda4775
commit 3f0c61666d
2 changed files with 24 additions and 17 deletions

View File

@ -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),
}
}

View File

@ -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),
}
}