Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using template.Must for HTMLReport. #222

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions backtest/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ func (h *HTMLReport) writeAssetReport(name string, results []*htmlReportResult)

defer helper.CloseAndLogError(file, "unable to close asset report file")

tmpl, err := template.New("report").Parse(htmlAssetReportTmpl)
if err != nil {
return fmt.Errorf("unable to initialize asset report template: %w", err)
}
tmpl := template.Must(template.New("report").Parse(htmlAssetReportTmpl))

err = tmpl.Execute(file, model)
if err != nil {
Expand Down Expand Up @@ -248,10 +245,7 @@ func (h *HTMLReport) writeReport() error {

defer helper.CloseAndLogError(file, "unable to close main report file")

tmpl, err := template.New("report").Parse(htmlReportTmpl)
if err != nil {
return fmt.Errorf("unable to execute main report template: %w", err)
}
tmpl := template.Must(template.New("report").Parse(htmlReportTmpl))

err = tmpl.Execute(file, model)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The information provided on this project is strictly for informational purposes
- [func CheckEquals\[T comparable\]\(inputs ...\<\-chan T\) error](<#CheckEquals>)
- [func CloseAndLogError\(closer io.Closer, message string\)](<#CloseAndLogError>)
- [func Count\[T Number, O any\]\(from T, other \<\-chan O\) \<\-chan T](<#Count>)
- [func DaysBetween\(from, to time.Time\) int](<#DaysBetween>)
- [func DecrementBy\[T Number\]\(c \<\-chan T, d T\) \<\-chan T](<#DecrementBy>)
- [func Divide\[T Number\]\(ac, bc \<\-chan T\) \<\-chan T](<#Divide>)
- [func DivideBy\[T Number\]\(c \<\-chan T, d T\) \<\-chan T](<#DivideBy>)
Expand Down Expand Up @@ -348,6 +349,15 @@ fmt.Println(<- s) // 3
fmt.Println(<- s) // 4
```

<a name="DaysBetween"></a>
## func [DaysBetween](<https://github.com/cinar/indicator/blob/master/helper/days_between.go#L13>)

```go
func DaysBetween(from, to time.Time) int
```

DaysBetween calculates the days between the given two times.

<a name="DecrementBy"></a>
## func [DecrementBy](<https://github.com/cinar/indicator/blob/master/helper/decrement_by.go#L16>)

Expand Down
Loading