MCPcopy Index your code
hub / github.com/emvi/hide

github.com/emvi/hide @v1.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.4 ↗ · + Follow
31 symbols 74 edges 7 files 14 documented · 45%

Browse by type

Functions 27 Types & classes 4
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Hide IDs

Go Reference Go Report Card Chat on Discord

Hide is a simple package to provide an ID type that is marshaled to/from a hash string. This prevents sending technical IDs to clients and converts them on the API layer. Hide uses hashids as its default hash function. But you can provide your own by implementing the Hash interface and configuring it using hide.UseHash.

Read our full article on Medium.

Installation

go get github.com/emvi/hide/v2

Example

Consider the following struct:

type User struct {
    Id       int64  `json:"id"`
    Username string `json:"username"`
}

When marshaling this struct to JSON, the ID will be represented by a number:

{
    "id": 123,
    "username": "foobar"
}

In this case, you expose the technical user ID to your clients. By changing the type of the ID, you get a better result:

type User struct {
    Id       hide.ID `json:"id"`
    Username string  `json:"username"`
}

Notice that the int64 ID got replaced by the hide.ID, which internally is represented as an int64 as well, but implements the marshal interface. This allows you to cast between them and use hide.ID as a replacement. The resulting JSON changes to the following:

{
  "id": "beJarVNaQM",
  "username": "foobar"
}

If you send the new ID (which is a string now) back to the server and unmarshal it into the hide.ID type, you'll get the original technical ID back. It's also worth mentioning that a value of 0 is translated to null when an ID is marshaled to JSON or stored in a database.

View the full demo

Contribute

See CONTRIBUTING.md

License

MIT

<img src="https://github.com/emvi/hide/raw/v1.1.4/hidegopher.png" width="300px" />

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 18
Method 9
Struct 2
Interface 1
TypeAlias 1

Languages

Go100%

Modules by API surface

id_test.go10 symbols
id.go5 symbols
hashid.go5 symbols
util_test.go4 symbols
hash.go4 symbols
util.go2 symbols
init.go1 symbols

For agents

$ claude mcp add hide \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page