1
0
Fork 0
mirror of https://github.com/Luzifer/nginx-sso.git synced 2024-12-20 12:51:17 +00:00
nginx-sso/pongo.go

29 lines
508 B
Go
Raw Permalink Normal View History

package main
import (
"bytes"
"encoding/json"
"strings"
"github.com/flosch/pongo2"
)
func init() {
pongo2.RegisterFilter("to_json", filterToJSON)
}
func filterToJSON(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
var buf = new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(in.Interface())
if err != nil {
return nil, &pongo2.Error{
Sender: "to_json",
OrigError: err,
}
}
result := strings.TrimSpace(buf.String())
return pongo2.AsValue(result), nil
}