{"id":17948836,"url":"https://github.com/eko/gofast","last_synced_at":"2025-03-24T22:35:39.206Z","repository":{"id":23627298,"uuid":"26996948","full_name":"eko/gofast","owner":"eko","description":"A simple micro-framework written in Go","archived":false,"fork":false,"pushed_at":"2023-03-07T03:47:34.000Z","size":67,"stargazers_count":39,"open_issues_count":2,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-19T05:07:02.279Z","etag":null,"topics":["cors","go","golang","micro-framework","middleware","pongo2"],"latest_commit_sha":null,"homepage":null,"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/eko.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":"2014-11-22T11:28:40.000Z","updated_at":"2025-03-12T07:34:57.000Z","dependencies_parsed_at":"2024-06-20T11:06:59.073Z","dependency_job_id":"19e14742-624b-4503-a11b-dbeb97a13bce","html_url":"https://github.com/eko/gofast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2Fgofast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2Fgofast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2Fgofast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eko%2Fgofast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eko","download_url":"https://codeload.github.com/eko/gofast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245366205,"owners_count":20603438,"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":["cors","go","golang","micro-framework","middleware","pongo2"],"created_at":"2024-10-29T09:10:16.991Z","updated_at":"2025-03-24T22:35:34.196Z","avatar_url":"https://github.com/eko.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Gofast - A light, fast and simple Go micro-framework\n====================================================\n\n[![GoDoc](https://godoc.org/github.com/eko/gofast?status.png)](https://godoc.org/github.com/eko/gofast)\n[![Build Status](https://secure.travis-ci.org/eko/gofast.png?branch=master)](http://travis-ci.org/eko/gofast)\n\nThis is a light and fast micro-framework I wrote in order to train to Go language.\n\nThis project uses \"pongo2\" library for rendering templates (compatible with Django Jinja templates)\n\nInstallation\n------------\n\nPrior to Go 1.11:\n\n```bash\n$ git clone git@github.com:eko/gofast.git\n$ go get -u github.com/flosch/pongo2\n$ go get -u golang.org/x/net/http2\n$ go get -u golang.org/sirupsen/logrus\n```\n\nPrefer using `dep`?\n\n```bash\n$ dep ensure\n```\n\nWhen using Go 1.11 (go modules) or later:\n\n```bash\n$ go build ./...\n```\n\nRunning an application\n----------------------\n\n```bash\n$ go run app.go\n2015/01/26 21:57:35 gofast v1.0-beta\n2015/01/26 21:57:48 [POST] 200 | route: 'add' | url: \"/add/toto\" (time: 143.238us)\n```\n\nThis will run the application on port 8080. Optionnaly, you can provide a port number this way:\n\n```bash\n$ PORT=8005 go run app.go\n```\n\nA simple application example\n----------------------------\n\nBecause an example will explain it better, here is an application example with things you can do with Gofast:\n\n```go\npackage main\n\nimport (\n    \"github.com/eko/gofast\"\n)\n\nfunc main() {\n    app := gofast.Bootstrap()\n    app.SetAssetsDirectory(\"assets\")\n    app.SetViewsDirectory(\"views\")\n\n    // This adds a fallback route for 404 (not found) resources\n    app.SetFallback(func(context gofast.Context) {\n        context.GetResponse().SetStatusCode(404)\n        app.Render(context, \"404.html\")\n    })\n\n    // You can add a simple GET route\n    app.Get(\"homepage\", \"/$\", func(context gofast.Context) {\n        app.Render(context, \"index.html\")\n    })\n\n    // ... or add a more complex POST route with a URL parameter\n    app.Post(\"add\", \"/add/([a-zA-Z]+)$\", func(context gofast.Context) {\n        request  := context.GetRequest()\n\n        pattern := context.GetRoute().GetPattern()\n        url     := request.GetHttpRequest().URL.Path\n\n        request.AddParameter(\"name\", pattern.FindStringSubmatch(url)[1])\n\n        // ... your custom code\n\n        app.Render(context, \"add.html\")\n    })\n\n    app.Listen()\n}\n```\n\nHTTP/2 Support\n--------------\n\nYou can use HTTP/2 support by using the following line instead of app.Listen():\n\n```\napp.ListenHttp2(\"./fullchain.pem\", \"./privkey.pem\")\n```\n\nOf course, you will have to precize SSL certificate and private key.\n\nYou can also set `Link` headers in order to preload assets:\n\n```\nresponse := c.GetResponse()\n\nresponse.Header().Add(\"Link\", \"\u003c/assets/img/rocket.png\u003e; rel=preload\")\nresponse.Header().Add(\"Link\", \"\u003c/assets/css/style.css\u003e; rel=preload\")\n```\n\n\nTemplating\n----------\n\nYou can use all Pongo2 template features and retrieve data like this:\n\n```twig\n{% extends \"../layout.html\" %}\n\n{% block navigation %}\n    {% include \"../include/navigation.html\" with current=\"blog\" %}\n{% endblock %}\n\n\u003ch2\u003eRetrieve a \"name\" parameter\u003c/h2\u003e\n\u003cp\u003e{{ request.GetParameter(\"name\") }}\u003c/p\u003e\n\n\u003ch2\u003eRetrieve a \"data\" POST form value\u003c/h2\u003e\n\u003cp\u003e{{ request.GetFormValue(\"data\") }}\u003c/p\u003e\n```\n\nYou have access to both `request` and `response` objects from context.\n\nRequesting this example\n-----------------------\n\nUsing the example given below, here is the request results:\n\n```bash\n\u003e $ curl -X GET http://127.0.0.1:8080/\n\u003ch1\u003eWelcome to the index template!\u003c/h1\u003e\n\n\u003e $ curl -X POST -d'data=my post data' http://127.0.0.1:8080/add/toto\n\u003ch2\u003eRetrieve a \"name\" parameter\u003c/h2\u003e\n\u003cp\u003etoto\u003c/p\u003e\n\n\u003ch2\u003eRetrieve a \"data\" POST form value\u003c/h2\u003e\n\u003cp\u003emy post data\u003c/p\u003e\n```\n\nMiddlewares\n-----------\n\nYou can add some middlewares in your application by the following way:\n\n```go\napp.Use(func(context gofast.Context, next gofast.MiddlewareFunc) gofast.Handler {\n  // Some code before calling the next middleware\n  handler := next(context, next)\n  // Some code after calling the next middleware\n\n  return handler\n})\n```\n\nIt allows you to access `context` (request, response, current route) and also\nallows to define a new `handler` function to update the application behavior.\n\nDefault CORS headers\n--------------------\n\nFollowing CORS headers are enabled by default when the request has an \"Origin\" header:\n\n```\nAccess-Control-Allow-Headers: Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\nAccess-Control-Allow-Origin: domainname.tld\n```\n\nYou can override any header (including CORS ones) by the following way into each action:\n\n```go\napp.Get(\"retrieve-data\", \"/retrieve$\", func(context gofast.Context) {\n    response := context.GetResponse()\n    response.Header().Set(\"Access-Control-Allow-Methods\", \"GET\")\n    response.Header().Set(\"Content-Type\", \"application/json\")\n\n    fmt.Fprint(response, \"{result: 200}\")\n})\n```\n\nUse the logger\n--------------\n\nThe Logrus logger instance can be used to write information in your application stdout if you need it. You can retrieve the logger instance from the context as follows:\n\n```go\napp.Get(\"test-logger\", \"/test-logger$\", func(context gofast.Context) {\n    logger := context.GetLogger()\n    logger.Info(\"Roger, this is my log information!\")\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feko%2Fgofast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feko%2Fgofast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feko%2Fgofast/lists"}