strutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: MIT Imports: 9 Imported by: 126

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Encode

func Base64Encode(src []byte) []byte

Base64Encode base64 encode

func GenMd5

func GenMd5(src interface{}) string

GenMd5 Generate a 32-bit md5 string

func LowerFirst

func LowerFirst(s string) string

LowerFirst lower first char for a string.

func PadLeft

func PadLeft(s, pad string, length int) string

PadLeft a string.

func PadRight

func PadRight(s, pad string, length int) string

PadRight a string.

func Padding

func Padding(s, pad string, length int, pos uint8) string

Padding a string.

func PrettyJSON

func PrettyJSON(v interface{}) (string, error)

PrettyJSON get pretty Json string

func RandomBytes

func RandomBytes(length int) ([]byte, error)

RandomBytes generate

func RandomString

func RandomString(length int) (string, error)

RandomString generate. Example: this will give us a 44 byte, base64 encoded output

	token, err := RandomString(32)
	if err != nil {
    // Serve an appropriately vague error to the
    // user, but log the details internally.
	}

func RenderTemplate

func RenderTemplate(input string, data interface{}, fns template.FuncMap, isFile ...bool) string

RenderTemplate render text template

func Repeat

func Repeat(s string, times int) string

Repeat repeat a string

func RepeatRune

func RepeatRune(char rune, times int) (chars []rune)

RepeatRune repeat a rune char.

func Replaces

func Replaces(str string, pairs map[string]string) string

Replaces replace multi strings pairs - [old => new] can also use: strings.NewReplacer("old1", "new1", "old2", "new2").Replace(str)

func Similarity

func Similarity(s, t string, rate float32) (float32, bool)

Similarity calc for two string. Usage:

rate, ok := Similarity("hello", "he")

func Split

func Split(s, sep string) (ss []string)

Split string to slice. will clear empty string node.

func Substr

func Substr(s string, pos, length int) string

Substr for a string.

func UpperFirst

func UpperFirst(s string) string

UpperFirst upper first char

func UpperWord

func UpperWord(s string) string

UpperWord Change the first character of each word to uppercase

Types

type SimilarComparator

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

SimilarComparator definition links:

https://github.com/mkideal/cli/blob/master/fuzzy.go

func NewComparator

func NewComparator(src, dst string) *SimilarComparator

NewComparator create

func (*SimilarComparator) Similar

func (c *SimilarComparator) Similar(minDifferRate float32) (float32, bool)

Similar by minDifferRate Usage:

c := NewComparator("hello", "he")
rate, ok :c.Similar(0.3)

Jump to

Keyboard shortcuts

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