change json encoder
This commit is contained in:
parent
43f4a42499
commit
e5e9cfd9f5
13
sign.go
13
sign.go
@ -6,7 +6,6 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
"hash/crc64"
|
"hash/crc64"
|
||||||
@ -60,10 +59,14 @@ func Format(token string) (txt string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
var handle codec.CborHandle
|
var cHandle codec.CborHandle
|
||||||
|
var jHandle codec.JsonHandle
|
||||||
|
jHandle.HTMLCharsAsIs = true
|
||||||
|
jHandle.MapKeyAsString = true
|
||||||
|
jHandle.Indent = 4
|
||||||
|
|
||||||
buf.Write(data)
|
buf.Write(data)
|
||||||
dec := codec.NewDecoder(buf, &handle)
|
dec := codec.NewDecoder(buf, &cHandle)
|
||||||
|
|
||||||
var td tokenData
|
var td tokenData
|
||||||
err = dec.Decode(&td)
|
err = dec.Decode(&td)
|
||||||
@ -79,9 +82,7 @@ func Format(token string) (txt string, err error) {
|
|||||||
buf.Reset()
|
buf.Reset()
|
||||||
buf.Write([]byte("SIGNATURE=" + hex.EncodeToString(td.Signature) + "\n"))
|
buf.Write([]byte("SIGNATURE=" + hex.EncodeToString(td.Signature) + "\n"))
|
||||||
|
|
||||||
enc := json.NewEncoder(buf)
|
enc := codec.NewEncoder(buf, &jHandle)
|
||||||
enc.SetEscapeHTML(false)
|
|
||||||
enc.SetIndent("", "\t")
|
|
||||||
err = enc.Encode(payload)
|
err = enc.Encode(payload)
|
||||||
txt = buf.String()
|
txt = buf.String()
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user