2020-09-13 19:27:47 +08:00
|
|
|
package serverconfigs
|
|
|
|
|
|
2020-12-18 21:19:25 +08:00
|
|
|
import "encoding/json"
|
|
|
|
|
|
2021-01-14 16:34:16 +08:00
|
|
|
func NewTCPProtocolConfigFromJSON(configJSON []byte) (*TCPProtocolConfig, error) {
|
|
|
|
|
config := &TCPProtocolConfig{}
|
|
|
|
|
if len(configJSON) > 0 {
|
|
|
|
|
err := json.Unmarshal(configJSON, config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return config, nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 19:27:47 +08:00
|
|
|
type TCPProtocolConfig struct {
|
|
|
|
|
BaseProtocol `yaml:",inline"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *TCPProtocolConfig) Init() error {
|
|
|
|
|
err := this.InitBase()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 *TCPProtocolConfig) AsJSON() ([]byte, error) {
|
|
|
|
|
return json.Marshal(this)
|
|
|
|
|
}
|