Browse Source

moved JSON to kvstore

master
David Haukeness 5 years ago
parent
commit
86217a5d63
No known key found for this signature in database
GPG Key ID: 54F2372DDB7F9462
  1. 23
      kvstore.go
  2. 23
      utils.go

23
kvstore.go

@ -3,6 +3,7 @@ package main @@ -3,6 +3,7 @@ package main
import (
"reflect"
"github.com/ugorji/go/codec"
"samhofi.us/x/keybase/types/chat1"
)
@ -63,3 +64,25 @@ func getTypeName(v interface{}) string { @@ -63,3 +64,25 @@ func getTypeName(v interface{}) string {
}
return t.Name()
}
func encodeStructToJSONString(v interface{}) (string, error) {
jh := codecHandle()
var bytes []byte
err := codec.NewEncoderBytes(&bytes, jh).Encode(v)
if err != nil {
return "", err
}
result := string(bytes)
return result, nil
}
func decodeJSONStringToStruct(v interface{}, src string) error {
bytes := []byte(src)
jh := codecHandle()
return codec.NewDecoderBytes(bytes, jh).Decode(v)
}
func codecHandle() *codec.JsonHandle {
var jh codec.JsonHandle
return &jh
}

23
utils.go

@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/teris-io/shortid"
"github.com/ugorji/go/codec"
"samhofi.us/x/keybase/types/chat1"
)
@ -30,28 +29,6 @@ func getFeedbackExtendedDescription(bc botConfig) *chat1.UserBotExtendedDescript @@ -30,28 +29,6 @@ func getFeedbackExtendedDescription(bc botConfig) *chat1.UserBotExtendedDescript
}
}
func encodeStructToJSONString(v interface{}) (string, error) {
jh := codecHandle()
var bytes []byte
err := codec.NewEncoderBytes(&bytes, jh).Encode(v)
if err != nil {
return "", err
}
result := string(bytes)
return result, nil
}
func decodeJSONStringToStruct(v interface{}, src string) error {
bytes := []byte(src)
jh := codecHandle()
return codec.NewDecoderBytes(bytes, jh).Decode(v)
}
func codecHandle() *codec.JsonHandle {
var jh codec.JsonHandle
return &jh
}
func (b *bot) logError(err error) string {
// generate the error id
eid := shortid.MustGenerate()

Loading…
Cancel
Save