{"id":24969275,"url":"https://github.com/yianandcode/gintonic","last_synced_at":"2025-10-06T14:48:58.538Z","repository":{"id":192602191,"uuid":"676612140","full_name":"YianAndCode/gintonic","owner":"YianAndCode","description":"It's lemon squeezy to make gin and tonic, and build webhooks. | The gin library for lemonsqueezy.com","archived":false,"fork":false,"pushed_at":"2025-04-03T02:42:59.000Z","size":463,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T03:28:06.180Z","etag":null,"topics":[],"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/YianAndCode.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":"2023-08-09T15:44:45.000Z","updated_at":"2025-04-03T02:42:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"22e83ac3-41b0-4e05-9343-210778684273","html_url":"https://github.com/YianAndCode/gintonic","commit_stats":null,"previous_names":["yianandcode/gintonic","yianandcode/gin-tonic"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YianAndCode%2Fgintonic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YianAndCode%2Fgintonic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YianAndCode%2Fgintonic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YianAndCode%2Fgintonic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YianAndCode","download_url":"https://codeload.github.com/YianAndCode/gintonic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345274,"owners_count":21088241,"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":"2025-02-03T14:36:55.829Z","updated_at":"2025-10-06T14:48:53.504Z","avatar_url":"https://github.com/YianAndCode.png","language":"Go","readme":"# Gin\u0026Tonic\n\n![Glance](glance.jpg)\n\nDocumentation | [中文文档](README_zh.md)\n\n## Introduction\n\nGin\u0026Tonic is a `LemonSqueezy` webhook library for `gin` framework that lets you build `LemonSqueezy` webhooks quickly and elegantly\n\n## Quick start\n\nInstallation\n\n```bash\ngo get -u github.com/YianAndCode/gintonic\n```\n\nImport\n\n```go\nimport \"github.com/YianAndCode/gintonic\"\n```\n\nWrite your bussines code\n\n```go\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/YianAndCode/gintonic\"\n\t\"github.com/YianAndCode/gintonic/lmdata\"\n)\n\nvar _ gintonic.OrderCreatedHandler = OrderCreated\n\nfunc OrderCreated(ctx context.Context, meta lmdata.Meta, data lmdata.Order) error {\n\tfmt.Printf(\"You made a sale! Total amount is %s\\n\", data.Attributes.TotalFormatted)\n\treturn nil\n}\n```\n\nRegister routes to `gin` and run\n\n```go\nfunc main() {\n\tr := gin.New()\n\tr.Use(gin.Recovery())\n\n\tgt := gintonic.New(\n\t\t\"[Load secret from somewhere]\",\n\t\tgintonic.WithOrderCreatedHandler(OrderCreated),\n\t)\n\tr.POST(\"/lemonsqueezy/webhook\", gt.LemonSqueezyWebhook)\n\n\tr.Run()\n}\n```\n\n## Definition\n\n### Instantiate\n\nYou can get an instantce of `gintonic` just by the `New` function, and the first parameter is fixed as `secret`, then you can set any handlers as needed:\n\n```go\ngt := gintonic.New(\n    \"[YOUR_SECRET]\",\n    gintonic.WithOrderCreatedHandler(OrderCreated), // The handler for orcer_created event\n    gintonic.WithDefaultHandler(DefaultHandler),    // The default handler\n)\n```\n\nSetting handler is done using the `gintonic.With[EventName]Handler()` option functions, the specific functions can be found in `option.go`\n\n### Handler\n\nHandler definitions are in `handler.go`, divided into two types: `Event Handler` and `DefaultHandler`.\n\nTheir relationship is like `case` and `default` in a `switch` statement. When instantiating a gintonic instance with `New`, the `Handler` registered using `gintonic.WithXXXHandler(XXX)` can be considered a `case`. When receiving a `webhook` event, `gintonic` will judge which `case` it belongs to and then call the corresponding `handler`. If it cannot find one, it will look for a `DefaultHandler`. If it cannot find the corresponding `Event Handler` and no `DefaultHandler` is set, then it will return an error.\n\n`DefaultHandler` is defined as:\n\n```go\ntype DefaultHandler func(ctx context.Context, eventName string, meta lmdata.Meta, data interface{}) error\n```\n\n`Event Handler` is like:\n\n```go\ntype OrderCreatedHandler func(ctx context.Context, meta lmdata.Meta, data lmdata.Order) error\n```\n\nThe only diffrence is the type of `data`.\n\n### Core\n\n`gintonic` interacts with `gin` using the `GinTonic.LemonSqueezyWebhook` method. This method will read `HTTP Headers` and `POST body` from `gin`, then verify the signature. After passing verification, it dispatches events to the registered `handler`.\n\nSo we just need to register the `LemonSqueezyWebhook` method of the `GinTonic` instance to a route in `gin`.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyianandcode%2Fgintonic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyianandcode%2Fgintonic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyianandcode%2Fgintonic/lists"}