Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jackc/go-extid
https://github.com/jackc/go-extid
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jackc/go-extid
- Owner: jackc
- License: mit
- Created: 2022-09-04T01:30:14.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-10-26T20:12:24.000Z (about 2 years ago)
- Last Synced: 2024-06-20T00:32:12.814Z (5 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/jackc/go-extid.svg)](https://pkg.go.dev/github.com/jackc/go-extid)
# go-extid
It can be valuable to internally use a serial integer as an ID without revealing that ID to the outside world. go-extid
uses AES-128 to convert to and from an external ID that cannot feasibly be decoded without the secret key.This prevents outsiders from quantifying the usage of your application by observing the rate of increase of IDs as well
as provides protection against brute force crawling of all resources.## Example Usage
```go
prefix := "user"
key := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}et, err := extid.NewType(prefix, key)
if err != nil {
return err
}et.Encode(1) // => "user_13189a6ae4ab07ae70a3aabd30be99de"
```## Performance
```
$ go test -bench=. -benchmem
goos: darwin
goarch: amd64
pkg: github.com/jackc/go-extid
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkEncode-16 8812752 126.3 ns/op 112 B/op 4 allocs/op
BenchmarkDecode-16 14138239 78.88 ns/op 32 B/op 2 allocs/op
PASS
ok github.com/jackc/go-extid 5.298s
```## Other Implementations
* [PostgreSQL](https://github.com/jackc/pg-extid)
* [Ruby](https://github.com/jackc/ruby-extid)