{"id":37130564,"url":"https://github.com/flothq/swap","last_synced_at":"2026-01-14T15:01:03.422Z","repository":{"id":256348082,"uuid":"855006001","full_name":"FlotHQ/swap","owner":"FlotHQ","description":"Minimal template engine written in go optimized for performance and a low memory footprint.","archived":false,"fork":false,"pushed_at":"2024-09-10T06:50:53.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-09-10T08:42:17.624Z","etag":null,"topics":["bytecode","engine","go","template","template-engine","variable-substitution"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FlotHQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-10T06:22:24.000Z","updated_at":"2024-09-10T06:50:56.000Z","dependencies_parsed_at":"2025-01-11T06:12:17.321Z","dependency_job_id":null,"html_url":"https://github.com/FlotHQ/swap","commit_stats":null,"previous_names":["flothq/swap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FlotHQ/swap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlotHQ%2Fswap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlotHQ%2Fswap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlotHQ%2Fswap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlotHQ%2Fswap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlotHQ","download_url":"https://codeload.github.com/FlotHQ/swap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlotHQ%2Fswap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28424038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode","engine","go","template","template-engine","variable-substitution"],"created_at":"2026-01-14T15:00:48.228Z","updated_at":"2026-01-14T15:01:03.344Z","avatar_url":"https://github.com/FlotHQ.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swap Template Engine\n\n\u003e [!CAUTION]\n\u003e This project is experimental and not recommended for production use. It prioritizes performance over feature completeness or safety.\n\n\nSwap is an experimental minimal Go template engine optimized for rapid variable substitution and execution, with a focus on performance and simplicity. \n\n1. Bytecode compilation for faster rendering\n2. Optimized variable substitution\n3. Zero dependencies\n4. Low memory footprint\n5. Simple API\n\nIdeal for high-throughput applications like web servers or report generators, Swap offers a lightweight, high-performance solution for Go template rendering.\n\n## Features\n- Fast template rendering using a bytecode VM\n- Compilation of templates into bytecode\n- Optional in-memory caching of compiled templates for improved performance\n- Support for basic control structures (e.g., loops)\n- Limited set of built-in functions\n\n## Benchmarks\nThe project includes benchmarks for:\n- Basic execution\n- Execution with caching\n- Pre-compiled template execution\n\nTemplate used for benchmarks:\n```\nHello, {{ .name }}!\n```\n\nBenchmark results:\n\n| Benchmark | Iterations | Time (ns/op) | Bytes/op | Allocs/op |\n|-----------|------------|--------------|----------|-----------|\n| BenchmarkRun-24 | 47,031,710 | 25.65 | 0 | 0 |\n| BenchmarkExecuteWithCache-24 | 16,992,112 | 70.06 | 48 | 1 |\n| BenchmarkExecute-24 | 2,100,693 | 568.8 | 442 | 19 |\n\n*goos: windows, goarch: amd64, cpu: 13th Gen Intel(R) Core(TM) i7-13700K*\n\n## Examples\n\nHere are three examples demonstrating how to use the Swap template engine:\n\n### 1. Basic Template Execution\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/flothq/swap\"\n)\n\nfunc main() {\n\ttemplate := \"Hello, {{ .name }}!\"\n\tcontext := map[string]interface{}{\"name\": \"John Doe\"}\n\n\tengine := swap.NewEngine()\n\tresult, err := engine.Execute(template, context)\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t\treturn\n\t}\n\n\tfmt.Println(string(result)) // Output: Hello, John Doe!\n}\n```\n\n### 2. Template Compilation and Execution\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/flothq/swap\"\n)\n\nfunc main() {\n\ttemplate := \"Hello, {{ .name }}!\"\n\tcontext := map[string]interface{}{\"name\": \"John Doe\"}\n\n\tengine := swap.NewEngine()\n\tprogram, _ := engine.Compile(template)\n\n\n    // save program to file or anywhere\n    bin, _ := program.Serialize()\n    os.WriteFile(\"program.bin\", program, 0o644)\n\n\tresult, err := engine.Run(program, context)\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t\treturn\n\t}\n\n\tfmt.Println(string(result)) // Output: Hello, John Doe!\n}\n\n```\t\n\n### 3. Loops and Built-in Functions\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/flothq/swap\"\n)\n\nfunc main() {\n\ttemplate := \"Users: {{ range .users }}{{ .name }} is a {{ upper(.occupation) }}\\n{{ end }}\"\n\n\tcontext := map[string]interface{}{\"users\": []map[string]interface{}{\n\t\t{\"name\": \"Alice\", \"occupation\": \"Engineer\"},\n\t\t{\"name\": \"Bob\", \"occupation\": \"Manager\"},\n\t\t{\"name\": \"Charlie\", \"occupation\": \"Designer\"},\n\t\t{\"name\": \"David\", \"occupation\": \"Developer\"},\n\t\t{\"name\": \"Eve\", \"occupation\": \"Analyst\"},\n\t}}\n\n\tengine := swap.NewEngine()\n\tresult, err := engine.Execute(template, context)\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t\treturn\n\t}\n\n\tfmt.Println(string(result))  \n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflothq%2Fswap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflothq%2Fswap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflothq%2Fswap/lists"}