| Crates.io | gotpl |
| lib.rs | gotpl |
| version | 0.2.6 |
| created_at | 2025-09-20 03:24:08.355725+00 |
| updated_at | 2025-10-01 13:37:28.073761+00 |
| description | A Rust library providing full Go template (text/template and html/template) support via FFI. |
| homepage | https://github.com/moyanj/gotpl |
| repository | https://github.com/moyanj/gotpl |
| max_upload_size | |
| id | 1847365 |
| size | 34,181 |
gotplA Rust library for using Go's powerful text/template and html/template engines via FFI. Get the safety of Rust with the mature templating power of Go.
text/template and html/template syntax.html/template.serde::Serialize-able Rust data.Result types.serde for data serialization.Add to your Cargo.toml:
[dependencies]
gotpl = "0.2.3" # Use the latest version
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
use gotpl::TemplateRenderer;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let template = "Hello, {{.name}}! You have {{len .items}} items.";
let data = json!({
"name": "MoYan",
"items": ["book", "pen"]
});
let output = TemplateRenderer::new(template, &data).render()?;
println!("{}", output);
Ok(())
}
This library supports the complete Go template syntax. For details, see the official docs:
gotpl uses a build.rs script to compile the Go source into a static library and generate Rust FFI bindings with bindgen.
Requirements:
The build is fully automated when you run cargo build.
Contributions are welcome via Pull Requests or Issues.
Licensed under the MIT License. See LICENSE for details.