Created
March 19, 2021 12:49
-
-
Save drocha87/6d3cba12f16233f4ad7d1fe13a31284b to your computer and use it in GitHub Desktop.
Changing gofiber JSON encoder to set SetEscapedHtml(false).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/json" | |
"log" | |
"os" | |
"github.com/gofiber/fiber/v2" | |
"github.com/gofiber/fiber/v2/middleware/cors" | |
) | |
func main { | |
app := fiber.New(fiber.Config{ | |
JSONEncoder: func(val interface{}) ([]byte, error) { | |
buf := new(bytes.Buffer) | |
encoder := json.NewEncoder(buf) | |
encoder.SetEscapeHTML(false) | |
if err := encoder.Encode(val); err != nil { | |
return nil, err | |
} | |
return buf.Bytes(), nil | |
}, | |
}) | |
app.Use(cors.New()) | |
log.Fatal(app.Listen(":3000")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment