🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

zgo.at/ztpl

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zgo.at/ztpl

Go
Version
v0.0.0-20250628022642-3b2c314e8e05
Version published
Created
Source

ztpl contains functiosn to deal with Go's text/template and html/template.

Import as zgo.at/ztpl; API docs: https://godocs.io/zgo.at/ztpl

What you can do with this:

  • You can set up templates with ztpl.Init(), which can then be reloaded from the filesystem with ztpl.Reload(), e.g. with github.com/teamwork/reload:

    ztpl.Init("tpl", pack.Templates)
    
    go func() {
        err := reload.Do(zlog.Module("main").Debugf, reload.Dir("./tpl", ztpl.Reload))
        if err != nil {
            panic(errors.Errorf("reload.Do: %v", err))
        }
    }()
    

    Simple replacing a templates variable introduces race conditions, this takes care of that.

    This also automatically runs either text/template or html/template depending on the file extension (.gotxt or .gohtml).

  • Trace template execution with Trace()/TestTemplateExecution(), as a kind of poor-man code coverage.

  • Additional template functions in tplfunc/.

TODO:

  • Proper coverage support.

  • Compile templates to Go code. Especially things like tight loops are surprisingly slow.

  • A template format tool, like the (unfinished) https://github.com/gotpl/gtfmt

Although, maybe it makes more sense to use https://github.com/valyala/quicktemplate or https://github.com/a-h/templ

FAQs

Package last updated on 28 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts