作为单元测试用例应该为这样的函数编写什么。代码段会有所帮助

时间:2018-02-19 11:09:49

标签: go

func Home(w http.ResponseWriter, r *staticAuth.AuthenticatedRequest) {
    t, err := template.ParseFiles("index.html") //parse the html file homepage.html
    if err != nil {                             // if there is an error
        log.Print("template parsing error: ", err) // log it
    }
    err = t.Execute(w, nil) //execute the template and pass it the HomePageVars struct to fill in the gaps
    if err != nil {         // if there is an error
        log.Print("template executing error: ", err) //log it
    }
}

1 个答案:

答案 0 :(得分:1)

gtkterm

在您的代码中,您检查并记录错误,然后继续并忽略错误。