{"id":20459749,"url":"https://github.com/rosbit/go-ejs","last_synced_at":"2026-03-09T12:06:29.810Z","repository":{"id":57643770,"uuid":"438827869","full_name":"rosbit/go-ejs","owner":"rosbit","description":"embding js in golang is so easy.","archived":false,"fork":false,"pushed_at":"2024-04-03T02:10:09.000Z","size":4876,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T22:37:14.511Z","etag":null,"topics":["embeddable","goja","golang","js"],"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/rosbit.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,"zenodo":null}},"created_at":"2021-12-16T01:50:01.000Z","updated_at":"2025-04-08T16:58:45.000Z","dependencies_parsed_at":"2024-03-23T12:37:03.928Z","dependency_job_id":"13e1d2a2-50ab-438e-9aeb-12f78f716b9b","html_url":"https://github.com/rosbit/go-ejs","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/rosbit/go-ejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-ejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-ejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-ejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-ejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/go-ejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-ejs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30294780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T11:12:22.024Z","status":"ssl_error","status_checked_at":"2026-03-09T11:10:54.577Z","response_time":61,"last_error":"SSL_read: 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":["embeddable","goja","golang","js"],"created_at":"2024-11-15T12:17:09.761Z","updated_at":"2026-03-09T12:06:29.777Z","avatar_url":"https://github.com/rosbit.png","language":"Go","readme":"# Embeding JS for golang\n\ngo-ejs is a wrapper of [goja](https://github.com/dop251/goja). go-ejs is intended to\nembed js in golang applications easily.\n\n### Usage\n\nThe package is fully go-getable, So, just type\n\n  `go get github.com/rosbit/go-ejs`\n\nto install.\n\n```go\npackage main\n\nimport \"fmt\"\nimport \"github.com/rosbit/go-ejs\"\n\nfunc main() {\n  ctx := ejs.NewContext()\n\n  res, _ := ctx.Eval(\"1 + 2\")\n  fmt.Println(\"result is:\", res)\n}\n```\n\n### Go calls JavaScript function\n\nSuppose there's a JavaScript file named `a.js` like this:\n\n```javascript\nfunction add(a, b) {\n    return a+b\n}\n```\n\none can call the JavaScript function add() in Go code like the following:\n\n```go\npackage main\n\nimport \"fmt\"\nimport \"github.com/rosbit/go-ejs\"\n\nvar add func(int, int)int\n\nfunc main() {\n  ctx := ejs.NewContext()\n  if err := ctx.LoadFile(\"a.js\", 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### JavaScript calls Go function\n\nJavaScript calling Go function is also easy. Just bind a golang func with a var name\nwith `AddVar(\"funcname\", function)`. There's the example:\n\n```go\npackage main\n\nimport \"github.com/rosbit/go-ejs\"\n\n// function to be called by JavaScript\nfunc adder(a1 float64, a2 float64) float64 {\n    return a1 + a2\n}\n\nfunc main() {\n  ctx := ejs.NewContext()\n\n  ctx.AddVar(\"adder\", adder)\n  ctx.EvalFile(\"b.js\", nil)  // b.js containing code calling \"adder\"\n}\n```\n\nIn JavaScript code, one can call the registered name directly. There's the example `b.js`.\n\n```javascript\nr = adder(1, 100)   // the function \"adder\" is implemented in Go\nconsole.log(r)\n```\n\n### add more than 1 variables and functions at one time\n\n```go\npackage main\n\nimport \"github.com/rosbit/go-ejs\"\nimport \"fmt\"\n\nfunc adder(a1 float64, a2 float64) float64 {\n    return a1 + a2\n}\n\nfunc main() {\n  vars := map[string]interface{}{\n     \"adder\": adder,    // to JavaScript built-in function\n     \"a\": []int{1,2,3}, // to JavaScript array\n  }\n\n  ctx := js.NewContext()\n  if err := ctx.LoadFile(\"file.js\", vars); err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n  // or call ctx.AddVars(vars) to add variables.\n\n  res, err := ctx.GetGlobals(\"global_var_name\") // get the value of var global_var_name\n  if err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n  fmt.Printf(\"res:\", res)\n}\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__Convention:__ fork the repository and make changes on your fork in a feature branch.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-ejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Fgo-ejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-ejs/lists"}