Skip to content

Commit

Permalink
utility function to convert json to base64 string
Browse files Browse the repository at this point in the history
  • Loading branch information
adnaan committed Jun 1, 2023
1 parent c15cb87 commit 07281ae
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fir

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"html/template"
Expand All @@ -26,9 +27,19 @@ func defaultFuncMap() template.FuncMap {
allFuncs["bytesToMap"] = bytesToMap
allFuncs["bytesToString"] = bytesToString
allFuncs["dump"] = dump
allFuncs["toJsonb64"] = toJsonb64
return allFuncs
}

func toJsonb64(data interface{}) (string, error) {
jsonData, err := json.Marshal(data)
if err != nil {
return "", err
}

return base64.StdEncoding.EncodeToString(jsonData), nil
}

func bytesToMap(data []byte) map[string]any {
m := make(map[string]any)
err := json.Unmarshal(data, &m)
Expand Down

0 comments on commit 07281ae

Please sign in to comment.