package main import ( "SafelineAPI/internal/Func" "SafelineAPI/internal/app/SafelineRequest" "SafelineAPI/internal/app/logger" "SafelineAPI/internal/class/config" "SafelineAPI/internal/moudle" "log" "os" ) func main() { logger.LogInit() var conf config.Config if len(os.Args) == 1 || os.Args[1][0] == '-' { conf.Command() } else { conf.Read(os.Args[1]) } certUpsert, update := Func.UpdateCertCheck(conf) if update { return } providers, provider := Func.ChooseProvider(conf.Acme) if provider { return } var email string var failedApply [][]string var successApply [][]string var taskChan = make(chan struct{}, conf.Concurrency) for _, cert := range certUpsert { taskChan <- struct{}{} go func(cert SafelineRequest.Nodes) { Certificate, PrivateKey, status := moudle.ApplyCert(cert.Domains, conf.Acme.Email, providers[0]) if status { failedApply = append(failedApply, cert.Domains) return } success, failed := moudle.UpdateCert(conf, email, Certificate, PrivateKey, cert) if success != nil { successApply = append(successApply, success) } if failed != nil { failedApply = append(failedApply, failed) } <-taskChan }(cert) } if len(successApply) != 0 { log.Printf("本次成功更新的域名证书如下: %s%s%s", logger.Cyan, successApply, logger.Reset) } if len(failedApply) != 0 { log.Printf("未成功更新的域名证书如下: %s%s%s", logger.Cyan, failedApply, logger.Reset) } log.Printf("本次任务执行完成") }