Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Hash ¶
type Hash interface { // Encode encodes the ID into a slice of byte. // The slice of byte generated is the result of Hashids algorithm. Encode(ID) ([]byte, error) // Decode decodes the slice of byte into an ID. Decode([]byte) (ID, error) }
Hash defines the contract to encode and decode the ID.
type HashID ¶
type HashID struct {
// contains filtered or unexported fields
}
HashID can be used to encode and decode hashids. It implements the Hash interface.
func NewHashID ¶
NewHashID creates an instance of HashID. It needs two parameters. The minimum length is used to define the mininum length of generated string. The salt is used to add the uniqueness of the generated hash.
type ID ¶
type ID int64
ID represents a unique identifier. It means to replace the old int64 as unique ID. Using this type allows the int64 to be obfuscated into a random string using the Hashids algorithm. Read more about hashids in https://hashids.org/.
func DecodeHash ¶ added in v0.1.0
DecodeHash decodes hash into an ID.
func (ID) EncodeString ¶ added in v0.2.0
EncodeString encodes ID to hashsids format and returns as a string. It ignores the error coming from encoding process. Thus, if there is any error during the process, it returns empty string.
func (ID) MarshalJSON ¶
MarshalJSON marshals the ID to JSON.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON back to ID.