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
Knut Ahlers 930a23f461
Modernize login dialog
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-04-22 19:43:56 +02:00

28 lines
508 B
Go

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
}