- Created backend structure with Go, including main application logic and API endpoints. - Added Docker support for both development and production environments. - Introduced frontend using Nuxt 3 with Tailwind CSS for styling. - Included configuration files for Docker and environment variables. - Established basic documentation for contributing, development, and deployment processes. - Set up .gitignore and .dockerignore files to manage ignored files in the repository.
40 lines
748 B
Go
40 lines
748 B
Go
package webapp
|
|
|
|
import (
|
|
"embed"
|
|
"html/template"
|
|
"io"
|
|
"io/fs"
|
|
)
|
|
|
|
//go:embed templates
|
|
var embedFS embed.FS
|
|
|
|
type WebApp struct {
|
|
templates *template.Template
|
|
}
|
|
|
|
// New creates a WebApp with templates loaded from the embedded filesystem.
|
|
func New() (*WebApp, error) {
|
|
sub, err := fs.Sub(embedFS, "templates")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
t, err := template.ParseFS(sub, "*.tmpl", "admin/*.tmpl")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &WebApp{templates: t}, nil
|
|
}
|
|
|
|
func Must(w *WebApp, err error) *WebApp {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return w
|
|
}
|
|
|
|
func (w *WebApp) ExecuteTemplate(wr io.Writer, t string, data interface{}) error {
|
|
return w.templates.ExecuteTemplate(wr, t, data)
|
|
}
|