Home > database >  Html path in golang?
Html path in golang?

Time:10-10

I have two folders:

 - utlis (folder contains GO files)
 --- sendMail.go

 - templates (folder)
 --- reset_code.html

- main.go

In sendMail Go file I have this template code:

t := template.New("./templates/reset_code.html")

var err error

t, err = t.ParseFiles("./templates/reset_code.html/")

if err != nil {
    log.Println(err)
}

I got in console this error!

open ./templates/reset_code.html/: not a directory

How go handle paths?

CodePudding user response:

First Go handle path in the root of your project dir like if you have created folder contains all your files you should make the code something like this:

var t = template.Must(template.ParseFiles("templates/reset_code.html")

.....

When you called any file from any where you have be began from the root path

  •  Tags:  
  • go
  • Related