rowkey

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package rowkey provides a simple way to build row keys. It's mostly useful when there's a need to reverse digits numeric identifiers.

Index

Examples

Constants

View Source
const DefaultSeparator = "#"

Variables

This section is empty.

Functions

func Reverse

func Reverse(s string) string

Reverse reverses all characters in a string so the first becomes the last and so on.

Example
processOpt := NewProcessOption(Reverse)
// we explicitly tell the builder to use the `Reverse` function to process each part of the key
b := NewBuilder(processOpt)
key := b.ToRowKey("1234", "john")
fmt.Println(key)
Output:

4321#nhoj

func ReverseIfInteger

func ReverseIfInteger(s string) string

ReverseIfInteger reverses the digits of a string if it's a numeric form. "Plain strings" won't be impacted.

Example
processOpt := NewProcessOption(ReverseIfInteger)
// we explicitly tell the builder to use the `ReverseIfInteger` function to process each part of the key
b := NewBuilder(processOpt)
key := b.ToRowKey("1234", "john")
fmt.Println(key)
Output:

4321#john

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(opts ...BuilderOption) *Builder
Example
sepOpt := NewSeparatorOption(":")
processOpt := NewProcessOption(func(s string) string {
	return s
})
b := NewBuilder(sepOpt, processOpt)
key := b.ToRowKey("1234", "john")
fmt.Println(key)
Output:

1234:john

func (*Builder) ToRowKey

func (b *Builder) ToRowKey(parts ...string) string

type BuilderOption

type BuilderOption interface {
	// contains filtered or unexported methods
}

BuilderOption is a function that can be used to configure a Builder.

type ProcessOption

type ProcessOption struct {
	// contains filtered or unexported fields
}

func NewProcessOption

func NewProcessOption(process func(string) string) ProcessOption

type SeparatorOption

type SeparatorOption struct {
	// contains filtered or unexported fields
}

func NewSeparatorOption

func NewSeparatorOption(separator string) SeparatorOption

Jump to

Keyboard shortcuts

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