{"id":20459724,"url":"https://github.com/rosbit/go-expr","last_synced_at":"2025-07-13T17:09:01.684Z","repository":{"id":215583038,"uuid":"739274740","full_name":"rosbit/go-expr","owner":"rosbit","description":"make expr-lang be embedded easily in Golang","archived":false,"fork":false,"pushed_at":"2024-01-06T13:48:57.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T11:16:39.434Z","etag":null,"topics":["expr-lang","extending","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rosbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-01-05T07:10:32.000Z","updated_at":"2024-01-06T13:41:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b4a5b89-56c6-43af-b5ef-5176897e8901","html_url":"https://github.com/rosbit/go-expr","commit_stats":null,"previous_names":["rosbit/go-expr"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/rosbit/go-expr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-expr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-expr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-expr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-expr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/go-expr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-expr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265175567,"owners_count":23722661,"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":["expr-lang","extending","golang"],"created_at":"2024-11-15T12:17:05.792Z","updated_at":"2025-07-13T17:09:01.649Z","avatar_url":"https://github.com/rosbit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-expr, an extending of expr-lang\n\n[Expr](https://github.com/expr-lang/expr) is a Go-centric expression language designed to deliver dynamic\nconfigurations with unparalleled accuracy, safety, and speed\n\n`go-expr` is a package extending the `Expr` and making it a **pragmatic embeddable** language.\nWith some helper functions provided by `go-expr`, calling Golang functions from `Expr`, \nor calling `Expr` functions from Golang are both very simple. So, with the help of `go-expr`, expr-lang\ncan be looked as **an embeddable expr-lang**.\n\n### Expr functions\n\nAll to be evaluated in `Expr` are expression strings. Function is an extending notion to wrapper `Expr` expressions.\nWe make use of `YAML` syntax to declare `Expr` functions. e.g., Function `add` is desclared like this:\n```yaml\nfuncs:\n  add:\n    params: [A, B]\n    expr: A + B\n\n  other-funcs:\n    ..\n```\n\n`params` are parameter variable names for function. `expr` is the body of function, is just the `Expr` expressions.\n\n### Usage\n\nThe package is fully go-getable, so, just type\n\n  `go get github.com/rosbit/go-expr`\n\nto install.\n\n#### 1. Evaluate expressions\n\n```go\npackage main\n\nimport (\n  \"github.com/rosbit/go-expr\"\n  \"fmt\"\n)\n\nfunc main() {\n  ctx := ex.New()\n\n  res, _ := ctx.Eval(\"1 + 2\", nil)\n  fmt.Println(\"result is:\", res)\n}\n```\n\n#### 2. Go calls Expr function:\n\nSuppose there's a Expr file named `a.yaml` like this:\n\n```yaml\nfuncs:\n  add:\n    params: [A, B]\n    expr: A + B\n\n```\n\none can call the Expr function `add()` in Go code like the following:\n\n```go\npackage main\n\nimport (\n  \"github.com/rosbit/go-expr\"\n  \"fmt\"\n)\n\nvar add func(int, int)int\n\nfunc main() {\n  ctx := ex.New()\n  if err := ctx.LoadFile(\"a.yaml\", nil); err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n\n  if err := ctx.BindFunc(\"add\", \u0026add); err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n\n  res := add(1, 2)\n  fmt.Println(\"result is:\", res)\n}\n```\n\n#### 3. Expr calls Go function\n\nExpr calling Go function is also easy. In the Go code, make a Golang function\nas Expr built-in function by registering golang functions. There's the example:\n\n```go\npackage main\n\nimport \"github.com/rosbit/go-expr\"\n\n// function to be called by Expr\nfunc adder(a1 float64, a2 float64) float64 {\n    return a1 + a2\n}\n\nfunc main() {\n  ctx := ex.New()\n\n  if err := ctx.LoadFile(\"b.yaml\", map[string]interface{}{\n     \"adder\": adder,\n  }); err != nil {\n     // error handler\n     return\n  }\n  res, _ := ctx.CallFunc(\"add\", 10, 2)\n  fmt.Println(\"result is:\", res)\n}\n```\n\nIn Expr code, one can call the registered function directly. There's the example `b.yaml`\n\n```yaml\nfuncs:\n  add:\n    params: [A, B]\n    expr: adder(A, B)  # the function \"adder\" is implmented in Go.\n```\n\n### Status\n\nThe package is not fully tested, so be careful.\n\n### Contribution\n\nPull requests are welcome! Also, if you want to discuss something send a pull request with proposal and changes.\n\n__Convention:__ fork the repository and make changes on your fork in a feature branch.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-expr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Fgo-expr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-expr/lists"}