Skip to content

Commit

Permalink
template: log rendering error (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon authored Jul 23, 2023
1 parent acc6b86 commit 6e428e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
Expand All @@ -38,11 +38,11 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run tests with coverage
run: go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic ./...
- name: Upload coverage report to Codecov
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# template

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/flamego/template/Go?logo=github&style=for-the-badge)](https://github.com/flamego/template/actions?query=workflow%3AGo)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/flamego/template/go.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/flamego/template/actions?query=workflow%3AGo)
[![Codecov](https://img.shields.io/codecov/c/gh/flamego/template?logo=codecov&style=for-the-badge)](https://app.codecov.io/gh/flamego/template)
[![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/flamego/template?tab=doc)
[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/flamego/template)
Expand Down
7 changes: 4 additions & 3 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type template struct {
bufPool *sync.Pool
}

func responseServerError(w http.ResponseWriter, err error) {
func (t *template) responseServerError(w http.ResponseWriter, err error) {
t.logger.Error("rendering", "error", err)
if flamego.Env() == flamego.EnvTypeDev {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
Expand All @@ -61,7 +62,7 @@ func (t *template) HTML(status int, name string) {

err := t.ExecuteTemplate(buf, name, t.Data)
if err != nil {
responseServerError(t.responseWriter, err)
t.responseServerError(t.responseWriter, err)
return
}

Expand Down Expand Up @@ -219,7 +220,7 @@ func Templater(opts ...Options) flamego.Handler {
return flamego.LoggerInvoker(func(c flamego.Context, logger *log.Logger) {
t := &template{
responseWriter: c.ResponseWriter(),
logger: logger,
logger: logger.WithPrefix("template"),
Template: tpl,
Data: make(Data),
contentType: opt.ContentType,
Expand Down

0 comments on commit 6e428e5

Please sign in to comment.