Why is 'title' an unexported field of struct?

I am getting this error:

template: header.gohtml:6:13: executing “header” at <.title>: title is an unexported field of struct type main.pageData


type pageData struct {
	title string
	firstname string

func apply(w http.ResponseWriter, r *http.Request) {
	pd := pageData{title: "Apply"}
	var firstname string
	if r.Method == http.MethodPost {
		firstname = r.FormValue("firstname")
		pd.firstname = firstname


{{template "header" .}}
{{if .title}}
Your name is {{.title}}
{{template "nav-main"}}
{{template "footer"}}


{{ define "header"}}
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/public">

What is wrong with my code?

“export” means “public” => with upper case first letter
the reason is simple: the renderer package use the reflect package in order to get/set fields values
the reflect package can only access public/exported struct fields.
So try defining

type pageData struct {
	Title string
	Firstname string

Wow I am glad to know this. Thank you very much!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.