bkit

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 11 Imported by: 0

README

bkit

自己常用的方法封装

  • 随机数

  • 字段加盐生成 md5 值

  • 字符串内容替换, 用于隐藏部分内容, 如: 13800******

  • 敏感词过滤

  • sego 分词的封装

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Seg *seg

因为词典要加载到内容中,初始化时间有点长,这里用了一个全局变量,避免每次调用都初始化浪费时间

Functions

func HiddenStr

func HiddenStr(origin string, opts ...hiddenStrOption) string

HiddenStr 字符串替换,用于隐藏部分内容 默认配置是隐藏手机中间4位, 如: 138****8000

func HiddenStrHead

func HiddenStrHead(origin string, length int, opts ...hiddenStrOption) string

HiddenStrHead 从头部开始替换 Example: ReplaceStrTail("13800138000", 4) Out: ****0138000

func HiddenStrLength

func HiddenStrLength(length uint) hiddenStrOption

HiddenStrLength 设置替换的长度, 默认是 4

func HiddenStrStart

func HiddenStrStart(start uint) hiddenStrOption

HiddenStrStart 设置替换的开始位置,默认是 3

func HiddenStrSymbol

func HiddenStrSymbol(symbol string) hiddenStrOption

HiddenStrSymbol 设置隐藏时的替换内容, 默认是 *

func HiddenStrTail

func HiddenStrTail(origin string, length int, opts ...hiddenStrOption) string

HiddenStrTail 尾部开始隐藏 Example: HiddenStrTail("13800138000", 4) Out: 1380013****

func NewSeg added in v0.1.5

func NewSeg(dictDir string) (err error)

需要注意, 分词使用的 github.com/huichen/sego 这个库, 使用前***必须需要初始化*** 初始化的时候要将 data 目录中的 dict 复制到项目可以找到的地方, 并且在 NewSeg 的时候要制定 dict 目录 如: NewSeg(./data/dict)

func RandomOptionCustomSeed added in v0.1.5

func RandomOptionCustomSeed(seed string) randomOption

RandomOptionCustomSeed 设置自定义的随机数

func RandomOptionLength

func RandomOptionLength(length uint) randomOption

RandomOptionLength 设置随机字符串长度

func RandomOptionLetter

func RandomOptionLetter() randomOption

RandomOptionLetter 设置随机字符串为大小写英文字母

func RandomOptionLower

func RandomOptionLower() randomOption

RandomOptionLower 设置随机数为纯小写字母

func RandomOptionNumber

func RandomOptionNumber() randomOption

RandomOptionNumber 设置随机字符串为纯数字

func RandomOptionUpper

func RandomOptionUpper() randomOption

RandomOptionUpper 设置随机字符串为纯大写字母

func Repr added in v0.1.5

func Repr(v any) string

Repr returns the string representation of v.

func SaltWithInt64Hex16 added in v0.1.4

func SaltWithInt64Hex16(password string, i64 int64) string

SaltWithInt64Hex16 给密码加盐, 盐是 int64 格式的的数字转成 16 进制字符串

func SaltWithString added in v0.1.4

func SaltWithString(origin, slat string) string

SaltWithString 加盐, 盐为字符串格式

Types

type AnyType added in v0.1.5

type AnyType = any

AnyType can be used to hold any type.

type PlaceholderType added in v0.1.5

type PlaceholderType = struct{}

PlaceholderType represents a placeholder type.

var Placeholder PlaceholderType

Placeholder is a placeholder object that can be used globally.

type RandomResult

type RandomResult []rune

随机字符串返回类型

func Random

func Random(opts ...randomOption) RandomResult

Random 生成随机字符串,默认为大小写英文+数字, 长度为6

func (RandomResult) Int

func (b RandomResult) Int() int

ToInt 转成 int 类型, 不保证一定成功,要保证 seed 必须是纯数字,否则此处转换失败就是 0

func (RandomResult) String

func (b RandomResult) String() string

type SegResult added in v0.1.5

type SegResult []string

func (SegResult) String added in v0.1.5

func (r SegResult) String(seps ...string) string

String 将结果转换成字符串

type Trie added in v0.1.5

type Trie interface {
	Filter(text string) (string, []string, bool)
	FindKeywords(text string) []string
}

A Trie is a tree implementation that used to find elements rapidly.

func NewTrie added in v0.1.5

func NewTrie(words []string, opts ...TrieOption) Trie

NewTrie returns a Trie.

func SWFilter added in v0.1.5

func SWFilter() Trie

type TrieOption added in v0.1.5

type TrieOption func(trie *trieNode)

TrieOption defines the method to customize a Trie.

func WithMask added in v0.1.5

func WithMask(mask rune) TrieOption

WithMask customizes a Trie with keywords masked as given mask char.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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