{"id":42712622,"url":"https://github.com/denismitr/go-hashids","last_synced_at":"2026-01-29T15:12:37.264Z","repository":{"id":57482565,"uuid":"152807652","full_name":"denismitr/go-hashids","owner":"denismitr","description":"Go hashids","archived":false,"fork":false,"pushed_at":"2018-10-17T18:44:39.000Z","size":78,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T05:22:08.680Z","etag":null,"topics":["go","golang","hash","hashids"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denismitr.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}},"created_at":"2018-10-12T21:06:39.000Z","updated_at":"2018-10-26T14:05:10.000Z","dependencies_parsed_at":"2022-09-02T04:20:27.919Z","dependency_job_id":null,"html_url":"https://github.com/denismitr/go-hashids","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/denismitr/go-hashids","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismitr%2Fgo-hashids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismitr%2Fgo-hashids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismitr%2Fgo-hashids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismitr%2Fgo-hashids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denismitr","download_url":"https://codeload.github.com/denismitr/go-hashids/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismitr%2Fgo-hashids/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28880017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T10:31:27.438Z","status":"ssl_error","status_checked_at":"2026-01-29T10:31:01.017Z","response_time":59,"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":["go","golang","hash","hashids"],"created_at":"2026-01-29T15:12:37.164Z","updated_at":"2026-01-29T15:12:37.259Z","avatar_url":"https://github.com/denismitr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GO implementation of Hashids with some additional features\n[![Build Status](https://travis-ci.org/denismitr/go-hashids.svg?branch=master)](https://travis-ci.org/denismitr/go-hashids)\n\nThis library can generate hashed/obfuscated ids from numbers. Usually this kind of functionality is required to create shorter slugs that don't reveal the DB incremental ids. The algorithm is reversable but you can use *salt* to make it more secure. However this algorithm is not suitable for cryptographical purpuses. More information on [hashids.org](https://hashids.org).\n\n#### Version 1\n\n#### Author\n[Denis Mitrofanov](https://thecollection.ru)\n\n### Usage\n\n```go get github.com/denismitr/go-hashids/v1```\n\n##### Public API\n\nImport\n```go\nimport (\n\thashids \"github.com/denismitr/go-hashids/v1\"\n)\n```\n\nAvailable constants:\n\n```go\n// DefaultAlphabet - with all latin letters and all digits\nDefaultAlphabet = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\"\n// LowercaseAlphabetWithDigits all latin lowercase characters and digits\nLowercaseAlphabetWithDigits = \"abcdefghijklmnopqrstuvwxyz1234567890\"\n// DefaultLength of the hash which is basically a minimal length of the hash\n// Length will grow automatically as required\nDefaultLength = 16\n// MinAlphabetLength - custome alphabet cannot be smaller than this value\nMinAlphabetLength = 16\n```\n\nCustom options\n```go\noptions := hashids.Options{\n    Length:   16,\n    Salt:     \"some salt\",\n    Alphabet: hashids.DefaultAlphabet,\n}\n\nh, err := hashids.New(options)\nif err != nil {\n    log.Fatal(err)\n}\n\nhash, err := h.Encode(1)\nif err != nil {\n    log.Fatal(err)\n}\n\nnumbers, err := h.Decode(hash).Unwrap()\n// numbers == []int64{1}\n```\n\nDefault options\n```go\nh, err := hashids.New(hashids.DefaultOptions(\"my salt\"))\n\nhash, err := h.Encode(1, 2, 3)\n\nnumbers, err := h.Decode(hash).Unwrap()\n// numbers == []int64{1, 2, 3}\n```\n\nAvailable input formats\n* []int64\n* []int\n* int64\n* int\n* hexidecimal string\n* time.Time\n\n```go\noptions := hashids.Options{\n    Length:   8,\n    Salt:     \"my salt\",\n    Alphabet: hashids.DefaultAlphabet,\n}\n\n\nh, err := hashids.New(options)\nif err != nil {\n    log.Fatal(err)\n}\n\n// single value\nhash, _ := h.Encode(1) \n// or\nhash, _ := h.Encode(int64(1)) \n// or multiple values\nhash, _ := h.Encode(1, 2, 3)\n// or\nhash, _ := h.Encode([]int{1, 2, 3})\n// or\nhash, _ := h.Encode([]int64{1, 2, 3})\n// hexidecimal string\nhash, _ := h.Encode(\"ab1f\")\n// time.Time\nhash, _ := h.Encode(time.Now())\n```\n\n### Retrieving results of the Decode method\nDecoding of hashes always yields an `[]int64` slice, wrapped by `DecodedResult` struct. You can retrieve that slice by using `Unwrap()` method. It will return `[]int64` and `error`.\nApart from the `Unwrap()` method that simply returns decoded number/numbers always as `[]int64` slice and the `error`. There are a number of helper method on `DecodedResult` to retieve result as the desired type:\n\n* `FirstInt()` returns `int` and `error` - when you know for sure that you encoded a single `int` number  \n* `FirstInt64()` returns `int64` and `error` - when you know you for sure that you encoded a single `int64` number \n* `IntSlice()` returns `[]int` and `error`\n* `Int64Slice` - essentially equal to `Unwrap()` \n\n### Hexidecimal strings\nAnother supported format is hexidecimal strings\n```go\n// you can use a special method for it\n// that is designed aspecially \nhash, _ := h.EncodeHex(\"ABECDF53\")\n\nhex, err := h.Decode(hash).AsHex()\nif err != nil {\n    log.Fatal(err)\n}\n\n// hex = \"abecdf53\" ATTENTION!!! all lower case\n```\n\n### Optional prefixing - making a Stripe style slug\n```go\noptions := hashids.Options{\n    Length:   12,\n    Salt:     \"some salt\",\n    Alphabet: hashids.LowercaseAlphabetWithDigits,\n    Prefix:   \"cus_\",\n}\n\nh, err := New(options)\nif err != nil {\n    t.Fatal(err)\n}\n\nhash, err := h.Encode(156)\nif err != nil {\n    log.Fatal(err)\n}\n\n// hash == cus_2vk4e9xpeng7\n\nnumbers, err := h.Decode(hash).Unwrap()\nif err != nil {\n    log.Fatal(err)\n}\n\n// numbers == []int64{156}\n// prefix will be stripped automatically during decode\n// as long as it was specified in the options or via a setter before decode\n```\n\nYou may not always want to specify prefix when creating a new hasher (even though it is recommended). You have an option to set prefix and clear it with dedicated methods.\n\n```go\n\noptions := hashids.Options{\n    Length:   12,\n    Salt:     \"some salt\",\n    Alphabet: hashids.LowercaseAlphabetWithDigits,\n}\n\nh, err := New(options)\nif err != nil {\n    t.Fatal(err)\n}\n\nhash, err := h.SetPrefix(\"cus_\").Encode(156)\nif err != nil {\n    log.Fatal(err)\n}\n\n// hash == cus_2vk4e9xpeng7\n\nnumbers, err := h.Decode(hash).Unwrap()\nif err != nil {\n    log.Fatal(err)\n}\n\n// numbers == []int64{156}\n// prefix will be stripped automatically during decode\n// as long as it was specified in the options or via a setter before decode\n\nh.ClearPrefix() // you can use this method to clear the prefix\n```\n\n#### Working with timestamps\nATTENTION!!! Use this feature with caution. If you wany to create hashid from a timestamp, there is always a chance that in a concurrent application two timestamps generated in two different processes, goroutines or simply web requests may actually turn out to be totally identical up to a nanosecond.\n\n```go\nt := time.Now() // just for example\n\nh, err := New(hashids.DefaultOptions(\"salt\"))\nif err != nil {\n    t.Fatal(err)\n}\n\nhash, err := h.EncodeTime(t)\nif err != nil {\n    t.Fatal(err)\n}\n\nu, err := h.Decode(hash).AsTime()\nif err != nil {\n    t.Fatal(err)\n}\n\nt.Equal(u) // true\nt.Sub(u).Nanoseconds() // 0 delta in nanoseconds \n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenismitr%2Fgo-hashids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenismitr%2Fgo-hashids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenismitr%2Fgo-hashids/lists"}