{"id":37142273,"url":"https://github.com/nikolay-turpitko/structor","last_synced_at":"2026-01-14T16:42:01.511Z","repository":{"id":57504186,"uuid":"91477566","full_name":"nikolay-turpitko/structor","owner":"nikolay-turpitko","description":"Uses EL in Go struct tags to compute struct fields.","archived":true,"fork":false,"pushed_at":"2019-01-06T05:50:06.000Z","size":87,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T08:16:22.725Z","etag":null,"topics":["el","expression-language","go","golang","goquery","regexp","scraping","struct","struct-field-visitor","struct-walker","tags","xpath"],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/nikolay-turpitko/structor","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/nikolay-turpitko.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}},"created_at":"2017-05-16T15:59:45.000Z","updated_at":"2024-06-20T08:16:22.726Z","dependencies_parsed_at":"2022-08-28T02:01:43.426Z","dependency_job_id":null,"html_url":"https://github.com/nikolay-turpitko/structor","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/nikolay-turpitko/structor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolay-turpitko%2Fstructor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolay-turpitko%2Fstructor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolay-turpitko%2Fstructor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolay-turpitko%2Fstructor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikolay-turpitko","download_url":"https://codeload.github.com/nikolay-turpitko/structor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolay-turpitko%2Fstructor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28426181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","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":["el","expression-language","go","golang","goquery","regexp","scraping","struct","struct-field-visitor","struct-walker","tags","xpath"],"created_at":"2026-01-14T16:42:00.862Z","updated_at":"2026-01-14T16:42:01.504Z","avatar_url":"https://github.com/nikolay-turpitko.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/nikolay-turpitko/structor.svg?branch=master)](https://travis-ci.com/nikolay-turpitko/structor)\n[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/nikolay-turpitko/structor/blob/master/LICENSE)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/nikolay-turpitko/structor)\n[![codecov](https://codecov.io/gh/nikolay-turpitko/structor/branch/master/graph/badge.svg)](https://codecov.io/gh/nikolay-turpitko/structor)\n\n# structor\nUses EL in Go struct tags to compute struct fields.\n\n## In a nutshell\n\nBasic idea is to use simple expression language (EL) within Go struct tags to\ncompute struct fields based on other fields or provided additional context.\n\nIt can be viewed/used as an advanced struct builder or constructor. Hence the\nname. Another possible use case is a \"struct walker\" or \"struct field visitor\".\n\nImplementation uses reflection and EL interpretation, so, it is relatively slow\nby design, and, because of that, should be used for infrequent tasks. For\nexample, during program initialization. Or in cases when all other alternatives\nare equally slow.\n\nInitial implementation uses `\"text/template\"` as EL, it get fields name, value,\ntags, full struct and extra context as a \"dot\" context and either use special\n\"set\" custom function to save new field's value as object or just stores result\nof the template evaluation as string into the field.\n\nMap of the custom functions can be passed to EL engine for use in the\nexpressions.  \"set\" is a special custom EL function which stores argument into\nthe currently processed field. Special case: if annotated field is struct and\nresult can not be converted to it, then result stored into `.Sub`, and\nevaluation executed recursively on the inner struct.\n\nAnother special custom EL function is \"eval\". This function allows to invoke\ninterpreter from within EL expression to evaluate another expression. Example\nusage is when expression of interest come from another field or extra context.\nFor instance, it can come from configuration file.\n\nSimple namespaces and \"import\" mechanism provided for custom functions - whole\nmap of custom functions can be combined from several maps with (optional)\ncustom prefixes, prepended to every function name within map. Maps for provided\nfunctions placed into separate Go packages and can be imported as needed. When\nused with [Glide](https://github.com/Masterminds/glide), they can be imported\nas subpackages, allowing to optimize dependencies.\n\nIt's simpler to illustrate on examples, see examples in tests\n([funcs_test.go](funcs_test.go), [goel_funcs_test.go](goel_funcs_test.go)) and\n[Godoc](http://godoc.org/github.com/nikolay-turpitko/structor).\n\n## Possible use cases\n\n- take a struct, filled up from configuration file using\n  [github.com/spf13/viper](https://github.com/spf13/viper) and compute additional fields:\n\n  * replace referencies in settings to their values (for example base URL in\n    othre URLs); also: templates in the settings themeselves, not in the tags\n    of structure;\n  * load short text files into string fields (with file names from config);\n  * decode passwords;\n  * extract data from environment variables, listed in config;\n  * execute bash scripts to compute fields (iconv, openssl, etc);\n  * parse complex types from string representation;\n\n- use engines like regexp, xpath or goquery to extract pieces of data from\n  text, xml, html etc. formats into fields (scraping data from html pages, text\n  files or emails); for long and complex expressions it can be convenient to\n  use multiline tags and process whole tag value as single expression;\n\n- registering a custom EL \"interpreter\", which executes arbitrary custom logic\n  in its Execute() method, it is possible to use structor as a \"struct walker\"\n  or \"field visitor\", which will traverse structure fields and invoke custom\n  function for every field, containing custom tag; it can be convenient with\n  ability to use multiline tags;\n\n## Ideas of functions, available in expressions\n\n- [x] atoi\n- [x] base64/unbase64\n- [x] exec - invoke external process (shell, for instance)\n- [x] encrypt/decrypt\n- [x] env\n- [x] eval\n- [x] fields\n- [x] readFile - read file content to []byte or string\n- [x] goquery\n- [x] hex/unhex\n- [x] match\n- [x] math (basic arithmetics)\n- [x] replace\n- [x] rot13\n- [x] set\n- [x] split\n- [x] standard for package `\"text/template\"`\n- [x] trimSpace\n- [x] xpath\n- [x] ... (custom)\n\n## Other ideas\n\n- [x] go expressions (using \"github.com/apaxa-go/eval\")\n\n## Godoc\n\n[Godoc](http://godoc.org/github.com/nikolay-turpitko/structor)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolay-turpitko%2Fstructor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikolay-turpitko%2Fstructor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolay-turpitko%2Fstructor/lists"}