diff --git a/internal/data/monitor.go b/internal/data/monitor.go index a584e5a6..e4c129f8 100644 --- a/internal/data/monitor.go +++ b/internal/data/monitor.go @@ -35,7 +35,7 @@ func (r monitorRepo) GetSetting() (*request.MonitorSetting, error) { setting := new(request.MonitorSetting) setting.Enabled = cast.ToBool(monitor) - setting.Days = cast.ToInt(monitorDays) + setting.Days = cast.ToUint(monitorDays) return setting, nil } diff --git a/internal/http/request/app.go b/internal/http/request/app.go index f47b4d2b..84d6794f 100644 --- a/internal/http/request/app.go +++ b/internal/http/request/app.go @@ -1,7 +1,7 @@ package request type App struct { - Slug string `json:"slug" form:"slug" validate:"required|not_exists:apps,slug"` + Slug string `json:"slug" form:"slug" validate:"required|notExists:apps,slug"` Channel string `json:"channel" form:"channel" validate:"required"` } diff --git a/internal/http/request/cert.go b/internal/http/request/cert.go index 26856a67..855ca403 100644 --- a/internal/http/request/cert.go +++ b/internal/http/request/cert.go @@ -27,6 +27,6 @@ type CertUpdate struct { } type CertDeploy struct { - ID uint `form:"id" json:"id" validate:"required,exists:certs,id"` - WebsiteID uint `form:"website_id" json:"website_id" validate:"required"` + ID uint `form:"id" json:"id" validate:"required|exists:certs,id"` + WebsiteID uint `form:"website_id" json:"website_id" validate:"required|exists:websites,id"` } diff --git a/internal/http/request/cert_dns.go b/internal/http/request/cert_dns.go index 20fe4714..78dcb3b0 100644 --- a/internal/http/request/cert_dns.go +++ b/internal/http/request/cert_dns.go @@ -5,12 +5,12 @@ import "github.com/TheTNB/panel/pkg/acme" type CertDNSCreate struct { Type string `form:"type" json:"type" validate:"required"` Name string `form:"name" json:"name" validate:"required"` - Data acme.DNSParam `form:"data" json:"data"` + Data acme.DNSParam `form:"data" json:"data" validate:"required"` } type CertDNSUpdate struct { ID uint `form:"id" json:"id" validate:"required|exists:cert_dns,id"` Type string `form:"type" json:"type" validate:"required"` Name string `form:"name" json:"name" validate:"required"` - Data acme.DNSParam `form:"data" json:"data"` + Data acme.DNSParam `form:"data" json:"data" validate:"required"` } diff --git a/internal/http/request/common.go b/internal/http/request/common.go index 5881b294..fe85395d 100644 --- a/internal/http/request/common.go +++ b/internal/http/request/common.go @@ -1,5 +1,5 @@ package request type ID struct { - ID uint `json:"id" form:"id" query:"id" validate:"required|number"` + ID uint `json:"id" form:"id" query:"id" validate:"required|min:1"` } diff --git a/internal/http/request/container_image.go b/internal/http/request/container_image.go index 3d8ff4a0..f3c4aae8 100644 --- a/internal/http/request/container_image.go +++ b/internal/http/request/container_image.go @@ -7,6 +7,6 @@ type ContainerImageID struct { type ContainerImagePull struct { Name string `form:"name" json:"name" validate:"required"` Auth bool `form:"auth" json:"auth"` - Username string `form:"username" json:"username"` - Password string `form:"password" json:"password"` + Username string `form:"username" json:"username" validate:"requiredIf=Auth,true"` + Password string `form:"password" json:"password" validate:"requiredIf=Auth,true"` } diff --git a/internal/http/request/container_network.go b/internal/http/request/container_network.go index 10b6ac3a..b6d0507a 100644 --- a/internal/http/request/container_network.go +++ b/internal/http/request/container_network.go @@ -8,7 +8,7 @@ type ContainerNetworkID struct { type ContainerNetworkCreate struct { Name string `form:"name" json:"name" validate:"required"` - Driver string `form:"driver" json:"driver"` + Driver string `form:"driver" json:"driver" validate:"required|in:bridge,host,overlay,macvlan,ipvlan,none"` Ipv4 types.ContainerContainerNetwork `form:"ipv4" json:"ipv4"` Ipv6 types.ContainerContainerNetwork `form:"ipv6" json:"ipv6"` Labels []types.KV `form:"labels" json:"labels"` diff --git a/internal/http/request/container_volume.go b/internal/http/request/container_volume.go index e3f297cc..c17003fb 100644 --- a/internal/http/request/container_volume.go +++ b/internal/http/request/container_volume.go @@ -8,7 +8,7 @@ type ContainerVolumeID struct { type ContainerVolumeCreate struct { Name string `form:"name" json:"name" validate:"required"` - Driver string `form:"driver" json:"driver"` + Driver string `form:"driver" json:"driver" validate:"required|in:local"` Labels []types.KV `form:"labels" json:"labels"` Options []types.KV `form:"options" json:"options"` } diff --git a/internal/http/request/cron.go b/internal/http/request/cron.go index c53ca1b3..454052e3 100644 --- a/internal/http/request/cron.go +++ b/internal/http/request/cron.go @@ -1,11 +1,11 @@ package request type CronCreate struct { - Name string `form:"name" json:"name" validate:"required|not_exists:crons,name"` + Name string `form:"name" json:"name" validate:"required|notExists:crons,name"` Type string `form:"type" json:"type" validate:"required"` Time string `form:"time" json:"time" validate:"required|cron"` Script string `form:"script" json:"script"` - BackupType string `form:"backup_type" json:"backup_type" validate:"required"` + BackupType string `form:"backup_type" json:"backup_type" validate:"requiredIf=Type,backup"` BackupPath string `form:"backup_path" json:"backup_path"` Target string `form:"target" json:"target" validate:"required"` Save int `form:"save" json:"save" validate:"required"` diff --git a/internal/http/request/database.go b/internal/http/request/database.go index 45fb0e60..95b0252e 100644 --- a/internal/http/request/database.go +++ b/internal/http/request/database.go @@ -4,8 +4,8 @@ type DatabaseCreate struct { ServerID uint `form:"server_id" json:"server_id" validate:"required|exists:database_servers,id"` Name string `form:"name" json:"name" validate:"required"` CreateUser bool `form:"create_user" json:"create_user"` - Username string `form:"username" json:"username" validate:"required_if:CreateUser,true"` - Password string `form:"password" json:"password" validate:"required_if:CreateUser,true"` + Username string `form:"username" json:"username" validate:"requiredIf:CreateUser,true"` + Password string `form:"password" json:"password" validate:"requiredIf:CreateUser,true"` Host string `form:"host" json:"host"` Comment string `form:"comment" json:"comment"` } diff --git a/internal/http/request/database_server.go b/internal/http/request/database_server.go index dbb31f67..e65bba7f 100644 --- a/internal/http/request/database_server.go +++ b/internal/http/request/database_server.go @@ -1,10 +1,10 @@ package request type DatabaseServerCreate struct { - Name string `form:"name" json:"name" validate:"required|not_exists:database_servers,name"` + Name string `form:"name" json:"name" validate:"required|notExists:database_servers,name"` Type string `form:"type" json:"type" validate:"required|in:mysql,postgresql,redis"` Host string `form:"host" json:"host" validate:"required"` - Port uint `form:"port" json:"port" validate:"required|number|min:1|max:65535"` + Port uint `form:"port" json:"port" validate:"required|min:1|max:65535"` Username string `form:"username" json:"username"` Password string `form:"password" json:"password"` Remark string `form:"remark" json:"remark"` @@ -14,7 +14,7 @@ type DatabaseServerUpdate struct { ID uint `form:"id" json:"id" validate:"required|exists:database_servers,id"` Name string `form:"name" json:"name" validate:"required"` Host string `form:"host" json:"host" validate:"required"` - Port uint `form:"port" json:"port" validate:"required|number|min:1|max:65535"` + Port uint `form:"port" json:"port" validate:"required|min:1|max:65535"` Username string `form:"username" json:"username"` Password string `form:"password" json:"password"` Remark string `form:"remark" json:"remark"` diff --git a/internal/http/request/file.go b/internal/http/request/file.go index e678ddb5..27b3548c 100644 --- a/internal/http/request/file.go +++ b/internal/http/request/file.go @@ -7,55 +7,55 @@ import ( ) type FileList struct { - Path string `json:"path" form:"path" validate:"required"` + Path string `json:"path" form:"path" validate:"required|isUnixPath"` Sort string `json:"sort" form:"sort"` } type FilePath struct { - Path string `json:"path" form:"path" validate:"required"` + Path string `json:"path" form:"path" validate:"required|isUnixPath"` } type FileCreate struct { Dir bool `json:"dir" form:"dir"` - Path string `json:"path" form:"path" validate:"required"` + Path string `json:"path" form:"path" validate:"required|isUnixPath"` } type FileSave struct { - Path string `form:"path" json:"path" validate:"required"` + Path string `form:"path" json:"path" validate:"required|isUnixPath"` Content string `form:"content" json:"content"` } type FileControl struct { - Source string `form:"source" json:"source" validate:"required"` - Target string `form:"target" json:"target" validate:"required"` + Source string `form:"source" json:"source" validate:"required|isUnixPath"` + Target string `form:"target" json:"target" validate:"required|isUnixPath"` Force bool `form:"force" json:"force"` } type FileRemoteDownload struct { - Path string `form:"path" json:"path" validate:"required"` - URL string `form:"url" json:"url" validate:"required"` + Path string `form:"path" json:"path" validate:"required|isUnixPath"` + URL string `form:"url" json:"url" validate:"required|isFullURL"` } type FilePermission struct { - Path string `form:"path" json:"path" validate:"required"` + Path string `form:"path" json:"path" validate:"required|isUnixPath"` Mode string `form:"mode" json:"mode" validate:"required"` Owner string `form:"owner" json:"owner" validate:"required"` Group string `form:"group" json:"group" validate:"required"` } type FileCompress struct { - Dir string `form:"dir" json:"dir" validate:"required"` + Dir string `form:"dir" json:"dir" validate:"required|isUnixPath"` Paths []string `form:"paths" json:"paths" validate:"required"` - File string `form:"file" json:"file" validate:"required"` + File string `form:"file" json:"file" validate:"required|isUnixPath"` } type FileUnCompress struct { - File string `form:"file" json:"file" validate:"required"` - Path string `form:"path" json:"path" validate:"required"` + File string `form:"file" json:"file" validate:"required|isUnixPath"` + Path string `form:"path" json:"path" validate:"required|isUnixPath"` } type FileSearch struct { - Path string `form:"path" json:"path" validate:"required"` + Path string `form:"path" json:"path" validate:"required|isUnixPath"` Keyword string `form:"keyword" json:"keyword" validate:"required"` Sub bool `form:"sub" json:"sub"` } diff --git a/internal/http/request/firewall.go b/internal/http/request/firewall.go index dfc74fe9..ff85e28f 100644 --- a/internal/http/request/firewall.go +++ b/internal/http/request/firewall.go @@ -12,7 +12,7 @@ type FirewallRule struct { Protocol string `json:"protocol" validate:"required|in:tcp,udp,tcp/udp"` Address string `json:"address"` Strategy string `json:"strategy" validate:"required|in:accept,drop,reject"` - Direction string `json:"direction"` + Direction string `json:"direction" validate:"required|in:in,out"` } type FirewallIPRule struct { @@ -20,7 +20,7 @@ type FirewallIPRule struct { Protocol string `json:"protocol" validate:"required|in:tcp,udp,tcp/udp"` Address string `json:"address"` Strategy string `json:"strategy" validate:"required|in:accept,drop,reject"` - Direction string `json:"direction"` + Direction string `json:"direction" validate:"required|in:in,out"` } type FirewallForward struct { diff --git a/internal/http/request/monitor.go b/internal/http/request/monitor.go index 82a1543d..76135900 100644 --- a/internal/http/request/monitor.go +++ b/internal/http/request/monitor.go @@ -2,7 +2,7 @@ package request type MonitorSetting struct { Enabled bool `json:"enabled"` - Days int `json:"days"` + Days uint `json:"days"` } type MonitorList struct { diff --git a/internal/http/request/paginate.go b/internal/http/request/paginate.go index 2126e761..b4d7f186 100644 --- a/internal/http/request/paginate.go +++ b/internal/http/request/paginate.go @@ -5,8 +5,8 @@ import ( ) type Paginate struct { - Page uint `json:"page" form:"page" query:"page" validate:"required|number|min:1"` - Limit uint `json:"limit" form:"limit" query:"limit" validate:"required|number|min:1|max:10000"` + Page uint `json:"page" form:"page" query:"page" validate:"required|min:1"` + Limit uint `json:"limit" form:"limit" query:"limit" validate:"required|min:1|max:10000"` } func (r *Paginate) Messages(_ *http.Request) map[string]string { diff --git a/internal/http/request/safe.go b/internal/http/request/safe.go index 47e912ef..c1f63a61 100644 --- a/internal/http/request/safe.go +++ b/internal/http/request/safe.go @@ -1,7 +1,7 @@ package request type SafeUpdateSSH struct { - Port uint `json:"port" form:"port" validate:"number|min:1|max:65535"` + Port uint `json:"port" form:"port" validate:"required|min:1|max:65535"` Status bool `json:"status" form:"status"` } diff --git a/internal/http/request/setting.go b/internal/http/request/setting.go index 980b4f7f..9c303a51 100644 --- a/internal/http/request/setting.go +++ b/internal/http/request/setting.go @@ -10,7 +10,7 @@ type PanelSetting struct { Username string `json:"username" validate:"required"` Password string `json:"password" validate:"password"` Email string `json:"email" validate:"required"` - Port uint `json:"port" validate:"number|min:1|max:65535"` + Port uint `json:"port" validate:"required|min:1|max:65535"` HTTPS bool `json:"https"` Cert string `json:"cert" validate:"required"` Key string `json:"key" validate:"required"` diff --git a/internal/http/request/ssh.go b/internal/http/request/ssh.go index 37c08bdf..52dab1c7 100644 --- a/internal/http/request/ssh.go +++ b/internal/http/request/ssh.go @@ -3,11 +3,11 @@ package request type SSHCreate struct { Name string `json:"name" form:"name"` Host string `json:"host" form:"host" validate:"required"` - Port uint `json:"port" form:"port" validate:"number|min:1|max:65535"` + Port uint `json:"port" form:"port" validate:"required|min:1|max:65535"` AuthMethod string `json:"auth_method" form:"auth_method" validate:"required|in:password,publickey"` - User string `json:"user" form:"user" validate:"required_if:AuthMethod,password"` - Password string `json:"password" form:"password" validate:"required_if:AuthMethod,password"` - Key string `json:"key" form:"key" validate:"required_if:AuthMethod,publickey"` + User string `json:"user" form:"user" validate:"requiredIf:AuthMethod,password"` + Password string `json:"password" form:"password" validate:"requiredIf:AuthMethod,password"` + Key string `json:"key" form:"key" validate:"requiredIf:AuthMethod,publickey"` Remark string `json:"remark" form:"remark"` } @@ -15,10 +15,10 @@ type SSHUpdate struct { ID uint `form:"id" json:"id" validate:"required|exists:sshes,id"` Name string `json:"name" form:"name"` Host string `json:"host" form:"host" validate:"required"` - Port uint `json:"port" form:"port" validate:"number|min:1|max:65535"` + Port uint `json:"port" form:"port" validate:"required|min:1|max:65535"` AuthMethod string `json:"auth_method" form:"auth_method" validate:"required|in:password,publickey"` - User string `json:"user" form:"user" validate:"required_if:AuthMethod,password"` - Password string `json:"password" form:"password" validate:"required_if:AuthMethod,password"` - Key string `json:"key" form:"key" validate:"required_if:AuthMethod,publickey"` + User string `json:"user" form:"user" validate:"requiredIf:AuthMethod,password"` + Password string `json:"password" form:"password" validate:"requiredIf:AuthMethod,password"` + Key string `json:"key" form:"key" validate:"requiredIf:AuthMethod,publickey"` Remark string `json:"remark" form:"remark"` } diff --git a/internal/http/request/website.go b/internal/http/request/website.go index 2b334dea..ee2cbc8f 100644 --- a/internal/http/request/website.go +++ b/internal/http/request/website.go @@ -8,16 +8,16 @@ type WebsiteDefaultConfig struct { } type WebsiteCreate struct { - Name string `form:"name" json:"name" validate:"required|not_exists:websites,name"` + Name string `form:"name" json:"name" validate:"required|notExists:websites,name"` Listens []string `form:"listens" json:"listens" validate:"required"` Domains []string `form:"domains" json:"domains" validate:"required"` Path string `form:"path" json:"path"` PHP int `form:"php" json:"php"` DB bool `form:"db" json:"db"` - DBType string `form:"db_type" json:"db_type" validate:"required_if:DB,true"` - DBName string `form:"db_name" json:"db_name" validate:"required_if:DB,true"` - DBUser string `form:"db_user" json:"db_user" validate:"required_if:DB,true"` - DBPassword string `form:"db_password" json:"db_password" validate:"required_if:DB,true"` + DBType string `form:"db_type" json:"db_type" validate:"requiredIf:DB,true"` + DBName string `form:"db_name" json:"db_name" validate:"requiredIf:DB,true"` + DBUser string `form:"db_user" json:"db_user" validate:"requiredIf:DB,true"` + DBPassword string `form:"db_password" json:"db_password" validate:"requiredIf:DB,true"` Remark string `form:"remark" json:"remark"` } @@ -42,8 +42,8 @@ type WebsiteUpdate struct { Raw string `form:"raw" json:"raw"` Rewrite string `form:"rewrite" json:"rewrite"` PHP int `form:"php" json:"php"` - SSLCertificate string `form:"ssl_certificate" json:"ssl_certificate" validate:"required_if:HTTPS,true"` - SSLCertificateKey string `form:"ssl_certificate_key" json:"ssl_certificate_key" validate:"required_if:HTTPS,true"` + SSLCertificate string `form:"ssl_certificate" json:"ssl_certificate" validate:"requiredIf:HTTPS,true"` + SSLCertificateKey string `form:"ssl_certificate_key" json:"ssl_certificate_key" validate:"requiredIf:HTTPS,true"` } type WebsiteUpdateRemark struct { diff --git a/internal/http/rule/not_exists.go b/internal/http/rule/not_exists.go index 7ee89bb5..e703d5fa 100644 --- a/internal/http/rule/not_exists.go +++ b/internal/http/rule/not_exists.go @@ -8,10 +8,10 @@ import ( // NotExists 验证一个值在某个表中的字段中不存在,支持同时判断多个字段 // NotExists verify a value does not exist in a table field, support judging multiple fields at the same time -// 用法:not_exists:表名称,字段名称,字段名称,字段名称 -// Usage: not_exists:table_name,field_name,field_name,field_name -// 例子:not_exists:users,phone,email -// Example: not_exists:users,phone,email +// 用法:notExists:表名称,字段名称,字段名称,字段名称 +// Usage: notExists:table_name,field_name,field_name,field_name +// 例子:notExists:users,phone,email +// Example: notExists:users,phone,email type NotExists struct { DB *gorm.DB } diff --git a/internal/http/rule/rule.go b/internal/http/rule/rule.go index 75266e38..07e02fe0 100644 --- a/internal/http/rule/rule.go +++ b/internal/http/rule/rule.go @@ -7,15 +7,15 @@ import ( func GlobalRules(db *gorm.DB) { validate.AddValidators(validate.M{ - "exists": NewExists(db).Passes, - "not_exists": NewNotExists(db).Passes, - "password": NewPassword().Passes, - "cron": NewCron().Passes, + "exists": NewExists(db).Passes, + "notExists": NewNotExists(db).Passes, + "password": NewPassword().Passes, + "cron": NewCron().Passes, }) validate.AddGlobalMessages(map[string]string{ - "exists": "{field} 不存在", - "not_exists": "{field} 已存在", - "password": "密码不满足要求(8-20位,至少包含字母、数字、特殊字符中的两种)", - "cron": "Cron 表达式不合法", + "exists": "{field} 不存在", + "notExists": "{field} 已存在", + "password": "密码不满足要求(8-20位,至少包含字母、数字、特殊字符中的两种)", + "cron": "Cron 表达式不合法", }) } diff --git a/renovate.json b/renovate.json index 1edb31ce..308cf6fa 100644 --- a/renovate.json +++ b/renovate.json @@ -28,7 +28,5 @@ "automerge": true } ], - "ignoreDeps": [ - "typescript" - ] + "ignoreDeps": [] }