utils

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 27 Imported by: 18

README

utils

update

- v0.4.1 slice/flags
- v0.3.5 nocolor on win
- v0.3.2 jwt协议增加多级key校验
- v0.3.1 忘记加了啥
- v0.2.1 添加了rsa加密,完善注册服务 
- v0.2.0 添加了些工具函数, 更新了cmd库,可以方便的注册服务和cli工具
- v0.1.5 更新了随机字符串函数,性能优化一倍
- v0.1.4 对日志添加了追踪error发生位置的功能
- v0.1.3 更新log HandleErrors 级别
- v0.1.2 添加了CallPath 方法
- v0.1.1 更新了一些方法和处理bug
- v0.1.0 更新了 log safe_bool fast_locker

Documentation

Index

Constants

View Source
const (
	Version = "v0.4.2"
)

Variables

This section is empty.

Functions

func Abs added in v0.2.2

func Abs(path string) (string, error)

func AesDecrypt

func AesDecrypt(encrypted, key, iv []byte) (string, error)

AesDecrypt 使用 AES-256-CBC 进行解密

func AesEncrypt

func AesEncrypt(plaintext, key, iv []byte) (string, error)

AesEncrypt 使用 AES-256-CBC 进行加密 key 256 bit / 32 Byte iv 128 bit / 16 Byte

func CallPath

func CallPath(s int) string

func CamelToSnake added in v0.4.2

func CamelToSnake(input string) string

CamelToSnake 将驼峰命名法转换为下划线命名法 例如:CamelToSnake("CamelToSnake") => "camel_to_snake" special case: CaseID => case_id

func ChMod added in v0.2.2

func ChMod(name string, mode os.FileMode)

func CopyFile added in v0.2.2

func CopyFile(src, dest string) (w int64, err error)

生成目录并拷贝文件

func Exec added in v0.2.2

func Exec(acts ...string) (string, error)

func FileExists added in v0.2.2

func FileExists(name string) bool

FileExists reports whether the named file or directory exists.

func FromBase64 added in v0.2.2

func FromBase64(src string) ([]byte, error)

func GetPrivateFromStr added in v0.2.2

func GetPrivateFromStr(key string) (*rsa.PrivateKey, error)

func GetPrivateStr added in v0.2.2

func GetPrivateStr(key *rsa.PrivateKey) (string, error)

func GetPublicFromStr added in v0.2.2

func GetPublicFromStr(key string) (*rsa.PublicKey, error)

func GetPublicStr added in v0.2.2

func GetPublicStr(key *rsa.PublicKey) (string, error)

func GetRsaKey added in v0.2.2

func GetRsaKey(bits int) (public *rsa.PublicKey, private *rsa.PrivateKey, err error)

func GetRunnerPath added in v0.2.2

func GetRunnerPath() string

Get the absolute path to the running directory

func HashMd5 added in v0.2.2

func HashMd5(s string) string

func HashSha256 added in v0.2.2

func HashSha256(msg string) string

func HashSha256Byte added in v0.2.2

func HashSha256Byte(msg []byte) []byte

func Home added in v0.2.2

func Home() (string, error)

func InList added in v0.2.2

func InList(str string, list []string) bool

InList 判断列表是否含有某元素

func InsertAt added in v0.4.2

func InsertAt[T any](slice []T, index int, value T) []T

func IsWindows added in v0.2.2

func IsWindows() bool

Determine whether the current system is a Windows system?

func MkFile added in v0.2.2

func MkFile(dest string) (*os.File, error)

func MultiErr added in v0.3.1

func MultiErr(errs ...error) error

func PKCS7Padding added in v0.4.2

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7Padding 添加 PKCS#7 填充

func PKCS7UnPadding added in v0.4.2

func PKCS7UnPadding(origData []byte) ([]byte, bool)

PKCS7UnPadding 移除 PKCS#7 填充

func PathExists added in v0.2.2

func PathExists(path string) (bool, error)

检测文件夹路径时候存在

func PathIsDir added in v0.4.0

func PathIsDir(p string) bool

func PathJoin added in v0.2.2

func PathJoin(paths ...string) string

func Rand

func Rand(n int) []byte

func RandSeq

func RandSeq(n int) string

RandSeq produce random string seq

func RemoveRep added in v0.2.2

func RemoveRep(slc []string) []string

RemoveRep 通过map主键唯一的特性过滤重复元素

func RsaCheckSign added in v0.2.2

func RsaCheckSign(msg string, sign string, key *rsa.PublicKey) error

func RsaDecode added in v0.2.2

func RsaDecode(msg string, key *rsa.PrivateKey) (string, error)

func RsaEncode added in v0.2.2

func RsaEncode(msg string, key *rsa.PublicKey) (string, error)

func RsaSign added in v0.2.2

func RsaSign(msg string, key *rsa.PrivateKey) (string, error)

func SliceGet added in v0.4.2

func SliceGet[T any](slice []T, fc func(T) bool) *T

func SnakeToCamel added in v0.4.2

func SnakeToCamel(input string) string

func SnakeToPrivateCamel added in v0.4.2

func SnakeToPrivateCamel(input string) string

func SortItems added in v0.4.2

func SortItems(x any, less func(i int, j int, sid func(string) int) bool, items ...string)

func ToBase64 added in v0.2.2

func ToBase64(src []byte) string

func ToLowerFirst added in v0.4.2

func ToLowerFirst(s string) string

ToLowerFirst 将字符串的第一个字母转换为小写

func ToTitle added in v0.4.2

func ToTitle(str string) string

Types

type FastLocker

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

func (*FastLocker) Lock

func (mu *FastLocker) Lock()

func (*FastLocker) Unlock

func (mu *FastLocker) Unlock()

type SafeBool

type SafeBool uint32

线程安全的标志位 set 方法保证置换操作的原子性

func (*SafeBool) ForceSetFalse

func (b *SafeBool) ForceSetFalse()

func (*SafeBool) ForceSetTrue

func (b *SafeBool) ForceSetTrue()

func (*SafeBool) IfTrue

func (b *SafeBool) IfTrue() bool

func (*SafeBool) SetFalse

func (b *SafeBool) SetFalse() bool

func (*SafeBool) SetTrue

func (b *SafeBool) SetTrue() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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