mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package templates
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"io"
|
|
"path/filepath"
|
|
"sync"
|
|
|
|
"github.com/hanzoteam/server/server/v8/channels/utils/fileutils"
|
|
)
|
|
|
|
// Container represents a set of templates that can be render
|
|
type Container struct {
|
|
templates *template.Template
|
|
mutex sync.RWMutex
|
|
}
|
|
|
|
// Data contains the data used to populate the template variables, it has Props
|
|
// that can be of any type and HTML that only can be `template.HTML` types.
|
|
type Data struct {
|
|
Props map[string]any
|
|
HTML map[string]template.HTML
|
|
}
|
|
|
|
func GetTemplateDirectory() (string, bool) {
|
|
return fileutils.FindDir("templates")
|
|
}
|
|
|
|
// NewFromTemplates creates a new templates container using a
|
|
// `template.Template` object
|
|
func NewFromTemplate(templates *template.Template) *Container {
|
|
return &Container{templates: templates}
|
|
}
|
|
|
|
// New creates a new templates container scanning a directory.
|
|
func New(directory string) (*Container, error) {
|
|
c := &Container{}
|
|
|
|
htmlTemplates, err := template.ParseGlob(filepath.Join(directory, "*.html"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
c.templates = htmlTemplates
|
|
|
|
return c, nil
|
|
}
|
|
|
|
// RenderToString renders the template referenced with the template name using
|
|
// the data provided and return a string with the result
|
|
func (c *Container) RenderToString(templateName string, data Data) (string, error) {
|
|
var text bytes.Buffer
|
|
if err := c.Render(&text, templateName, data); err != nil {
|
|
return "", err
|
|
}
|
|
return text.String(), nil
|
|
}
|
|
|
|
// RenderToString renders the template referenced with the template name using
|
|
// the data provided and write it to the writer provided
|
|
func (c *Container) Render(w io.Writer, templateName string, data Data) error {
|
|
c.mutex.RLock()
|
|
htmlTemplates := c.templates
|
|
c.mutex.RUnlock()
|
|
|
|
if err := htmlTemplates.ExecuteTemplate(w, templateName, data); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|