Invalid file parsing (bad file descriptor)

Good morning everyone,

I’m trying to create a basic go server with go notation.

Here is the project architecture :

  • gohtml
    ---- index.gohtml
    ---- about.gohtml

  • templates
    ---- layout.gohtml


And here is the code for each file :


{{define "page_title"}} Welcome Page {{ end }}

{{define "page_body"}}

<p>Welcome on home page !</p>



{{define "page_title"}} About Page {{ end }}

{{define "page_body"}}

<p>Welcome on about page !</p>



{{define "layout}}

<!DOCTYPE html>


    <meta charset="utf-8">
    <title>{{template "page_title"}}</title>


 {{template "page_body"}}





package main

import (

func main(){

// Handle client's requests to templates system

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){

// Manage template's layout path

layout_path := filepath.Join("templates","layout.gohtml")

// Manage *http.request

request_path := filepath.Join("gohtml",filepath.Clean(r.URL.Path))

// Parse layout and client's request files

template_page, err := template.ParseFiles(request_path, layout_path)

if err != nil{

    log.Println("Error : Failed to parse files")



// Execute template on http.ResponseWriter

template_page.ExecuteTemplate(w, "layout", nil)


// Start server
// Error handling OK

log.Fatal(http.ListenAndServe(":8080", nil))


When I run my server.go file I get :

2020/03/31 11:44:58 Error : Failed to parse files
2020/03/31 11:44:58 read gohtml: Bad file descriptor
exit status 1     

Thank you in advance for your help

Ok guys,

I found the solution myself ahah !

Apparently the template.Parsefiles work that way :

template_page, err := template.Parsefiles(layout_path, request_path)

Instead of

template_page, err := template.Parsefiles(request_path, layout_path)

Also I forgot a quote in layout.gohtml :

{{define "layout}}

Should be :

{{define "layout"}}