1 Star 1 Fork 0

FlexLB/flexlb-api

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
endpoint.go 13.03 KB
一键复制 编辑 原始数据 按行查看 历史
王耀辉 提交于 2022-04-21 19:05 +08:00 . add license
// Copyright (c) 2022 Yaohui Wang (yaohuiwang@outlook.com)
// FlexLB is licensed under Mulan PubL v2.
// You can use this software according to the terms and conditions of the Mulan PubL v2.
// You may obtain a copy of Mulan PubL v2 at:
// http://license.coscl.org.cn/MulanPubL-2.0
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PubL v2 for more details.
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"encoding/json"
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Endpoint Endpoint
//
// swagger:model Endpoint
type Endpoint struct {
// backend check commands
BackendCheckCommands *EndpointBackendCheckCommands `json:"backend_check_commands,omitempty"`
// Backend default server options
BackendDefaultServer *string `json:"backend_default_server,omitempty"`
// Backend options
// Example: ["httpchk GET /"]
BackendOptions []string `json:"backend_options"`
// Backend servers
// Required: true
BackendServers []*BackendServer `json:"backend_servers"`
// Balance algorithm
// Required: true
Balance string `json:"balance"`
// Frontend options
// Example: ssl
FrontendOptions *string `json:"frontend_options,omitempty"`
// Frontend port
// Example: 443
// Required: true
FrontendPort uint16 `json:"frontend_port"`
// frontend ssl options
FrontendSslOptions *EndpointFrontendSslOptions `json:"frontend_ssl_options,omitempty"`
// Protocol mode
// Required: true
// Enum: [tcp udp http]
Mode string `json:"mode"`
}
// Validate validates this endpoint
func (m *Endpoint) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateBackendCheckCommands(formats); err != nil {
res = append(res, err)
}
if err := m.validateBackendServers(formats); err != nil {
res = append(res, err)
}
if err := m.validateBalance(formats); err != nil {
res = append(res, err)
}
if err := m.validateFrontendPort(formats); err != nil {
res = append(res, err)
}
if err := m.validateFrontendSslOptions(formats); err != nil {
res = append(res, err)
}
if err := m.validateMode(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Endpoint) validateBackendCheckCommands(formats strfmt.Registry) error {
if swag.IsZero(m.BackendCheckCommands) { // not required
return nil
}
if m.BackendCheckCommands != nil {
if err := m.BackendCheckCommands.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("backend_check_commands")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("backend_check_commands")
}
return err
}
}
return nil
}
func (m *Endpoint) validateBackendServers(formats strfmt.Registry) error {
if err := validate.Required("backend_servers", "body", m.BackendServers); err != nil {
return err
}
for i := 0; i < len(m.BackendServers); i++ {
if swag.IsZero(m.BackendServers[i]) { // not required
continue
}
if m.BackendServers[i] != nil {
if err := m.BackendServers[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("backend_servers" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("backend_servers" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Endpoint) validateBalance(formats strfmt.Registry) error {
if err := validate.RequiredString("balance", "body", m.Balance); err != nil {
return err
}
return nil
}
func (m *Endpoint) validateFrontendPort(formats strfmt.Registry) error {
if err := validate.Required("frontend_port", "body", uint16(m.FrontendPort)); err != nil {
return err
}
return nil
}
func (m *Endpoint) validateFrontendSslOptions(formats strfmt.Registry) error {
if swag.IsZero(m.FrontendSslOptions) { // not required
return nil
}
if m.FrontendSslOptions != nil {
if err := m.FrontendSslOptions.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("frontend_ssl_options")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("frontend_ssl_options")
}
return err
}
}
return nil
}
var endpointTypeModePropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["tcp","udp","http"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
endpointTypeModePropEnum = append(endpointTypeModePropEnum, v)
}
}
const (
// EndpointModeTCP captures enum value "tcp"
EndpointModeTCP string = "tcp"
// EndpointModeUDP captures enum value "udp"
EndpointModeUDP string = "udp"
// EndpointModeHTTP captures enum value "http"
EndpointModeHTTP string = "http"
)
// prop value enum
func (m *Endpoint) validateModeEnum(path, location string, value string) error {
if err := validate.EnumCase(path, location, value, endpointTypeModePropEnum, true); err != nil {
return err
}
return nil
}
func (m *Endpoint) validateMode(formats strfmt.Registry) error {
if err := validate.RequiredString("mode", "body", m.Mode); err != nil {
return err
}
// value enum
if err := m.validateModeEnum("mode", "body", m.Mode); err != nil {
return err
}
return nil
}
// ContextValidate validate this endpoint based on the context it is used
func (m *Endpoint) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateBackendCheckCommands(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateBackendServers(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateFrontendSslOptions(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Endpoint) contextValidateBackendCheckCommands(ctx context.Context, formats strfmt.Registry) error {
if m.BackendCheckCommands != nil {
if err := m.BackendCheckCommands.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("backend_check_commands")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("backend_check_commands")
}
return err
}
}
return nil
}
func (m *Endpoint) contextValidateBackendServers(ctx context.Context, formats strfmt.Registry) error {
for i := 0; i < len(m.BackendServers); i++ {
if m.BackendServers[i] != nil {
if err := m.BackendServers[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("backend_servers" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("backend_servers" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Endpoint) contextValidateFrontendSslOptions(ctx context.Context, formats strfmt.Registry) error {
if m.FrontendSslOptions != nil {
if err := m.FrontendSslOptions.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("frontend_ssl_options")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("frontend_ssl_options")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *Endpoint) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Endpoint) UnmarshalBinary(b []byte) error {
var res Endpoint
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
// EndpointBackendCheckCommands Backend check commands
//
// swagger:model EndpointBackendCheckCommands
type EndpointBackendCheckCommands struct {
// check type
// Example: http-check
// Enum: [http-check tcp-check]
CheckType string `json:"check_type,omitempty"`
// Backend TCP check commands
// Example: ["expect status 200"]
Commands []string `json:"commands"`
}
// Validate validates this endpoint backend check commands
func (m *EndpointBackendCheckCommands) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCheckType(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
var endpointBackendCheckCommandsTypeCheckTypePropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["http-check","tcp-check"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
endpointBackendCheckCommandsTypeCheckTypePropEnum = append(endpointBackendCheckCommandsTypeCheckTypePropEnum, v)
}
}
const (
// EndpointBackendCheckCommandsCheckTypeHTTPDashCheck captures enum value "http-check"
EndpointBackendCheckCommandsCheckTypeHTTPDashCheck string = "http-check"
// EndpointBackendCheckCommandsCheckTypeTCPDashCheck captures enum value "tcp-check"
EndpointBackendCheckCommandsCheckTypeTCPDashCheck string = "tcp-check"
)
// prop value enum
func (m *EndpointBackendCheckCommands) validateCheckTypeEnum(path, location string, value string) error {
if err := validate.EnumCase(path, location, value, endpointBackendCheckCommandsTypeCheckTypePropEnum, true); err != nil {
return err
}
return nil
}
func (m *EndpointBackendCheckCommands) validateCheckType(formats strfmt.Registry) error {
if swag.IsZero(m.CheckType) { // not required
return nil
}
// value enum
if err := m.validateCheckTypeEnum("backend_check_commands"+"."+"check_type", "body", m.CheckType); err != nil {
return err
}
return nil
}
// ContextValidate validates this endpoint backend check commands based on context it is used
func (m *EndpointBackendCheckCommands) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *EndpointBackendCheckCommands) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *EndpointBackendCheckCommands) UnmarshalBinary(b []byte) error {
var res EndpointBackendCheckCommands
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
// EndpointFrontendSslOptions Backend check commands
//
// swagger:model EndpointFrontendSslOptions
type EndpointFrontendSslOptions struct {
// ca cert
CaCert *string `json:"ca_cert,omitempty"`
// server cert
ServerCert string `json:"server_cert,omitempty"`
// server key
ServerKey string `json:"server_key,omitempty"`
// verify
// Enum: [required optional]
Verify *string `json:"verify,omitempty"`
}
// Validate validates this endpoint frontend ssl options
func (m *EndpointFrontendSslOptions) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateVerify(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
var endpointFrontendSslOptionsTypeVerifyPropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["required","optional"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
endpointFrontendSslOptionsTypeVerifyPropEnum = append(endpointFrontendSslOptionsTypeVerifyPropEnum, v)
}
}
const (
// EndpointFrontendSslOptionsVerifyRequired captures enum value "required"
EndpointFrontendSslOptionsVerifyRequired string = "required"
// EndpointFrontendSslOptionsVerifyOptional captures enum value "optional"
EndpointFrontendSslOptionsVerifyOptional string = "optional"
)
// prop value enum
func (m *EndpointFrontendSslOptions) validateVerifyEnum(path, location string, value string) error {
if err := validate.EnumCase(path, location, value, endpointFrontendSslOptionsTypeVerifyPropEnum, true); err != nil {
return err
}
return nil
}
func (m *EndpointFrontendSslOptions) validateVerify(formats strfmt.Registry) error {
if swag.IsZero(m.Verify) { // not required
return nil
}
// value enum
if err := m.validateVerifyEnum("frontend_ssl_options"+"."+"verify", "body", *m.Verify); err != nil {
return err
}
return nil
}
// ContextValidate validates this endpoint frontend ssl options based on context it is used
func (m *EndpointFrontendSslOptions) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *EndpointFrontendSslOptions) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *EndpointFrontendSslOptions) UnmarshalBinary(b []byte) error {
var res EndpointFrontendSslOptions
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/flexlb/flexlb-api.git
git@gitee.com:flexlb/flexlb-api.git
flexlb
flexlb-api
flexlb-api
v0.4.2

搜索帮助