字段中的blob和JSON类型映射为[]byte和dbs.JSON

This commit is contained in:
GoEdgeLab
2022-03-21 21:39:36 +08:00
parent a2cf2e5b03
commit 31599bee13
105 changed files with 1537 additions and 1156 deletions

2
go.mod
View File

@@ -12,7 +12,7 @@ require (
github.com/go-acme/lego/v4 v4.5.2
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.5.2
github.com/iwind/TeaGo v0.0.0-20220321112016-5a2cd71d3151 // indirect
github.com/iwind/TeaGo v0.0.0-20220321132348-7da816422f25 // indirect
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3
github.com/json-iterator/go v1.1.12 // indirect
github.com/mozillazg/go-pinyin v0.18.0

4
go.sum
View File

@@ -240,6 +240,10 @@ github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7Q
github.com/iwind/TeaGo v0.0.0-20220304043459-0dd944a5b475/go.mod h1:HRHK0zoC/og3c9/hKosD9yYVMTnnzm3PgXUdhRYHaLc=
github.com/iwind/TeaGo v0.0.0-20220321112016-5a2cd71d3151 h1:jksmjwlGC8QMpyHZmzxr7J+3NeMOr9Zy2+yNJxVSIjI=
github.com/iwind/TeaGo v0.0.0-20220321112016-5a2cd71d3151/go.mod h1:HRHK0zoC/og3c9/hKosD9yYVMTnnzm3PgXUdhRYHaLc=
github.com/iwind/TeaGo v0.0.0-20220321131553-fd7b112ba7e7 h1:gdMQZQk/aXfNuKuWCBQhP3byy5Dr8XHMe5+GXdGHcPQ=
github.com/iwind/TeaGo v0.0.0-20220321131553-fd7b112ba7e7/go.mod h1:HRHK0zoC/og3c9/hKosD9yYVMTnnzm3PgXUdhRYHaLc=
github.com/iwind/TeaGo v0.0.0-20220321132348-7da816422f25 h1:UpJ52iq8FEz2OeaXFhW1kuYeqVRUQ/5N+NVHvVuTnvw=
github.com/iwind/TeaGo v0.0.0-20220321132348-7da816422f25/go.mod h1:HRHK0zoC/og3c9/hKosD9yYVMTnnzm3PgXUdhRYHaLc=
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3 h1:aBSonas7vFcgTj9u96/bWGILGv1ZbUSTLiOzcI1ZT6c=
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA=
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=

View File

@@ -1,5 +1,7 @@
package accounts
import "github.com/iwind/TeaGo/dbs"
// UserAccountLog 用户账户日志
type UserAccountLog struct {
Id uint64 `field:"id"` // ID
@@ -13,7 +15,7 @@ type UserAccountLog struct {
Description string `field:"description"` // 描述文字
Day string `field:"day"` // YYYYMMDD
CreatedAt uint64 `field:"createdAt"` // 时间
Params string `field:"params"` // 参数
Params dbs.JSON `field:"params"` // 参数
}
type UserAccountLogOperator struct {

View File

@@ -1,5 +1,7 @@
package acme
import "github.com/iwind/TeaGo/dbs"
// ACMETask ACME任务
type ACMETask struct {
Id uint64 `field:"id"` // ID
@@ -9,7 +11,7 @@ type ACMETask struct {
AcmeUserId uint32 `field:"acmeUserId"` // ACME用户ID
DnsDomain string `field:"dnsDomain"` // DNS主域名
DnsProviderId uint64 `field:"dnsProviderId"` // DNS服务商
Domains string `field:"domains"` // 证书域名
Domains dbs.JSON `field:"domains"` // 证书域名
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
CertId uint64 `field:"certId"` // 生成的证书ID

View File

@@ -5,13 +5,13 @@ import (
"github.com/iwind/TeaGo/logs"
)
// 将域名解析成字符串数组
// DecodeDomains 将域名解析成字符串数组
func (this *ACMETask) DecodeDomains() []string {
if len(this.Domains) == 0 || this.Domains == "null" {
if len(this.Domains) == 0 {
return nil
}
result := []string{}
err := json.Unmarshal([]byte(this.Domains), &result)
err := json.Unmarshal(this.Domains, &result)
if err != nil {
logs.Error(err)
return nil

View File

@@ -1,5 +1,7 @@
package acme
import "github.com/iwind/TeaGo/dbs"
// ACMEUser ACME用户
type ACMEUser struct {
Id uint64 `field:"id"` // ID
@@ -10,7 +12,7 @@ type ACMEUser struct {
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
Description string `field:"description"` // 备注介绍
Registration string `field:"registration"` // 注册信息
Registration dbs.JSON `field:"registration"` // 注册信息
ProviderCode string `field:"providerCode"` // 服务商代号
AccountId uint64 `field:"accountId"` // 提供商ID
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// Admin 管理员
type Admin struct {
Id uint32 `field:"id"` // ID
@@ -11,7 +13,7 @@ type Admin struct {
CreatedAt uint64 `field:"createdAt"` // 创建时间
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
State uint8 `field:"state"` // 状态
Modules string `field:"modules"` // 允许的模块
Modules dbs.JSON `field:"modules"` // 允许的模块
CanLogin uint8 `field:"canLogin"` // 是否可以登录
Theme string `field:"theme"` // 模板设置
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// API节点
type APINode struct {
Id uint32 `field:"id"` // ID
@@ -9,18 +11,18 @@ type APINode struct {
Secret string `field:"secret"` // 密钥
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
Http string `field:"http"` // 监听的HTTP配置
Https string `field:"https"` // 监听的HTTPS配置
Http dbs.JSON `field:"http"` // 监听的HTTP配置
Https dbs.JSON `field:"https"` // 监听的HTTPS配置
RestIsOn uint8 `field:"restIsOn"` // 是否开放REST
RestHTTP string `field:"restHTTP"` // REST HTTP配置
RestHTTPS string `field:"restHTTPS"` // REST HTTPS配置
AccessAddrs string `field:"accessAddrs"` // 外部访问地址
RestHTTP dbs.JSON `field:"restHTTP"` // REST HTTP配置
RestHTTPS dbs.JSON `field:"restHTTPS"` // REST HTTPS配置
AccessAddrs dbs.JSON `field:"accessAddrs"` // 外部访问地址
Order uint32 `field:"order"` // 排序
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
AdminId uint32 `field:"adminId"` // 管理员ID
Weight uint32 `field:"weight"` // 权重
Status string `field:"status"` // 运行状态
Status dbs.JSON `field:"status"` // 运行状态
}
type APINodeOperator struct {

View File

@@ -1,5 +1,7 @@
package authority
import "github.com/iwind/TeaGo/dbs"
// AuthorityKey 企业版认证信息
type AuthorityKey struct {
Id uint32 `field:"id"` // ID
@@ -7,7 +9,7 @@ type AuthorityKey struct {
DayFrom string `field:"dayFrom"` // 开始日期
DayTo string `field:"dayTo"` // 结束日期
Hostname string `field:"hostname"` // Hostname
MacAddresses string `field:"macAddresses"` // MAC地址
MacAddresses dbs.JSON `field:"macAddresses"` // MAC地址
UpdatedAt uint64 `field:"updatedAt"` // 创建/修改时间
Company string `field:"company"` // 公司组织
}

View File

@@ -1,5 +1,7 @@
package authority
import "github.com/iwind/TeaGo/dbs"
// AuthorityNode 监控节点
type AuthorityNode struct {
Id uint32 `field:"id"` // ID
@@ -13,7 +15,7 @@ type AuthorityNode struct {
CreatedAt uint64 `field:"createdAt"` // 创建时间
AdminId uint32 `field:"adminId"` // 管理员ID
Weight uint32 `field:"weight"` // 权重
Status string `field:"status"` // 运行状态
Status dbs.JSON `field:"status"` // 运行状态
}
type AuthorityNodeOperator struct {

View File

@@ -1,10 +1,12 @@
package models
// 终端浏览器信息
import "github.com/iwind/TeaGo/dbs"
// ClientBrowser 终端浏览器信息
type ClientBrowser struct {
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 浏览器名称
Codes string `field:"codes"` // 代号
Codes dbs.JSON `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
}

View File

@@ -1,10 +1,12 @@
package models
// 终端操作系统信息
import "github.com/iwind/TeaGo/dbs"
// ClientSystem 终端操作系统信息
type ClientSystem struct {
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 系统名称
Codes string `field:"codes"` // 代号
Codes dbs.JSON `field:"codes"` // 代号
State uint8 `field:"state"` //
}

View File

@@ -1,5 +1,7 @@
package dns
import "github.com/iwind/TeaGo/dbs"
// DNSDomain 管理的域名
type DNSDomain struct {
Id uint32 `field:"id"` // ID
@@ -12,8 +14,8 @@ type DNSDomain struct {
DataUpdatedAt uint64 `field:"dataUpdatedAt"` // 数据更新时间
DataError string `field:"dataError"` // 数据更新错误
Data string `field:"data"` // 原始数据信息
Records string `field:"records"` // 所有解析记录
Routes string `field:"routes"` // 线路数据
Records dbs.JSON `field:"records"` // 所有解析记录
Routes dbs.JSON `field:"routes"` // 线路数据
IsUp uint8 `field:"isUp"` // 是否在线
State uint8 `field:"state"` // 状态
IsDeleted uint8 `field:"isDeleted"` // 是否已删除

View File

@@ -7,11 +7,11 @@ import (
// DecodeRoutes 获取所有的线路
func (this *DNSDomain) DecodeRoutes() ([]*dnstypes.Route, error) {
if len(this.Routes) == 0 || this.Routes == "null" {
if len(this.Routes) == 0 {
return nil, nil
}
result := []*dnstypes.Route{}
err := json.Unmarshal([]byte(this.Routes), &result)
err := json.Unmarshal(this.Routes, &result)
if err != nil {
return nil, err
}
@@ -35,7 +35,7 @@ func (this *DNSDomain) ContainsRouteCode(route string) (bool, error) {
// DecodeRecords 获取所有的记录
func (this *DNSDomain) DecodeRecords() ([]*dnstypes.Record, error) {
records := this.Records
if len(records) == 0 || records == "null" {
if len(records) == 0 {
return nil, nil
}
result := []*dnstypes.Record{}

View File

@@ -1,13 +1,15 @@
package dns
// DNS服务商
import "github.com/iwind/TeaGo/dbs"
// DNSProvider DNS服务商
type DNSProvider struct {
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 名称
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
Type string `field:"type"` // 供应商类型
ApiParams string `field:"apiParams"` // API参数
ApiParams dbs.JSON `field:"apiParams"` // API参数
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
DataUpdatedAt uint64 `field:"dataUpdatedAt"` // 数据同步时间

View File

@@ -5,9 +5,9 @@ import (
"github.com/iwind/TeaGo/maps"
)
// 获取API参数
// DecodeAPIParams 获取API参数
func (this *DNSProvider) DecodeAPIParams() (maps.Map, error) {
if len(this.ApiParams) == 0 || this.ApiParams == "null" {
if len(this.ApiParams) == 0 {
return maps.Map{}, nil
}
result := maps.Map{}

View File

@@ -4,7 +4,7 @@ package models
type FileChunk struct {
Id uint32 `field:"id"` // ID
FileId uint32 `field:"fileId"` // 文件ID
Data string `field:"data"` // 分块内容
Data []byte `field:"data"` // 分块内容
}
type FileChunkOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPAccessLog 访问日志
type HTTPAccessLog struct {
Id uint64 `field:"id"` // ID
@@ -7,7 +9,7 @@ type HTTPAccessLog struct {
NodeId uint32 `field:"nodeId"` // 节点ID
Status uint32 `field:"status"` // 状态码
CreatedAt uint64 `field:"createdAt"` // 创建时间
Content string `field:"content"` // 日志内容
Content dbs.JSON `field:"content"` // 日志内容
RequestId string `field:"requestId"` // 请求ID
FirewallPolicyId uint32 `field:"firewallPolicyId"` // WAF策略ID
FirewallRuleGroupId uint32 `field:"firewallRuleGroupId"` // WAF分组ID
@@ -15,8 +17,8 @@ type HTTPAccessLog struct {
FirewallRuleId uint32 `field:"firewallRuleId"` // WAF规则ID
RemoteAddr string `field:"remoteAddr"` // IP地址
Domain string `field:"domain"` // 域名
RequestBody string `field:"requestBody"` // 请求内容
ResponseBody string `field:"responseBody"` // 响应内容
RequestBody []byte `field:"requestBody"` // 请求内容
ResponseBody []byte `field:"responseBody"` // 响应内容
}
type HTTPAccessLogOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPAccessLogPolicy 访问日志策略
type HTTPAccessLogPolicy struct {
Id uint32 `field:"id"` // ID
@@ -11,8 +13,8 @@ type HTTPAccessLogPolicy struct {
Name string `field:"name"` // 名称
IsOn uint8 `field:"isOn"` // 是否启用
Type string `field:"type"` // 存储类型
Options string `field:"options"` // 存储选项
Conds string `field:"conds"` // 请求条件
Options dbs.JSON `field:"options"` // 存储选项
Conds dbs.JSON `field:"conds"` // 请求条件
IsPublic uint8 `field:"isPublic"` // 是否为公用
Version uint32 `field:"version"` // 版本号
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPAuthPolicy HTTP认证策略
type HTTPAuthPolicy struct {
Id uint64 `field:"id"` // ID
@@ -8,7 +10,7 @@ type HTTPAuthPolicy struct {
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 名称
Type string `field:"type"` // 类型
Params string `field:"params"` // 参数
Params dbs.JSON `field:"params"` // 参数
State uint8 `field:"state"` // 状态
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPBrotliPolicy Gzip配置
type HTTPBrotliPolicy struct {
Id uint32 `field:"id"` // ID
@@ -7,11 +9,11 @@ type HTTPBrotliPolicy struct {
UserId uint32 `field:"userId"` // 用户ID
IsOn uint8 `field:"isOn"` // 是否启用
Level uint32 `field:"level"` // 压缩级别
MinLength string `field:"minLength"` // 可压缩最小值
MaxLength string `field:"maxLength"` // 可压缩最大值
MinLength dbs.JSON `field:"minLength"` // 可压缩最小值
MaxLength dbs.JSON `field:"maxLength"` // 可压缩最大值
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
Conds string `field:"conds"` // 条件
Conds dbs.JSON `field:"conds"` // 条件
}
type HTTPBrotliPolicyOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPCachePolicy HTTP缓存策略
type HTTPCachePolicy struct {
Id uint32 `field:"id"` // ID
@@ -8,15 +10,15 @@ type HTTPCachePolicy struct {
TemplateId uint32 `field:"templateId"` // 模版ID
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 名称
Capacity string `field:"capacity"` // 容量数据
Capacity dbs.JSON `field:"capacity"` // 容量数据
MaxKeys uint64 `field:"maxKeys"` // 最多Key值
MaxSize string `field:"maxSize"` // 最大缓存内容尺寸
MaxSize dbs.JSON `field:"maxSize"` // 最大缓存内容尺寸
Type string `field:"type"` // 存储类型
Options string `field:"options"` // 存储选项
Options dbs.JSON `field:"options"` // 存储选项
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
Description string `field:"description"` // 描述
Refs string `field:"refs"` // 默认的缓存设置
Refs dbs.JSON `field:"refs"` // 默认的缓存设置
SyncCompressionCache uint8 `field:"syncCompressionCache"` // 是否同步写入压缩缓存
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPDeflatePolicy Gzip配置
type HTTPDeflatePolicy struct {
Id uint32 `field:"id"` // ID
@@ -7,11 +9,11 @@ type HTTPDeflatePolicy struct {
UserId uint32 `field:"userId"` // 用户ID
IsOn uint8 `field:"isOn"` // 是否启用
Level uint32 `field:"level"` // 压缩级别
MinLength string `field:"minLength"` // 可压缩最小值
MaxLength string `field:"maxLength"` // 可压缩最大值
MinLength dbs.JSON `field:"minLength"` // 可压缩最小值
MaxLength dbs.JSON `field:"maxLength"` // 可压缩最大值
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
Conds string `field:"conds"` // 条件
Conds dbs.JSON `field:"conds"` // 条件
}
type HTTPDeflatePolicyOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPFastcgi Fastcgi设置
type HTTPFastcgi struct {
Id uint64 `field:"id"` // ID
@@ -7,9 +9,9 @@ type HTTPFastcgi struct {
UserId uint32 `field:"userId"` // 用户ID
IsOn uint8 `field:"isOn"` // 是否启用
Address string `field:"address"` // 地址
Params string `field:"params"` // 参数
ReadTimeout string `field:"readTimeout"` // 读取超时
ConnTimeout string `field:"connTimeout"` // 连接超时
Params dbs.JSON `field:"params"` // 参数
ReadTimeout dbs.JSON `field:"readTimeout"` // 读取超时
ConnTimeout dbs.JSON `field:"connTimeout"` // 连接超时
PoolSize uint32 `field:"poolSize"` // 连接池尺寸
PathInfoPattern string `field:"pathInfoPattern"` // PATH_INFO匹配
State uint8 `field:"state"` // 状态

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPFirewallPolicy HTTP防火墙
type HTTPFirewallPolicy struct {
Id uint32 `field:"id"` // ID
@@ -13,12 +15,12 @@ type HTTPFirewallPolicy struct {
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
Inbound string `field:"inbound"` // 入站规则
Outbound string `field:"outbound"` // 出站规则
BlockOptions string `field:"blockOptions"` // BLOCK选项
Inbound dbs.JSON `field:"inbound"` // 入站规则
Outbound dbs.JSON `field:"outbound"` // 出站规则
BlockOptions dbs.JSON `field:"blockOptions"` // BLOCK选项
Mode string `field:"mode"` // 模式
UseLocalFirewall uint8 `field:"useLocalFirewall"` // 是否自动使用本地防火墙
SynFlood string `field:"synFlood"` // SynFlood防御设置
SynFlood dbs.JSON `field:"synFlood"` // SynFlood防御设置
}
type HTTPFirewallPolicyOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPFirewallRuleGroup 防火墙规则分组
type HTTPFirewallRuleGroup struct {
Id uint32 `field:"id"` // ID
@@ -11,7 +13,7 @@ type HTTPFirewallRuleGroup struct {
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
State uint8 `field:"state"` // 状态
Sets string `field:"sets"` // 规则集列表
Sets dbs.JSON `field:"sets"` // 规则集列表
CreatedAt uint64 `field:"createdAt"` // 创建时间
}

View File

@@ -1,16 +1,18 @@
package models
// 防火墙规则
import "github.com/iwind/TeaGo/dbs"
// HTTPFirewallRule 防火墙规则
type HTTPFirewallRule struct {
Id uint32 `field:"id"` // ID
IsOn uint8 `field:"isOn"` // 是否启用
Description string `field:"description"` // 说明
Param string `field:"param"` // 参数
ParamFilters string `field:"paramFilters"` // 处理器
ParamFilters dbs.JSON `field:"paramFilters"` // 处理器
Operator string `field:"operator"` // 操作符
Value string `field:"value"` // 对比值
IsCaseInsensitive uint8 `field:"isCaseInsensitive"` // 是否大小写不敏感
CheckpointOptions string `field:"checkpointOptions"` // 检查点参数
CheckpointOptions dbs.JSON `field:"checkpointOptions"` // 检查点参数
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
AdminId uint32 `field:"adminId"` // 管理员ID

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPFirewallRuleSet 防火墙规则集
type HTTPFirewallRuleSet struct {
Id uint32 `field:"id"` // ID
@@ -8,14 +10,14 @@ type HTTPFirewallRuleSet struct {
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
CreatedAt uint64 `field:"createdAt"` // 创建时间
Rules string `field:"rules"` // 规则列表
Rules dbs.JSON `field:"rules"` // 规则列表
Connector string `field:"connector"` // 规则之间的关系
State uint8 `field:"state"` // 状态
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
Action string `field:"action"` // 执行的动作(过期)
ActionOptions string `field:"actionOptions"` // 动作的选项(过期)
Actions string `field:"actions"` // 一组动作
ActionOptions dbs.JSON `field:"actionOptions"` // 动作的选项(过期)
Actions dbs.JSON `field:"actions"` // 一组动作
IgnoreLocal uint8 `field:"ignoreLocal"` // 忽略局域网请求
}

View File

@@ -1,17 +1,19 @@
package models
// Gzip配置
import "github.com/iwind/TeaGo/dbs"
// HTTPGzip Gzip配置
type HTTPGzip struct {
Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
IsOn uint8 `field:"isOn"` // 是否启用
Level uint32 `field:"level"` // 压缩级别
MinLength string `field:"minLength"` // 可压缩最小值
MaxLength string `field:"maxLength"` // 可压缩最大值
MinLength dbs.JSON `field:"minLength"` // 可压缩最小值
MaxLength dbs.JSON `field:"maxLength"` // 可压缩最大值
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
Conds string `field:"conds"` // 条件
Conds dbs.JSON `field:"conds"` // 条件
}
type HTTPGzipOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPHeader HTTP Header
type HTTPHeader struct {
Id uint32 `field:"id"` // ID
@@ -10,13 +12,13 @@ type HTTPHeader struct {
Name string `field:"name"` // 名称
Value string `field:"value"` // 值
Order uint32 `field:"order"` // 排序
Status string `field:"status"` // 状态码设置
Status dbs.JSON `field:"status"` // 状态码设置
DisableRedirect uint8 `field:"disableRedirect"` // 是否不支持跳转
ShouldAppend uint8 `field:"shouldAppend"` // 是否为附加
ShouldReplace uint8 `field:"shouldReplace"` // 是否替换变量
ReplaceValues string `field:"replaceValues"` // 替换的值
Methods string `field:"methods"` // 支持的方法
Domains string `field:"domains"` // 支持的域名
ReplaceValues dbs.JSON `field:"replaceValues"` // 替换的值
Methods dbs.JSON `field:"methods"` // 支持的方法
Domains dbs.JSON `field:"domains"` // 支持的域名
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
//
type HTTPHeaderPolicy struct {
Id uint32 `field:"id"` // ID
@@ -8,12 +10,12 @@ type HTTPHeaderPolicy struct {
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
CreatedAt uint64 `field:"createdAt"` // 创建时间
AddHeaders string `field:"addHeaders"` // 添加的Header
AddTrailers string `field:"addTrailers"` // 添加的Trailers
SetHeaders string `field:"setHeaders"` // 设置Header
ReplaceHeaders string `field:"replaceHeaders"` // 替换Header内容
Expires string `field:"expires"` // Expires单独设置
DeleteHeaders string `field:"deleteHeaders"` // 删除的Headers
AddHeaders dbs.JSON `field:"addHeaders"` // 添加的Header
AddTrailers dbs.JSON `field:"addTrailers"` // 添加的Trailers
SetHeaders dbs.JSON `field:"setHeaders"` // 设置Header
ReplaceHeaders dbs.JSON `field:"replaceHeaders"` // 替换Header内容
Expires dbs.JSON `field:"expires"` // Expires单独设置
DeleteHeaders dbs.JSON `field:"deleteHeaders"` // 删除的Headers
}
type HTTPHeaderPolicyOperator struct {

View File

@@ -189,7 +189,7 @@ func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64,
// reverse proxy
if IsNotNull(location.ReverseProxy) {
ref := &serverconfigs.ReverseProxyRef{}
err = json.Unmarshal([]byte(location.ReverseProxy), ref)
err = json.Unmarshal(location.ReverseProxy, ref)
if err != nil {
return nil, err
}
@@ -204,9 +204,9 @@ func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64,
}
// conds
if len(location.Conds) > 0 {
if IsNotNull(location.Conds) {
conds := &shared.HTTPRequestCondsConfig{}
err = json.Unmarshal([]byte(location.Conds), conds)
err = json.Unmarshal(location.Conds, conds)
if err != nil {
return nil, err
}
@@ -214,9 +214,9 @@ func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64,
}
// domains
if len(location.Domains) > 0 {
if IsNotNull(location.Domains) {
var domains = []string{}
err = json.Unmarshal([]byte(location.Domains), &domains)
err = json.Unmarshal(location.Domains, &domains)
if err != nil {
return nil, err
}
@@ -241,7 +241,7 @@ func (this *HTTPLocationDAO) FindLocationReverseProxy(tx *dbs.Tx, locationId int
if err != nil {
return nil, err
}
if IsNotNull(refString) {
if IsNotNull([]byte(refString)) {
ref := &serverconfigs.ReverseProxyRef{}
err = json.Unmarshal([]byte(refString), ref)
if err != nil {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPLocation 路由规则配置
type HTTPLocation struct {
Id uint32 `field:"id"` // ID
@@ -14,11 +16,11 @@ type HTTPLocation struct {
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
WebId uint32 `field:"webId"` // Web配置ID
ReverseProxy string `field:"reverseProxy"` // 反向代理
ReverseProxy dbs.JSON `field:"reverseProxy"` // 反向代理
UrlPrefix string `field:"urlPrefix"` // URL前缀
IsBreak uint8 `field:"isBreak"` // 是否终止匹配
Conds string `field:"conds"` // 匹配条件
Domains string `field:"domains"` // 专属域名
Conds dbs.JSON `field:"conds"` // 匹配条件
Domains dbs.JSON `field:"domains"` // 专属域名
}
type HTTPLocationOperator struct {

View File

@@ -1,12 +1,14 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPPage 特殊页面
type HTTPPage struct {
Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
IsOn uint8 `field:"isOn"` // 是否启用
StatusList string `field:"statusList"` // 状态列表
StatusList dbs.JSON `field:"statusList"` // 状态列表
Url string `field:"url"` // 页面URL
NewStatus int32 `field:"newStatus"` // 新状态码
State uint8 `field:"state"` // 状态

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// 重写规则
type HTTPRewriteRule struct {
Id uint32 `field:"id"` // ID
@@ -16,7 +18,7 @@ type HTTPRewriteRule struct {
ProxyHost string `field:"proxyHost"` // 代理的主机名
IsBreak uint8 `field:"isBreak"` // 是否终止解析
WithQuery uint8 `field:"withQuery"` // 是否保留URI参数
Conds string `field:"conds"` // 匹配条件
Conds dbs.JSON `field:"conds"` // 匹配条件
}
type HTTPRewriteRuleOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// HTTPWeb HTTP Web
type HTTPWeb struct {
Id uint32 `field:"id"` // ID
@@ -9,32 +11,32 @@ type HTTPWeb struct {
UserId uint32 `field:"userId"` // 用户ID
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
Root string `field:"root"` // 根目录
Charset string `field:"charset"` // 字符集
Shutdown string `field:"shutdown"` // 临时关闭页面配置
Pages string `field:"pages"` // 特殊页面
RedirectToHttps string `field:"redirectToHttps"` // 跳转到HTTPS设置
Indexes string `field:"indexes"` // 首页文件列表
MaxRequestBodySize string `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸
RequestHeader string `field:"requestHeader"` // 请求Header配置
ResponseHeader string `field:"responseHeader"` // 响应Header配置
AccessLog string `field:"accessLog"` // 访问日志配置
Stat string `field:"stat"` // 统计配置
Gzip string `field:"gzip"` // Gzip配置v0.3.2弃用)
Compression string `field:"compression"` // 压缩配置
Cache string `field:"cache"` // 缓存配置
Firewall string `field:"firewall"` // 防火墙设置
Locations string `field:"locations"` // 路由规则配置
Websocket string `field:"websocket"` // Websocket设置
RewriteRules string `field:"rewriteRules"` // 重写规则配置
HostRedirects string `field:"hostRedirects"` // 域名跳转
Fastcgi string `field:"fastcgi"` // Fastcgi配置
Auth string `field:"auth"` // 认证策略配置
Webp string `field:"webp"` // WebP配置
RemoteAddr string `field:"remoteAddr"` // 客户端IP配置
Root dbs.JSON `field:"root"` // 根目录
Charset dbs.JSON `field:"charset"` // 字符集
Shutdown dbs.JSON `field:"shutdown"` // 临时关闭页面配置
Pages dbs.JSON `field:"pages"` // 特殊页面
RedirectToHttps dbs.JSON `field:"redirectToHttps"` // 跳转到HTTPS设置
Indexes dbs.JSON `field:"indexes"` // 首页文件列表
MaxRequestBodySize dbs.JSON `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸
RequestHeader dbs.JSON `field:"requestHeader"` // 请求Header配置
ResponseHeader dbs.JSON `field:"responseHeader"` // 响应Header配置
AccessLog dbs.JSON `field:"accessLog"` // 访问日志配置
Stat dbs.JSON `field:"stat"` // 统计配置
Gzip dbs.JSON `field:"gzip"` // Gzip配置v0.3.2弃用)
Compression dbs.JSON `field:"compression"` // 压缩配置
Cache dbs.JSON `field:"cache"` // 缓存配置
Firewall dbs.JSON `field:"firewall"` // 防火墙设置
Locations dbs.JSON `field:"locations"` // 路由规则配置
Websocket dbs.JSON `field:"websocket"` // Websocket设置
RewriteRules dbs.JSON `field:"rewriteRules"` // 重写规则配置
HostRedirects dbs.JSON `field:"hostRedirects"` // 域名跳转
Fastcgi dbs.JSON `field:"fastcgi"` // Fastcgi配置
Auth dbs.JSON `field:"auth"` // 认证策略配置
Webp dbs.JSON `field:"webp"` // WebP配置
RemoteAddr dbs.JSON `field:"remoteAddr"` // 客户端IP配置
MergeSlashes uint8 `field:"mergeSlashes"` // 是否合并路径中的斜杠
RequestLimit string `field:"requestLimit"` // 请求限制
RequestScripts string `field:"requestScripts"` // 请求脚本
RequestLimit dbs.JSON `field:"requestLimit"` // 请求限制
RequestScripts dbs.JSON `field:"requestScripts"` // 请求脚本
}
type HTTPWebOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// Websocket设置
type HTTPWebsocket struct {
Id uint32 `field:"id"` // ID
@@ -8,9 +10,9 @@ type HTTPWebsocket struct {
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
IsOn uint8 `field:"isOn"` // 是否启用
HandshakeTimeout string `field:"handshakeTimeout"` // 握手超时时间
HandshakeTimeout dbs.JSON `field:"handshakeTimeout"` // 握手超时时间
AllowAllOrigins uint8 `field:"allowAllOrigins"` // 是否支持所有源
AllowedOrigins string `field:"allowedOrigins"` // 支持的源域名列表
AllowedOrigins dbs.JSON `field:"allowedOrigins"` // 支持的源域名列表
RequestSameOrigin uint8 `field:"requestSameOrigin"` // 是否请求一样的Origin
RequestOrigin string `field:"requestOrigin"` // 请求Origin
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// IPList IP名单
type IPList struct {
Id uint32 `field:"id"` // ID
@@ -11,8 +13,8 @@ type IPList struct {
Code string `field:"code"` // 代号
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
Timeout string `field:"timeout"` // 默认超时时间
Actions string `field:"actions"` // IP触发的动作
Timeout dbs.JSON `field:"timeout"` // 默认超时时间
Actions dbs.JSON `field:"actions"` // IP触发的动作
Description string `field:"description"` // 描述
IsPublic uint8 `field:"isPublic"` // 是否公用
IsGlobal uint8 `field:"isGlobal"` // 是否全局

View File

@@ -1,13 +1,15 @@
package models
// 第三方登录认证
import "github.com/iwind/TeaGo/dbs"
// Login 第三方登录认证
type Login struct {
Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
IsOn uint8 `field:"isOn"` // 是否启用
Type string `field:"type"` // 认证方式
Params string `field:"params"` // 参数
Params dbs.JSON `field:"params"` // 参数
State uint8 `field:"state"` // 状态
}

View File

@@ -1,14 +1,16 @@
package models
import "github.com/iwind/TeaGo/dbs"
// MessageMediaInstance 消息媒介接收人
type MessageMediaInstance struct {
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 名称
IsOn uint8 `field:"isOn"` // 是否启用
MediaType string `field:"mediaType"` // 媒介类型
Params string `field:"params"` // 媒介参数
Params dbs.JSON `field:"params"` // 媒介参数
Description string `field:"description"` // 备注
Rate string `field:"rate"` // 发送频率
Rate dbs.JSON `field:"rate"` // 发送频率
State uint8 `field:"state"` // 状态
HashLife int32 `field:"hashLife"` // HASH有效期
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// Message 消息通知
type Message struct {
Id uint64 `field:"id"` // ID
@@ -12,7 +14,7 @@ type Message struct {
Subject string `field:"subject"` // 标题
Body string `field:"body"` // 内容
Type string `field:"type"` // 消息类型
Params string `field:"params"` // 额外的参数
Params dbs.JSON `field:"params"` // 额外的参数
IsRead uint8 `field:"isRead"` // 是否已读
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// MessageReceiver 消息通知接收人
type MessageReceiver struct {
Id uint32 `field:"id"` // ID
@@ -8,7 +10,7 @@ type MessageReceiver struct {
NodeId uint32 `field:"nodeId"` // 节点ID
ServerId uint32 `field:"serverId"` // 服务ID
Type string `field:"type"` // 类型
Params string `field:"params"` // 参数
Params dbs.JSON `field:"params"` // 参数
RecipientId uint32 `field:"recipientId"` // 接收人ID
RecipientGroupId uint32 `field:"recipientGroupId"` // 接收人分组ID
State uint8 `field:"state"` // 状态

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// MessageRecipient 消息媒介接收人
type MessageRecipient struct {
Id uint32 `field:"id"` // ID
@@ -7,7 +9,7 @@ type MessageRecipient struct {
IsOn uint8 `field:"isOn"` // 是否启用
InstanceId uint32 `field:"instanceId"` // 实例ID
User string `field:"user"` // 接收人信息
GroupIds string `field:"groupIds"` // 分组ID
GroupIds dbs.JSON `field:"groupIds"` // 分组ID
State uint8 `field:"state"` // 状态
TimeFrom string `field:"timeFrom"` // 开始时间
TimeTo string `field:"timeTo"` // 结束时间

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// MessageTask 消息发送相关任务
type MessageTask struct {
Id uint64 `field:"id"` // ID
@@ -13,7 +15,7 @@ type MessageTask struct {
Status uint8 `field:"status"` // 发送状态
SentAt uint64 `field:"sentAt"` // 最后一次发送时间
State uint8 `field:"state"` // 状态
Result string `field:"result"` // 结果
Result dbs.JSON `field:"result"` // 结果
Day string `field:"day"` // YYYYMMDD
IsPrimary uint8 `field:"isPrimary"` // 是否优先
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// MetricChart 指标图表
type MetricChart struct {
Id uint32 `field:"id"` // ID
@@ -8,13 +10,13 @@ type MetricChart struct {
Code string `field:"code"` // 代号
Type string `field:"type"` // 图形类型
WidthDiv int32 `field:"widthDiv"` // 宽度划分
Params string `field:"params"` // 图形参数
Params dbs.JSON `field:"params"` // 图形参数
Order uint32 `field:"order"` // 排序
IsOn uint8 `field:"isOn"` // 是否启用
State uint8 `field:"state"` // 状态
MaxItems uint32 `field:"maxItems"` // 最多条目
IgnoreEmptyKeys uint8 `field:"ignoreEmptyKeys"` // 忽略空的键值
IgnoredKeys string `field:"ignoredKeys"` // 忽略键值
IgnoredKeys dbs.JSON `field:"ignoredKeys"` // 忽略键值
}
type MetricChartOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// MetricItem 指标定义
type MetricItem struct {
Id uint64 `field:"id"` // ID
@@ -9,7 +11,7 @@ type MetricItem struct {
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
Name string `field:"name"` // 指标名称
Keys string `field:"keys"` // 统计的Key
Keys dbs.JSON `field:"keys"` // 统计的Key
Period uint32 `field:"period"` // 周期
PeriodUnit string `field:"periodUnit"` // 周期单位
Value string `field:"value"` // 值运算

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// MetricStat 指标统计数据
type MetricStat struct {
Id uint64 `field:"id"` // ID
@@ -8,7 +10,7 @@ type MetricStat struct {
NodeId uint32 `field:"nodeId"` // 节点ID
ServerId uint32 `field:"serverId"` // 服务ID
ItemId uint64 `field:"itemId"` // 指标
Keys string `field:"keys"` // 键值
Keys dbs.JSON `field:"keys"` // 键值
Value float64 `field:"value"` // 数值
Time string `field:"time"` // 分钟值YYYYMMDDHHII
Version uint32 `field:"version"` // 版本号

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// 监控节点
type MonitorNode struct {
Id uint32 `field:"id"` // ID
@@ -13,7 +15,7 @@ type MonitorNode struct {
CreatedAt uint64 `field:"createdAt"` // 创建时间
AdminId uint32 `field:"adminId"` // 管理员ID
Weight uint32 `field:"weight"` // 权重
Status string `field:"status"` // 运行状态
Status dbs.JSON `field:"status"` // 运行状态
}
type MonitorNodeOperator struct {

View File

@@ -1,5 +1,7 @@
package nameservers
import "github.com/iwind/TeaGo/dbs"
// NSDomain DNS域名
type NSDomain struct {
Id uint32 `field:"id"` // ID
@@ -10,7 +12,7 @@ type NSDomain struct {
CreatedAt uint64 `field:"createdAt"` // 创建时间
Version uint64 `field:"version"` // 版本
State uint8 `field:"state"` // 状态
Tsig string `field:"tsig"` // TSIG配置
Tsig dbs.JSON `field:"tsig"` // TSIG配置
}
type NSDomainOperator struct {

View File

@@ -1,10 +1,12 @@
package nameservers
import "github.com/iwind/TeaGo/dbs"
// NSQuestionOption DNS请求选项
type NSQuestionOption struct {
Id uint64 `field:"id"` // ID
Name string `field:"name"` // 选项名
Values string `field:"values"` // 选项值
Values dbs.JSON `field:"values"` // 选项值
CreatedAt uint64 `field:"createdAt"` // 创建时间
}

View File

@@ -13,17 +13,17 @@ func TestNSRecord_DecodeRouteIds(t *testing.T) {
}
{
record := &NSRecord{RouteIds: "[]"}
record := &NSRecord{RouteIds: []byte("[]")}
t.Log(record.DecodeRouteIds())
}
{
record := &NSRecord{RouteIds: "[1, 2, 3]"}
record := &NSRecord{RouteIds: []byte("[1, 2, 3]")}
t.Log(record.DecodeRouteIds())
}
{
record := &NSRecord{RouteIds: `["id:1", "id:2", "isp:liantong"]`}
record := &NSRecord{RouteIds: []byte(`["id:1", "id:2", "isp:liantong"]`)}
t.Log(record.DecodeRouteIds())
}
}

View File

@@ -1,5 +1,7 @@
package nameservers
import "github.com/iwind/TeaGo/dbs"
// NSRecord DNS记录
type NSRecord struct {
Id uint64 `field:"id"` // ID
@@ -11,7 +13,7 @@ type NSRecord struct {
Value string `field:"value"` // 值
Ttl uint32 `field:"ttl"` // TTL
Weight uint32 `field:"weight"` // 权重
RouteIds string `field:"routeIds"` // 线路
RouteIds dbs.JSON `field:"routeIds"` // 线路
CreatedAt uint64 `field:"createdAt"` // 创建时间
Version uint64 `field:"version"` //
State uint8 `field:"state"` // 状态

View File

@@ -1,5 +1,7 @@
package nameservers
import "github.com/iwind/TeaGo/dbs"
// NSRoute DNS线路
type NSRoute struct {
Id uint32 `field:"id"` // ID
@@ -8,7 +10,7 @@ type NSRoute struct {
DomainId uint32 `field:"domainId"` // 域名ID
UserId uint32 `field:"userId"` // 用户ID
Name string `field:"name"` // 名称
Ranges string `field:"ranges"` // 范围
Ranges dbs.JSON `field:"ranges"` // 范围
Order uint32 `field:"order"` // 排序
Version uint64 `field:"version"` // 版本号
Code string `field:"code"` // 代号

View File

@@ -1,5 +1,7 @@
package nameservers
import "github.com/iwind/TeaGo/dbs"
// NSZone 域名子域
type NSZone struct {
Id uint64 `field:"id"` // ID
@@ -7,7 +9,7 @@ type NSZone struct {
IsOn uint8 `field:"isOn"` // 是否启用
Order uint32 `field:"order"` // 排序
Version uint64 `field:"version"` // 版本
Tsig string `field:"tsig"` // TSIG配置
Tsig dbs.JSON `field:"tsig"` // TSIG配置
State uint8 `field:"state"` // 状态
}

View File

@@ -279,7 +279,7 @@ func (this *NodeClusterDAO) FindAllAPINodeAddrsWithCluster(tx *dbs.Tx, clusterId
if !IsNotNull(cluster.ApiNodes) {
return
}
err = json.Unmarshal([]byte(cluster.ApiNodes), &apiNodeIds)
err = json.Unmarshal(cluster.ApiNodes, &apiNodeIds)
if err != nil {
return nil, err
}
@@ -526,7 +526,7 @@ func (this *NodeClusterDAO) FindClusterTOAConfig(tx *dbs.Tx, clusterId int64, ca
if err != nil {
return nil, err
}
if !IsNotNull(toa) {
if !IsNotNull([]byte(toa)) {
return nodeconfigs.DefaultTOAConfig(), nil
}
@@ -719,16 +719,16 @@ func (this *NodeClusterDAO) UpdateNodeClusterSystemService(tx *dbs.Tx, clusterId
if clusterId <= 0 {
return errors.New("invalid clusterId")
}
service, err := this.Query(tx).
serviceData, err := this.Query(tx).
Pk(clusterId).
Result("systemServices").
FindStringCol("")
FindBytesCol()
if err != nil {
return err
}
servicesMap := map[string]maps.Map{}
if IsNotNull(service) {
err = json.Unmarshal([]byte(service), &servicesMap)
if IsNotNull(serviceData) {
err = json.Unmarshal(serviceData, &servicesMap)
if err != nil {
return err
}
@@ -766,7 +766,7 @@ func (this *NodeClusterDAO) FindNodeClusterSystemServiceParams(tx *dbs.Tx, clust
return nil, err
}
servicesMap := map[string]maps.Map{}
if IsNotNull(service) {
if IsNotNull([]byte(service)) {
err = json.Unmarshal([]byte(service), &servicesMap)
if err != nil {
return nil, err
@@ -797,7 +797,7 @@ func (this *NodeClusterDAO) FindNodeClusterSystemServices(tx *dbs.Tx, clusterId
return nil, err
}
servicesMap := map[string]maps.Map{}
if IsNotNull(service) {
if IsNotNull([]byte(service)) {
err = json.Unmarshal([]byte(service), &servicesMap)
if err != nil {
return nil, err

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// 防火墙动作
type NodeClusterFirewallAction struct {
Id uint32 `field:"id"` // ID
@@ -8,7 +10,7 @@ type NodeClusterFirewallAction struct {
Name string `field:"name"` // 名称
EventLevel string `field:"eventLevel"` // 级别
Type string `field:"type"` // 动作类型
Params string `field:"params"` // 参数
Params dbs.JSON `field:"params"` // 参数
State uint8 `field:"state"` // 状态
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeCluster 节点集群
type NodeCluster struct {
Id uint32 `field:"id"` // ID
@@ -8,7 +10,7 @@ type NodeCluster struct {
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 名称
UseAllAPINodes uint8 `field:"useAllAPINodes"` // 是否使用所有API节点
ApiNodes string `field:"apiNodes"` // 使用的API节点
ApiNodes dbs.JSON `field:"apiNodes"` // 使用的API节点
InstallDir string `field:"installDir"` // 安装目录
Order uint32 `field:"order"` // 排序
CreatedAt uint64 `field:"createdAt"` // 创建时间
@@ -17,15 +19,15 @@ type NodeCluster struct {
AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册
UniqueId string `field:"uniqueId"` // 唯一ID
Secret string `field:"secret"` // 密钥
HealthCheck string `field:"healthCheck"` // 健康检查
HealthCheck dbs.JSON `field:"healthCheck"` // 健康检查
DnsName string `field:"dnsName"` // DNS名称
DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID
Dns string `field:"dns"` // DNS配置
Toa string `field:"toa"` // TOA配置
Dns dbs.JSON `field:"dns"` // DNS配置
Toa dbs.JSON `field:"toa"` // TOA配置
CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID
HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID
AccessLog string `field:"accessLog"` // 访问日志设置
SystemServices string `field:"systemServices"` // 系统服务设置
AccessLog dbs.JSON `field:"accessLog"` // 访问日志设置
SystemServices dbs.JSON `field:"systemServices"` // 系统服务设置
TimeZone string `field:"timeZone"` // 时区
NodeMaxThreads uint32 `field:"nodeMaxThreads"` // 节点最大线程数
NodeTCPMaxConnections uint32 `field:"nodeTCPMaxConnections"` // TCP最大连接数

View File

@@ -7,7 +7,7 @@ import (
// DecodeDNSConfig 解析DNS配置
func (this *NodeCluster) DecodeDNSConfig() (*dnsconfigs.ClusterDNSConfig, error) {
if len(this.Dns) == 0 || this.Dns == "null" {
if len(this.Dns) == 0 {
// 一定要返回一个默认的值防止产生nil
return &dnsconfigs.ClusterDNSConfig{
NodesAutoSync: false,

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeIPAddress 节点IP地址
type NodeIPAddress struct {
Id uint32 `field:"id"` // ID
@@ -15,8 +17,8 @@ type NodeIPAddress struct {
IsOn uint8 `field:"isOn"` // 是否启用
IsUp uint8 `field:"isUp"` // 是否上线
IsHealthy uint8 `field:"isHealthy"` // 是否健康
Thresholds string `field:"thresholds"` // 上线阈值
Connectivity string `field:"connectivity"` // 连通性状态
Thresholds dbs.JSON `field:"thresholds"` // 上线阈值
Connectivity dbs.JSON `field:"connectivity"` // 连通性状态
BackupIP string `field:"backupIP"` // 备用IP
BackupThresholdId uint32 `field:"backupThresholdId"` // 触发备用IP的阈值
CountUp uint32 `field:"countUp"` // UP状态次数

View File

@@ -230,7 +230,7 @@ func (this *NodeIPAddressThresholdDAO) formatThreshold(tx *dbs.Tx, threshold *No
if err != nil {
return err
}
threshold.Items = string(itemsJSON)
threshold.Items = itemsJSON
return nil
}

View File

@@ -1,11 +1,13 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeIPAddressThreshold IP地址阈值
type NodeIPAddressThreshold struct {
Id uint64 `field:"id"` // ID
AddressId uint64 `field:"addressId"` // IP地址ID
Items string `field:"items"` // 阈值条目
Actions string `field:"actions"` // 动作
Items dbs.JSON `field:"items"` // 阈值条目
Actions dbs.JSON `field:"actions"` // 动作
NotifiedAt uint64 `field:"notifiedAt"` // 上次通知时间
IsMatched uint8 `field:"isMatched"` // 上次是否匹配
State uint8 `field:"state"` // 状态

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeLog 节点日志
type NodeLog struct {
Id uint64 `field:"id"` // ID
@@ -17,7 +19,7 @@ type NodeLog struct {
Count uint32 `field:"count"` // 重复次数
IsFixed uint8 `field:"isFixed"` // 是否已处理
IsRead uint8 `field:"isRead"` // 是否已读
Params string `field:"params"` // 参数
Params dbs.JSON `field:"params"` // 参数
}
type NodeLogOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeLogin 节点登录信息
type NodeLogin struct {
Id uint32 `field:"id"` // ID
@@ -7,7 +9,7 @@ type NodeLogin struct {
Role string `field:"role"` // 角色
Name string `field:"name"` // 名称
Type string `field:"type"` // 类型ssh,agent
Params string `field:"params"` // 配置参数
Params dbs.JSON `field:"params"` // 配置参数
State uint8 `field:"state"` // 状态
}

View File

@@ -5,13 +5,13 @@ import (
"errors"
)
// 解析SSH登录参数
// DecodeSSHParams 解析SSH登录参数
func (this *NodeLogin) DecodeSSHParams() (*NodeLoginSSHParams, error) {
if this.Type != NodeLoginTypeSSH {
return nil, errors.New("invalid login type '" + this.Type + "'")
}
if len(this.Params) == 0 || this.Params == "null" {
if len(this.Params) == 0 {
return nil, errors.New("'params' should not be empty")
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// Node 节点
type Node struct {
Id uint32 `field:"id"` // ID
@@ -15,22 +17,22 @@ type Node struct {
Name string `field:"name"` // 节点名
Code string `field:"code"` // 代号
ClusterId uint32 `field:"clusterId"` // 主集群ID
SecondaryClusterIds string `field:"secondaryClusterIds"` // 从集群ID
SecondaryClusterIds dbs.JSON `field:"secondaryClusterIds"` // 从集群ID
RegionId uint32 `field:"regionId"` // 区域ID
GroupId uint32 `field:"groupId"` // 分组ID
CreatedAt uint64 `field:"createdAt"` // 创建时间
Status string `field:"status"` // 最新的状态
Status dbs.JSON `field:"status"` // 最新的状态
Version uint32 `field:"version"` // 当前版本号
LatestVersion uint32 `field:"latestVersion"` // 最后版本号
InstallDir string `field:"installDir"` // 安装目录
IsInstalled uint8 `field:"isInstalled"` // 是否已安装
InstallStatus string `field:"installStatus"` // 安装状态
InstallStatus dbs.JSON `field:"installStatus"` // 安装状态
State uint8 `field:"state"` // 状态
ConnectedAPINodes string `field:"connectedAPINodes"` // 当前连接的API节点
ConnectedAPINodes dbs.JSON `field:"connectedAPINodes"` // 当前连接的API节点
MaxCPU uint32 `field:"maxCPU"` // 可以使用的最多CPU
DnsRoutes string `field:"dnsRoutes"` // DNS线路设置
MaxCacheDiskCapacity string `field:"maxCacheDiskCapacity"` // 硬盘缓存容量
MaxCacheMemoryCapacity string `field:"maxCacheMemoryCapacity"` // 内存缓存容量
DnsRoutes dbs.JSON `field:"dnsRoutes"` // DNS线路设置
MaxCacheDiskCapacity dbs.JSON `field:"maxCacheDiskCapacity"` // 硬盘缓存容量
MaxCacheMemoryCapacity dbs.JSON `field:"maxCacheMemoryCapacity"` // 内存缓存容量
CacheDiskDir string `field:"cacheDiskDir"` // 缓存目录
}

View File

@@ -9,7 +9,7 @@ import (
// DecodeInstallStatus 安装状态
func (this *Node) DecodeInstallStatus() (*NodeInstallStatus, error) {
if len(this.InstallStatus) == 0 || this.InstallStatus == "null" {
if len(this.InstallStatus) == 0 {
return NewNodeInstallStatus(), nil
}
status := &NodeInstallStatus{}
@@ -30,7 +30,7 @@ func (this *Node) DecodeInstallStatus() (*NodeInstallStatus, error) {
// DecodeStatus 节点状态
func (this *Node) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
if len(this.Status) == 0 || this.Status == "null" {
if len(this.Status) == 0 {
return nil, nil
}
status := &nodeconfigs.NodeStatus{}
@@ -44,7 +44,7 @@ func (this *Node) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
// DNSRouteCodes 所有的DNS线路
func (this *Node) DNSRouteCodes() map[int64][]string {
routes := map[int64][]string{} // domainId => routes
if len(this.DnsRoutes) == 0 || this.DnsRoutes == "null" {
if len(this.DnsRoutes) == 0 {
return routes
}
err := json.Unmarshal([]byte(this.DnsRoutes), &routes)
@@ -58,7 +58,7 @@ func (this *Node) DNSRouteCodes() map[int64][]string {
// DNSRouteCodesForDomainId DNS线路
func (this *Node) DNSRouteCodesForDomainId(dnsDomainId int64) ([]string, error) {
routes := map[int64][]string{} // domainId => routes
if len(this.DnsRoutes) == 0 || this.DnsRoutes == "null" {
if len(this.DnsRoutes) == 0 {
return nil, nil
}
err := json.Unmarshal([]byte(this.DnsRoutes), &routes)

View File

@@ -162,8 +162,8 @@ func (this *NodeRegionDAO) UpdateRegionItemPrice(tx *dbs.Tx, regionId int64, ite
}
prices := one.(*NodeRegion).Prices
pricesMap := map[string]float32{}
if len(prices) > 0 && prices != "null" {
err = json.Unmarshal([]byte(prices), &pricesMap)
if IsNotNull(prices) {
err = json.Unmarshal(prices, &pricesMap)
if err != nil {
return err
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeRegion 节点区域
type NodeRegion struct {
Id uint32 `field:"id"` // ID
@@ -9,7 +11,7 @@ type NodeRegion struct {
Description string `field:"description"` // 描述
Order uint32 `field:"order"` // 排序
CreatedAt uint64 `field:"createdAt"` // 创建时间
Prices string `field:"prices"` // 价格
Prices dbs.JSON `field:"prices"` // 价格
State uint8 `field:"state"` // 状态
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeThreshold 集群阈值设置
type NodeThreshold struct {
Id uint64 `field:"id"` // ID
@@ -10,7 +12,7 @@ type NodeThreshold struct {
Item string `field:"item"` // 监控项
Param string `field:"param"` // 参数
Operator string `field:"operator"` // 操作符
Value string `field:"value"` // 对比值
Value dbs.JSON `field:"value"` // 对比值
Message string `field:"message"` // 消息内容
NotifyDuration uint32 `field:"notifyDuration"` // 通知间隔
NotifiedAt uint32 `field:"notifiedAt"` // 上次通知时间

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NodeValue 节点监控数据
type NodeValue struct {
Id uint64 `field:"id"` // ID
@@ -7,7 +9,7 @@ type NodeValue struct {
NodeId uint32 `field:"nodeId"` // 节点ID
Role string `field:"role"` // 节点角色
Item string `field:"item"` // 监控项
Value string `field:"value"` // 数据
Value dbs.JSON `field:"value"` // 数据
CreatedAt uint64 `field:"createdAt"` // 创建时间
Day string `field:"day"` // 日期
Hour string `field:"hour"` // 小时

View File

@@ -1,12 +1,14 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NSAccessLog 域名服务访问日志
type NSAccessLog struct {
Id uint64 `field:"id"` // ID
NodeId uint32 `field:"nodeId"` // 节点ID
DomainId uint32 `field:"domainId"` // 域名ID
RecordId uint32 `field:"recordId"` // 记录ID
Content string `field:"content"` // 访问数据
Content dbs.JSON `field:"content"` // 访问数据
RequestId string `field:"requestId"` // 请求ID
CreatedAt uint64 `field:"createdAt"` // 创建时间
RemoteAddr string `field:"remoteAddr"` // IP

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NSCluster 域名服务器集群
type NSCluster struct {
Id uint32 `field:"id"` // ID
@@ -7,9 +9,9 @@ type NSCluster struct {
Name string `field:"name"` // 集群名
InstallDir string `field:"installDir"` // 安装目录
State uint8 `field:"state"` // 状态
AccessLog string `field:"accessLog"` // 访问日志配置
AccessLog dbs.JSON `field:"accessLog"` // 访问日志配置
GrantId uint32 `field:"grantId"` // 授权ID
Recursion string `field:"recursion"` // 递归DNS设置
Recursion dbs.JSON `field:"recursion"` // 递归DNS设置
}
type NSClusterOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// NSNode 域名服务器节点
type NSNode struct {
Id uint32 `field:"id"` // ID
@@ -7,17 +9,17 @@ type NSNode struct {
ClusterId uint32 `field:"clusterId"` // 集群ID
Name string `field:"name"` // 节点名称
IsOn uint8 `field:"isOn"` // 是否启用
Status string `field:"status"` // 运行状态
Status dbs.JSON `field:"status"` // 运行状态
UniqueId string `field:"uniqueId"` // 节点ID
Secret string `field:"secret"` // 密钥
IsUp uint8 `field:"isUp"` // 是否运行
IsInstalled uint8 `field:"isInstalled"` // 是否已安装
InstallStatus string `field:"installStatus"` // 安装状态
InstallStatus dbs.JSON `field:"installStatus"` // 安装状态
InstallDir string `field:"installDir"` // 安装目录
State uint8 `field:"state"` // 状态
IsActive uint8 `field:"isActive"` // 是否活跃
StatusIsNotified uint8 `field:"statusIsNotified"` // 活跃状态已经通知
ConnectedAPINodes string `field:"connectedAPINodes"` // 当前连接的API节点
ConnectedAPINodes dbs.JSON `field:"connectedAPINodes"` // 当前连接的API节点
}
type NSNodeOperator struct {

View File

@@ -8,7 +8,7 @@ import (
// DecodeInstallStatus 安装状态
func (this *NSNode) DecodeInstallStatus() (*NodeInstallStatus, error) {
if len(this.InstallStatus) == 0 || this.InstallStatus == "null" {
if len(this.InstallStatus) == 0 {
return NewNodeInstallStatus(), nil
}
status := &NodeInstallStatus{}
@@ -29,7 +29,7 @@ func (this *NSNode) DecodeInstallStatus() (*NodeInstallStatus, error) {
// DecodeStatus 节点状态
func (this *NSNode) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
if len(this.Status) == 0 || this.Status == "null" {
if len(this.Status) == 0 {
return nil, nil
}
status := &nodeconfigs.NodeStatus{}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// Origin 源站
type Origin struct {
Id uint32 `field:"id"` // ID
@@ -8,25 +10,25 @@ type Origin struct {
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 名称
Version uint32 `field:"version"` // 版本
Addr string `field:"addr"` // 地址
Addr dbs.JSON `field:"addr"` // 地址
Description string `field:"description"` // 描述
Code string `field:"code"` // 代号
Weight uint32 `field:"weight"` // 权重
ConnTimeout string `field:"connTimeout"` // 连接超时
ReadTimeout string `field:"readTimeout"` // 读超时
IdleTimeout string `field:"idleTimeout"` // 空闲连接超时
ConnTimeout dbs.JSON `field:"connTimeout"` // 连接超时
ReadTimeout dbs.JSON `field:"readTimeout"` // 读超时
IdleTimeout dbs.JSON `field:"idleTimeout"` // 空闲连接超时
MaxFails uint32 `field:"maxFails"` // 最多失败次数
MaxConns uint32 `field:"maxConns"` // 最大并发连接数
MaxIdleConns uint32 `field:"maxIdleConns"` // 最多空闲连接数
HttpRequestURI string `field:"httpRequestURI"` // 转发后的请求URI
HttpRequestHeader string `field:"httpRequestHeader"` // 请求Header配置
HttpResponseHeader string `field:"httpResponseHeader"` // 响应Header配置
HttpRequestHeader dbs.JSON `field:"httpRequestHeader"` // 请求Header配置
HttpResponseHeader dbs.JSON `field:"httpResponseHeader"` // 响应Header配置
Host string `field:"host"` // 自定义主机名
HealthCheck string `field:"healthCheck"` // 健康检查设置
Cert string `field:"cert"` // 证书设置
Ftp string `field:"ftp"` // FTP相关设置
HealthCheck dbs.JSON `field:"healthCheck"` // 健康检查设置
Cert dbs.JSON `field:"cert"` // 证书设置
Ftp dbs.JSON `field:"ftp"` // FTP相关设置
CreatedAt uint64 `field:"createdAt"` // 创建时间
Domains string `field:"domains"` // 所属域名
Domains dbs.JSON `field:"domains"` // 所属域名
State uint8 `field:"state"` // 状态
}

View File

@@ -9,18 +9,18 @@ import (
// DecodeAddr 解析地址
func (this *Origin) DecodeAddr() (*serverconfigs.NetworkAddressConfig, error) {
if len(this.Addr) == 0 || this.Addr == "null" {
if len(this.Addr) == 0 {
return nil, errors.New("addr is empty")
}
addr := &serverconfigs.NetworkAddressConfig{}
err := json.Unmarshal([]byte(this.Addr), addr)
err := json.Unmarshal(this.Addr, addr)
return addr, err
}
func (this *Origin) DecodeDomains() []string {
var result = []string{}
if len(this.Domains) > 0 {
err := json.Unmarshal([]byte(this.Domains), &result)
err := json.Unmarshal(this.Domains, &result)
if err != nil {
remotelogs.Error("Origin.DecodeDomains", err.Error())
}

View File

@@ -1,15 +1,17 @@
package models
import "github.com/iwind/TeaGo/dbs"
// Plan 用户套餐
type Plan struct {
Id uint32 `field:"id"` // ID
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 套餐名
ClusterId uint32 `field:"clusterId"` // 集群ID
TrafficLimit string `field:"trafficLimit"` // 流量限制
Features string `field:"features"` // 允许的功能
TrafficPrice string `field:"trafficPrice"` // 流量价格设定
BandwidthPrice string `field:"bandwidthPrice"` // 带宽价格
TrafficLimit dbs.JSON `field:"trafficLimit"` // 流量限制
Features dbs.JSON `field:"features"` // 允许的功能
TrafficPrice dbs.JSON `field:"trafficPrice"` // 流量价格设定
BandwidthPrice dbs.JSON `field:"bandwidthPrice"` // 带宽价格
MonthlyPrice float64 `field:"monthlyPrice"` // 月付
SeasonallyPrice float64 `field:"seasonallyPrice"` // 季付
YearlyPrice float64 `field:"yearlyPrice"` // 年付

View File

@@ -1,11 +1,13 @@
package regions
//
import "github.com/iwind/TeaGo/dbs"
// RegionCity 区域城市
type RegionCity struct {
Id uint32 `field:"id"` // ID
ProvinceId uint32 `field:"provinceId"` // 省份ID
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
Codes dbs.JSON `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
DataId string `field:"dataId"` // 原始数据ID
}

View File

@@ -1,13 +1,15 @@
package regions
//
import "github.com/iwind/TeaGo/dbs"
// RegionCountry 区域国家|地区
type RegionCountry struct {
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
Codes dbs.JSON `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
DataId string `field:"dataId"` // 原始数据ID
Pinyin string `field:"pinyin"` // 拼音
Pinyin dbs.JSON `field:"pinyin"` // 拼音
}
type RegionCountryOperator struct {

View File

@@ -1,10 +1,12 @@
package regions
//
import "github.com/iwind/TeaGo/dbs"
// RegionProvider 区域ISP
type RegionProvider struct {
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
Codes dbs.JSON `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
}

View File

@@ -1,11 +1,13 @@
package regions
//
import "github.com/iwind/TeaGo/dbs"
// RegionProvince 区域省份
type RegionProvince struct {
Id uint32 `field:"id"` // ID
CountryId uint32 `field:"countryId"` // 国家ID
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
Codes dbs.JSON `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
DataId string `field:"dataId"` // 原始数据ID
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// ReportNode 连通性报告终端
type ReportNode struct {
Id uint32 `field:"id"` // ID
@@ -9,12 +11,12 @@ type ReportNode struct {
Name string `field:"name"` // 名称
Location string `field:"location"` // 所在区域
Isp string `field:"isp"` // 网络服务商
AllowIPs string `field:"allowIPs"` // 允许的IP
AllowIPs dbs.JSON `field:"allowIPs"` // 允许的IP
IsActive uint8 `field:"isActive"` // 是否活跃
Status string `field:"status"` // 状态
Status dbs.JSON `field:"status"` // 状态
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
GroupIds string `field:"groupIds"` // 分组ID
GroupIds dbs.JSON `field:"groupIds"` // 分组ID
}
type ReportNodeOperator struct {

View File

@@ -110,16 +110,16 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
config.FollowRedirects = reverseProxy.FollowRedirects == 1
schedulingConfig := &serverconfigs.SchedulingConfig{}
if len(reverseProxy.Scheduling) > 0 && reverseProxy.Scheduling != "null" {
err = json.Unmarshal([]byte(reverseProxy.Scheduling), schedulingConfig)
if IsNotNull(reverseProxy.Scheduling) {
err = json.Unmarshal(reverseProxy.Scheduling, schedulingConfig)
if err != nil {
return nil, err
}
config.Scheduling = schedulingConfig
}
if len(reverseProxy.PrimaryOrigins) > 0 && reverseProxy.PrimaryOrigins != "null" {
if IsNotNull(reverseProxy.PrimaryOrigins) {
originRefs := []*serverconfigs.OriginRef{}
err = json.Unmarshal([]byte(reverseProxy.PrimaryOrigins), &originRefs)
err = json.Unmarshal(reverseProxy.PrimaryOrigins, &originRefs)
if err != nil {
return nil, err
}
@@ -134,9 +134,9 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
}
}
if len(reverseProxy.BackupOrigins) > 0 && reverseProxy.BackupOrigins != "null" {
if IsNotNull(reverseProxy.BackupOrigins) {
originRefs := []*serverconfigs.OriginRef{}
err = json.Unmarshal([]byte(reverseProxy.BackupOrigins), &originRefs)
err = json.Unmarshal(reverseProxy.BackupOrigins, &originRefs)
if err != nil {
return nil, err
}
@@ -154,7 +154,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
// add headers
if IsNotNull(reverseProxy.AddHeaders) {
addHeaders := []string{}
err = json.Unmarshal([]byte(reverseProxy.AddHeaders), &addHeaders)
err = json.Unmarshal(reverseProxy.AddHeaders, &addHeaders)
if err != nil {
return nil, err
}
@@ -167,7 +167,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
if IsNotNull(reverseProxy.ConnTimeout) {
connTimeout := &shared.TimeDuration{}
err = json.Unmarshal([]byte(reverseProxy.ConnTimeout), &connTimeout)
err = json.Unmarshal(reverseProxy.ConnTimeout, &connTimeout)
if err != nil {
return nil, err
}
@@ -176,7 +176,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
if IsNotNull(reverseProxy.ReadTimeout) {
readTimeout := &shared.TimeDuration{}
err = json.Unmarshal([]byte(reverseProxy.ReadTimeout), &readTimeout)
err = json.Unmarshal(reverseProxy.ReadTimeout, &readTimeout)
if err != nil {
return nil, err
}
@@ -185,7 +185,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
if IsNotNull(reverseProxy.IdleTimeout) {
idleTimeout := &shared.TimeDuration{}
err = json.Unmarshal([]byte(reverseProxy.IdleTimeout), &idleTimeout)
err = json.Unmarshal(reverseProxy.IdleTimeout, &idleTimeout)
if err != nil {
return nil, err
}
@@ -195,7 +195,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
// PROXY Protocol
if IsNotNull(reverseProxy.ProxyProtocol) {
var proxyProtocolConfig = &serverconfigs.ProxyProtocolConfig{}
err = json.Unmarshal([]byte(reverseProxy.ProxyProtocol), proxyProtocolConfig)
err = json.Unmarshal(reverseProxy.ProxyProtocol, proxyProtocolConfig)
if err != nil {
return nil, err
}
@@ -225,13 +225,13 @@ func (this *ReverseProxyDAO) CreateReverseProxy(tx *dbs.Tx, adminId int64, userI
}
op.AddHeaders = defaultHeadersJSON
if len(schedulingJSON) > 0 {
if IsNotNull(schedulingJSON) {
op.Scheduling = string(schedulingJSON)
}
if len(primaryOriginsJSON) > 0 {
if IsNotNull(primaryOriginsJSON) {
op.PrimaryOrigins = string(primaryOriginsJSON)
}
if len(backupOriginsJSON) > 0 {
if IsNotNull(backupOriginsJSON) {
op.BackupOrigins = string(backupOriginsJSON)
}
err = this.Save(tx, op)

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// ReverseProxy 反向代理配置
type ReverseProxy struct {
Id uint32 `field:"id"` // ID
@@ -7,23 +9,23 @@ type ReverseProxy struct {
UserId uint32 `field:"userId"` // 用户ID
TemplateId uint32 `field:"templateId"` // 模版ID
IsOn uint8 `field:"isOn"` // 是否启用
Scheduling string `field:"scheduling"` // 调度算法
PrimaryOrigins string `field:"primaryOrigins"` // 主要源站
BackupOrigins string `field:"backupOrigins"` // 备用源站
Scheduling dbs.JSON `field:"scheduling"` // 调度算法
PrimaryOrigins dbs.JSON `field:"primaryOrigins"` // 主要源站
BackupOrigins dbs.JSON `field:"backupOrigins"` // 备用源站
StripPrefix string `field:"stripPrefix"` // 去除URL前缀
RequestHostType uint8 `field:"requestHostType"` // 请求Host类型
RequestHost string `field:"requestHost"` // 请求Host
RequestURI string `field:"requestURI"` // 请求URI
AutoFlush uint8 `field:"autoFlush"` // 是否自动刷新缓冲区
AddHeaders string `field:"addHeaders"` // 自动添加的Header列表
AddHeaders dbs.JSON `field:"addHeaders"` // 自动添加的Header列表
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
ConnTimeout string `field:"connTimeout"` // 连接超时时间
ReadTimeout string `field:"readTimeout"` // 读取超时时间
IdleTimeout string `field:"idleTimeout"` // 空闲超时时间
ConnTimeout dbs.JSON `field:"connTimeout"` // 连接超时时间
ReadTimeout dbs.JSON `field:"readTimeout"` // 读取超时时间
IdleTimeout dbs.JSON `field:"idleTimeout"` // 空闲超时时间
MaxConns uint32 `field:"maxConns"` // 最大并发连接数
MaxIdleConns uint32 `field:"maxIdleConns"` // 最大空闲连接数
ProxyProtocol string `field:"proxyProtocol"` // Proxy Protocol配置
ProxyProtocol dbs.JSON `field:"proxyProtocol"` // Proxy Protocol配置
FollowRedirects uint8 `field:"followRedirects"` // 回源跟随
}

View File

@@ -145,12 +145,12 @@ func (this *ServerDAO) CreateServer(tx *dbs.Tx,
serverNamesJSON []byte,
isAuditing bool,
auditingServerNamesJSON []byte,
httpJSON string,
httpsJSON string,
tcpJSON string,
tlsJSON string,
unixJSON string,
udpJSON string,
httpJSON []byte,
httpsJSON []byte,
tcpJSON []byte,
tlsJSON []byte,
unixJSON []byte,
udpJSON []byte,
webId int64,
reverseProxyJSON []byte,
clusterId int64,
@@ -550,7 +550,7 @@ func (this *ServerDAO) FindServerServerNames(tx *dbs.Tx, serverId int64) (server
return
}
server := one.(*Server)
return []byte(server.ServerNames), server.IsAuditing == 1, int64(server.AuditingAt), []byte(server.AuditingServerNames), []byte(server.AuditingResult), nil
return server.ServerNames, server.IsAuditing == 1, int64(server.AuditingAt), server.AuditingServerNames, server.AuditingResult, nil
}
// UpdateServerNames 修改ServerNames配置
@@ -909,9 +909,9 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
config.Group = groupConfig
// ServerNames
if len(server.ServerNames) > 0 && server.ServerNames != "null" {
if IsNotNull(server.ServerNames) {
serverNames := []*serverconfigs.ServerNameConfig{}
err := json.Unmarshal([]byte(server.ServerNames), &serverNames)
err := json.Unmarshal(server.ServerNames, &serverNames)
if err != nil {
return nil, err
}
@@ -938,9 +938,9 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
}
// HTTP
if len(server.Http) > 0 && server.Http != "null" {
if IsNotNull(server.Http) {
httpConfig := &serverconfigs.HTTPProtocolConfig{}
err := json.Unmarshal([]byte(server.Http), httpConfig)
err := json.Unmarshal(server.Http, httpConfig)
if err != nil {
return nil, err
}
@@ -948,9 +948,9 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
}
// HTTPS
if len(server.Https) > 0 && server.Https != "null" {
if IsNotNull(server.Https) {
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
err := json.Unmarshal([]byte(server.Https), httpsConfig)
err := json.Unmarshal(server.Https, httpsConfig)
if err != nil {
return nil, err
}
@@ -970,9 +970,9 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
}
// TCP
if len(server.Tcp) > 0 && server.Tcp != "null" {
if IsNotNull(server.Tcp) {
tcpConfig := &serverconfigs.TCPProtocolConfig{}
err := json.Unmarshal([]byte(server.Tcp), tcpConfig)
err := json.Unmarshal(server.Tcp, tcpConfig)
if err != nil {
return nil, err
}
@@ -980,9 +980,9 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
}
// TLS
if len(server.Tls) > 0 && server.Tls != "null" {
if IsNotNull(server.Tls) {
tlsConfig := &serverconfigs.TLSProtocolConfig{}
err := json.Unmarshal([]byte(server.Tls), tlsConfig)
err := json.Unmarshal(server.Tls, tlsConfig)
if err != nil {
return nil, err
}
@@ -1002,9 +1002,9 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
}
// Unix
if len(server.Unix) > 0 && server.Unix != "null" {
if IsNotNull(server.Unix) {
unixConfig := &serverconfigs.UnixProtocolConfig{}
err := json.Unmarshal([]byte(server.Unix), unixConfig)
err := json.Unmarshal(server.Unix, unixConfig)
if err != nil {
return nil, err
}
@@ -1012,9 +1012,9 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
}
// UDP
if len(server.Udp) > 0 && server.Udp != "null" {
if IsNotNull(server.Udp) {
udpConfig := &serverconfigs.UDPProtocolConfig{}
err := json.Unmarshal([]byte(server.Udp), udpConfig)
err := json.Unmarshal(server.Udp, udpConfig)
if err != nil {
return nil, err
}
@@ -1035,7 +1035,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
// ReverseProxy
if IsNotNull(server.ReverseProxy) {
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
err := json.Unmarshal([]byte(server.ReverseProxy), reverseProxyRef)
err := json.Unmarshal(server.ReverseProxy, reverseProxyRef)
if err != nil {
return nil, err
}
@@ -1072,7 +1072,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
// traffic limit
if len(server.TrafficLimit) > 0 {
var trafficLimitConfig = &serverconfigs.TrafficLimitConfig{}
err = json.Unmarshal([]byte(server.TrafficLimit), trafficLimitConfig)
err = json.Unmarshal(server.TrafficLimit, trafficLimitConfig)
if err != nil {
return nil, err
}
@@ -1106,7 +1106,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
if len(plan.TrafficLimit) > 0 && (config.TrafficLimit == nil || !config.TrafficLimit.IsOn) {
var trafficLimitConfig = &serverconfigs.TrafficLimitConfig{}
err = json.Unmarshal([]byte(plan.TrafficLimit), trafficLimitConfig)
err = json.Unmarshal(plan.TrafficLimit, trafficLimitConfig)
if err != nil {
return nil, err
}
@@ -1119,7 +1119,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
if config.TrafficLimit != nil && config.TrafficLimit.IsOn && !config.TrafficLimit.IsEmpty() {
if len(server.TrafficLimitStatus) > 0 {
var status = &serverconfigs.TrafficLimitStatus{}
err = json.Unmarshal([]byte(server.TrafficLimitStatus), status)
err = json.Unmarshal(server.TrafficLimitStatus, status)
if err != nil {
return nil, err
}
@@ -1829,9 +1829,9 @@ func (this *ServerDAO) NotifyServerPortsUpdate(tx *dbs.Tx, serverId int64) error
// HTTP
var tcpListens = []*serverconfigs.NetworkAddressConfig{}
var udpListens = []*serverconfigs.NetworkAddressConfig{}
if len(server.Http) > 0 && server.Http != "null" {
if IsNotNull(server.Http) {
httpConfig := &serverconfigs.HTTPProtocolConfig{}
err := json.Unmarshal([]byte(server.Http), httpConfig)
err := json.Unmarshal(server.Http, httpConfig)
if err != nil {
return err
}
@@ -1839,9 +1839,9 @@ func (this *ServerDAO) NotifyServerPortsUpdate(tx *dbs.Tx, serverId int64) error
}
// HTTPS
if len(server.Https) > 0 && server.Https != "null" {
if IsNotNull(server.Https) {
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
err := json.Unmarshal([]byte(server.Https), httpsConfig)
err := json.Unmarshal(server.Https, httpsConfig)
if err != nil {
return err
}
@@ -1849,9 +1849,9 @@ func (this *ServerDAO) NotifyServerPortsUpdate(tx *dbs.Tx, serverId int64) error
}
// TCP
if len(server.Tcp) > 0 && server.Tcp != "null" {
if IsNotNull(server.Tcp) {
tcpConfig := &serverconfigs.TCPProtocolConfig{}
err := json.Unmarshal([]byte(server.Tcp), tcpConfig)
err := json.Unmarshal(server.Tcp, tcpConfig)
if err != nil {
return err
}
@@ -1859,9 +1859,9 @@ func (this *ServerDAO) NotifyServerPortsUpdate(tx *dbs.Tx, serverId int64) error
}
// TLS
if len(server.Tls) > 0 && server.Tls != "null" {
if IsNotNull(server.Tls) {
tlsConfig := &serverconfigs.TLSProtocolConfig{}
err := json.Unmarshal([]byte(server.Tls), tlsConfig)
err := json.Unmarshal(server.Tls, tlsConfig)
if err != nil {
return err
}
@@ -1869,9 +1869,9 @@ func (this *ServerDAO) NotifyServerPortsUpdate(tx *dbs.Tx, serverId int64) error
}
// UDP
if len(server.Udp) > 0 && server.Udp != "null" {
if IsNotNull(server.Udp) {
udpConfig := &serverconfigs.UDPProtocolConfig{}
err := json.Unmarshal([]byte(server.Udp), udpConfig)
err := json.Unmarshal(server.Udp, udpConfig)
if err != nil {
return err
}
@@ -2006,7 +2006,7 @@ func (this *ServerDAO) CalculateServerTrafficLimitConfig(tx *dbs.Tx, serverId in
return limitConfig, nil
}
err = json.Unmarshal([]byte(trafficLimit), limitConfig)
err = json.Unmarshal(trafficLimit, limitConfig)
if err != nil {
return nil, err
}
@@ -2081,8 +2081,8 @@ func (this *ServerDAO) UpdateServerTrafficLimitStatus(tx *dbs.Tx, trafficLimitCo
var server = serverOne.(*Server)
var oldStatus = &serverconfigs.TrafficLimitStatus{}
if len(server.TrafficLimitStatus) > 0 {
err = json.Unmarshal([]byte(server.TrafficLimitStatus), oldStatus)
if IsNotNull(server.TrafficLimitStatus) {
err = json.Unmarshal(server.TrafficLimitStatus, oldStatus)
if err != nil {
return err
}

View File

@@ -186,7 +186,7 @@ func TestServerDAO_FindAllEnabledServersWithDomain(t *testing.T) {
}
if len(servers) > 0 {
for _, server := range servers {
t.Log(domain + ": " + server.ServerNames)
t.Log(domain + ": " + string(server.ServerNames))
}
} else {
t.Log(domain + ": not found")

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// ServerGroup 服务分组
type ServerGroup struct {
Id uint32 `field:"id"` // ID
@@ -10,9 +12,9 @@ type ServerGroup struct {
Order uint32 `field:"order"` // 排序
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
HttpReverseProxy string `field:"httpReverseProxy"` // 反向代理设置
TcpReverseProxy string `field:"tcpReverseProxy"` // TCP反向代理
UdpReverseProxy string `field:"udpReverseProxy"` // UDP反向代理
HttpReverseProxy dbs.JSON `field:"httpReverseProxy"` // 反向代理设置
TcpReverseProxy dbs.JSON `field:"tcpReverseProxy"` // TCP反向代理
UdpReverseProxy dbs.JSON `field:"udpReverseProxy"` // UDP反向代理
WebId uint32 `field:"webId"` // Web配置ID
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// Server 服务
type Server struct {
Id uint32 `field:"id"` // ID
@@ -9,38 +11,38 @@ type Server struct {
Type string `field:"type"` // 服务类型
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
ServerNames string `field:"serverNames"` // 域名列表
ServerNames dbs.JSON `field:"serverNames"` // 域名列表
AuditingAt uint64 `field:"auditingAt"` // 审核提交时间
AuditingServerNames string `field:"auditingServerNames"` // 审核中的域名
AuditingServerNames dbs.JSON `field:"auditingServerNames"` // 审核中的域名
IsAuditing uint8 `field:"isAuditing"` // 是否正在审核
AuditingResult string `field:"auditingResult"` // 审核结果
Http string `field:"http"` // HTTP配置
Https string `field:"https"` // HTTPS配置
Tcp string `field:"tcp"` // TCP配置
Tls string `field:"tls"` // TLS配置
Unix string `field:"unix"` // Unix配置
Udp string `field:"udp"` // UDP配置
AuditingResult dbs.JSON `field:"auditingResult"` // 审核结果
Http dbs.JSON `field:"http"` // HTTP配置
Https dbs.JSON `field:"https"` // HTTPS配置
Tcp dbs.JSON `field:"tcp"` // TCP配置
Tls dbs.JSON `field:"tls"` // TLS配置
Unix dbs.JSON `field:"unix"` // Unix配置
Udp dbs.JSON `field:"udp"` // UDP配置
WebId uint32 `field:"webId"` // WEB配置
ReverseProxy string `field:"reverseProxy"` // 反向代理配置
GroupIds string `field:"groupIds"` // 分组ID列表
Config string `field:"config"` // 服务配置,自动生成
ReverseProxy dbs.JSON `field:"reverseProxy"` // 反向代理配置
GroupIds dbs.JSON `field:"groupIds"` // 分组ID列表
Config dbs.JSON `field:"config"` // 服务配置,自动生成
ConfigMd5 string `field:"configMd5"` // Md5
ClusterId uint32 `field:"clusterId"` // 集群ID
IncludeNodes string `field:"includeNodes"` // 部署条件
ExcludeNodes string `field:"excludeNodes"` // 节点排除条件
IncludeNodes dbs.JSON `field:"includeNodes"` // 部署条件
ExcludeNodes dbs.JSON `field:"excludeNodes"` // 节点排除条件
Version uint32 `field:"version"` // 版本号
CreatedAt uint64 `field:"createdAt"` // 创建时间
State uint8 `field:"state"` // 状态
DnsName string `field:"dnsName"` // DNS名称
TcpPorts string `field:"tcpPorts"` // 所包含TCP端口
UdpPorts string `field:"udpPorts"` // 所包含UDP端口
TcpPorts dbs.JSON `field:"tcpPorts"` // 所包含TCP端口
UdpPorts dbs.JSON `field:"udpPorts"` // 所包含UDP端口
SupportCNAME uint8 `field:"supportCNAME"` // 允许CNAME不在域名名单
TrafficLimit string `field:"trafficLimit"` // 流量限制
TrafficLimit dbs.JSON `field:"trafficLimit"` // 流量限制
TrafficDay string `field:"trafficDay"` // YYYYMMDD
TrafficMonth string `field:"trafficMonth"` // YYYYMM
TotalDailyTraffic float64 `field:"totalDailyTraffic"` // 日流量
TotalMonthlyTraffic float64 `field:"totalMonthlyTraffic"` // 月流量
TrafficLimitStatus string `field:"trafficLimitStatus"` // 流量限制状态
TrafficLimitStatus dbs.JSON `field:"trafficLimitStatus"` // 流量限制状态
TotalTraffic float64 `field:"totalTraffic"` // 总流量
UserPlanId uint32 `field:"userPlanId"` // 所属套餐ID
LastUserPlanId uint32 `field:"lastUserPlanId"` // 上一次使用的套餐

View File

@@ -13,7 +13,7 @@ func (this *Server) DecodeGroupIds() []int64 {
}
var result = []int64{}
err := json.Unmarshal([]byte(this.GroupIds), &result)
err := json.Unmarshal(this.GroupIds, &result)
if err != nil {
remotelogs.Error("Server.DecodeGroupIds", err.Error())
// 忽略错误
@@ -23,9 +23,9 @@ func (this *Server) DecodeGroupIds() []int64 {
// DecodeHTTPPorts 获取HTTP所有端口
func (this *Server) DecodeHTTPPorts() (ports []int) {
if len(this.Http) > 0 && this.Http != "null" {
if len(this.Http) > 0 {
config := &serverconfigs.HTTPProtocolConfig{}
err := json.Unmarshal([]byte(this.Http), config)
err := json.Unmarshal(this.Http, config)
if err != nil {
return nil
}
@@ -44,9 +44,9 @@ func (this *Server) DecodeHTTPPorts() (ports []int) {
// DecodeHTTPSPorts 获取HTTPS所有端口
func (this *Server) DecodeHTTPSPorts() (ports []int) {
if len(this.Https) > 0 && this.Https != "null" {
if len(this.Https) > 0 {
config := &serverconfigs.HTTPSProtocolConfig{}
err := json.Unmarshal([]byte(this.Https), config)
err := json.Unmarshal(this.Https, config)
if err != nil {
return nil
}
@@ -65,9 +65,9 @@ func (this *Server) DecodeHTTPSPorts() (ports []int) {
// DecodeTCPPorts 获取TCP所有端口
func (this *Server) DecodeTCPPorts() (ports []int) {
if len(this.Tcp) > 0 && this.Tcp != "null" {
if len(this.Tcp) > 0 {
config := &serverconfigs.TCPProtocolConfig{}
err := json.Unmarshal([]byte(this.Tcp), config)
err := json.Unmarshal(this.Tcp, config)
if err != nil {
return nil
}
@@ -86,9 +86,9 @@ func (this *Server) DecodeTCPPorts() (ports []int) {
// DecodeTLSPorts 获取TLS所有端口
func (this *Server) DecodeTLSPorts() (ports []int) {
if len(this.Tls) > 0 && this.Tls != "null" {
if len(this.Tls) > 0 {
config := &serverconfigs.TLSProtocolConfig{}
err := json.Unmarshal([]byte(this.Tls), config)
err := json.Unmarshal(this.Tls, config)
if err != nil {
return nil
}
@@ -107,9 +107,9 @@ func (this *Server) DecodeTLSPorts() (ports []int) {
// DecodeUDPPorts 获取UDP所有端口
func (this *Server) DecodeUDPPorts() (ports []int) {
if len(this.Udp) > 0 && this.Udp != "null" {
if len(this.Udp) > 0 {
config := &serverconfigs.UDPProtocolConfig{}
err := json.Unmarshal([]byte(this.Udp), config)
err := json.Unmarshal(this.Udp, config)
if err != nil {
return nil
}

View File

@@ -148,7 +148,7 @@ func (this *SSLCertDAO) UpdateCert(tx *dbs.Tx,
return nil
}
var oldCert = oldOne.(*SSLCert)
var dataIsChanged = bytes.Compare(certData, []byte(oldCert.CertData)) != 0 || bytes.Compare(keyData, []byte(oldCert.KeyData)) != 0
var dataIsChanged = bytes.Compare(certData, oldCert.CertData) != 0 || bytes.Compare(keyData, oldCert.KeyData) != 0
var op = NewSSLCertOperator()
op.Id = certId
@@ -224,31 +224,31 @@ func (this *SSLCertDAO) ComposeCertConfig(tx *dbs.Tx, certId int64, cacheMap *ut
config.IsACME = cert.IsACME == 1
config.Name = cert.Name
config.Description = cert.Description
config.CertData = []byte(cert.CertData)
config.KeyData = []byte(cert.KeyData)
config.CertData = cert.CertData
config.KeyData = cert.KeyData
config.ServerName = cert.ServerName
config.TimeBeginAt = int64(cert.TimeBeginAt)
config.TimeEndAt = int64(cert.TimeEndAt)
// OCSP
if int64(cert.OcspExpiresAt) > time.Now().Unix() {
config.OCSP = []byte(cert.Ocsp)
config.OCSP = cert.Ocsp
config.OCSPExpiresAt = int64(cert.OcspExpiresAt)
}
config.OCSPError = cert.OcspError
if IsNotNull(cert.DnsNames) {
dnsNames := []string{}
err := json.Unmarshal([]byte(cert.DnsNames), &dnsNames)
err := json.Unmarshal(cert.DnsNames, &dnsNames)
if err != nil {
return nil, err
}
config.DNSNames = dnsNames
}
if IsNotNull(cert.CommonNames) {
if cert.CommonNames.IsNotNull() {
commonNames := []string{}
err := json.Unmarshal([]byte(cert.CommonNames), &commonNames)
err := json.Unmarshal(cert.CommonNames, &commonNames)
if err != nil {
return nil, err
}

View File

@@ -1,19 +1,240 @@
package models_test
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/dbs"
timeutil "github.com/iwind/TeaGo/utils/time"
"testing"
)
func TestSSLCertDAO_ListCertsToUpdateOCSP(t *testing.T) {
var dao = models.NewSSLCertDAO()
certs, err := dao.ListCertsToUpdateOCSP(nil, 3600, 10)
certs, err := dao.ListCertsToUpdateOCSP(nil, 3, 10)
if err != nil {
t.Fatal(err)
}
for _, cert := range certs {
t.Log(cert.Id, cert.Name, "updatedAt:", cert.OcspUpdatedAt, timeutil.FormatTime("Y-m-d H:i:s", int64(cert.OcspUpdatedAt)), cert.OcspIsUpdated)
t.Log(cert.Id, cert.Name, "updatedAt:", cert.OcspUpdatedAt, timeutil.FormatTime("Y-m-d H:i:s", int64(cert.OcspUpdatedAt)), cert.OcspIsUpdated, string(cert.Ocsp))
}
}
func TestSSLCertDAO_Update_Blob(t *testing.T) {
var a = assert.NewAssertion(t)
var certId = 2
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("ocsp", 123).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).Ocsp) == "123")
}
}
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("ocsp", 456).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).Ocsp) == "456")
}
}
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("ocsp", []byte("789")).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).Ocsp) == "789")
}
}
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("ocsp", []byte("")).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).Ocsp) == "")
}
}
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("ocsp", nil).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).Ocsp) == "")
}
}
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("ocsp", []byte("1.2.3")).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).Ocsp) == "1.2.3")
}
}
}
func TestSSLCertDAO_Update_JSON(t *testing.T) {
var a = assert.NewAssertion(t)
var certId = 2
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("commonNames", []byte("null")).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).CommonNames) == "null")
}
}
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("commonNames", dbs.JSON(`["a","b"]`)).
UpdateQuickly()
if err != nil {
t.Fatal(err)
}
{
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).CommonNames) == `["a", "b"]`)
}
}
{
commonNames, _ := dao.Query(nil).Pk(certId).Result("commonNames").FindBytesCol()
t.Log("commonNames:", commonNames)
a.IsTrue(string(commonNames) == `["a", "b"]`)
}
}
{
var op = models.NewSSLCertOperator()
op.Id = certId
op.CommonNames = dbs.JSON(`["a", "b"]`)
var dao = models.NewSSLCertDAO()
err := dao.Save(nil, op)
if err != nil {
t.Fatal(err)
}
{
commonNames, _ := dao.Query(nil).Pk(certId).Result("commonNames").FindBytesCol()
t.Log("commonNames:", commonNames)
a.IsTrue(string(commonNames) == `["a", "b"]`)
}
}
{
var op = models.NewSSLCertOperator()
op.Id = certId
op.CommonNames = []byte(`["a", "b"]`)
var dao = models.NewSSLCertDAO()
err := dao.Save(nil, op)
if err != nil {
t.Fatal(err)
}
{
commonNames, _ := dao.Query(nil).Pk(certId).Result("commonNames").FindBytesCol()
t.Log("commonNames:", commonNames)
a.IsTrue(string(commonNames) == `["a", "b"]`)
}
}
{
var dao = models.NewSSLCertDAO()
err := dao.Query(nil).
Pk(certId).
Set("commonNames", []byte("")).
UpdateQuickly()
a.IsTrue(err != nil)
if err != nil {
a.Log("expected has error:", err.Error())
}
one, _ := dao.Query(nil).Pk(certId).Find()
if one != nil {
a.IsTrue(string(one.(*models.SSLCert).CommonNames) == `["a", "b"]`)
}
}
{
var commonNames = []string{}
err := json.Unmarshal([]byte("null"), &commonNames)
if err != nil {
t.Fatal(err)
}
t.Log(commonNames)
}
{
var cert = &models.SSLCert{}
err := json.Unmarshal([]byte("null"), &cert)
if err != nil {
t.Fatal(err)
}
t.Log(cert)
}
}

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// SSLCert SSL证书
type SSLCert struct {
Id uint32 `field:"id"` // ID
@@ -11,19 +13,19 @@ type SSLCert struct {
IsOn uint8 `field:"isOn"` // 是否启用
Name string `field:"name"` // 证书名
Description string `field:"description"` // 描述
CertData string `field:"certData"` // 证书内容
KeyData string `field:"keyData"` // 密钥内容
CertData []byte `field:"certData"` // 证书内容
KeyData []byte `field:"keyData"` // 密钥内容
ServerName string `field:"serverName"` // 证书使用的主机名
IsCA uint8 `field:"isCA"` // 是否为CA证书
GroupIds string `field:"groupIds"` // 证书分组
GroupIds dbs.JSON `field:"groupIds"` // 证书分组
TimeBeginAt uint64 `field:"timeBeginAt"` // 开始时间
TimeEndAt uint64 `field:"timeEndAt"` // 结束时间
DnsNames string `field:"dnsNames"` // DNS名称列表
CommonNames string `field:"commonNames"` // 发行单位列表
DnsNames dbs.JSON `field:"dnsNames"` // DNS名称列表
CommonNames dbs.JSON `field:"commonNames"` // 发行单位列表
IsACME uint8 `field:"isACME"` // 是否为ACME自动生成的
AcmeTaskId uint64 `field:"acmeTaskId"` // ACME任务ID
NotifiedAt uint64 `field:"notifiedAt"` // 最后通知时间
Ocsp string `field:"ocsp"` // OCSP缓存
Ocsp []byte `field:"ocsp"` // OCSP缓存
OcspIsUpdated uint8 `field:"ocspIsUpdated"` // OCSP是否已更新
OcspUpdatedAt uint64 `field:"ocspUpdatedAt"` // OCSP更新时间
OcspError string `field:"ocspError"` // OCSP更新错误

View File

@@ -1,18 +1,20 @@
package models
import "github.com/iwind/TeaGo/dbs"
// SSLPolicy SSL配置策略
type SSLPolicy struct {
Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
IsOn uint8 `field:"isOn"` // 是否启用
Certs string `field:"certs"` // 证书列表
ClientCACerts string `field:"clientCACerts"` // 客户端证书
Certs dbs.JSON `field:"certs"` // 证书列表
ClientCACerts dbs.JSON `field:"clientCACerts"` // 客户端证书
ClientAuthType uint32 `field:"clientAuthType"` // 客户端认证类型
MinVersion string `field:"minVersion"` // 支持的SSL最小版本
CipherSuitesIsOn uint8 `field:"cipherSuitesIsOn"` // 是否自定义加密算法套件
CipherSuites string `field:"cipherSuites"` // 加密算法套件
Hsts string `field:"hsts"` // HSTS设置
CipherSuites dbs.JSON `field:"cipherSuites"` // 加密算法套件
Hsts dbs.JSON `field:"hsts"` // HSTS设置
Http2Enabled uint8 `field:"http2Enabled"` // 是否启用HTTP/2
OcspIsOn uint8 `field:"ocspIsOn"` // 是否启用OCSP
State uint8 `field:"state"` // 状态

View File

@@ -1,10 +1,12 @@
package models
// 系统事件
import "github.com/iwind/TeaGo/dbs"
// SysEvent 系统事件
type SysEvent struct {
Id uint64 `field:"id"` // ID
Type string `field:"type"` // 类型
Params string `field:"params"` // 参数
Params dbs.JSON `field:"params"` // 参数
CreatedAt uint64 `field:"createdAt"` // 创建时间
}

View File

@@ -1,11 +1,13 @@
package models
// 系统配置
import "github.com/iwind/TeaGo/dbs"
// SysSetting 系统配置
type SysSetting struct {
Id uint32 `field:"id"` // ID
UserId uint32 `field:"userId"` // 用户ID
Code string `field:"code"` // 代号
Value string `field:"value"` // 配置值
Value dbs.JSON `field:"value"` // 配置值
}
type SysSettingOperator struct {

View File

@@ -1,5 +1,7 @@
package models
import "github.com/iwind/TeaGo/dbs"
// User 用户
type User struct {
Id uint32 `field:"id"` // ID
@@ -19,7 +21,7 @@ type User struct {
State uint8 `field:"state"` // 状态
Source string `field:"source"` // 来源
ClusterId uint32 `field:"clusterId"` // 集群ID
Features string `field:"features"` // 允许操作的特征
Features dbs.JSON `field:"features"` // 允许操作的特征
RegisteredIP string `field:"registeredIP"` // 注册使用的IP
IsRejected uint8 `field:"isRejected"` // 是否已拒绝
RejectReason string `field:"rejectReason"` // 拒绝理由

View File

@@ -1,6 +1,8 @@
package models
// API节点
import "github.com/iwind/TeaGo/dbs"
// 用户节点
type UserNode struct {
Id uint32 `field:"id"` // ID
IsOn uint8 `field:"isOn"` // 是否启用
@@ -8,15 +10,15 @@ type UserNode struct {
Secret string `field:"secret"` // 密钥
Name string `field:"name"` // 名称
Description string `field:"description"` // 描述
Http string `field:"http"` // 监听的HTTP配置
Https string `field:"https"` // 监听的HTTPS配置
AccessAddrs string `field:"accessAddrs"` // 外部访问地址
Http dbs.JSON `field:"http"` // 监听的HTTP配置
Https dbs.JSON `field:"https"` // 监听的HTTPS配置
AccessAddrs dbs.JSON `field:"accessAddrs"` // 外部访问地址
Order uint32 `field:"order"` // 排序
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
AdminId uint32 `field:"adminId"` // 管理员ID
Weight uint32 `field:"weight"` // 权重
Status string `field:"status"` // 运行状态
Status dbs.JSON `field:"status"` // 运行状态
}
type UserNodeOperator struct {

View File

@@ -5,10 +5,10 @@ import (
"sync"
)
// 缓存专用Locker
// SharedCacheLocker 缓存专用Locker
var SharedCacheLocker = sync.RWMutex{}
// 处理JSON字节Slice
// JSONBytes 处理JSON字节Slice
func JSONBytes(data []byte) []byte {
if len(data) == 0 {
return []byte("null")
@@ -16,12 +16,18 @@ func JSONBytes(data []byte) []byte {
return data
}
// 判断JSON是否不为空
func IsNotNull(data string) bool {
return len(data) > 0 && data != "null"
// IsNotNull 判断JSON是否不为空
func IsNotNull(data []byte) bool {
if len(data) == 0 {
return false
}
if len(data) == 4 && string(data) == "null" {
return false
}
return true
}
// 构造Query
// NewQuery 构造Query
func NewQuery(tx *dbs.Tx, dao dbs.DAOWrapper, adminId int64, userId int64) *dbs.Query {
query := dao.Object().Query(tx)
if adminId > 0 {

View File

@@ -148,8 +148,8 @@ func (this *AdminService) FindEnabledAdmin(ctx context.Context, req *pb.FindEnab
pbModules := []*pb.AdminModule{}
modules := []*systemconfigs.AdminModule{}
if len(admin.Modules) > 0 && admin.Modules != "null" {
err = json.Unmarshal([]byte(admin.Modules), &modules)
if len(admin.Modules) > 0 {
err = json.Unmarshal(admin.Modules, &modules)
if err != nil {
return nil, err
}
@@ -281,8 +281,8 @@ func (this *AdminService) FindAllAdminModules(ctx context.Context, req *pb.FindA
result := []*pb.AdminModuleList{}
for _, admin := range admins {
modules := []*systemconfigs.AdminModule{}
if len(admin.Modules) > 0 && admin.Modules != "null" {
err = json.Unmarshal([]byte(admin.Modules), &modules)
if len(admin.Modules) > 0 {
err = json.Unmarshal(admin.Modules, &modules)
if err != nil {
return nil, err
}

View File

@@ -331,8 +331,8 @@ func (this *DNSDomainService) convertDomainToPB(tx *dbs.Tx, domain *dns.DNSDomai
}
records := []*dnstypes.Record{}
if len(domain.Records) > 0 && domain.Records != "null" {
err := json.Unmarshal([]byte(domain.Records), &records)
if models.IsNotNull(domain.Records) {
err := json.Unmarshal(domain.Records, &records)
if err != nil {
return nil, err
}
@@ -653,8 +653,8 @@ func (this *DNSDomainService) syncClusterDNS(req *pb.SyncDNSDomainDataRequest) (
return &pb.SyncDNSDomainDataResponse{IsOk: false, Error: "域名没有设置服务商"}, nil
}
apiParams := maps.Map{}
if len(provider.ApiParams) > 0 && provider.ApiParams != "null" {
err = json.Unmarshal([]byte(provider.ApiParams), &apiParams)
if models.IsNotNull(provider.ApiParams) {
err = json.Unmarshal(provider.ApiParams, &apiParams)
if err != nil {
return nil, err
}

Some files were not shown because too many files have changed in this diff Show More