特殊页面可以直接使用HTML

This commit is contained in:
GoEdgeLab
2021-10-10 10:35:09 +08:00
parent 146b477c17
commit 1935fc83d8
5 changed files with 131 additions and 57 deletions

View File

@@ -1,27 +1,31 @@
package serverconfigs
// 特殊页面配置
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
// HTTPPageConfig 特殊页面配置
// TODO 需要支持Header定义
// TODO 需要可以自定义文本
type HTTPPageConfig struct {
Id int64 `yaml:"id" json:"id"` // 页面ID
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启 TODO
Status []string `yaml:"status" json:"status"` // 响应支持40x, 50x, 3x2
URL string `yaml:"url" json:"url"` // URL
NewStatus int `yaml:"newStatus" json:"newStatus"` // 新状态码
BodyType shared.BodyType `yaml:"bodyType" json:"bodyType"` // 内容类型
URL string `yaml:"url" json:"url"` // URL
Body string `yaml:"body" json:"body"` // 输出的内容
statusList []*WildcardStatus
hasStatusList bool
}
// 获取新对象
// NewHTTPPageConfig 获取新对象
func NewHTTPPageConfig() *HTTPPageConfig {
return &HTTPPageConfig{
IsOn: true,
}
}
// 校验
// Init 校验
func (this *HTTPPageConfig) Init() error {
this.statusList = []*WildcardStatus{}
for _, s := range this.Status {
@@ -31,7 +35,7 @@ func (this *HTTPPageConfig) Init() error {
return nil
}
// 检查是否匹配
// Match 检查是否匹配
func (this *HTTPPageConfig) Match(status int) bool {
if !this.hasStatusList {
return false

View File

@@ -1,18 +1,23 @@
package serverconfigs
// 关闭页面配置
type HTTPShutdownConfig struct {
IsPrior bool `yaml:"isPrior" json:"isPrior"`
IsOn bool `yaml:"isOn" json:"isOn"`
URL string `yaml:"url" json:"url"`
Status int `yaml:"status" json:"status"`
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
// HTTPShutdownConfig 关闭页面配置
type HTTPShutdownConfig struct {
IsPrior bool `yaml:"isPrior" json:"isPrior"`
IsOn bool `yaml:"isOn" json:"isOn"`
BodyType shared.BodyType `yaml:"bodyType" json:"bodyType"` // 内容类型
URL string `yaml:"url" json:"url"` // URL
Body string `yaml:"body" json:"body"` // 输出的内容
Status int `yaml:"status" json:"status"`
// TODO 可以自定义文本
// TODO 可以自定义Content-Type
// TODO 可以设置是否立即断开与客户端的连接
}
// 校验
// Init 校验
func (this *HTTPShutdownConfig) Init() error {
return nil
}

View File

@@ -0,0 +1,23 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package shared
type BodyType = string
const (
BodyTypeURL BodyType = "url"
BodyTypeHTML BodyType = "html"
)
func FindAllBodyTypes() []*Definition {
return []*Definition{
{
Name: "读取URL",
Code: BodyTypeURL,
},
{
Name: "HTML",
Code: BodyTypeHTML,
},
}
}