mirror of
https://github.com/fumiama/tienyik.git
synced 2026-06-29 23:40:28 +08:00
feat: add more apis
This commit is contained in:
@@ -2,12 +2,18 @@ package hson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/fumiama/tienyik"
|
||||
"github.com/fumiama/tienyik/internal/log"
|
||||
"github.com/fumiama/tienyik/internal/op"
|
||||
)
|
||||
|
||||
type reqbody struct {
|
||||
EData string `json:"edata"`
|
||||
}
|
||||
|
||||
func Marshal(tya *tienyik.AES, v any) []byte {
|
||||
w := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
err := json.NewEncoder(w).Encode(v)
|
||||
@@ -16,7 +22,9 @@ func Marshal(tya *tienyik.AES, v any) []byte {
|
||||
}
|
||||
log.Debugln("Marshal JSON:", w.String())
|
||||
if tya != nil {
|
||||
return tya.Encrypt(w.Bytes())
|
||||
return tya.Encrypt(op.Must(json.Marshal(&reqbody{
|
||||
EData: base64.StdEncoding.EncodeToString(w.Bytes()),
|
||||
})))
|
||||
}
|
||||
return w.Bytes()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user