本文整理匯總了Golang中github.com/companieshouse/gotcha/http.Session.RenderException方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.RenderException方法的具體用法?Golang Session.RenderException怎麽用?Golang Session.RenderException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/companieshouse/gotcha/http.Session
的用法示例。
在下文中一共展示了Session.RenderException方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getindex
func getindex(session *http.Session) {
idx := session.Stash["index"]
switch idx {
case "CPAN":
go func() {
config.CPANStatus = "Downloading"
res, err := nethttp.Get("https://s3-eu-west-1.amazonaws.com/gopan/cpan_index.gz")
if err != nil {
log.Error("Error downloading index: %s", err.Error())
session.RenderException(500, errors.New("Error downloading CPAN index: "+err.Error()))
config.CPANStatus = "Failed"
return
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Error("Error reading index: %s", err.Error())
session.RenderException(500, errors.New("Error reading CPAN index: "+err.Error()))
config.CPANStatus = "Failed"
return
}
fi, err := os.Create(config.CacheDir + "/" + config.CPANIndex)
if err != nil {
log.Error("Error creating output file: %s", err.Error())
session.RenderException(500, errors.New("Error creating output file: "+err.Error()))
config.CPANStatus = "Failed"
return
}
defer fi.Close()
fi.Write(b)
config.CPANStatus = "Downloaded"
config.HasCPANIndex = true
config.CPANIndexDate = time.Now().String()
config.CPANStatus = "Loading"
load_index(config.CPANIndex, config.CacheDir+"/"+config.CPANIndex)
config.CPANStatus = "Indexing"
update_indexes()
config.CPANStatus = "Loaded"
}()
session.Redirect(&url.URL{Path: "/settings"})
return
case "BackPAN":
go func() {
config.BackPANStatus = "Downloading"
res, err := nethttp.Get("https://s3-eu-west-1.amazonaws.com/gopan/backpan_index.gz")
if err != nil {
log.Error("Error downloading index: %s", err.Error())
session.RenderException(500, errors.New("Error downloading BackPAN index: "+err.Error()))
config.BackPANStatus = "Failed"
return
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Error("Error reading index: %s", err.Error())
session.RenderException(500, errors.New("Error reading BackPAN index: "+err.Error()))
config.BackPANStatus = "Failed"
return
}
fi, err := os.Create(config.CacheDir + "/" + config.BackPANIndex)
if err != nil {
log.Error("Error creating output file: %s", err.Error())
session.RenderException(500, errors.New("Error creating output file: "+err.Error()))
config.BackPANStatus = "Failed"
return
}
defer fi.Close()
fi.Write(b)
config.BackPANStatus = "Downloaded"
config.HasBackPANIndex = true
config.BackPANIndexDate = time.Now().String()
config.BackPANStatus = "Loading"
load_index(config.BackPANIndex, config.CacheDir+"/"+config.BackPANIndex)
config.BackPANStatus = "Indexing"
update_indexes()
config.BackPANStatus = "Loaded"
}()
session.Redirect(&url.URL{Path: "/settings"})
return
}
session.RenderNotFound()
}