xt := &Template{} leaves the templates field nil.

Ehioje Henry Erabor <erab...@gmail.com> schrieb am Mi. 8. Jan. 2020 um
15:59:

> I am having issues using extemplate library in my echo framework project.
> Library :https://github.com/dannyvankooten/extemplate
>
> My Code is below:
>
> Enter code here...package main
>
> import (
> "fmt"
> "io"
> "net/http"
>
> "github.com/dannyvankooten/extemplate"
> "github.com/labstack/echo/v4"
> )
>
> // Template ...
> type Template struct {
> templates *extemplate.Extemplate
> }
>
> // Render ...
> func (t *Template) Render(w io.Writer, name string, data interface{}, c
> echo.Context) error {
> err := t.templates.ExecuteTemplate(w, name, data)
> if err != nil {
> fmt.Println("error", err)
> return err
> }
>
> return nil
> }
>
> // Page ...
> type Page struct {
> Name string
> Content string
> }
>
> // Hello ...
> func Hello(c echo.Context) error {
> return c.Render(http.StatusOK, "hello.html", "Guys")
> }
>
> // About ...
> func About(c echo.Context) error {
>
> data := Page{
> Name: "About", Content: `Lorem ipsum dolor sit amet, consectetur
> adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
> aliqua.
> Nisi scelerisque eu ultrices vitae auctor eu augue ut lectus. Quam
> pellentesque nec nam aliquam sem et tortor consequat.
> Pharetra vel turpis nunc eget lorem dolor. Vitae turpis massa sed
> elementum tempus egestas. Turpis egestas pretium aenean pharetra magna ac
> placerat.
> Neque ornare aenean euismod elementum nisi quis eleifend quam. In
> fermentum et sollicitudin ac orci. Ut porttitor leo a diam sollicitudin
> tempor id eu nisl.
> Sed viverra tellus in hac habitasse platea dictumst vestibulum rhoncus.
> Lorem ipsum dolor sit amet. A diam sollicitudin tempor id eu. Sit amet
> facilisis magna etiam.
> Praesent tristique magna sit amet purus gravida.`,
> }
> return c.Render(http.StatusOK, "about.html", data)
> }
>
> func main() {
>
> xt := &Template{}
> err := xt.templates.ParseDir("templates/", []string{".html"})
> if err != nil {
> fmt.Println("ErrorExt: ", err)
> }
>
> e := echo.New()
> e.Renderer = xt
> e.GET("/hello", Hello)
> e.GET("/about", About)
>
> e.Logger.Fatal(e.Start(":4000"))
>
> }
>
>
> My folder structure where the template resides is below:
>
> --main--
> --templates--
>    --about.html--
>    --home.html--
> --go.mod--
> --go.sum--
>
> I am using go modules for the project.
> Why do I keep on getting these errors below:
>
> panic: runtime error: invalid memory address or nil pointer dereference
>> [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x776c85]
>> goroutine 1 [running]:
>> github.com/dannyvankooten/extemplate.(*Extemplate).ParseDir(0x0,
>> 0x8cb153, 0xa, 0xc0000ebf20, 0x1, 0x1, 0x32, 0x963ae0)
>> /home/henry/work/pkg/mod/
>> github.com/dannyvankooten/extemplate@v0.0.0-20180818082729-efbdf6eacd7e/template.go:110
>> +0x125
>> main.main()
>> /home/henry/goproject/extemplate/main.go:56 +0xa7
>> exit status 2
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/0b664dbf-4ca4-41e5-aa55-b514101b81c6%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/0b664dbf-4ca4-41e5-aa55-b514101b81c6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALWqRZq9-JxPakU7L3Brds7F4J0E6NeJPc-TxzJ2b0m9KQkgOg%40mail.gmail.com.

Reply via email to