{"id":15117072,"url":"https://github.com/gowebly/helpers","last_synced_at":"2026-01-27T12:20:07.310Z","repository":{"id":233897837,"uuid":"696604880","full_name":"gowebly/helpers","owner":"gowebly","description":"🙋 A most useful helpers for build the best Go web applications with the gowebly CLI (and not so).","archived":false,"fork":false,"pushed_at":"2024-04-17T15:17:19.000Z","size":34,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-26T01:54:40.893Z","etag":null,"topics":["go","golang","golang-library","golang-package","gowebly"],"latest_commit_sha":null,"homepage":"https://gowebly.org","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/gowebly.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}},"created_at":"2023-09-26T04:49:22.000Z","updated_at":"2024-09-08T14:03:25.000Z","dependencies_parsed_at":"2024-04-17T16:49:45.055Z","dependency_job_id":null,"html_url":"https://github.com/gowebly/helpers","commit_stats":null,"previous_names":["gowebly/helpers"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowebly%2Fhelpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowebly%2Fhelpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowebly%2Fhelpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowebly%2Fhelpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gowebly","download_url":"https://codeload.github.com/gowebly/helpers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234462159,"owners_count":18837274,"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":["go","golang","golang-library","golang-package","gowebly"],"created_at":"2024-09-26T01:45:49.096Z","updated_at":"2025-09-27T22:31:59.033Z","avatar_url":"https://github.com/gowebly.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Helpers for the Gowebly CLI (and not so)\n\n[![Go version][go_version_img]][go_dev_url]\n[![Go report][go_report_img]][go_report_url]\n[![Code coverage][go_code_coverage_img]][go_code_coverage_url]\n[![License][repo_license_img]][repo_license_url]\n\nA most useful helpers for build the best **Go** web applications with [Gowebly CLI][gowebly_url].\n\n\u003e 💡 Note: You can use these helpers in other projects as well.\n\n## 📖 List of helpers\n\n### `gowebly.Getenv`\n\nHelper to get the given environment variable. If key is not found, sets a fallback value.\n\n```go\nimport (\n    gowebly \"github.com/gowebly/helpers\"\n)\n\n// Get a value of the environment variable 'BACKEND_PORT'\n// or sets it to a fallback value '5000'.\ngowebly.Getenv(\"BACKEND_PORT\", \"5000\")\n```\n\n\u003e 💡 Note: This is a more advanced version of the built-in [os.Getenv][go_os_getenv_url] function.\n\n### `gowebly.ParseTemplates`\n\nHelper to parse list of the given templates to the HTTP handler.\n\n```go\nimport (\n    \"log/slog\"\n\n    gowebly \"github.com/gowebly/helpers\"\n)\n\nfunc handler(w http.ResponseWriter, r *http.Request) {\n    // Define paths to the user templates.\n    indexPage := filepath.Join(\"templates\", \"pages\", \"index.html\")\n    indexLoginForm := filepath.Join(\"templates\", \"components\", \"index-login-form.html\")\n\n    // Parse user templates, using gowebly helper, or return error.\n    tmpl, err := gowebly.ParseTemplates(indexPage, indexLoginForm)\n    if err != nil {\n        w.WriteHeader(http.StatusBadRequest)\n        slog.Error(err.Error(), \"method\", r.Method, \"status\", http.StatusBadRequest, \"path\", r.URL.Path)\n        return\n    }\n\n    // Execute (render) all templates or return error.\n    if err := tmpl.Execute(w, nil); err != nil {\n        w.WriteHeader(http.StatusInternalServerError)\n        slog.Error(err.Error(), \"method\", r.Method, \"status\", http.StatusInternalServerError, \"path\", r.URL.Path)\n        return\n    }\n}\n```\n\n\u003e 💡 Note: The main layout template (`templates/main.html`) is already included.\n\n### `gowebly.ParseTemplatesWithCustomMainLayout`\n\nHelper to parse a list of the given templates with a custom main layout to the HTTP handler. Useful to use at times when you want to override file name of the default `templates/main.html` layout template.\n\n```go\nimport (\n    \"log/slog\"\n\n    gowebly \"github.com/gowebly/helpers\"\n)\n\nfunc handler(w http.ResponseWriter, r *http.Request) {\n    // Define path to the main layout template.\n    customMainLayout := filepath.Join(\"templates\", \"my-custom-main.html\")\n\n    // Define paths to the user templates.\n    indexPage := filepath.Join(\"templates\", \"pages\", \"index.html\")\n    indexLoginForm := filepath.Join(\"templates\", \"components\", \"index-login-form.html\")\n\n    // Parse user templates or return error.\n    tmpl, err := gowebly.ParseTemplatesWithCustomMainLayout(customMainLayout, indexPage, indexLoginForm)\n    if err != nil {\n        w.WriteHeader(http.StatusBadRequest)\n        slog.Error(err.Error(), \"method\", r.Method, \"status\", http.StatusBadRequest, \"path\", r.URL.Path)\n        return\n    }\n\n    // Execute (render) all templates or return error.\n    if err := tmpl.Execute(w, nil); err != nil {\n        w.WriteHeader(http.StatusInternalServerError)\n        slog.Error(err.Error(), \"method\", r.Method, \"status\", http.StatusInternalServerError, \"path\", r.URL.Path)\n        return\n    }\n}\n```\n\n### `gowebly.StaticFileServerHandler`\n\nHelpers to create a custom handler for serve embed `./static` folder.\n\n```go\nimport (\n    \"embed\"\n    \"net/http\"\n\n    gowebly \"github.com/gowebly/helpers\"\n)\n\n//go:embed static/*\nvar static embed.FS\n\n// Create the gowebly helper for serve embed static folder.\nstaticFileServer := gowebly.StaticFileServerHandler(http.FS(static))\n\n// Handle static files (with a custom handler).\nhttp.Handle(\"/static/\", staticFileServer)\n```\n\n## ⚠️ License\n\n[`The Gowebly Helpers`][repo_url] is free and open-source software licensed under the [Apache 2.0 License][repo_license_url], created and supported by [Vic Shóstak][author_url] with 🩵 for people and robots.\n\n\u003c!-- Go links --\u003e\n\n[go_report_url]: https://goreportcard.com/report/github.com/gowebly/helpers\n[go_dev_url]: https://pkg.go.dev/github.com/gowebly/helpers\n[go_version_img]: https://img.shields.io/badge/Go-1.22+-00ADD8?style=for-the-badge\u0026logo=go\n[go_code_coverage_url]: https://codecov.io/gh/gowebly/helpers\n[go_code_coverage_img]: https://img.shields.io/codecov/c/gh/gowebly/helpers.svg?logo=codecov\u0026style=for-the-badge\n[go_report_img]: https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge\u0026logo=none\n[go_os_getenv_url]: https://pkg.go.dev/os#Getenv\n\n\u003c!-- Repository links --\u003e\n\n[repo_url]: https://github.com/gowebly/helpers\n[repo_license_url]: https://github.com/gowebly/helpers/blob/main/LICENSE\n[repo_license_img]: https://img.shields.io/badge/license-Apache_2.0-red?style=for-the-badge\u0026logo=none\n\n\u003c!-- Author links --\u003e\n\n[author_url]: https://github.com/koddr\n\n\u003c!-- README links --\u003e\n\n[gowebly_url]: https://github.com/gowebly/gowebly\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowebly%2Fhelpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgowebly%2Fhelpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowebly%2Fhelpers/lists"}