Go の html/templates について学び始めたところです。私が得ているエラーは、「システムは指定されたファイルパスを見つけることができません」というものです。ファイル パスは templates/time.html です。time.html (レンダリングしようとしているページ) の場所は
src/templates/time.html
私のgoメインの場所はsrc/timeserver/timerserver.goです
これが私が使用したコードです
func TimeServer(w http.ResponseWriter, req *http.Request) {
// if user goes to another website after time/...
if req.URL.Path != "/time/" {
errorHandler(w, req, http.StatusNotFound)
return
}
cookie, _ := req.Cookie("UUID")
//existCheck := false
//temp2 := ""
profile := Profile{"",time.Now().Format("3:04:04 PM")}
if cookie != nil { // if cookie exist set flags
name, check := cookieJar.GetValue(cookie.Value)
profile = Profile{name,time.Now().Format("3:04:04 PM")}
fmt.Println(name)
//existCheck = check
//temp2 = name
fmt.Println(check)
}
fp := path.Join("templates", "time.html")
tmpl, err := template.ParseFiles(fp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tmpl.Execute(w, profile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}