go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/viewutil/main_test.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package viewutil 9 10 import ( 11 "bytes" 12 "text/template" 13 ) 14 15 func compile(text string) *template.Template { 16 temp := template.New("") 17 temp.Funcs(Funcs) 18 output, err := temp.Parse(text) 19 if err != nil { 20 panic(err) 21 } 22 return output 23 } 24 25 func process(temp *template.Template, data any) (output string, err error) { 26 buf := new(bytes.Buffer) 27 if err = temp.Execute(buf, data); err != nil { 28 return 29 } 30 return buf.String(), nil 31 }