{"id":19922862,"url":"https://github.com/tochk/twf","last_synced_at":"2025-09-26T12:02:25.970Z","repository":{"id":90933001,"uuid":"259687168","full_name":"tochk/twf","owner":"tochk","description":"Web library for go applications","archived":false,"fork":false,"pushed_at":"2023-07-01T11:49:04.000Z","size":183,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T00:14:44.764Z","etag":null,"topics":["admin-ui","forms","golang","web"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tochk.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}},"created_at":"2020-04-28T16:08:04.000Z","updated_at":"2023-07-02T13:19:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"7e4e8d04-8618-4b4f-8f44-9b181d8a4835","html_url":"https://github.com/tochk/twf","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tochk%2Ftwf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tochk%2Ftwf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tochk%2Ftwf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tochk%2Ftwf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tochk","download_url":"https://codeload.github.com/tochk/twf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241348358,"owners_count":19948164,"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":["admin-ui","forms","golang","web"],"created_at":"2024-11-12T22:12:18.063Z","updated_at":"2025-09-26T12:02:20.932Z","avatar_url":"https://github.com/tochk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TWF\r\n\r\nSimple golang library for easily creating admin portals (or another web interfaces with many forms :)  )\r\n\r\n## Usage\r\n\r\nAdd form example\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"github.com/gorilla/mux\"\r\n\t\"github.com/tochk/twf\"\r\n\t\"github.com/tochk/twf/twftemplates\"\r\n\t\"log\"\r\n\t\"net/http\"\r\n)\r\n\r\ntype Auth struct {\r\n\t// Login field in form - simple text field with name, title and placeholder described below\r\n\tLogin string `twf:\"name:login,title:Login,placeholder:Enter any login\"`\r\n\t// Password field in form - password field with name, title and placeholder described below\r\n\tPassword string `twf:\"name:password,title:Password,type:password,placeholder:Enter any password\"`\r\n}\r\n\r\nfunc indexHandler(w http.ResponseWriter, r *http.Request) {\r\n\ttwfInstance := twf.New() // create new instance with default parameters\r\n\r\n\ttwfInstance.FormFunc = twftemplates.MultipartForm // you should redefine twf.FormFunc to twftemplates.MultipartForm if you need to use file upload in forms\r\n\r\n\t// build add form\r\n\tdata, err := twfInstance.AddForm(\"Login\", \u0026Auth{}, \"\")\r\n\tif err != nil {\r\n\t\treturn\r\n\t}\r\n\r\n\t// print add form to user\r\n\tfmt.Fprint(w, data)\r\n}\r\n\r\nfunc main() {\r\n\tr := mux.NewRouter() // create router\r\n\tr.HandleFunc(\"/\", indexHandler)\r\n\r\n\tif err := http.ListenAndServe(\":8080\", r); err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n}\r\n```\r\n\r\nFor more exaples go to [example](examples).\r\n\r\n### Allowed tags\r\n\r\nTags format - comma-separated parameters in `twf` tag:\r\n\r\n```go\r\ntype Test struct {\r\n\tID string `twf:\"name:id,title:ID\"`\r\n}\r\n```\r\n\r\nImportant! TWF doesn't support escaping commas and other symbols in tags.\r\n\r\nTags:\r\n\r\n- `name` format: `name:id` used in form as input internal name\r\n- `title` format: `title:ID` used in form or table as column title\r\n- `type` format: `type:textarea` used in form to determine input type, allowed values:\r\n    - `textarea`\r\n    - `password`\r\n    - `number` - default for numeric types\r\n    - `checkbox` - default for bool\r\n    - `file` - use this type for marshal file from form to []byte type\r\n    - `select` - default for fks\r\n- `placeholder` format: `placeholder:Enter ID` used in form as placeholder\r\n- `reqiured` format: `required` used as required flag in form\r\n- `no_create` format: `no_create` disable showing in add form\r\n- `no_edit` format: `no_edit` disable showing in edit form\r\n- `not_show_on_table` format: `not_show_on_table` disable showing in table\r\n- `process_parameters` format: `process_parameters` add template parameters to value (see [template parameters](#Template parameters))\r\n- `value` format: `value:default value` default value\r\n- `disabled` format: `disabled` disable field in forms\r\n- `fk` format: `fk:0,id,name` fks info, (see [FKs](#FKs))\r\n\r\n### Template parameters\r\n\r\nIf `process_parameters` is enabled replaces template parameters in value\r\n\r\nFor example, edit link in table: \r\n\r\n```go\r\ntype Test struct {\r\n\tID   int    `twf:\"title:ID,name:id\"`\r\n\tEdit string `twf:\"title:Edit,name:edit,value:\u003ca href=\\\"/users/edit/{id}\\\"\u003eEdit\u003c/a\u003e,no_create,no_edit,process_parameters\"`\r\n}\r\n```\r\n\r\nEdit will be printed in separate column and for id = 1 it will be `\u003ca href=\"/users/edit/1\"\u003eEdit\u003c/a\u003e`\r\n\r\n### FKs\r\n\r\nFeature for linking another tables (by id, for example)\r\n\r\nExample: [link](examples/users_page.go) `GroupID` field and `groups slice\r\n\r\n## Example\r\n\r\nExample docs: [link](examples/README.md)\r\n\r\nTo run the example:\r\n\r\n`make run_example`\r\n\r\n### Screenshots\r\n\r\n#### Login form\r\n\r\n![Add form](docs/images/add_form.png)\r\n\r\n#### Table view\r\n\r\n![Add form](docs/images/table.png)\r\n\r\n#### Edit user form\r\n\r\n![Add form](docs/images/edit_form.png)\r\n\r\n## TODO\r\n\r\n- Paging\r\n- More tests\r\n- Benchmarks","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftochk%2Ftwf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftochk%2Ftwf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftochk%2Ftwf/lists"}