{"id":36799927,"url":"https://github.com/kamalshkeir/kmux","last_synced_at":"2026-01-12T13:33:14.207Z","repository":{"id":61840055,"uuid":"555605688","full_name":"kamalshkeir/kmux","owner":"kamalshkeir","description":"kmux is a powerful Go package that revolutionizes the way proxies are implemented by allowing developers to define proxies as code. By providing an intuitive and expressive syntax, kmux simplifies server setup, route management, and proxy configuration. With kmux, developers can create robust and flexible proxy solutions that are easy to maintain","archived":false,"fork":false,"pushed_at":"2024-01-09T23:15:25.000Z","size":275,"stargazers_count":34,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-01-10T21:10:17.321Z","etag":null,"topics":["framework","go","golang","proxy","proxy-server","router","server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kamalshkeir.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-10-21T23:19:33.000Z","updated_at":"2024-01-10T21:10:17.322Z","dependencies_parsed_at":"2023-12-03T23:19:47.417Z","dependency_job_id":"56ae93bd-a18e-4075-ab70-2453562f1c09","html_url":"https://github.com/kamalshkeir/kmux","commit_stats":null,"previous_names":[],"tags_count":140,"template":null,"template_full_name":null,"purl":"pkg:github/kamalshkeir/kmux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamalshkeir%2Fkmux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamalshkeir%2Fkmux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamalshkeir%2Fkmux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamalshkeir%2Fkmux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kamalshkeir","download_url":"https://codeload.github.com/kamalshkeir/kmux/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamalshkeir%2Fkmux/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28339178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["framework","go","golang","proxy","proxy-server","router","server"],"created_at":"2026-01-12T13:33:12.428Z","updated_at":"2026-01-12T13:33:14.196Z","avatar_url":"https://github.com/kamalshkeir.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kmux minimalistic radix server/proxy, very fast and efficient, and without path conflicts using multiple path params\nkmux simplifies server setup, route management, and proxy configuration. With kmux, developers can create robust and flexible proxy solutions that are easy to maintain\n# Install\n```sh\ngo get -u github.com/kamalshkeir/kmux@v1.91.95\n```\n\n```go\npackage main\n\nimport (\n\t\"github.com/kamalshkeir/klog\"\n\t\"github.com/kamalshkeir/kmux\"\n)\n\nfunc main() {\n\tapp := kmux.New().WithDocs(true) // enable /docs \n\n    // use global middlewares\n    app.Use(kmux.Gzip(),kmux.Cors(\"*\"),kmux.Recovery(),kmux.Limiter(),kmux.Logs())\n\n    // Group\n    anyGroup := app.Group(\"/any\") // or grp := app.Group(\"any\")\n\n  \n    anyGroup.Get(\"/api/:table\", func(c *kmux.Context) {\n\t\tc.Text(\"ok \"+c.Param(\"table\"))\n\t})\n\n\t// wild card param\n    app.Get(\"/test/*param\", func(c *kmux.Context) {\n\t\tc.Text(c.Param(\"param\"))\n\t})\n\n    app.Get(\"/\",kmux.BasicAuth(IndexHandler,\"username\",\"password\"))\n\tapp.Post(\"/somePost\", posting , \"localhost:3333\") // kmux.Cors(\"*\")  or kmux.Cors(\"localhost:3333\") should be used, and only for this handler, we check if origin is http://127.0.0.1:3333\n\tapp.Put(\"/somePut\", putting)\n\tapp.Patch(\"/somePatch\", patching)\n\tapp.Delete(\"/someDelete\", deleting)\n\tapp.Head(\"/someDelete\", head)\n\tapp.Options(\"/someDelete\", options)\n\n    // Websockets\n    app.Ws(\"/ws/test\",func(c *kmux.WsContext) {\n\t\trand := utils.GenerateRandomString(5)\n\t\tc.AddClient(rand) // add connection to broadcast list\n\n\t\t// listen for messages coming from 1 user\n\t\tfor {\n\t\t\t// receive Json\n\t\t\tmapStringAny,err := c.ReceiveJson()\n\t\t\tif err != nil {\n\t\t\t\t// on error you can remove client from broadcastList and break the loop\n\t\t\t\tc.RemoveRequester(rand)\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\t// send Json to current user\n\t\t\terr = c.Json(map[string]any{\n\t\t\t\t\"Hello\":\"World\",\n\t\t\t})\n\n\t\t\t// send Text to current user\n\t\t\terr = c.Text(\"any data string\")\n\n\t\t\t// broadcast to all connected users\n\t\t\tc.Broadcast(map[string]any{\n\t\t\t\t\"you can send\":\"struct insetead of maps here\",\n\t\t\t})\n\n\t\t\t// broadcast to all connected users except current user, the one who send the last message\n\t\t\tc.BroadcastExceptCaller(map[string]any{\n\t\t\t\t\"you can send\":\"struct insetead of maps here\",\n\t\t\t})\n\n\t\t}\n\t})\n\n    // Server Sent Events\n    app.Sse(\"/sse/logs\", func(c *kmux.Context) {\n\t\tfor i := 0; i \u003c 10;i++ {\n\t\t\tc.Stream(\"working...\"+strconv.Itoa(i))\n\t\t\ttime.Sleep(time.Second)\n\t\t}\n\t})\n\n\tapp.Run(\"localhost:9313\")\n}\n```\n\n```go\n// BeforeRenderHtml executed before every html c.Html, you can use c.Request.Context().Value(key).(type.User) for example and add data to templates globaly\nfunc BeforeRenderHtml(uniqueName string, fn func(reqCtx context.Context, data *map[string]any))\n```\n\n\n## Context\n\n```go\nfunc (c *Context) Status(code int) *Context\nfunc (c *Context) ParamsMap() map[string]string\nfunc (c *Context) Param(paramName string) string\nfunc (c *Context) AddHeader(key, value string)\nfunc (c *Context) SetHeader(key, value string)\nfunc (c *Context) SetStatus(statusCode int)\nfunc (c *Context) QueryParam(name string) string\nfunc (c *Context) Json(data any)\nfunc (c *Context) JsonIndent(data any)\nfunc (c *Context) ContextValue(key ...ContextKey) (any, bool)\nfunc (c *Context) Text(body string)\nfunc (c *Context) TextHtml(body string)\nfunc (c *Context) Html(template_name string, data map[string]any) // it add .Request in all templates\nfunc (c *Context) Stream(response string) // SSE\n// BodyJson get json body from request and return map\n// USAGE : data := c.BodyJson(r)\nfunc (c *Context) BodyJson() map[string]any\nfunc (c *Context) BodyText() string\n// Redirect redirect the client to the specified path with a custom code\nfunc (c *Context) Redirect(path string)\n// ServeFile serve a file from handler\nfunc (c *Context) ServeFile(content_type, path_to_file string)\n// ServeEmbededFile serve an embeded file from handler\nfunc (c *Context) ServeEmbededFile(content_type string, embed_file []byte)\nfunc (c *Context) ParseMultipartForm(size ...int64) (formData url.Values, formFiles map[string][]*multipart.FileHeader)\n// UploadFile upload received_filename into folder_out and return url,fileByte,error\nfunc (*Context) SaveFile(fileheader *multipart.FileHeader, path string) error\nfunc (c *Context) UploadFile(received_filename, folder_out string, acceptedFormats ...string) (string, []byte, error)\nfunc (c *Context) UploadFiles(received_filenames []string, folder_out string, acceptedFormats ...string) ([]string, [][]byte, error)\n// DELETE FILE\nfunc (c *Context) DeleteFile(path string) error\n// Download download data_bytes(content) asFilename(test.json,data.csv,...) to the client\nfunc (c *Context) Download(data_bytes []byte, asFilename string)\nfunc (c *Context) GetUserIP() string\n\n```\n\n\n### Cookies\n```go\nfunc (c *Context) SetCookie(key, value string)\nfunc (c *Context) GetCookie(key string) (string, error)\nfunc (c *Context) DeleteCookie(key string)\n```\n\n### Templates and statics\n\n```go\nfunc (r *Router) Embed(staticDir *embed.FS, templateDir *embed.FS)\nfunc (router *Router) NewFuncMap(funcName string, function any)\nfunc (router *Router) LocalStatics(dirPath, webPath string)\nfunc (router *Router) EmbededStatics(embeded embed.FS, pathLocalDir, webPath string)\nfunc (router *Router) LocalTemplates(pathToDir string) error\nfunc (router *Router) EmbededTemplates(template_embed embed.FS, rootDir string) error\n```\n\n### SSE\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/kamalshkeir/kmux\"\n)\n\nfunc main() {\n\tapp := kmux.New()\n\tapp.Get(\"/\", func(c *kmux.Context) {\n\t\tc.Html(\"index.html\", nil)\n\t})\n\tapp.LocalTemplates(\"temps\")\n\n\tmsgChan := make(chan string)\n\tapp.Sse(\"/test/:param\", func(c *kmux.Context) {\n\t\tfmt.Println(c.Param(\"param\"))\n\t\tnotify := c.ResponseWriter.(http.CloseNotifier).CloseNotify()\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase v := \u003c-msgChan:\n\t\t\t\terr := c.Stream(v)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\tcase \u003c-notify:\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t})\n\n\t// when someone hit this endpoint we publish to SSE using msgChan\n\tapp.Get(\"/pub/sse\", func(c *kmux.Context) {\n\t\tgo func() {\n\t\t\tmsgChan \u003c- \"hello stream\"\n\t\t}()\n\t\tc.Text(\"sse\")\n\t})\n\n\tapp.Run(\":9313\")\n}\n```\n\n# Proxy\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/kamalshkeir/kmux\"\n)\n\nfunc main() {\n\tapp := kmux.New()\n\tapp.Use(func(h http.Handler) http.Handler {\n\t\treturn kmux.Handler(func(c *kmux.Context) {\n\t\t\tfmt.Println(\"PROXY:\", c.Request.Host+c.Request.URL.Path)\n\t\t\th.ServeHTTP(c.ResponseWriter, c.Request)\n\t\t})\n\t})\n\n\tnc := app.ReverseProxy(\"nc.localhost\", \"http://localhost:9313\") // http://nc.localhost:9999\n\tnc.Use(func(h http.Handler) http.Handler {\n\t\treturn kmux.Handler(func(c *kmux.Context) {\n\t\t\tfmt.Println(\"NC APP:\", c.Request.Host+c.Request.URL.Path)\n\t\t})\n\t})\n\n\tcv := app.ReverseProxy(\"dev.localhost\", \"https://kamalshkeir.dev\") // http://dev.localhost:9999\n\tcv.Use(func(h http.Handler) http.Handler {\n\t\treturn http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t\tfmt.Println(\"PORTFOLIO:\", r.Host+r.URL.Path)\n\t\t})\n\t})\n\n\tapp.Run(\":9999\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamalshkeir%2Fkmux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkamalshkeir%2Fkmux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamalshkeir%2Fkmux/lists"}