{"id":16318236,"url":"https://github.com/kos-v/dsnparser","last_synced_at":"2025-03-20T22:30:51.431Z","repository":{"id":37117953,"uuid":"336898361","full_name":"kos-v/dsnparser","owner":"kos-v","description":"Data source name (DSN) parser","archived":false,"fork":false,"pushed_at":"2024-05-14T02:52:19.000Z","size":66,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-11T22:22:53.682Z","etag":null,"topics":["dsn","golang","parser"],"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/kos-v.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":"2021-02-07T21:54:55.000Z","updated_at":"2024-05-13T07:58:44.000Z","dependencies_parsed_at":"2024-10-28T09:07:19.356Z","dependency_job_id":"33c00a05-8418-44fb-aa8e-e3570aacb9ff","html_url":"https://github.com/kos-v/dsnparser","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kos-v%2Fdsnparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kos-v%2Fdsnparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kos-v%2Fdsnparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kos-v%2Fdsnparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kos-v","download_url":"https://codeload.github.com/kos-v/dsnparser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085005,"owners_count":20395523,"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":["dsn","golang","parser"],"created_at":"2024-10-10T22:22:53.191Z","updated_at":"2025-03-20T22:30:51.126Z","avatar_url":"https://github.com/kos-v.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## DSN Parser\n[![Build Status](https://app.travis-ci.com/kos-v/dsnparser.svg?branch=main)](https://app.travis-ci.com/kos-v/dsnparser)\n[![Coverage Status](https://codecov.io/gh/kos-v/dsnparser/branch/main/graph/badge.svg)](https://codecov.io/gh/kos-v/dsnparser)\n[![Go Report Card](https://goreportcard.com/badge/github.com/kos-v/dsnparser)](https://goreportcard.com/report/github.com/kos-v/dsnparser)\n\nThis library parses a DSN of the form:  \n![](doc/structure.png)  \nEach of the sections is optional, so, for example, a DSN can be without schema or credentials.  \n\n##### Installation\n```shell\ngo get github.com/kos-v/dsnparser\n```\n\n##### Using\n```go\nimport \"github.com/kos-v/dsnparser\"\n\ndsn := dsnparser.Parse(\"mysql://user:password@tcp(example.local:3306)/dbname?encoding=utf8mb4\");\ndsn.GetScheme()          // string \"mysql\"\ndsn.GetUser()            // string \"user\"\ndsn.GetPassword()        // string \"password\"\ndsn.GetHost()            // string \"example.local\"\ndsn.GetPort()            // string \"3306\"\ndsn.GetPath()            // string \"dbname\"\ndsn.GetParam(\"encoding\") // string \"utf8mb4\"\ndsn.GetParams()          // map[string]string [encoding: \"utf8mb4\"]\ndsn.GetTransport()       // string \"tcp\"\ndsn.HasParam(\"encoding\") // bool true\ndsn.GetRaw()             // string \"mysql://user:password@example.local:3306/dbname?encoding=utf8mb4\"\n```\n\n##### Examples:\n- `user:password@example.local`\n- `example.local:65535`\n- `user:password@`\n- `socket:///foo/bar.sock`\n- `mysql://user:password@example.local/dbname`\n- `mysql://example.local/?db=dbname\u0026user=user\u0026password=password`\n\n##### Credentials\n`user:password@` - user and password.  \n`user@` or `user:@` - only user, without password.  \n`:password@` - only password, without user.  \n\n##### Escaping\nYou can escape the \":\" and \"@\" characters in credentials, as well as the \"=\" and \"\u0026\" characters in the extra options. To do this, specify \"\\\\\" before the desired character.  \nExamples:  \n`us\\:e\\@r:p\\@ssw\\:ord@` -\u003e `us:e@r:p@ssw:ord`  \n`us\\:e\\@r:p\\@ssw\\:ord@` -\u003e `us:e@r:p@ssw:ord`  \n`?key1=foo \\\u0026 bar\u0026key2=baz \\= quux` -\u003e `key1=foo \u0026 bar\u0026key2=baz = quux`  \n`?foo\\\u0026key=fool val\u0026bar\\=key=bar val` -\u003e `foo\u0026key=fool val\u0026bar=key=bar val`  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkos-v%2Fdsnparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkos-v%2Fdsnparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkos-v%2Fdsnparser/lists"}