zk/internal/core/id.go
Mickaël Menu 50855154e2
Architecture (#27)
* Move everything under the internal package.
* Better separation between core and adapter packages, for easier unit testing.
* Simplify data models.
* Support multiple opened notebooks during runtime (useful for the LSP server).
* Proper surface API which might be exposed later as a public Go package.
2021-04-14 20:14:01 +02:00

38 lines
1.0 KiB
Go

package core
// IDOptions holds the options used to generate an ID.
type IDOptions struct {
Length int
Charset Charset
Case Case
}
// Charset is a set of characters.
type Charset []rune
var (
// CharsetAlphanum is a charset containing letters and numbers.
CharsetAlphanum = Charset("0123456789abcdefghijklmnopqrstuvwxyz")
// CharsetAlphanum is a charset containing hexadecimal characters.
CharsetHex = Charset("0123456789abcdef")
// CharsetLetters is a charset containing only letters.
CharsetLetters = Charset("abcdefghijklmnopqrstuvwxyz")
// CharsetNumbers is a charset containing only numbers.
CharsetNumbers = Charset("0123456789")
)
// Case represents the letter case to use when generating an ID.
type Case int
const (
CaseLower Case = iota + 1
CaseUpper
CaseMixed
)
// IDGenerator is a function returning a new ID with each invocation.
type IDGenerator func() string
// IDGeneratorFactory creates a new IDGenerator function using the given IDOptions.
type IDGeneratorFactory func(opts IDOptions) func() string