{"id":20317918,"url":"https://github.com/crowdsecurity/go-cs-bouncer","last_synced_at":"2025-04-11T18:02:40.619Z","repository":{"id":41854637,"uuid":"301142899","full_name":"crowdsecurity/go-cs-bouncer","owner":"crowdsecurity","description":"Go library to use crowdsec API.","archived":false,"fork":false,"pushed_at":"2025-04-03T14:16:53.000Z","size":224,"stargazers_count":10,"open_issues_count":4,"forks_count":11,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-05T20:33:36.809Z","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/crowdsecurity.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":"2020-10-04T13:59:14.000Z","updated_at":"2025-04-03T14:16:56.000Z","dependencies_parsed_at":"2022-08-11T19:31:28.200Z","dependency_job_id":"4efc6141-0968-4bf7-afc0-877c34316877","html_url":"https://github.com/crowdsecurity/go-cs-bouncer","commit_stats":{"total_commits":55,"total_committers":12,"mean_commits":4.583333333333333,"dds":0.6909090909090909,"last_synced_commit":"7cc974ab5476febd0afeaa2ecb062ad043255938"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdsecurity%2Fgo-cs-bouncer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdsecurity%2Fgo-cs-bouncer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdsecurity%2Fgo-cs-bouncer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdsecurity%2Fgo-cs-bouncer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crowdsecurity","download_url":"https://codeload.github.com/crowdsecurity/go-cs-bouncer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248456376,"owners_count":21106602,"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-11-14T18:37:18.097Z","updated_at":"2025-04-11T18:02:40.580Z","avatar_url":"https://github.com/crowdsecurity.png","language":"Go","funding_links":[],"categories":["API Clients \u0026 SDKs"],"sub_categories":["Other Bouncers"],"readme":"# Go CrowdSec Bouncer\n\n`go-cs-bouncer` is a golang easy library to use to create golang CrowdSec bouncer.\n\n## Installation\n\nTo install `go-cs-bouncer` package, you need to install Go and set your Go workspace first.\n\n1. You can use the below Go command to install `go-cs-bouncer`:\n\n```sh\n$ go get -u github.com/crowdsecurity/go-cs-bouncer\n```\n\n2. Import it in your code:\n\n```go\nimport \"github.com/crowdsecurity/go-cs-bouncer\"\n```\n\n## Quick Start\n\n\n### Streaming Bouncer\n \n```sh\n# assume the following codes in main.go file\n$ cat main.go\n```\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\tcsbouncer \"github.com/crowdsecurity/go-cs-bouncer\"\n)\n\nfunc main() {\n\n\tbouncer := \u0026csbouncer.StreamBouncer{\n\t\tAPIKey:         \"\u003cAPI_TOKEN\u003e\",\n\t\tAPIUrl:         \"http://localhost:8080/\",\n\t\tTickerInterval: \"20s\",\n\t}\n\n\tif err := bouncer.Init(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n        go func() {\n            bouncer.Run(ctx)\n            cancel()\n        }\n\n\tfor streamDecision := range bouncer.Stream {\n\t\tfor _, decision := range streamDecision.Deleted {\n\t\t\tfmt.Printf(\"expired decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\\n\", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)\n\t\t}\n\t\tfor _, decision := range streamDecision.New {\n\t\t\tfmt.Printf(\"new decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\\n\", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)\n\t\t}\n\t}\n}\n```\n\n```sh\n# run main.go\n$ go run main.go\n```\n\n### Live Bouncer\n \n```sh\n# assume the following codes in main.go file\n$ cat main.go\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\tcsbouncer \"github.com/crowdsecurity/go-cs-bouncer\"\n)\n\nfunc main() {\n\n\tbouncer := \u0026csbouncer.LiveBouncer{\n\t\tAPIKey: \"\u003cAPI_TOKEN\u003e\",\n\t\tAPIUrl: \"http://localhost:8080/\",\n\t}\n\n\tif err := bouncer.Init(); err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\n\tipToQuery := \"1.2.3.4\"\n\tresponse, err := bouncer.Get(ipToQuery)\n\tif err != nil {\n\t\tlog.Fatalf(\"unable to get decision for ip '%s' : '%s'\", ipToQuery, err)\n\t}\n\tif len(*response) == 0 {\n\t\tlog.Printf(\"no decision for '%s'\", ipToQuery)\n\t}\n\n\tfor _, decision := range *response {\n\t\tfmt.Printf(\"decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\\n\", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)\n\t}\n}\n\n```\n\n```sh\n# run main.go\n$ go run main.go\n```\n\n\n## Decision object\n\nThe decision objet correspond to the following structure:\n\n```go\ntype Decision struct {\n\n\t// duration\n\tDuration *string `json:\"duration\"`\n\n\tEndIP int64 `json:\"end_ip,omitempty\"`\n\n\tID int64 `json:\"id,omitempty\"`\n\n\t// the origin of the decision : cscli, crowdsec\n\tOrigin *string `json:\"origin\"`\n\n\t// scenario\n\tScenario *string `json:\"scenario\"`\n\n\t// the scope of decision : does it apply to an IP, a range, a username, etc\n\tScope *string `json:\"scope\"`\n\n\tStartIP int64 `json:\"start_ip,omitempty\"`\n\n\t// the type of decision, might be 'ban', 'captcha' or something custom. Ignored when watcher (cscli/crowdsec) is pushing to APIL.\n\tType *string `json:\"type\"`\n\n\t// the value of the decision scope : an IP, a range, a username, etc\n\tValue *string `json:\"value\"`\n}\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrowdsecurity%2Fgo-cs-bouncer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrowdsecurity%2Fgo-cs-bouncer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrowdsecurity%2Fgo-cs-bouncer/lists"}