mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 03:07:20 +08:00
feat: 添加切片的校验
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package request
|
||||
|
||||
import "net/http"
|
||||
|
||||
type CertUpload struct {
|
||||
Cert string `form:"cert" json:"cert" validate:"required"`
|
||||
Key string `form:"key" json:"key" validate:"required"`
|
||||
@@ -14,6 +16,12 @@ type CertCreate struct {
|
||||
WebsiteID uint `form:"website_id" json:"website_id"`
|
||||
}
|
||||
|
||||
func (r *CertCreate) Rules(_ *http.Request) map[string]string {
|
||||
return map[string]string{
|
||||
"Domains.*": "required",
|
||||
}
|
||||
}
|
||||
|
||||
type CertUpdate struct {
|
||||
ID uint `form:"id" json:"id" validate:"required|exists:certs,id"`
|
||||
Type string `form:"type" json:"type" validate:"required|in:P256,P384,2048,3072,4096,upload"`
|
||||
@@ -27,6 +35,12 @@ type CertUpdate struct {
|
||||
WebsiteID uint `form:"website_id" json:"website_id"`
|
||||
}
|
||||
|
||||
func (r *CertUpdate) Rules(_ *http.Request) map[string]string {
|
||||
return map[string]string{
|
||||
"Domains.*": "required",
|
||||
}
|
||||
}
|
||||
|
||||
type CertDeploy struct {
|
||||
ID uint `form:"id" json:"id" validate:"required|exists:certs,id"`
|
||||
WebsiteID uint `form:"website_id" json:"website_id" validate:"required|exists:websites,id"`
|
||||
|
||||
@@ -56,6 +56,12 @@ type FileCompress struct {
|
||||
File string `form:"file" json:"file" validate:"required|isUnixPath"`
|
||||
}
|
||||
|
||||
func (r *FileCompress) Rules(_ *http.Request) map[string]string {
|
||||
return map[string]string{
|
||||
"Paths.*": "required",
|
||||
}
|
||||
}
|
||||
|
||||
type FileUnCompress struct {
|
||||
File string `form:"file" json:"file" validate:"required|isUnixPath"`
|
||||
Path string `form:"path" json:"path" validate:"required|isUnixPath"`
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/acepanel/panel/pkg/webserver/types"
|
||||
)
|
||||
|
||||
@@ -12,6 +14,12 @@ type WebsiteDefaultConfig struct {
|
||||
CipherSuites string `json:"cipher_suites" form:"cipher_suites" validate:"required"`
|
||||
}
|
||||
|
||||
func (r *WebsiteDefaultConfig) Rules(_ *http.Request) map[string]string {
|
||||
return map[string]string{
|
||||
"TLSVersions.*": "required",
|
||||
}
|
||||
}
|
||||
|
||||
type WebsiteList struct {
|
||||
Type string `json:"type" form:"type" validate:"required|in:all,proxy,static,php"`
|
||||
Paginate
|
||||
@@ -34,6 +42,13 @@ type WebsiteCreate struct {
|
||||
Proxy string `form:"proxy" json:"proxy" validate:"requiredIf:Type,proxy"` // 仅反向代理网站需要
|
||||
}
|
||||
|
||||
func (r *WebsiteCreate) Rules(_ *http.Request) map[string]string {
|
||||
return map[string]string{
|
||||
"Listens.*": "required",
|
||||
"Domains.*": "required",
|
||||
}
|
||||
}
|
||||
|
||||
type WebsiteDelete struct {
|
||||
ID uint `form:"id" json:"id" validate:"required|exists:websites,id"`
|
||||
Path bool `form:"path" json:"path"`
|
||||
@@ -81,6 +96,14 @@ type WebsiteUpdate struct {
|
||||
CustomConfigs []WebsiteCustomConfig `json:"custom_configs"`
|
||||
}
|
||||
|
||||
func (r *WebsiteUpdate) Rules(_ *http.Request) map[string]string {
|
||||
return map[string]string{
|
||||
"Listens.*": "required",
|
||||
"Domains.*": "required",
|
||||
"Index.*": "required",
|
||||
}
|
||||
}
|
||||
|
||||
// WebsiteCustomConfig 网站自定义配置请求
|
||||
type WebsiteCustomConfig struct {
|
||||
Name string `json:"name" validate:"required|regex:^[a-zA-Z0-9_-]+$"` // 配置名称
|
||||
|
||||
Reference in New Issue
Block a user