2018-11-08 17:22:26 +08:00
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package v1
2018-11-12 19:33:16 +08:00
type ProtocolType string
const (
STREAM ProtocolType = "stream"
HTTP ProtocolType = "http"
)
2018-11-08 17:22:26 +08:00
//VirtualService VirtualService
type VirtualService struct {
Meta
2018-11-13 12:01:23 +08:00
Enabled bool ` json:"enable" `
2018-11-12 19:33:16 +08:00
Protocol ProtocolType ` json:"protocol" ` //default stream
2018-11-08 17:22:26 +08:00
// BackendProtocol indicates which protocol should be used to communicate with the service
2018-11-13 12:01:23 +08:00
BackendProtocol string ` json:"backend-protocol" `
Port int32 ` json:"port" `
Listening [ ] string ` json:"listening" ` //if Listening is nil,will listen all
Note string ` json:"note" `
DefaultPoolName string ` json:"default_pool_name" `
RuleNames [ ] string ` json:"rule_names" `
SSLdecrypt bool ` json:"ssl_decrypt" `
DefaultCertificateName string ` json:"default_certificate_name" `
RequestLogEnable bool ` json:"request_log_enable" `
RequestLogFileName string ` json:"request_log_file_name" `
RequestLogFormat string ` json:"request_log_format" `
2018-11-08 17:22:26 +08:00
//ConnectTimeout The time, in seconds, to wait for data from a new connection. If no data is received within this time, the connection will be closed. A value of 0 (zero) will disable the timeout.
ConnectTimeout int ` json:"connect_timeout" `
//Timeout A connection should be closed if no additional data has been received for this period of time. A value of 0 (zero) will disable this timeout. Note that the default value may vary depending on the protocol selected.
Timeout int ` json:"timeout" `
2018-11-13 12:01:23 +08:00
ServerName string ` json:"server_name" `
PoolName string ` json:"pool_name" `
SSLCert * SSLCert ` json:"ssl_cert" `
Locations [ ] * Location ` json:"locations" `
ForceSSLRedirect bool ` json:"force_ssl_redirect" `
2018-11-08 17:22:26 +08:00
}
func ( v * VirtualService ) Equals ( c * VirtualService ) bool {
if v == c {
return true
}
if v == nil || c == nil {
return false
}
if ! v . Meta . Equals ( & c . Meta ) {
return false
}
if v . Enabled != c . Enabled {
return false
}
if v . Protocol != c . Protocol {
return false
}
if v . BackendProtocol != c . BackendProtocol {
return false
}
if v . Port != c . Port {
return false
}
// TODO
if len ( v . Listening ) != len ( c . Listening ) {
return false
}
for _ , vl := range v . Listening {
flag := false
for _ , cl := range c . Listening {
if vl == cl {
flag = true
break
}
}
if ! flag {
return false
}
}
if v . Note != c . Note {
return false
}
if v . DefaultPoolName != c . DefaultPoolName {
return false
}
// TODO
if len ( v . RuleNames ) != len ( c . RuleNames ) {
return false
}
for _ , vr := range v . RuleNames {
flag := false
for _ , cr := range c . RuleNames {
if vr == cr {
flag = true
break
}
}
if ! flag {
return false
}
}
if v . SSLdecrypt != c . SSLdecrypt {
return false
}
if v . DefaultCertificateName != c . DefaultCertificateName {
return false
}
if v . RequestLogEnable != c . RequestLogEnable {
return false
}
if v . RequestLogFileName != c . RequestLogFileName {
return false
}
if v . RequestLogFormat != c . RequestLogFormat {
return false
}
if v . ConnectTimeout != c . ConnectTimeout {
return false
}
if v . Timeout != c . Timeout {
return false
}
if v . ServerName != c . ServerName {
return false
}
if v . PoolName != c . PoolName {
return false
}
if len ( v . Locations ) != len ( c . Locations ) {
return false
}
for _ , vloc := range v . Locations {
flag := false
for _ , cloc := range c . Locations {
if vloc . Equals ( cloc ) {
flag = true
break
}
}
if ! flag {
return false
}
}
return true
}