1 Star 0 Fork 0

leminewx / gov2x

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
req_certificate.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
leminewx 提交于 2024-03-30 17:51 . 0.0.5.2:优化OM编解码器
package om
import (
"encoding/json"
"fmt"
)
// certificateRequest 定义 OM 认证指令的数据结构
type certificateRequest struct {
Class Class `json:"class"`
Command Command `json:"command"`
Certificate string `json:"certificate"`
}
// DefaultCert OM 协议默认的证书
var DefaultCert = "BQACRHQAAQEJcGFyYW1ldGVyBQCAAQBIMEYCIQDbbu86X1E5e1uXkpvKeuMSL6U4rcbmpyXUKFd83HBs/wIhAI0iVz4/eWay5D1FwznBge7KYkCMepTg7MW97YQozdlv"
// NewCertficateCommand 创建OM协议的认证指令
func NewCertficateRequest() *certificateRequest {
return &certificateRequest{
Class: CLS_CERTIFICATE,
Command: CMD_REQ_SET,
Certificate: DefaultCert,
}
}
func (own *certificateRequest) SET(cert ...string) *certificateRequest {
if len(cert) > 0 {
if cert[0] == "" {
own.Certificate = DefaultCert
return own
}
own.Certificate = cert[0]
}
return own
}
func (own *certificateRequest) Validate() error {
if own.Class != CLS_CERTIFICATE {
return fmt.Errorf("[Om.Certificate.Set] class error: %v", own.Class)
} else if own.Command != CMD_REQ_SET {
return fmt.Errorf("[Om.Certificate.Set] command error: %v", own.Command)
} else if own.Certificate == "" {
return fmt.Errorf("[Om.Certificate.Set] certificateRequest empty")
}
return nil
}
func (own *certificateRequest) String() string {
res, _ := json.Marshal(&own)
return string(res)
}
func (own *certificateRequest) GetClass() Class {
return own.Class
}
func (own *certificateRequest) GetCommand() Command {
return own.Command
}
Go
1
https://gitee.com/leminewx/gov2x.git
git@gitee.com:leminewx/gov2x.git
leminewx
gov2x
gov2x
a88e0b321ff7

搜索帮助