Documentation
¶
Overview ¶
Package stringkey creates a key from multiple strings. This package is intended to be used with few small strings. The total number of input bytes should be reasonably small to be compatible with a 64 bit hash.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StringKey ¶
type StringKey struct {
// contains filtered or unexported fields
}
StringKey stores the encoded key.
func New ¶
New encode (hash) input strings into a uint64 key.
Example ¶
package main
import (
"fmt"
"github.com/Vonage/gosrvlib/pkg/stringkey"
)
func main() {
// input strings
args := []string{
"0123456789",
"abcdefghijklmnopqrstuvwxyz",
"Lorem ipsum dolor sit amet",
}
// generate a new key
sk := stringkey.New(args...)
fmt.Println(sk)
}
Output: 2p8dmari397l8
func (*StringKey) Hex ¶
Hex returns a fixed-length 16 digits hexadecimal string key.
Example ¶
package main
import (
"fmt"
"github.com/Vonage/gosrvlib/pkg/stringkey"
)
func main() {
// generate a new key as fixed-length 16 digits hexadecimal string key.
k := stringkey.New(
"0123456789",
"abcdefghijklmnopqrstuvwxyz",
"Lorem ipsum dolor sit amet",
).Hex()
fmt.Println(k)
}
Output: b19b688e8e3229ac
func (*StringKey) Key ¶
Key returns a uint64 key.
Example ¶
package main
import (
"fmt"
"github.com/Vonage/gosrvlib/pkg/stringkey"
)
func main() {
// generate a new key as uint64
k := stringkey.New(
"0123456789",
"abcdefghijklmnopqrstuvwxyz",
"Lorem ipsum dolor sit amet",
).Key()
fmt.Println(k)
}
Output: 12797937727583693228
func (*StringKey) String ¶
String returns a variable-length string key.
Example ¶
package main
import (
"fmt"
"github.com/Vonage/gosrvlib/pkg/stringkey"
)
func main() {
// generate a new key as 36-char encoded string
k := stringkey.New(
"0123456789",
"abcdefghijklmnopqrstuvwxyz",
"Lorem ipsum dolor sit amet",
).String()
fmt.Println(k)
}
Output: 2p8dmari397l8
Click to show internal directories.
Click to hide internal directories.