Merge pull request #974 from 0xJacky/feat/workspace

enhance: replace error handling with cosy wrapper for nginx reload and test
This commit is contained in:
Jacky 2025-04-18 16:41:44 +08:00
commit 818bf9bcf6
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
31 changed files with 230 additions and 58 deletions

View file

@ -76,9 +76,7 @@ func AddConfig(c *gin.Context) {
output := nginx.Reload()
if nginx.GetLogLevel(output) >= nginx.Warn {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
cosy.ErrHandler(c, cosy.WrapErrorWithParams(config.ErrNginxReloadFailed, output))
return
}

View file

@ -1,4 +1,6 @@
export default {
50006: () => $gettext('Path: {0} is not under the nginx conf dir: {1}'),
50007: () => $gettext('Destination file: {0} already exists'),
50008: () => $gettext('Nginx test failed: {0}'),
50009: () => $gettext('Nginx reload failed: {0}'),
}

View file

@ -3,4 +3,6 @@ export default {
50001: () => $gettext('Destination file already exists'),
50002: () => $gettext('Site is enabled'),
50003: () => $gettext('Site is in maintenance mode'),
50004: () => $gettext('Nginx test failed: {0}'),
50005: () => $gettext('Nginx reload failed: {0}'),
}

View file

@ -2,4 +2,6 @@ export default {
40401: () => $gettext('Stream not found'),
50001: () => $gettext('Destination file already exists'),
50002: () => $gettext('Stream is enabled'),
50003: () => $gettext('Nginx test failed: {0}'),
50004: () => $gettext('Nginx reload failed: {0}'),
}

View file

@ -2689,6 +2689,12 @@ msgstr "مسار PID لـ Nginx"
msgid "Nginx Reload Command"
msgstr "أمر إعادة تحميل Nginx"
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "فشل في التفعيل %{msg}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2714,6 +2720,12 @@ msgstr "تم إعادة تشغيل Nginx بنجاح"
msgid "Nginx Test Config Command"
msgstr "أمر إعادة تشغيل Nginx"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "فشل في التفعيل %{msg}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4728,7 +4740,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2765,6 +2765,12 @@ msgstr "Nginx PID-Pfad"
msgid "Nginx Reload Command"
msgstr "Befehl zum Neuladen von Nginx"
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "Aktiviern von %{msg} fehlgeschlagen"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2792,6 +2798,12 @@ msgstr "Speichern erfolgreich"
msgid "Nginx Test Config Command"
msgstr "Beffehl zum Neustarten von Nginx"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "Aktiviern von %{msg} fehlgeschlagen"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4873,7 +4885,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2735,6 +2735,12 @@ msgstr ""
msgid "Nginx Reload Command"
msgstr ""
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "Failed to enable %{msg}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2761,6 +2767,12 @@ msgstr "Saved successfully"
msgid "Nginx Test Config Command"
msgstr ""
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "Failed to enable %{msg}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4780,7 +4792,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2694,6 +2694,12 @@ msgstr "Ruta de registro de errores de Nginx"
msgid "Nginx Reload Command"
msgstr "Comando de recarga de Nginx"
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "Error al habilitar %{msg}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2720,6 +2726,12 @@ msgstr "Nginx reiniciado con éxito"
msgid "Nginx Test Config Command"
msgstr "Comando de inicio de terminal"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "Error al habilitar %{msg}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4774,7 +4786,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2780,6 +2780,12 @@ msgstr "Chemin du journal des erreurs Nginx"
msgid "Nginx Reload Command"
msgstr "Commande de démarrage du terminal"
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "Impossible d'activer %{msg}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2806,6 +2812,12 @@ msgstr "Nginx a redémarré avec succès"
msgid "Nginx Test Config Command"
msgstr "Commande de démarrage du terminal"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "Impossible d'activer %{msg}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4838,7 +4850,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2696,6 +2696,12 @@ msgstr "Nginx 오류 로그 경로"
msgid "Nginx Reload Command"
msgstr ""
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "%{msg} 활성화 실패"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2724,6 +2730,12 @@ msgstr "Nginx가 성공적으로 재시작됨"
msgid "Nginx Test Config Command"
msgstr "터미널 시작 명령"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "%{msg} 활성화 실패"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4753,7 +4765,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2500,6 +2500,12 @@ msgstr ""
msgid "Nginx Reload Command"
msgstr ""
#: src/constants/errors/config.ts:5
#: src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
msgid "Nginx reload failed: {0}"
msgstr ""
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2524,6 +2530,12 @@ msgstr ""
msgid "Nginx Test Config Command"
msgstr ""
#: src/constants/errors/config.ts:4
#: src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
msgid "Nginx test failed: {0}"
msgstr ""
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4312,7 +4324,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40
#: src/layouts/HeaderLayout.vue:49
#: src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"

View file

@ -2674,6 +2674,12 @@ msgstr "Путь для Nginx Error Log"
msgid "Nginx Reload Command"
msgstr "Команда перезагрузки Nginx"
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "Не удалось включить %{msg}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2700,6 +2706,12 @@ msgstr "Nginx успешно перезапущен"
msgid "Nginx Test Config Command"
msgstr "Терминальная команда запуска"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "Не удалось включить %{msg}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4720,7 +4732,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2741,6 +2741,12 @@ msgstr "Nginx Hata Günlüğü Yolu"
msgid "Nginx Reload Command"
msgstr ""
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "Etkinleştirilemedi %{msg}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2769,6 +2775,12 @@ msgstr "Nginx başarıyla yeniden başlatıldı"
msgid "Nginx Test Config Command"
msgstr "Terminal Başlatma Komutu"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "Etkinleştirilemedi %{msg}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4997,7 +5009,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2516,6 +2516,11 @@ msgstr ""
msgid "Nginx Reload Command"
msgstr ""
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
msgid "Nginx reload failed: {0}"
msgstr ""
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2540,6 +2545,11 @@ msgstr ""
msgid "Nginx Test Config Command"
msgstr ""
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
msgid "Nginx test failed: {0}"
msgstr ""
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4413,7 +4423,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -2730,6 +2730,12 @@ msgstr "Vị trí lưu log lỗi (Error log) của Nginx"
msgid "Nginx Reload Command"
msgstr ""
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "Không thể bật %{msg}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr ""
@ -2756,6 +2762,12 @@ msgstr "Restart Nginx thành công"
msgid "Nginx Test Config Command"
msgstr ""
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "Không thể bật %{msg}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4776,7 +4788,7 @@ msgstr ""
msgid "Workers"
msgstr ""
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr ""

View file

@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2025-04-18 14:05+0800\n"
"PO-Revision-Date: 2025-04-18 16:49+0800\n"
"Last-Translator: 0xJacky <me@jackyu.cn>\n"
"Language-Team: Chinese (Simplified Han script) <https://weblate.nginxui.com/"
"projects/nginx-ui/frontend/zh_Hans/>\n"
@ -2526,6 +2526,11 @@ msgstr "Nginx PID 路径"
msgid "Nginx Reload Command"
msgstr "Nginx 重载命令"
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
msgid "Nginx reload failed: {0}"
msgstr "Nginx 重载失败:{0}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr "Nginx 重载操作已发送到远程节点"
@ -2550,6 +2555,11 @@ msgstr "Nginx 重启成功"
msgid "Nginx Test Config Command"
msgstr "Nginx 测试配置命令"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
msgid "Nginx test failed: {0}"
msgstr "Nginx 测试失败:{0}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr "Nginx 理论最高性能"
@ -4458,7 +4468,7 @@ msgstr "工作进程"
msgid "Workers"
msgstr "Workers"
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
msgid "Workspace"
msgstr "工作区"

View file

@ -2538,6 +2538,12 @@ msgstr "Nginx PID 路徑"
msgid "Nginx Reload Command"
msgstr "Nginx 重新載入指令"
#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7
#: src/constants/errors/stream.ts:6
#, fuzzy
msgid "Nginx reload failed: {0}"
msgstr "讀取檔案失敗:{0}"
#: src/views/environments/list/Environment.vue:41
msgid "Nginx reload operations have been dispatched to remote nodes"
msgstr "Nginx 重新載入操作已分發至遠端節點"
@ -2562,6 +2568,12 @@ msgstr "Nginx 重啟成功"
msgid "Nginx Test Config Command"
msgstr "Nginx 測試設定指令"
#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6
#: src/constants/errors/stream.ts:5
#, fuzzy
msgid "Nginx test failed: {0}"
msgstr "無法建立檔案:{0}"
#: src/views/dashboard/components/PerformanceTablesCard.vue:180
msgid "Nginx theoretical maximum performance"
msgstr ""
@ -4471,7 +4483,7 @@ msgstr "worker 行程"
msgid "Workers"
msgstr "worker"
#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56
#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56
#: src/views/workspace/WorkSpace.vue:52
#, fuzzy
msgid "Workspace"

View file

@ -35,13 +35,6 @@ const isWorkspace = computed(() => {
<div class="tool">
<MenuUnfoldOutlined @click="emit('clickUnFold')" />
</div>
<div v-if="!isWorkspace" class="workspace-entry">
<RouterLink to="/workspace">
<ATooltip :title="$gettext('Workspace')">
<DesktopOutlined />
</ATooltip>
</RouterLink>
</div>
<ASpace
class="user-wrapper"
@ -51,6 +44,14 @@ const isWorkspace = computed(() => {
<SwitchAppearance />
<div v-if="!isWorkspace" class="workspace-entry">
<RouterLink to="/workspace">
<ATooltip :title="$gettext('Workspace')">
<DesktopOutlined />
</ATooltip>
</RouterLink>
</div>
<Notification :header-ref="headerRef" />
<NginxControl />
@ -98,8 +99,6 @@ const isWorkspace = computed(() => {
}
.workspace-entry {
position: absolute;
left: 20px;
@media (max-width: 600px) {
display: none;
}

View file

@ -1,4 +1,4 @@
//go:generate go run . -project . -type ts -output ../../app/src/constants/errors -ignore-dirs .devcontainer,app,.github
//go:generate go run . -project ../../ -type ts -output ../../app/src/constants/errors -ignore-dirs .devcontainer,app,.github,cmd
package main
import "github.com/uozi-tech/cosy/errdef"

View file

@ -6,4 +6,6 @@ var (
e = cosy.NewErrorScope("config")
ErrPathIsNotUnderTheNginxConfDir = e.New(50006, "path: {0} is not under the nginx conf dir: {1}")
ErrDstFileExists = e.New(50007, "destination file: {0} already exists")
ErrNginxTestFailed = e.New(50008, "nginx test failed: {0}")
ErrNginxReloadFailed = e.New(50009, "nginx reload failed: {0}")
)

View file

@ -1,13 +1,13 @@
package config
import (
"fmt"
"os"
"github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/query"
"github.com/uozi-tech/cosy"
"gorm.io/gen/field"
)
@ -47,7 +47,7 @@ func Save(absPath string, content string, cfg *model.Config) (err error) {
output := nginx.Reload()
if nginx.GetLogLevel(output) >= nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
err = SyncToRemoteServer(cfg)

View file

@ -2,15 +2,17 @@ package site
import (
"fmt"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/0xJacky/Nginx-UI/model"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy/logger"
"net/http"
"os"
"runtime"
"sync"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/0xJacky/Nginx-UI/model"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
)
// Disable disables a site by removing the symlink in sites-enabled
@ -35,7 +37,7 @@ func Disable(name string) (err error) {
output := nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
go syncDisable(name)

View file

@ -11,6 +11,7 @@ import (
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
)
@ -37,12 +38,12 @@ func Enable(name string) (err error) {
output := nginx.TestConf()
if nginx.GetLogLevel(output) > nginx.Warn {
_ = os.Remove(enabledConfigFilePath)
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxTestFailed, output)
}
output = nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
go syncEnable(name)

View file

@ -8,4 +8,6 @@ var (
ErrDstFileExists = e.New(50001, "destination file already exists")
ErrSiteIsEnabled = e.New(50002, "site is enabled")
ErrSiteIsInMaintenance = e.New(50003, "site is in maintenance mode")
ErrNginxTestFailed = e.New(50004, "nginx test failed: {0}")
ErrNginxReloadFailed = e.New(50005, "nginx reload failed: {0}")
)

View file

@ -16,6 +16,7 @@ import (
"github.com/go-resty/resty/v2"
"github.com/tufanbarisyildirim/gonginx/config"
"github.com/tufanbarisyildirim/gonginx/parser"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
cSettings "github.com/uozi-tech/cosy/settings"
)
@ -82,13 +83,13 @@ func EnableMaintenance(name string) (err error) {
if helper.FileExists(originalEnabledPath + "_backup") {
_ = os.Rename(originalEnabledPath+"_backup", originalEnabledPath)
}
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxTestFailed, output)
}
// Reload nginx
output = nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
// Synchronize with other nodes

View file

@ -14,6 +14,7 @@ import (
"github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/query"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
)
@ -40,13 +41,13 @@ func Save(name string, content string, overwrite bool, envGroupId uint64, syncNo
output := nginx.TestConf()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxTestFailed, output)
}
if postAction == model.PostSyncActionReloadNginx {
output = nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
}
}

View file

@ -2,15 +2,17 @@ package stream
import (
"fmt"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/0xJacky/Nginx-UI/model"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy/logger"
"net/http"
"os"
"runtime"
"sync"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/0xJacky/Nginx-UI/model"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
)
// Disable disables a site by removing the symlink in sites-enabled
@ -35,7 +37,7 @@ func Disable(name string) (err error) {
output := nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
go syncDisable(name)

View file

@ -2,15 +2,17 @@ package stream
import (
"fmt"
"github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy/logger"
"net/http"
"os"
"runtime"
"sync"
"github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
)
// Enable enables a site by creating a symlink in sites-enabled
@ -36,12 +38,12 @@ func Enable(name string) (err error) {
output := nginx.TestConf()
if nginx.GetLogLevel(output) > nginx.Warn {
_ = os.Remove(enabledConfigFilePath)
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxTestFailed, output)
}
output = nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
go syncEnable(name)

View file

@ -7,4 +7,6 @@ var (
ErrStreamNotFound = e.New(40401, "stream not found")
ErrDstFileExists = e.New(50001, "destination file already exists")
ErrStreamIsEnabled = e.New(50002, "stream is enabled")
ErrNginxTestFailed = e.New(50003, "nginx test failed: {0}")
ErrNginxReloadFailed = e.New(50004, "nginx reload failed: {0}")
)

View file

@ -7,6 +7,7 @@ import (
"github.com/0xJacky/Nginx-UI/internal/notification"
"github.com/0xJacky/Nginx-UI/query"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
"net/http"
"os"
@ -49,13 +50,13 @@ func Rename(oldName string, newName string) (err error) {
// test nginx configuration
output := nginx.TestConf()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxTestFailed, output)
}
// reload nginx
output = nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
go syncRename(oldName, newName)

View file

@ -14,6 +14,7 @@ import (
"github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/query"
"github.com/go-resty/resty/v2"
"github.com/uozi-tech/cosy"
"github.com/uozi-tech/cosy/logger"
)
@ -40,13 +41,13 @@ func Save(name string, content string, overwrite bool, syncNodeIds []uint64, pos
output := nginx.TestConf()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxTestFailed, output)
}
if postAction == model.PostSyncActionReloadNginx {
output = nginx.Reload()
if nginx.GetLogLevel(output) > nginx.Warn {
return fmt.Errorf("%s", output)
return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output)
}
}
}