{"id":13764093,"url":"https://github.com/gernest/alien","last_synced_at":"2025-08-20T10:33:03.947Z","repository":{"id":57481981,"uuid":"50749924","full_name":"gernest/alien","owner":"gernest","description":"A lightweight and  fast http router from outer space","archived":false,"fork":false,"pushed_at":"2024-03-24T14:59:06.000Z","size":49,"stargazers_count":132,"open_issues_count":3,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-06T13:43:07.669Z","etag":null,"topics":["aliens","golang","http","lightweight","router"],"latest_commit_sha":null,"homepage":"","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/gernest.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":"2016-01-30T23:23:10.000Z","updated_at":"2024-10-17T08:35:16.000Z","dependencies_parsed_at":"2024-06-18T17:02:02.182Z","dependency_job_id":"462f0e1e-bb1c-452b-ba97-2640459489fa","html_url":"https://github.com/gernest/alien","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Falien","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Falien/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Falien/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Falien/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gernest","download_url":"https://codeload.github.com/gernest/alien/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230415318,"owners_count":18222158,"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":["aliens","golang","http","lightweight","router"],"created_at":"2024-08-03T15:01:13.598Z","updated_at":"2024-12-19T10:10:28.258Z","avatar_url":"https://github.com/gernest.png","language":"Go","funding_links":[],"categories":["Routers","Web Frameworks","Web框架","XML","路由"],"sub_categories":["HTTP Clients","Routers","路由器","路由","创建http中间件的代码库"],"readme":"# Alien [![Coverage Status](https://coveralls.io/repos/github/gernest/alien/badge.svg?branch=master)](https://coveralls.io/github/gernest/alien?branch=master) [![Build Status](https://travis-ci.org/gernest/alien.svg?branch=master)](https://travis-ci.org/gernest/alien) [![GoDoc](https://godoc.org/github.com/gernest/alien?status.svg)](https://godoc.org/github.com/gernest/alien) [![Go Report Card](https://goreportcard.com/badge/github.com/gernest/alien)](https://goreportcard.com/report/github.com/gernest/alien)\n\nAlien is a lightweight http router( multiplexer) for Go( Golang ), made for\nhumans who don't like magic.\n\nDocumentation [docs](https://godoc.org/github.com/gernest/alien)\n\n# Features\n\n* fast ( see the benchmarks, or run them yourself)\n* lightweight ( just [a single file](alien.go) read all of it in less than a minute)\n* safe( designed with concurrency in mind)\n* middleware support.\n* routes groups\n* no external dependency( only the standard library )\n\n\n# Motivation\nI wanted a simple, fast, and lightweight router that has no unnecessary overhead\nusing the standard library only, following good practices and well tested code(\nOver 90% coverage)\n\n# Installation\n\n```bash\ngo get github.com/gernest/alien\n```\n\n# Usage\n\n## normal static routes\n\n```go\n\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/gernest/alien\"\n)\n\nfunc main() {\n\tm := alien.New()\n\tm.Get(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Write([]byte(\"hello world\"))\n\t})\n\tlog.Fatal(http.ListenAndServe(\":8090\", m))\n}\n```\n\nvisiting your localhost at path `/` will print `hello world`\n\n## named params\n\n```go\n\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/gernest/alien\"\n)\n\nfunc main() {\n\tm := alien.New()\n\tm.Get(\"/hello/:name\", func(w http.ResponseWriter, r *http.Request) {\n\t\tp := alien.GetParams(r)\n\t\tw.Write([]byte(p.Get(\"name\")))\n\t})\n\tlog.Fatal(http.ListenAndServe(\":8090\", m))\n}\n```\n\nvisiting your localhost at path `/hello/tanzania` will print `tanzania`\n\n## catch all params\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/gernest/alien\"\n)\n\nfunc main() {\n\tm := alien.New()\n\tm.Get(\"/hello/*name\", func(w http.ResponseWriter, r *http.Request) {\n\t\tp := alien.GetParams(r)\n\t\tw.Write([]byte(p.Get(\"name\")))\n\t})\n\tlog.Fatal(http.ListenAndServe(\":8090\", m))\n}\n```\n\nvisiting your localhost at path `/hello/my/margicl/sheeplike/ship` will print \n`my/margical/sheeplike/ship`\n\n## middlewares\nMiddlewares are anything that satisfy the interface\n`func(http.Handler)http.Handler` . Meaning you have thousands of middlewares at\nyour disposal, you can use middlewares from many golang http frameworks on\nalien(most support the interface).\n\n\n```go\n\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/gernest/alien\"\n)\n\nfunc middleware(h http.Handler) http.Handler {\n\treturn http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Write([]byte(\"hello middlware\"))\n\t})\n}\n\nfunc main() {\n\tm := alien.New()\n\tm.Use(middleware)\n\tm.Get(\"/\", func(_ http.ResponseWriter, _ *http.Request) {\n\t})\n\tlog.Fatal(http.ListenAndServe(\":8090\", m))\n}\n```\n\nvisiting your localhost at path `/` will print `hello middleware`\n\n## groups\n\nYou can group routes\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/gernest/alien\"\n)\n\nfunc main() {\n\tm := alien.New()\n\tg := m.Group(\"/home\")\n\tm.Use(middleware)\n\tg.Get(\"/alone\", func(w http.ResponseWriter, _ *http.Request) {\n\t\tw.Write([]byte(\"home alone\"))\n\t})\n\tlog.Fatal(http.ListenAndServe(\":8090\", m))\n}\n```\n\nvisiting your localhost at path `/home/alone` will print `home alone`\n\n# Contributing\nStart with clicking the star button to make the author and his neighbors happy. Then fork the repository and submit a pull request for whatever change you want to be added to this project.\n\nIf you have any questions, just open an issue.\n\n# Author\nGeofrey Ernest  [@gernesti](https://twitter.com/gernesti) on twitter\n\n# Licence\nMIT see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgernest%2Falien","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgernest%2Falien","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgernest%2Falien/lists"}