From 288e1b75e94a5ab00a3f43502b86a6a29b344546 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Sat, 16 Nov 2024 20:57:03 +0800 Subject: [PATCH] fix struct tags (#7) --- model/alertrule.go | 6 +++--- model/alertrule_api.go | 6 +++--- model/config.go | 8 ++++---- model/cron.go | 18 +++++++++--------- model/cron_api.go | 10 +++++----- model/ddns.go | 8 ++++---- model/ddns_api.go | 22 +++++++++++----------- model/nat.go | 8 ++++---- model/nat_api.go | 2 +- model/notification.go | 12 ++++++------ model/notification_api.go | 10 +++++----- model/notification_group_api.go | 2 +- model/notification_test.go | 4 ++-- model/server.go | 6 +++--- model/server_api.go | 12 ++++++------ model/server_group_api.go | 2 +- model/service.go | 4 ++-- model/service_api.go | 14 +++++++------- model/setting_api.go | 14 +++++++------- model/transfer.go | 6 +++--- 20 files changed, 87 insertions(+), 87 deletions(-) diff --git a/model/alertrule.go b/model/alertrule.go index e1fafcd..f8f6847 100644 --- a/model/alertrule.go +++ b/model/alertrule.go @@ -12,11 +12,11 @@ const ( type AlertRule struct { Common - Name string `json:"name,omitempty"` + Name string `json:"name"` RulesRaw string `json:"-"` Enable *bool `json:"enable,omitempty"` - TriggerMode int `gorm:"default:0" json:"trigger_mode,omitempty"` // 触发模式: 0-始终触发(默认) 1-单次触发 - NotificationGroupID uint64 `json:"notification_group_id,omitempty"` // 该报警规则所在的通知组 + TriggerMode uint8 `gorm:"default:0" json:"trigger_mode"` // 触发模式: 0-始终触发(默认) 1-单次触发 + NotificationGroupID uint64 `json:"notification_group_id"` // 该报警规则所在的通知组 FailTriggerTasksRaw string `gorm:"default:'[]'" json:"-"` RecoverTriggerTasksRaw string `gorm:"default:'[]'" json:"-"` Rules []Rule `gorm:"-" json:"rules"` diff --git a/model/alertrule_api.go b/model/alertrule_api.go index 194a8ef..074cb81 100644 --- a/model/alertrule_api.go +++ b/model/alertrule_api.go @@ -1,11 +1,11 @@ package model type AlertRuleForm struct { - Name string `json:"name"` + Name string `json:"name" minLength:"1"` Rules []Rule `json:"rules"` FailTriggerTasks []uint64 `json:"fail_trigger_tasks"` // 失败时触发的任务id RecoverTriggerTasks []uint64 `json:"recover_trigger_tasks"` // 恢复时触发的任务id NotificationGroupID uint64 `json:"notification_group_id"` - TriggerMode int `json:"trigger_mode"` - Enable bool `json:"enable"` + TriggerMode uint8 `json:"trigger_mode" default:"0"` + Enable bool `json:"enable" validate:"optional"` } diff --git a/model/config.go b/model/config.go index 70eb0c2..9887e4a 100644 --- a/model/config.go +++ b/model/config.go @@ -18,8 +18,8 @@ const ( type Config struct { Debug bool `mapstructure:"debug" json:"debug,omitempty"` // debug模式开关 - Language string `mapstructure:"language" json:"language,omitempty"` // 系统语言,默认 zh_CN - SiteName string `mapstructure:"site_name" json:"site_name,omitempty"` + Language string `mapstructure:"language" json:"language"` // 系统语言,默认 zh_CN + SiteName string `mapstructure:"site_name" json:"site_name"` JWTSecretKey string `mapstructure:"jwt_secret_key" json:"jwt_secret_key,omitempty"` AgentSecretKey string `mapstructure:"agent_secret_key" json:"agent_secret_key,omitempty"` ListenPort uint `mapstructure:"listen_port" json:"listen_port,omitempty"` @@ -31,8 +31,8 @@ type Config struct { // IP变更提醒 EnableIPChangeNotification bool `mapstructure:"enable_ip_change_notification" json:"enable_ip_change_notification,omitempty"` - IPChangeNotificationGroupID uint64 `mapstructure:"ip_change_notification_group_id" json:"ip_change_notification_group_id,omitempty"` - Cover uint8 `mapstructure:"cover" json:"cover,omitempty"` // 覆盖范围(0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;) + IPChangeNotificationGroupID uint64 `mapstructure:"ip_change_notification_group_id" json:"ip_change_notification_group_id"` + Cover uint8 `mapstructure:"cover" json:"cover"` // 覆盖范围(0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;) IgnoredIPNotification string `mapstructure:"ignored_ip_notification" json:"ignored_ip_notification,omitempty"` // 特定服务器IP(多个服务器用逗号分隔) IgnoredIPNotificationServerIDs map[uint64]bool `mapstructure:"ignored_ip_notification_server_ids" json:"ignored_ip_notification_server_ids,omitempty"` // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内) diff --git a/model/cron.go b/model/cron.go index f3a59ba..de3cbd9 100644 --- a/model/cron.go +++ b/model/cron.go @@ -18,16 +18,16 @@ const ( type Cron struct { Common - Name string `json:"name,omitempty"` - TaskType uint8 `gorm:"default:0" json:"task_type,omitempty"` // 0:计划任务 1:触发任务 - Scheduler string `json:"scheduler,omitempty"` // 分钟 小时 天 月 星期 + Name string `json:"name"` + TaskType uint8 `gorm:"default:0" json:"task_type"` // 0:计划任务 1:触发任务 + Scheduler string `json:"scheduler"` // 分钟 小时 天 月 星期 Command string `json:"command,omitempty"` - Servers []uint64 `gorm:"-" json:"servers,omitempty"` - PushSuccessful bool `json:"push_successful,omitempty"` // 推送成功的通知 - NotificationGroupID uint64 `json:"notification_group_id,omitempty"` // 指定通知方式的分组 - LastExecutedAt time.Time `json:"last_executed_at,omitempty"` // 最后一次执行时间 - LastResult bool `json:"last_result,omitempty"` // 最后一次执行结果 - Cover uint8 `json:"cover,omitempty"` // 计划任务覆盖范围 (0:仅覆盖特定服务器 1:仅忽略特定服务器 2:由触发该计划任务的服务器执行) + Servers []uint64 `gorm:"-" json:"servers"` + PushSuccessful bool `json:"push_successful,omitempty"` // 推送成功的通知 + NotificationGroupID uint64 `json:"notification_group_id"` // 指定通知方式的分组 + LastExecutedAt time.Time `json:"last_executed_at,omitempty"` // 最后一次执行时间 + LastResult bool `json:"last_result,omitempty"` // 最后一次执行结果 + Cover uint8 `json:"cover"` // 计划任务覆盖范围 (0:仅覆盖特定服务器 1:仅忽略特定服务器 2:由触发该计划任务的服务器执行) CronJobID cron.EntryID `gorm:"-" json:"cron_job_id,omitempty"` ServersRaw string `json:"-"` diff --git a/model/cron_api.go b/model/cron_api.go index c468b8d..a124ecf 100644 --- a/model/cron_api.go +++ b/model/cron_api.go @@ -2,12 +2,12 @@ package model type CronForm struct { ID uint64 `json:"id,omitempty"` - TaskType uint8 `json:"task_type,omitempty"` // 0:计划任务 1:触发任务 - Name string `json:"name,omitempty"` + TaskType uint8 `json:"task_type,omitempty" default:"0"` // 0:计划任务 1:触发任务 + Name string `json:"name,omitempty" minLength:"1"` Scheduler string `json:"scheduler,omitempty"` - Command string `json:"command,omitempty"` + Command string `json:"command,omitempty" validate:"optional"` Servers []uint64 `json:"servers,omitempty"` - Cover uint8 `json:"cover,omitempty"` - PushSuccessful bool `json:"push_successful,omitempty"` + Cover uint8 `json:"cover,omitempty" default:"0"` + PushSuccessful bool `json:"push_successful,omitempty" validate:"optional"` NotificationGroupID uint64 `json:"notification_group_id,omitempty"` } diff --git a/model/ddns.go b/model/ddns.go index 989e412..e38d947 100644 --- a/model/ddns.go +++ b/model/ddns.go @@ -22,9 +22,9 @@ type DDNSProfile struct { Common EnableIPv4 *bool `json:"enable_ipv4,omitempty"` EnableIPv6 *bool `json:"enable_ipv6,omitempty"` - MaxRetries uint64 `json:"max_retries,omitempty"` - Name string `json:"name,omitempty"` - Provider string `json:"provider,omitempty"` + MaxRetries uint64 `json:"max_retries"` + Name string `json:"name"` + Provider string `json:"provider"` AccessID string `json:"access_id,omitempty"` AccessSecret string `json:"access_secret,omitempty"` WebhookURL string `json:"webhook_url,omitempty"` @@ -32,7 +32,7 @@ type DDNSProfile struct { WebhookRequestType uint8 `json:"webhook_request_type,omitempty"` WebhookRequestBody string `json:"webhook_request_body,omitempty"` WebhookHeaders string `json:"webhook_headers,omitempty"` - Domains []string `json:"domains,omitempty" gorm:"-"` + Domains []string `json:"domains" gorm:"-"` DomainsRaw string `json:"-"` } diff --git a/model/ddns_api.go b/model/ddns_api.go index dba3a51..d14c464 100644 --- a/model/ddns_api.go +++ b/model/ddns_api.go @@ -1,17 +1,17 @@ package model type DDNSForm struct { - MaxRetries uint64 `json:"max_retries,omitempty"` - EnableIPv4 bool `json:"enable_ipv4,omitempty"` - EnableIPv6 bool `json:"enable_ipv6,omitempty"` - Name string `json:"name,omitempty"` + MaxRetries uint64 `json:"max_retries,omitempty" default:"3"` + EnableIPv4 bool `json:"enable_ipv4,omitempty" validate:"optional"` + EnableIPv6 bool `json:"enable_ipv6,omitempty" validate:"optional"` + Name string `json:"name,omitempty" minLength:"1"` Provider string `json:"provider,omitempty"` Domains []string `json:"domains,omitempty"` - AccessID string `json:"access_id,omitempty"` - AccessSecret string `json:"access_secret,omitempty"` - WebhookURL string `json:"webhook_url,omitempty"` - WebhookMethod uint8 `json:"webhook_method,omitempty"` - WebhookRequestType uint8 `json:"webhook_request_type,omitempty"` - WebhookRequestBody string `json:"webhook_request_body,omitempty"` - WebhookHeaders string `json:"webhook_headers,omitempty"` + AccessID string `json:"access_id,omitempty" validate:"optional"` + AccessSecret string `json:"access_secret,omitempty" validate:"optional"` + WebhookURL string `json:"webhook_url,omitempty" validate:"optional"` + WebhookMethod uint8 `json:"webhook_method,omitempty" validate:"optional" default:"1"` + WebhookRequestType uint8 `json:"webhook_request_type,omitempty" validate:"optional" default:"1"` + WebhookRequestBody string `json:"webhook_request_body,omitempty" validate:"optional"` + WebhookHeaders string `json:"webhook_headers,omitempty" validate:"optional"` } diff --git a/model/nat.go b/model/nat.go index 83ac5fa..f43ab0f 100644 --- a/model/nat.go +++ b/model/nat.go @@ -2,8 +2,8 @@ package model type NAT struct { Common - Name string - ServerID uint64 - Host string - Domain string `gorm:"unique"` + Name string `json:"name"` + ServerID uint64 `json:"server_id"` + Host string `json:"host"` + Domain string `json:"domain" gorm:"unique"` } diff --git a/model/nat_api.go b/model/nat_api.go index 7f7665f..97e4738 100644 --- a/model/nat_api.go +++ b/model/nat_api.go @@ -1,7 +1,7 @@ package model type NATForm struct { - Name string `json:"name,omitempty"` + Name string `json:"name,omitempty" minLength:"1"` ServerID uint64 `json:"server_id,omitempty"` Host string `json:"host,omitempty"` Domain string `json:"domain,omitempty"` diff --git a/model/notification.go b/model/notification.go index 02c683b..10ad186 100644 --- a/model/notification.go +++ b/model/notification.go @@ -32,12 +32,12 @@ type NotificationServerBundle struct { type Notification struct { Common - Name string `json:"name,omitempty"` - URL string `json:"url,omitempty"` - RequestMethod int `json:"request_method,omitempty"` - RequestType int `json:"request_type,omitempty"` - RequestHeader string `json:"request_header,omitempty" gorm:"type:longtext"` - RequestBody string `json:"request_body,omitempty" gorm:"type:longtext"` + Name string `json:"name"` + URL string `json:"url"` + RequestMethod uint8 `json:"request_method"` + RequestType uint8 `json:"request_type"` + RequestHeader string `json:"request_header" gorm:"type:longtext"` + RequestBody string `json:"request_body" gorm:"type:longtext"` VerifyTLS *bool `json:"verify_tls,omitempty"` } diff --git a/model/notification_api.go b/model/notification_api.go index 8f36189..5bee8d2 100644 --- a/model/notification_api.go +++ b/model/notification_api.go @@ -1,12 +1,12 @@ package model type NotificationForm struct { - Name string `json:"name,omitempty"` + Name string `json:"name,omitempty" minLength:"1"` URL string `json:"url,omitempty"` - RequestMethod int `json:"request_method,omitempty"` - RequestType int `json:"request_type,omitempty"` + RequestMethod uint8 `json:"request_method,omitempty"` + RequestType uint8 `json:"request_type,omitempty"` RequestHeader string `json:"request_header,omitempty"` RequestBody string `json:"request_body,omitempty"` - VerifyTLS bool `json:"verify_tls,omitempty"` - SkipCheck bool `json:"skip_check,omitempty"` + VerifyTLS bool `json:"verify_tls,omitempty" validate:"optional"` + SkipCheck bool `json:"skip_check,omitempty" validate:"optional"` } diff --git a/model/notification_group_api.go b/model/notification_group_api.go index bac006e..68cc759 100644 --- a/model/notification_group_api.go +++ b/model/notification_group_api.go @@ -1,7 +1,7 @@ package model type NotificationGroupForm struct { - Name string `json:"name"` + Name string `json:"name" minLength:"1"` Notifications []uint64 `json:"notifications"` } diff --git a/model/notification_test.go b/model/notification_test.go index 0a5112c..515ea7d 100644 --- a/model/notification_test.go +++ b/model/notification_test.go @@ -17,8 +17,8 @@ type testSt struct { url string body string header string - reqType int - reqMethod int + reqType uint8 + reqMethod uint8 expectURL string expectBody string expectMethod string diff --git a/model/server.go b/model/server.go index 090f186..c26cba6 100644 --- a/model/server.go +++ b/model/server.go @@ -14,16 +14,16 @@ import ( type Server struct { Common - Name string `json:"name,omitempty"` + Name string `json:"name"` UUID string `json:"uuid,omitempty" gorm:"unique"` Note string `json:"note,omitempty"` // 管理员可见备注 PublicNote string `json:"public_note,omitempty"` // 公开备注 - DisplayIndex int `json:"display_index,omitempty"` // 展示排序,越大越靠前 + DisplayIndex int `json:"display_index"` // 展示排序,越大越靠前 HideForGuest bool `json:"hide_for_guest,omitempty"` // 对游客隐藏 EnableDDNS bool `json:"enable_ddns,omitempty"` // 启用DDNS DDNSProfilesRaw string `gorm:"default:'[]';column:ddns_profiles_raw" json:"-"` - DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles,omitempty"` // DDNS配置 + DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles"` // DDNS配置 Host *Host `gorm:"-" json:"host,omitempty"` State *HostState `gorm:"-" json:"state,omitempty"` diff --git a/model/server_api.go b/model/server_api.go index 3b9d7a6..ddd5abe 100644 --- a/model/server_api.go +++ b/model/server_api.go @@ -20,10 +20,10 @@ type StreamServerData struct { type ServerForm struct { Name string `json:"name,omitempty"` - Note string `json:"note,omitempty"` // 管理员可见备注 - PublicNote string `json:"public_note,omitempty"` // 公开备注 - DisplayIndex int `json:"display_index,omitempty"` // 展示排序,越大越靠前 - HideForGuest bool `json:"hide_for_guest,omitempty"` // 对游客隐藏 - EnableDDNS bool `json:"enable_ddns,omitempty"` // 启用DDNS - DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles,omitempty"` // DDNS配置 + Note string `json:"note,omitempty" validate:"optional"` // 管理员可见备注 + PublicNote string `json:"public_note,omitempty" validate:"optional"` // 公开备注 + DisplayIndex int `json:"display_index,omitempty" default:"0"` // 展示排序,越大越靠前 + HideForGuest bool `json:"hide_for_guest,omitempty" validate:"optional"` // 对游客隐藏 + EnableDDNS bool `json:"enable_ddns,omitempty" validate:"optional"` // 启用DDNS + DDNSProfiles []uint64 `gorm:"-" json:"ddns_profiles,omitempty"` // DDNS配置 } diff --git a/model/server_group_api.go b/model/server_group_api.go index 591b5d2..e36a236 100644 --- a/model/server_group_api.go +++ b/model/server_group_api.go @@ -1,7 +1,7 @@ package model type ServerGroupForm struct { - Name string `json:"name"` + Name string `json:"name" minLength:"1"` Servers []uint64 `json:"servers"` } diff --git a/model/service.go b/model/service.go index 6262c92..019e7c5 100644 --- a/model/service.go +++ b/model/service.go @@ -63,8 +63,8 @@ type Service struct { FailTriggerTasks []uint64 `gorm:"-" json:"fail_trigger_tasks"` // 失败时执行的触发任务id RecoverTriggerTasks []uint64 `gorm:"-" json:"recover_trigger_tasks"` // 恢复时执行的触发任务id - MinLatency float32 `json:"min_latency,omitempty"` - MaxLatency float32 `json:"max_latency,omitempty"` + MinLatency float32 `json:"min_latency"` + MaxLatency float32 `json:"max_latency"` LatencyNotify bool `json:"latency_notify,omitempty"` SkipServers map[uint64]bool `gorm:"-" json:"skip_servers"` diff --git a/model/service_api.go b/model/service_api.go index 6a394ba..c52b6f9 100644 --- a/model/service_api.go +++ b/model/service_api.go @@ -3,17 +3,17 @@ package model import "time" type ServiceForm struct { - Name string `json:"name,omitempty"` + Name string `json:"name,omitempty" minLength:"1"` Target string `json:"target,omitempty"` Type uint8 `json:"type,omitempty"` Cover uint8 `json:"cover,omitempty"` - Notify bool `json:"notify,omitempty"` + Notify bool `json:"notify,omitempty" validate:"optional"` Duration uint64 `json:"duration,omitempty"` - MinLatency float32 `json:"min_latency,omitempty"` - MaxLatency float32 `json:"max_latency,omitempty"` - LatencyNotify bool `json:"latency_notify,omitempty"` - EnableTriggerTask bool `json:"enable_trigger_task,omitempty"` - EnableShowInService bool `json:"enable_show_in_service,omitempty"` + MinLatency float32 `json:"min_latency,omitempty" default:"0.0"` + MaxLatency float32 `json:"max_latency,omitempty" default:"0.0"` + LatencyNotify bool `json:"latency_notify,omitempty" validate:"optional"` + EnableTriggerTask bool `json:"enable_trigger_task,omitempty" validate:"optional"` + EnableShowInService bool `json:"enable_show_in_service,omitempty" validate:"optional"` FailTriggerTasks []uint64 `json:"fail_trigger_tasks,omitempty"` RecoverTriggerTasks []uint64 `json:"recover_trigger_tasks,omitempty"` SkipServers map[uint64]bool `json:"skip_servers,omitempty"` diff --git a/model/setting_api.go b/model/setting_api.go index a3cdf6d..b48a8eb 100644 --- a/model/setting_api.go +++ b/model/setting_api.go @@ -1,16 +1,16 @@ package model type SettingForm struct { - CustomNameservers string `json:"custom_nameservers,omitempty"` - IgnoredIPNotification string `json:"ignored_ip_notification,omitempty"` + CustomNameservers string `json:"custom_nameservers,omitempty" validate:"optional"` + IgnoredIPNotification string `json:"ignored_ip_notification,omitempty" validate:"optional"` IPChangeNotificationGroupID uint64 `json:"ip_change_notification_group_id,omitempty"` // IP变更提醒的通知组 Cover uint8 `json:"cover,omitempty"` SiteName string `json:"site_name,omitempty"` Language string `json:"language,omitempty"` - InstallHost string `json:"install_host,omitempty"` - CustomCode string `json:"custom_code,omitempty"` - CustomCodeDashboard string `json:"custom_code_dashboard,omitempty"` + InstallHost string `json:"install_host,omitempty" validate:"optional"` + CustomCode string `json:"custom_code,omitempty" validate:"optional"` + CustomCodeDashboard string `json:"custom_code_dashboard,omitempty" validate:"optional"` - EnableIPChangeNotification bool `json:"enable_ip_change_notification,omitempty"` - EnablePlainIPInNotification bool `json:"enable_plain_ip_in_notification,omitempty"` + EnableIPChangeNotification bool `json:"enable_ip_change_notification,omitempty" validate:"optional"` + EnablePlainIPInNotification bool `json:"enable_plain_ip_in_notification,omitempty" validate:"optional"` } diff --git a/model/transfer.go b/model/transfer.go index 0cbde6c..78a98a1 100644 --- a/model/transfer.go +++ b/model/transfer.go @@ -2,7 +2,7 @@ package model type Transfer struct { Common - ServerID uint64 - In uint64 - Out uint64 + ServerID uint64 `json:"server_id"` + In uint64 `json:"in"` + Out uint64 `json:"out"` }