From fbfbb3d0e29b5fd23f550964e4a94697df1d69d8 Mon Sep 17 00:00:00 2001 From: ciricc Date: Tue, 2 Apr 2024 15:55:10 +0300 Subject: [PATCH] feat: added hex format supporting --- README.md | 1 + cliutil/cliutil.go | 6 +++++- commands/showCommand.go | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a7ed779..7783054 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ Displays all content of the database limited by "LIMIT". * `geohash` - Attempts to convert the data format of the `geohash` in the coordinates of the center (lat, lng) * `int64` - Attempts to display the data as an integer 64-bit number * `float64` - Attempts to display the data as a 64-bit number c with a floating point + * `hex` - Converts raw data to a hexademical ### help > help diff --git a/cliutil/cliutil.go b/cliutil/cliutil.go index 449ee4e..005eaaa 100644 --- a/cliutil/cliutil.go +++ b/cliutil/cliutil.go @@ -8,10 +8,12 @@ package cliutil import ( "encoding/binary" + "encoding/hex" "fmt" + "math" + "github.com/TomiHiltunen/geohash-golang" "gopkg.in/mgo.v2/bson" - "math" ) // Converts data to a string @@ -26,6 +28,8 @@ func ToString(format string, value []byte) string { case "float64": return float64ToString(value) case "raw": + case "hex": + return hex.EncodeToString(value) default: } diff --git a/commands/showCommand.go b/commands/showCommand.go index f441f62..a67d992 100644 --- a/commands/showCommand.go +++ b/commands/showCommand.go @@ -10,10 +10,11 @@ import ( "bufio" "bytes" "fmt" + "text/tabwriter" + "github.com/liderman/leveldb-cli/cliutil" "github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/util" - "text/tabwriter" ) // It shows the contents of the database prefix filtering.