Вот с контролера пытаюсь вызвать вьюшку.
package kontroller
import (
"fmt"
"generais/kernel/views"
"github.com/julienschmidt/httprouter"
"net/http"
)
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
//fmt.Fprint(w, "Welcome!\n")
p := map[string]string{
"H": "Hydrogen",
"He": "Helium",
}
views.get("TestPage.txt", p)
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
fmt.Fprintf(w, "Fam, %s!\n", ps.ByName("fam"))
}
Код generais/kernel/views
package views
import (
"github.com/julienschmidt/httprouter"
"html/template"
"io/ioutil"
"net/http"
)
func get(template, p, w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
pathTemplate := "template/" + template
bs, err := ioutil.ReadFile(pathTemplate)
if err != nil {
return
}
str := string(bs)
t := template.New("Test Template")
t, _ = t.Parse(str)
res.Header().Set(
"Content-Type",
"text/html",
)
t.Execute(res, p)
}
При компиляции получаю такие ошибки
v-smerti@vsmerti-K8N:~/localhost/login/src/generais$ go run main.go
# generais/kernel/views
kernel/views/views.go:5: imported and not used: "html/template"
kernel/views/views.go:12: invalid operation: "template/" + template (mismatched types string and http.ResponseWriter)
kernel/views/views.go:18: template.New undefined (type http.ResponseWriter has no field or method New)
kernel/views/views.go:21: undefined: res
kernel/views/views.go:25: undefined: res
Зарание спасибо