From f5fa4eb7c8540f5e9d5d8a761e44d4aa59f8219c Mon Sep 17 00:00:00 2001 From: Nathan Slaughter <28688390+nslaughter@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:06:38 -0500 Subject: [PATCH] stubs for templates --- tools/internal/text/text.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tools/internal/text/text.go diff --git a/tools/internal/text/text.go b/tools/internal/text/text.go new file mode 100644 index 0000000..ee268ca --- /dev/null +++ b/tools/internal/text/text.go @@ -0,0 +1,31 @@ +package text + +import( + "text/template" +) + +var ErrUnknownType errors.New("unexpected type") + +type Context any + +// Validate is a run-time type check to ensure that the Context is one of +/// - a string with key=value pairs delimited by commas: e.g. "ServicePort=8888,ScrapePort=9090" +// - a map of type map[string]any +// - any Go struct +func (c Context) Validate() error { + // check the type of c - fine to use %T format directive or reflect + return fmt.Errorf("error: unimplemented") +} + +// Renders the Go template at path with input data which can be any of the following... +// - a string with key=value pairs delimited by commas: e.g. "ServicePort=8888,ScrapePort=9090" +// - a map of type map[string]any +// - any Go struct +// +// Errors: +// 1. fine to return errors from text/template functions: .Parse, .Execute, and friends +// 2. +// Type notes: if you know how to constrain +func TemplateFileRender(path string, context Context) ([]byte, error) { + return nil, nil +}