stringkey

package
v1.66.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 7 Imported by: 0

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

func New(fields ...string) *StringKey

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

func (sk *StringKey) Hex() string

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

func (sk *StringKey) Key() uint64

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

func (sk *StringKey) String() 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL