{"id":27880871,"url":"https://github.com/atomicgo/f","last_synced_at":"2025-05-05T04:39:05.685Z","repository":{"id":204510907,"uuid":"712031334","full_name":"atomicgo/f","owner":"atomicgo","description":"🦄 The closest thing to template literals in Go. Parse expressions in strings - the simple way.","archived":false,"fork":false,"pushed_at":"2024-08-08T17:04:17.000Z","size":40,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-08T19:59:45.030Z","etag":null,"topics":["atomicgo","evaluate","expressions","go","golang","golang-library","hacktoberfest","literal","string","template","template-engine"],"latest_commit_sha":null,"homepage":"https://atomicgo.dev","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/atomicgo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":["MarvinJWendt"]}},"created_at":"2023-10-30T16:50:04.000Z","updated_at":"2024-08-08T17:04:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"24358d65-03c4-4467-941d-57ef05ff6f88","html_url":"https://github.com/atomicgo/f","commit_stats":null,"previous_names":["atomicgo/f"],"tags_count":0,"template":false,"template_full_name":"atomicgo/template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomicgo","download_url":"https://codeload.github.com/atomicgo/f/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252442480,"owners_count":21748448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["atomicgo","evaluate","expressions","go","golang","golang-library","hacktoberfest","literal","string","template","template-engine"],"created_at":"2025-05-05T04:39:04.881Z","updated_at":"2025-05-05T04:39:05.680Z","avatar_url":"https://github.com/atomicgo.png","language":"Go","readme":"\u003ch1 align=\"center\"\u003eAtomicGo | f\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fatomicgo.dev%2Fapi%2Fshields%2Ff\u0026style=flat-square\" alt=\"Downloads\"\u003e\n\n\u003ca href=\"https://github.com/atomicgo/f/releases\"\u003e\n\u003cimg src=\"https://img.shields.io/github/v/release/atomicgo/f?style=flat-square\" alt=\"Latest Release\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/f\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/atomicgo/f/go.yml?style=flat-square\" alt=\"Tests\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/f\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/codecov/c/gh/atomicgo/f?color=magenta\u0026logo=codecov\u0026style=flat-square\" alt=\"Coverage\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/f\"\u003e\n\u003c!-- unittestcount:start --\u003e\u003cimg src=\"https://img.shields.io/badge/Unit_Tests-14-magenta?style=flat-square\" alt=\"Unit test count\"\u003e\u003c!-- unittestcount:end --\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square\" alt=\"License: MIT\"\u003e\n\u003c/a\u003e\n  \n\u003ca href=\"https://goreportcard.com/report/github.com/atomicgo/f\" target=\"_blank\"\u003e\n\u003cimg src=\"https://goreportcard.com/badge/github.com/atomicgo/f?style=flat-square\" alt=\"Go report\"\u003e\n\u003c/a\u003e   \n\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n\u003cstrong\u003e\u003ca href=\"https://pkg.go.dev/atomicgo.dev/f#section-documentation\" target=\"_blank\"\u003eDocumentation\u003c/a\u003e\u003c/strong\u003e\n|\n\u003cstrong\u003e\u003ca href=\"https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md\" target=\"_blank\"\u003eContributing\u003c/a\u003e\u003c/strong\u003e\n|\n\u003cstrong\u003e\u003ca href=\"https://github.com/atomicgo/atomicgo/blob/main/CODE_OF_CONDUCT.md\" target=\"_blank\"\u003eCode of Conduct\u003c/a\u003e\u003c/strong\u003e\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/atomicgo/atomicgo/main/assets/header.png\" alt=\"AtomicGo\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\u003ch3  align=\"center\"\u003e\u003cpre\u003ego get atomicgo.dev/f\u003c/pre\u003e\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\n\u003c!-- gomarkdoc:embed:start --\u003e\n\n\u003c!-- Code generated by gomarkdoc. DO NOT EDIT --\u003e\n\n# f\n\n```go\nimport \"atomicgo.dev/f\"\n```\n\nF is the closest thing to template literals in Go.\n\nF is a simple, fast and safe way to format strings in Go, with a familiar syntax. It evaluates expressions inside \\`$\\{\\}\\` and replaces them with their values.\n\nThe expressions support many operators, including ternary operator, and function calls. See the syntax here: https://expr.medv.io/docs/Language-Definition\n\n\u003cdetails\u003e\u003csummary\u003eExample (Demo)\u003c/summary\u003e\n\u003cp\u003e\n\n\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"atomicgo.dev/f\"\n)\n\ntype Person struct {\n\tName string\n\tAge  int\n}\n\nfunc main() {\n\t// Format a string with a struct\n\tjohn := Person{Name: \"Bob\", Age: 22}\n\tfmt.Println(f.Format(\"${Name} is ${Age} years old\", john))\n\n\t// Format a string with a map\n\talice := map[string]any{\"Name\": \"Alice\", \"Age\": 27}\n\tfmt.Println(f.Format(\"${Name} is ${Age} years old\", alice))\n\n\t// Evaluate an expression\n\tfmt.Println(f.Format(\"John is 22 years old: ${Age == 22}\", john))\n\n\t// Ternary operator\n\tfmt.Println(f.Format(\"John is 22 years old: ${Age == 22 ? 'yes' : 'no'}\", john))\n\n}\n```\n\n#### Output\n\n```\nBob is 22 years old\nAlice is 27 years old\nJohn is 22 years old: true\nJohn is 22 years old: yes\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n## Index\n\n- [func Format\\(template string, data ...any\\) string](\u003c#Format\u003e)\n- [func FormatSafe\\(template string, data ...any\\) \\(string, error\\)](\u003c#FormatSafe\u003e)\n- [type Parsed](\u003c#Parsed\u003e)\n  - [func Parse\\(template string\\) Parsed](\u003c#Parse\u003e)\n  - [func \\(parsed Parsed\\) Eval\\(data any\\) \\(string, error\\)](\u003c#Parsed.Eval\u003e)\n  - [func \\(parsed Parsed\\) String\\(\\) string](\u003c#Parsed.String\u003e)\n- [type Part](\u003c#Part\u003e)\n\n\n\u003ca name=\"Format\"\u003e\u003c/a\u003e\n## func [Format](\u003chttps://github.com/atomicgo/f/blob/main/f.go#L4\u003e)\n\n```go\nfunc Format(template string, data ...any) string\n```\n\nFormat formats the template string.\n\n\u003ca name=\"FormatSafe\"\u003e\u003c/a\u003e\n## func [FormatSafe](\u003chttps://github.com/atomicgo/f/blob/main/f.go#L10\u003e)\n\n```go\nfunc FormatSafe(template string, data ...any) (string, error)\n```\n\nFormatSafe formats the template string and returns an additional, optional error, if something goes wrong.\n\n\u003ca name=\"Parsed\"\u003e\u003c/a\u003e\n## type [Parsed](\u003chttps://github.com/atomicgo/f/blob/main/parser.go#L12-L15\u003e)\n\nParsed contains a parsed template string, ready to be evaluated.\n\n```go\ntype Parsed struct {\n    Template string\n    Parts    []Part\n}\n```\n\n\u003ca name=\"Parse\"\u003e\u003c/a\u003e\n### func [Parse](\u003chttps://github.com/atomicgo/f/blob/main/parser.go#L18\u003e)\n\n```go\nfunc Parse(template string) Parsed\n```\n\nParse parses a template string into a Parsed struct.\n\n\u003ca name=\"Parsed.Eval\"\u003e\u003c/a\u003e\n### func \\(Parsed\\) [Eval](\u003chttps://github.com/atomicgo/f/blob/main/parser.go#L36\u003e)\n\n```go\nfunc (parsed Parsed) Eval(data any) (string, error)\n```\n\nEval evaluated expressions in the parsed template string.\n\n\u003ca name=\"Parsed.String\"\u003e\u003c/a\u003e\n### func \\(Parsed\\) [String](\u003chttps://github.com/atomicgo/f/blob/main/parser.go#L26\u003e)\n\n```go\nfunc (parsed Parsed) String() string\n```\n\nString returns the parsed template parts as a single string.\n\n\u003ca name=\"Part\"\u003e\u003c/a\u003e\n## type [Part](\u003chttps://github.com/atomicgo/f/blob/main/parser.go#L60-L63\u003e)\n\nPart is a single part of a template string. Can either be a raw string, or an expression.\n\n```go\ntype Part struct {\n    Value  string\n    Parsed bool\n}\n```\n\nGenerated by [gomarkdoc](\u003chttps://github.com/princjef/gomarkdoc\u003e)\n\n\n\u003c!-- gomarkdoc:embed:end --\u003e\n\n---\n\n\u003e [AtomicGo.dev](https://atomicgo.dev) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e with ❤️ by [@MarvinJWendt](https://github.com/MarvinJWendt) |\n\u003e [MarvinJWendt.com](https://marvinjwendt.com)\n","funding_links":["https://github.com/sponsors/MarvinJWendt"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicgo%2Ff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomicgo%2Ff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicgo%2Ff/lists"}