Files
EdgeCommon/pkg/serverconfigs/protocol_https_config.go

50 lines
1.0 KiB
Go
Raw Normal View History

2020-09-13 19:27:47 +08:00
package serverconfigs
2020-12-18 21:19:25 +08:00
import (
"context"
2020-12-18 21:19:25 +08:00
"encoding/json"
2024-07-27 13:29:26 +08:00
2020-12-18 21:19:25 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
)
2020-09-13 19:27:47 +08:00
2020-12-23 10:30:42 +08:00
func NewHTTPSProtocolConfigFromJSON(configJSON []byte) (*HTTPSProtocolConfig, error) {
config := &HTTPSProtocolConfig{}
if len(configJSON) > 0 {
err := json.Unmarshal(configJSON, config)
if err != nil {
return nil, err
}
}
return config, nil
}
2022-07-27 16:56:32 +08:00
// HTTPSProtocolConfig HTTPS协议配置
2020-09-13 19:27:47 +08:00
type HTTPSProtocolConfig struct {
BaseProtocol `yaml:",inline"`
2020-10-01 16:01:28 +08:00
SSLPolicyRef *sslconfigs.SSLPolicyRef `yaml:"sslPolicyRef" json:"sslPolicyRef"`
SSLPolicy *sslconfigs.SSLPolicy `yaml:"sslPolicy" json:"sslPolicy"`
2020-09-13 19:27:47 +08:00
}
2022-07-27 16:56:32 +08:00
// Init 初始化
func (this *HTTPSProtocolConfig) Init(ctx context.Context) error {
2020-09-13 19:27:47 +08:00
err := this.InitBase()
if err != nil {
return err
}
2020-09-30 17:46:33 +08:00
if this.SSLPolicy != nil {
err := this.SSLPolicy.Init(ctx)
2020-09-30 17:46:33 +08:00
if err != nil {
return err
}
}
2020-09-13 19:27:47 +08:00
return nil
}
2020-12-18 21:19:25 +08:00
2022-07-27 16:56:32 +08:00
// AsJSON 转换为JSON
2020-12-18 21:19:25 +08:00
func (this *HTTPSProtocolConfig) AsJSON() ([]byte, error) {
return json.Marshal(this)
}