moved JSON to kvstore
This commit is contained in:
23
kvstore.go
23
kvstore.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/ugorji/go/codec"
|
||||||
"samhofi.us/x/keybase/types/chat1"
|
"samhofi.us/x/keybase/types/chat1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,3 +64,25 @@ func getTypeName(v interface{}) string {
|
|||||||
}
|
}
|
||||||
return t.Name()
|
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
23
utils.go
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/teris-io/shortid"
|
"github.com/teris-io/shortid"
|
||||||
"github.com/ugorji/go/codec"
|
|
||||||
"samhofi.us/x/keybase/types/chat1"
|
"samhofi.us/x/keybase/types/chat1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -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 {
|
func (b *bot) logError(err error) string {
|
||||||
// generate the error id
|
// generate the error id
|
||||||
eid := shortid.MustGenerate()
|
eid := shortid.MustGenerate()
|
||||||
|
|||||||
Reference in New Issue
Block a user