{"id":21674295,"url":"https://github.com/anhgelus/golatt","last_synced_at":"2025-08-30T20:07:03.538Z","repository":{"id":261772220,"uuid":"885270807","full_name":"anhgelus/golatt","owner":"anhgelus","description":"Golatt is a new Go framework helping the creation of websites!","archived":false,"fork":false,"pushed_at":"2025-05-20T17:03:46.000Z","size":103,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-20T17:51:22.716Z","etag":null,"topics":["framework","gemini","gemini-protocol","gemini-server","go","golang","http","http-server","website"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anhgelus.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":"2024-11-08T09:24:40.000Z","updated_at":"2025-05-20T16:58:00.000Z","dependencies_parsed_at":"2024-11-08T11:24:42.872Z","dependency_job_id":"3ff39051-04b8-4eb9-a664-66bff9ded5c5","html_url":"https://github.com/anhgelus/golatt","commit_stats":null,"previous_names":["anhgelus/golatt"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/anhgelus/golatt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhgelus%2Fgolatt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhgelus%2Fgolatt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhgelus%2Fgolatt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhgelus%2Fgolatt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anhgelus","download_url":"https://codeload.github.com/anhgelus/golatt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhgelus%2Fgolatt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272900157,"owners_count":25012033,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["framework","gemini","gemini-protocol","gemini-server","go","golang","http","http-server","website"],"created_at":"2024-11-25T13:43:59.834Z","updated_at":"2025-08-30T20:07:03.515Z","avatar_url":"https://github.com/anhgelus.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golatt\n\nGolatt is a new Go framework helping the creation of websites!\nIt is an integration of Go templating in gorilla/mux.\n\nIt is lightweight and heavily customizable.\n\n## Usage\n### Basic usage\nInstall the framework with\n```bash\ngo get -u github.com/anhgelus/golatt@v0.4.0\n```\n\nCreate a new directories called `templates`, `static` and `assets`, and embed them with go:embed, e.g.\n```go\n//go:embed templates\nvar templates embed.FS\n//go:embed dist public\nvar contents embed.FS\n```\nThese directories will contain all your Go templates, static files and assets.\n\nCreate a new `Golatt` instance with `golatt.New(fs.FS)`, e.g.\n```go\ng := golatt.New(\n\tgolatt.UsableEmbedFS(\"templates\", templates),\n\tgolatt.UsableEmbedFS(\"public\", contents),\n\tgolatt.UsableEmbedFS(\"dist\", contents),\n)\n```\n\nThen you can use this instance to handle http queries, e.g.\n```go\ng.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\tw.Write([]byte(\"Yeah!\"))\n})\n```\n\nAnd you can start the server with `g.StartServer(string)`, e.g.\n```go\ng.StartServer(\":8000\")\n```\n\nFull example file:\n```go\npackage main\n\nimport (\n\t\"embed\"\n\n\t\"github.com/anhgelus/golatt\"\n)\n\nvar (\n\t//go:embed templates\n\ttemplates embed.FS\n    //go:embed dist public\n    contents embed.FS\n)\n\nfunc main() {\n\tg := golatt.New(\n\t\tgolatt.UsableEmbedFS(\"templates\", templates),\n\t\tgolatt.UsableEmbedFS(\"public\", contents),\n\t\tgolatt.UsableEmbedFS(\"dist\", contents),\n\t)\n\tg.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Write([]byte(\"Yeah!\"))\n\t})\n\tg.StartServer(\":8000\")\n}\n```\n### Templates\nGolatt is designed to add Go templates in gorilla/mux.\n\nTo use it, you must name the folder containing all your templates `templates` and place it at the root of your project.\nYou also have to create the directory `templates/page`.\nYou can modify these names with a config, take a look at the next section to learn how to do it.\n\nThen, you have to create two folders:\n- `public` which is the folder containing static files (image, font...)\n- `dist` which is the folder containing compiled stuff not in Go (css, javascript...)\nThese names can also be modified with a config.\n\nYour project directory must look like this:\n```\n📁 dist/\n    | ...\n📁 templates/\n    | 📁 page/\n        | ...\n    | ...\n📁 public/\n    | ...\n🗎 .gitignore\n🗎 main.go\n🗎 go.mod\n🗎 go.sum\n```\n\n#### Setting up general information\nGolatt supports out-of-the-box opengraph.\nTo use it, you have to set some global SEO information after creating your Golatt instance.\nTo do it, just create a new `golatt.SeoData` instance.\nYou can now fill in all required information, i.e. domain, image and description.\nImage must be a relative path inside your `public` directory (e.g., if your image is `public/foo/bar.webp`, the path\nmust be `foo/bar.webp`).\nYou must put this inside `Golatt.DefaultSeoData`.\n```go\ng.DefaultSeoData = \u0026golatt.SeoData{\n    Domain: \"example.org\", // as required by opengraph specification\n    Image: \"foo/bar.webp\",\n    Description: \"An amazing example website!\",\n}\n```\n\nThen, you have to create your own templates.\nThese templates will be parsed at every request.\nIt can be components, html templates or what else needed to be loaded at each request.\n\nLet's create a html template. \nIn the new file `templates/base/base.gohtml`, you can fill it with your html template, e.g.\n```html\n{{define \"base\"}}\n    \u003c!DOCTYPE html\u003e\n    \u003chtml lang=\"en\" prefix=\"og: https://ogp.me/ns#\"\u003e\n    \u003chead\u003e\n        \u003cmeta charset=\"UTF-8\" /\u003e\n        \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n        \u003ctitle\u003e{{ .Title }}\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n    {{template \"body\" .}}\n    \u003c/body\u003e\n    \u003c/html\u003e\n{{end}}\n```\nThe template \"body\" will be replaced by your page.\n`.Title` refers to the title of the page.\n\nIn this example, this initial section is `base`: our templates will be loaded with this entry.\nYou can change this by setting `Golatt.InitialSection` to any other value.\n\nFinally, we have to register these templates in Golatt.\nYou must simply add the relative path of each template into the slice `Golatt.Templates`.\nYou must NOT register your page body (the template defining the section `body`).\n```go\n// \"templates/\" is omitted because it was already defined by golatt.UsableEmbedFS(\"templates\", templates)\ng.Templates = append(g.Templates, \"base/*.gohtml\") \n```\nIf you changed the name of the folder, you have to change the relative path too!\n#### Static paths and assets paths \nGolatt splits files in two categories:\n- `static`\n- `assets`\n\nStatic files are not compiled files by you like images, fonts or whatever.\nThese are usually placed in the folder `public` and are available with the prefix `/static/`.\nYou can generate the URL of the file `public/foo/bar.jpg` with `getStaticPath foo/bar.jpg` inside your templates.\n\nAssets files are compiled files by you like css (from scss, less), javascript or whatever.\nThese are usually placed in the folder `dist` and are available with the prefix `/assets/`.\nYou can generate the URL of the file `assets/foo/bar.js` with `getAssetPath foo/bar.jpg` inside your templates.\n\nIf you want to get a path inside your program, you can use `golatt.GetStaticPath` and `golatt.GetAssetPath`.\n#### Simple template\nYou can handle simple template very easily with `Golatt.HandleSimpleTemplate(name string, title string)`.\n- `name` is the name the template desired containing the body section, e.g. `foo/bar` for `templates/page/foo/bar.gohtml`.\nThese templates must be put in `templates/page` and have the extension `.gohtml`!\n(Can be modified.)\n- `title` is the title of your page.\n\nYou can handle a simple request with this, e.g.\n```go\ng.HandleSimpleTemplate(\"hello\", \"Hello\")\n```\n:warning: The URL generated could possibly be the wrong one!\nThe generated URL will be `\"/\"+name`.\nHere it's `/hello` which is correct, but if you call this with `\"index\"` to handle `/`, the URL will not be working!\n#### Advanced template\nAdvanced template is like the simple one but with more options.\nTo use it, you must create a new instance of `golatt.Template`.\n- `Golatt` is the current instance of Golatt.\n- `Name` and `Title` are the same parameters of `Golatt.HandleSimpleTemplate`.\n- `Image` is the image to use for opengraph (see the definition of DefaultSeoData for more information).\n- `Description` is the description of the page.\n- `Data` is any kind of data that you want to pass to your template. \nThis is accessible via `.Data` inside the template.\n- `URL` is the URL of the page.\nIf not set, it will be generated automatically like in simple template.\n\nYou can also call `Golatt.NewTemplate` to create a new template.\n\nAfter, you can call `Template.Handle()` to handle an HTTP request.\n\n```go\nt := golatt.Template{\n    Golatt: g,\n    Name: \"index\",\n    Title: \"Home\",\n    Image: \"index.webp\",\n    Description: \"Home of my website!\",\n    URL: \"/\",\n}\nt.Handle()\n// or\ng.NewTemplate(\"index\", \"/\", \"Home\", \"index.webp\", \"Home of my website!\", nil).Handle()\n```\n#### Custom render\nIf you need more customization, you can use `Golatt.Render(w http.ResponseWriter, name string, data *TemplateData)`.\n- `w` is the `http.ResponseWriter` to write the response \n- `name` is the name of the template (like the previous name given) \n- `data` are the data to pass to the template, but these are more complicated than the data given in `golatt.Template`.\n\nFor example:\n```go\ng.HandleFunc(\"/foo\", g.Render(w, \"foo/index\", \u0026golatt.TemplateData{\n\tTitle: \"Foo\",\n\tSEO:   \u0026golatt.SeoData{\n\t\tURL: \"/foo\",\n\t\tDescription: \"Foo page!\",\n\t\tImage: \"foo.jpg\",\n    },\n\tData:  nil,\n}))\n```\n#### Errors 404\nYou can handle errors 404 by setting `Golatt.NotFoundHandler`, e.g.\n```go\nt := golatt.Template{\n    Golatt: g,\n    Name: \"not_found\",\n    Title: \"Home\",\n    Image: \"\",\n    Description: \"Error 404\",\n    URL: \"\",\n}\ng.NotFoundHandler = t.Handle()\n```\n### Configuration\nYou can format each page's title by setting `Golatt.FormatTitle`.\nIt takes a string representing the page's title, and it returns the new title.\n```go\ng.FormatTitle = func(t string) string {\n\treturn t + \" - Example Website\"\n} // default: no modification of the title\n```\n\nIt is also possible to edit the directory containing all your pages' template by modifying `Golatt.PageDirectory`.\n```go\n// new location is templates/foo/bar\ng.PageDirectory = \"foo/bar\" // default: \"page\"\n```\n\nYou can also use another extension for the templates file.\nModify `Golatt.TemplateExtension` to change it.\n```go\n// all your template files must have this extension\ng.TemplateExtension = \"html\" // default: \"gohtml\"\n```\n## Technologies\n\n- Go 1.23\n- [gorilla/mux](https://github.com/gorilla/mux)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanhgelus%2Fgolatt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanhgelus%2Fgolatt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanhgelus%2Fgolatt/lists"}