From 58a8548822bdc743331be2db351f835abd6a0c2f Mon Sep 17 00:00:00 2001 From: Danis Kirasirov <dbgbbu@gmail.com> Date: Wed, 29 Nov 2023 15:29:28 +0300 Subject: [PATCH] add SetURLWithTemplate method to File --- pkg/files/file.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/files/file.go b/pkg/files/file.go index 8f9f3bfe..0e4d89f7 100644 --- a/pkg/files/file.go +++ b/pkg/files/file.go @@ -1,9 +1,11 @@ package files import ( + "bytes" "fmt" "io/fs" "strings" + "text/template" "git.perx.ru/perxis/perxis-go/pkg/id" ) @@ -31,6 +33,20 @@ func (f File) Temporary() bool { return strings.HasPrefix(f.ID, TemporaryPrefix) } +func (f *File) SetURLWithTemplate(t *template.Template) error { + if t == nil { + return nil + } + + res := new(bytes.Buffer) + if err := t.Execute(res, f); err != nil { + return err + } + + f.URL = res.String() + return nil +} + func (f File) Fetch(i interface{}) interface{} { p, _ := i.(string) switch p { -- GitLab