utils

package module
v0.0.0-...-46aef10 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 20 Imported by: 1

README

utils

Documentation

Overview

Package utils provides utility functions for common operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecryptCBC

func AesDecryptCBC(encrypted []byte, key []byte) (decrypted []byte)

func AesDecryptCBCIV

func AesDecryptCBCIV(encrypted []byte, key, iv []byte) (decrypted []byte)

func AesDecryptCFB

func AesDecryptCFB(encrypted []byte, key []byte) (decrypted []byte)

func AesDecryptECB

func AesDecryptECB(encrypted []byte, key []byte) (decrypted []byte)

func AesEncryptCBC

func AesEncryptCBC(origData []byte, key []byte) (encrypted []byte)

=================== CBC ======================

func AesEncryptCBCIV

func AesEncryptCBCIV(origData []byte, key, iv []byte) (encrypted []byte)

func AesEncryptCFB

func AesEncryptCFB(origData []byte, key []byte) (encrypted []byte)

=================== CFB ======================

func AesEncryptECB

func AesEncryptECB(origData []byte, key []byte) (encrypted []byte)

=================== ECB ======================

func Base64Decode

func Base64Decode(data string) []byte

func Base64Encode

func Base64Encode(data []byte) string

func BytesToUint16

func BytesToUint16(in []byte) uint16

func BytesToUint16s

func BytesToUint16s(in []byte) (out []uint16)

func BytesToUint32

func BytesToUint32(in []byte) uint32

func BytesToUint32s

func BytesToUint32s(in []byte) (out []uint32)

func Get

func Get[T any](url string) (*T, error)

func GetHeader

func GetHeader[T any](url string, h map[string]string) (*T, error)

func If

func If[T any](cond bool, ifTrue T, ifFalse T) T

If returns ifTrue if cond is true, otherwise returns ifFalse

func LoadConfig

func LoadConfig[T Config[T]]() (*T, error)

func LoadConfigReader

func LoadConfigReader[T Config[T]](reader io.Reader) (*T, error)

func MD5

func MD5(s string) string

func ObjsTrans

func ObjsTrans[K, T any](objs []K, fn func(K) T) []T

ObjsTrans concurrently transforms a slice of type K to a slice of type T using the provided transformation function fn.

This function processes each element of the input slice in parallel using goroutines, waits for all transformations to complete, and returns the resulting slice.

Parameters:

  • objs: Input slice of type K to be transformed
  • fn: Transformation function that converts a single element of type K to type T

Returns:

  • []T: Slice containing the transformed elements in the same order as the input

Example:

// Convert []int to []string by converting each integer to its string representation
nums := []int{1, 2, 3, 4, 5}
strs := ObjsTrans(nums, func(n int) string {
    return fmt.Sprintf("Number: %d", n)
})

func Post

func Post[T any](url string, data any) (*T, error)

func PostHeader

func PostHeader[T any](url string, data any, h map[string]string) (*T, error)

func RandString

func RandString(n int) string

func SHA

func SHA(s string) string

func TimeID

func TimeID() string

func Uint16ToBytes

func Uint16ToBytes(in uint16) (out []byte)

func Uint32ToBytes

func Uint32ToBytes(in uint32) (out []byte)

Types

type AppKey

type AppKey struct {
	Appkey     string   `json:"appkey"     yaml:"appkey"`
	Secret     string   `json:"secret"     yaml:"secret"`
	Permission []string `json:"permission" yaml:"permission"`
}

type BaseConfig

type BaseConfig struct {
	Listen string
	Mode   string
}

func (BaseConfig) Release

func (b BaseConfig) Release() bool

type Config

type Config[T any] interface {
	Release() bool
}

type Range

type Range struct {
	Name string
	// 最大值
	Max int64
}

数据区间

type Ranges

type Ranges []Range

func (Ranges) Check

func (r Ranges) Check(t int64) string

获取名称

func (Ranges) Index

func (r Ranges) Index(n string) int

获取索引

func (Ranges) Names

func (r Ranges) Names() []string

func (Ranges) RangesSort

func (r Ranges) RangesSort(i, j string) bool

Directories

Path Synopsis
db
ex command
ex command
ex command

Jump to

Keyboard shortcuts

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