{"id":22911529,"url":"https://github.com/bndrmrtn/go-gale","last_synced_at":"2025-05-09T01:30:04.888Z","repository":{"id":256953387,"uuid":"856002891","full_name":"bndrmrtn/go-gale","owner":"bndrmrtn","description":"A lightweight Go framework","archived":false,"fork":false,"pushed_at":"2024-12-05T22:31:29.000Z","size":60,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T21:45:43.197Z","etag":null,"topics":[],"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/bndrmrtn.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-09-11T20:18:12.000Z","updated_at":"2024-12-05T22:31:09.000Z","dependencies_parsed_at":"2024-09-14T03:55:28.390Z","dependency_job_id":"986a9b7c-f2be-4793-9b6b-221d639ffc6b","html_url":"https://github.com/bndrmrtn/go-gale","commit_stats":null,"previous_names":["bndrmrtn/go-bolt","bndrmrtn/go-gale"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndrmrtn%2Fgo-gale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndrmrtn%2Fgo-gale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndrmrtn%2Fgo-gale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndrmrtn%2Fgo-gale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bndrmrtn","download_url":"https://codeload.github.com/bndrmrtn/go-gale/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253174032,"owners_count":21865788,"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":[],"created_at":"2024-12-14T04:17:07.332Z","updated_at":"2025-05-09T01:30:04.829Z","avatar_url":"https://github.com/bndrmrtn.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gale\n\nA fast and easy-to-use Go router.\n\n## Installation\n\nCreate a new go project and install the package with the following command:\n```\ngo get github.com/bndrmrtn/go-gale@latest\n```\n\n## Usage\n\n### Creating and configuring a new Gale application\n\n```go\napp := gale.New() // with default configuration\napp := gale.New(\u0026gale.Config{...}) // with custom configuration\n```\n\n### Routing with Gale\n\nA simple hello world response:\n```go\napp.Get(\"/\", func(c gale.Ctx) error {\n\treturn c.Status(http.StatusOK).SendString(\"Hello, World!\")\n})\n```\n\nA route with a custom parameter:\n```go\napp.Get(\"/user/{name}\", func(c gale.Ctx) error {\n\treturn c.SendString(\"Hello, \" + c.Param(\"name\") + \"!\")\n})\n```\n\nA route with an optional parameter:\n```go\napp.Get(\"/user/{name}?\", func(c gale.Ctx) error {\n\t// The c.Param() second option can be a default value if the parameter is not provided\n\treturn c.SendString(\"Hello, \" + c.Param(\"name\", \"World\") + \"!\")\n})\n```\n\nRoute parameter validation:\n```go\napp.RegisterRouteParamValidator(\"webp\", func(value string) (string, error) {\n\tif strings.HasSuffix(value, \".webp\") {\n\t\treturn strings.TrimSuffix(value, \".webp\"), nil\n\t}\n\treturn \"\", errors.New(\"invalid file\")\n})\n```\n\nUse a parameter validation:\n```go\napp.Get(\"/images/{image@webp}\", func(c gale.Ctx) error {\n\treturn c.JSON(gale.Map{\n\t\t\"image_name\": c.Param(\"image\"), // it will return the image name without the .webp extension.\n\t})\n})\n```\n\nPiping a response:\n```go\napp.Get(\"/pipe\", func(c gale.Ctx) error {\n\treturn c.Pipe(func(pw *io.PipeWriter) {\n\t\tfor i := 0; i \u003c 5; i++ {\n\t\t\tpw.Write([]byte(fmt.Sprintf(\"Streaming data chunk %d\\n\", i)))\n\t\t\ttime.Sleep(1 * time.Second) // Simulate some delay\n\t\t}\n\t})\n})\n```\n\n### Middleware with Gale\n\nAll middleware function comes after the main handler with Gale:\n\n```go\napp.Get(path string, handler gale.HandlerFunc, middlewares ...gale.MiddlewareFunc)\n```\n\nA simple middleware:\n```go\napp.Get(\"/secret\", func(c gale.Ctx) error {\n\t\treturn c.SendString(\"Secret data\")\n\t}, func(c gale.Ctx) (bool, error) {\n\t\tif c.URL().Query().Get(\"auth\") != \"123\" {\n\t\t\treturn c.Break().Status(http.StatusUnauthorized).SendString(\"Unauthorized\")\n\t\t}\n\t\treturn nil\n})\n```\n\n### Websockets with Gale\n\nGale uses https://github.com/coder/websocket package for handling websocket connections.\nWe wrapped our `Ctx` and `*websocket.Conn` into a `WSConn` struct for easier usage.\n\nYou can create a websocket connection like this:\n```go\nserver := gale.NewWSServer(context.Background())\n\n// This must be set. Here you can define your own websocket connection handler.\nserver.OnMessage(func(s gale.WSServer, conn gale.WSConn, msg []byte) error {})\n```\n\nYou don't have to set up loops are anything. The server will handle everything for you.\nYou only need to handle the incoming message and broadcast to your desired clients.\n\n```go\napp.WS(\"/ws\", func(c WSConn) {\n\t// Handle the connection here with a loop by itself or add it to the server.\n\tserver.AddConn(c)\n})\n```\n⚠️ Attention: The `WS` method is just like a `Get` method with a special adapter used for websocket connections.\nYou can't specify the same route for both `Get` and `WS` methods.\n\n### Sessions with Gale\n\nGale supports sessions. You can edit the default configuration or use it as it is.\nBy default, Gale uses `uuidv4` and cookies to manage `Session ID`-s.\nSessions are stored in an in-memory store. You can change the store by implementing the `gale.SessionStore` interface.\n\nSetting a session:\n```go\napp.Get(\"/session-set\", func(c gale.Ctx) error {\n\tsession := c.Session()\n\tsession.Set(\"key\", []byte(\"value\"))\n\treturn c.SendString(\"Session created\")\n})\n```\n\nGetting a session:\n```go\napp.Get(\"/session-get\", func(c gale.Ctx) error {\n\tsession := c.Session()\n\tvalue, _ := session.Get(\"key\")\n\treturn c.Send(value)\n})\n```\n\nIt also supports `session.Delete(\"key\")` and `session.Destroy()` methods.\n\n### Hooks with Gale\n\nGale supports hooks. Hooks are functions that are called on a specific event. You can register a hook for a specific event.\n\n```go\napp.Hook(gale.PreRequestHook, func(c Ctx) error {\n\t// A simple hook handler with an error return.\n\treturn nil // or just return nil to continue the request chain.\n})\n```\n\nYou can also use `gale.PostRequestHook` that runs after the request handled.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndrmrtn%2Fgo-gale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbndrmrtn%2Fgo-gale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndrmrtn%2Fgo-gale/lists"}