{"id":37156222,"url":"https://github.com/farhanmobashir/twix","last_synced_at":"2026-01-14T18:30:19.788Z","repository":{"id":251118651,"uuid":"835456845","full_name":"FarhanMobashir/twix","owner":"FarhanMobashir","description":"A mini router for building Go HTTP Services","archived":false,"fork":false,"pushed_at":"2024-08-03T18:48:03.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-04T01:52:18.223Z","etag":null,"topics":["go","golang","http-server","rest-api","router"],"latest_commit_sha":null,"homepage":"https://twix-go.netlify.app/","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/FarhanMobashir.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":"2024-07-29T22:05:08.000Z","updated_at":"2024-08-03T17:51:22.000Z","dependencies_parsed_at":"2024-08-01T02:08:20.567Z","dependency_job_id":null,"html_url":"https://github.com/FarhanMobashir/twix","commit_stats":null,"previous_names":["farhanmobashir/twix"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FarhanMobashir/twix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarhanMobashir%2Ftwix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarhanMobashir%2Ftwix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarhanMobashir%2Ftwix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarhanMobashir%2Ftwix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FarhanMobashir","download_url":"https://codeload.github.com/FarhanMobashir/twix/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarhanMobashir%2Ftwix/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28430833,"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":["go","golang","http-server","rest-api","router"],"created_at":"2026-01-14T18:30:18.857Z","updated_at":"2026-01-14T18:30:19.771Z","avatar_url":"https://github.com/FarhanMobashir.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twix\n\nTwix is a lightweight, modular router designed to simplify the process of building HTTP services in Go. With an intuitive API and support for middleware, Twix helps you create clean and maintainable web applications.\n\n## Features\n\n- Simple and intuitive routing\n- Middleware support\n- Routing groups for modular organization\n- Context management for request data\n- CORS, logging, rate limiting, and JWT authentication middleware\n\n## Documentation\n\nComprehensive documentation for Twix can be found at the [Twix Documentation Site](https://twix-go.netlify.app/).\n\n## Installation\n\nTo install Twix, run:\n\n```bash\ngo get github.com/farhanmobashir/twix\n```\n\n## Quick Start\n\nHere's a quick example to get you started with Twix:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/farhanmobashir/twix\"\n\t\"github.com/farhanmobashir/twix/middlewares\"\n)\n\n// Handler function for the route\nfunc nameHandler(w http.ResponseWriter, r *http.Request) {\n\tctx, ok := r.Context().Value(twix.TwixContextKey).(*twix.Context)\n\tif !ok {\n\t\thttp.Error(w, \"Invalid context\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tname := ctx.Param(\"name\")\n\tif name == \"\" {\n\t\thttp.Error(w, \"Name parameter is missing\", http.StatusBadRequest)\n\t\treturn\n\t}\n\tstr := \"Hello, \" + name\n\tw.Header().Set(\"Content-Type\", \"text/plain\")\n\tw.WriteHeader(http.StatusOK)\n\t_, err := w.Write([]byte(str))\n\tif err != nil {\n\t\thttp.Error(w, \"Internal Server Error\", http.StatusInternalServerError)\n\t}\n}\n\nfunc main() {\n\trouter := twix.New()\n\n\tcorsConfig := middlewares.CorsConfig{\n\t\tAllowedOrigins:   []string{\"*\"},\n\t\tAllowedMethods:   []string{\"GET\"},\n\t\tAllowedHeaders:   []string{\"Content-Type\", \"Authorization\"},\n\t\tAllowCredentials: true,\n\t}\n\n\trateLimitConfig := middlewares.RateLimitConfig{\n\t\tRequestLimit: 5,\n\t\tWindowSize:   time.Second * 15,\n\t}\n\n\tjwtConfig := middlewares.JWTConfig{\n\t\tSecretKey:   []byte(\"hello\"),\n\t\tTokenSource: middlewares.Header,\n\t\tCookieName:  \"jwt_token\",\n\t}\n\n\trouter.Use(middlewares.CorsMiddleware(corsConfig))\n\trouter.Use(middlewares.RecoveryMiddleware)\n\trouter.Use(middlewares.RateLimit(rateLimitConfig))\n\trouter.Use(middlewares.LoggingMiddleware)\n\n\trouter.Get(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tpanic(\"foo\")\n\t})\n\n\tapiGroup := router.Group(\"/api\")\n\tapiGroup.Use(middlewares.JWTAuth(jwtConfig))\n\tapiGroup.Get(\"/hello/:name\", nameHandler)\n\n\tserver := \u0026http.Server{\n\t\tAddr:    \":8080\",\n\t\tHandler: router,\n\t}\n\n\tlog.Println(\"Starting server on :8080\")\n\tif err := server.ListenAndServe(); err != nil {\n\t\tlog.Fatal(\"ListenAndServe: \", err)\n\t}\n}\n```\n\n## Middleware\n\nTwix comes with several built-in middleware:\n\n### CORS Middleware\n\nAllows cross-origin requests.\n\n```go\ncorsConfig := middlewares.CorsConfig{\n\tAllowedOrigins:   []string{\"*\"},\n\tAllowedMethods:   []string{\"GET\"},\n\tAllowedHeaders:   []string{\"Content-Type\", \"Authorization\"},\n\tAllowCredentials: true,\n}\nrouter.Use(middlewares.CorsMiddleware(corsConfig))\n```\n\n### Logging Middleware\n\nLogs incoming requests with colored output.\n\n```go\nrouter.Use(middlewares.LoggingMiddleware)\n```\n\n### Rate Limiting Middleware\n\nLimits the number of requests from a single IP address within a specified time window.\n\n```go\nrateLimitConfig := middlewares.RateLimitConfig{\n\tRequestLimit: 5,\n\tWindowSize:   time.Second * 15,\n}\nrouter.Use(middlewares.RateLimit(rateLimitConfig))\n```\n\n### JWT Authentication Middleware\n\nHandles JWT authentication, supporting both header and cookie token sources.\n\n```go\njwtConfig := middlewares.JWTConfig{\n\tSecretKey:   []byte(\"hello\"),\n\tTokenSource: middlewares.Header, // or middlewares.Cookie\n\tCookieName:  \"jwt_token\",\n}\nrouter.Use(middlewares.JWTAuth(jwtConfig))\n```\n\n### Recovery Middleware\n\nRecovers from panics and returns a 500 Internal Server Error.\n\n```go\nrouter.Use(middlewares.RecoveryMiddleware)\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request with any improvements or features you'd like to add.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarhanmobashir%2Ftwix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarhanmobashir%2Ftwix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarhanmobashir%2Ftwix/lists"}