mirror of
https://git.um-react.app/um/cli.git
synced 2025-11-28 03:33:02 +00:00
Init Project
This commit is contained in:
41
internal/logging/logging.go
Normal file
41
internal/logging/logging.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// newDefaultProductionLog configures a custom log that is
|
||||
// intended for use by default if no other log is specified
|
||||
// in a config. It writes to stderr, uses the console encoder,
|
||||
// and enables INFO-level logs and higher.
|
||||
func newDefaultProductionLog() *zap.Logger {
|
||||
encCfg := zap.NewProductionEncoderConfig()
|
||||
// if interactive terminal, make output more human-readable by default
|
||||
encCfg.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
|
||||
encoder.AppendString(ts.Format("2006/01/02 15:04:05.000"))
|
||||
}
|
||||
encCfg.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
enc := zapcore.NewConsoleEncoder(encCfg)
|
||||
core := zapcore.NewCore(enc, zapcore.Lock(os.Stdout), zap.NewAtomicLevelAt(zap.DebugLevel))
|
||||
return zap.New(core)
|
||||
|
||||
}
|
||||
|
||||
// Log returns the current default logger.
|
||||
func Log() *zap.Logger {
|
||||
defaultLoggerMu.RLock()
|
||||
defer defaultLoggerMu.RUnlock()
|
||||
return defaultLogger
|
||||
}
|
||||
|
||||
var (
|
||||
defaultLogger = newDefaultProductionLog()
|
||||
defaultLoggerMu sync.RWMutex
|
||||
)
|
||||
19
internal/utils/crypto.go
Normal file
19
internal/utils/crypto.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package utils
|
||||
|
||||
import "crypto/aes"
|
||||
|
||||
func PKCS7UnPadding(encrypt []byte) []byte {
|
||||
length := len(encrypt)
|
||||
unPadding := int(encrypt[length-1])
|
||||
return encrypt[:(length - unPadding)]
|
||||
}
|
||||
|
||||
func DecryptAes128Ecb(data, key []byte) []byte {
|
||||
cipher, _ := aes.NewCipher(key)
|
||||
decrypted := make([]byte, len(data))
|
||||
size := 16
|
||||
for bs, be := 0, size; bs < len(data); bs, be = bs+size, be+size {
|
||||
cipher.Decrypt(decrypted[bs:be], data[bs:be])
|
||||
}
|
||||
return decrypted
|
||||
}
|
||||
Reference in New Issue
Block a user