添加SSL证书管理功能,包括安装、续期、列出、撤销和申请证书的命令,同时更新依赖项和修复磁盘使用情况计算逻辑。

This commit is contained in:
zeaslity
2025-03-27 23:06:41 +08:00
parent 8d09a4191a
commit d8554ae8ae
19 changed files with 2742 additions and 28 deletions

View File

@@ -0,0 +1,72 @@
package log
import (
"fmt"
"runtime"
"strconv"
"strings"
"time"
)
const (
colorReset = "\033[0m"
colorRed = "\033[31m"
colorGreen = "\033[32m"
colorYellow = "\033[33m"
colorBlue = "\033[34m"
)
func main() {
Debug("Debug message: %s", "connection established")
Info("System %s", "started successfully")
Warning("Disk space at %d%%", 85)
Error("Failed to %s", "load config")
}
func Debug(format string, args ...interface{}) {
log("DEBUG", colorBlue, format, args...)
}
func Info(format string, args ...interface{}) {
log("INFO", colorGreen, format, args...)
}
func Warning(format string, args ...interface{}) {
log("WARNING", colorYellow, format, args...)
}
func Error(format string, args ...interface{}) {
log("ERROR", colorRed, format, args...)
}
func log(level string, color string, format string, args ...interface{}) {
// 获取调用者信息跳过2层调用栈
_, file, line, _ := runtime.Caller(2)
// fmt.Println("file is ", file)
s := strings.Split(file, "WddSuperAgent")[1]
callerInfo := strings.TrimLeft(s, "/") + " "
callerInfo += strconv.FormatInt(int64(line), 10)
timestamp := currentTimeString()
message := fmt.Sprintf(format, args...)
fmt.Printf("%s %s%-7s%s [%s] %s\n",
timestamp,
color,
level,
colorReset,
callerInfo,
message)
}
func currentTimeString() string {
// 加载东八区时区
loc, _ := time.LoadLocation("Asia/Shanghai")
// 获取当前时间并转换为东八区时间
now := time.Now().In(loc)
// 格式化为 "2006-01-02 15:04:05" 的布局
formattedTime := now.Format(time.DateTime)
return formattedTime
}