mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 01:08:31 +02:00
refactor: refine byte pools usage and fix memory leak in rules
This commit is contained in:
@@ -304,6 +304,15 @@ func isTemplate(tmplStr string) bool {
|
||||
return strings.Contains(tmplStr, "{{")
|
||||
}
|
||||
|
||||
type templateWithLen struct {
|
||||
*template.Template
|
||||
len int
|
||||
}
|
||||
|
||||
func (t *templateWithLen) Len() int {
|
||||
return t.len
|
||||
}
|
||||
|
||||
func validateTemplate(tmplStr string, newline bool) (templateOrStr, gperr.Error) {
|
||||
if newline && !strings.HasSuffix(tmplStr, "\n") {
|
||||
tmplStr += "\n"
|
||||
@@ -317,7 +326,7 @@ func validateTemplate(tmplStr string, newline bool) (templateOrStr, gperr.Error)
|
||||
if err != nil {
|
||||
return nil, ErrInvalidArguments.With(err)
|
||||
}
|
||||
return tmpl, nil
|
||||
return &templateWithLen{tmpl, len(tmplStr)}, nil
|
||||
}
|
||||
|
||||
func validateLevel(level string) (zerolog.Level, gperr.Error) {
|
||||
|
||||
Reference in New Issue
Block a user