I am trying to build a simple webserver. I want to replace all
with <br>
.
I wanted to use bytes
for this, because my page body is stored as an []byte
.
I use bytes.ReplaceAll()
for this. But it keeps saying that it's a reference to undefined identifier.
Can someone tell me why? I tried the exact same line within an online Compiler and it worked just fine. Do I miss the library?
See my code below:
import (
"bytes"
"html/template"
"io/ioutil"
"log"
"net/http"
"regexp"
)
type Page struct {
Title string
Body []byte
}
func editHandler(w http.ResponseWriter, r *http.Request, title string) {
p, err := loadPage(title)
if err != nil {
p = &Page{Title: title}
}
// THE LINE THAT CAUSES TROUBLE
p.Body = bytes.ReplaceAll(p.Body, []byte("
"), []byte("<br>"))
renderTemplate(w, "edit", p)
}